Fix golangci-lint warnings
This commit is contained in:
parent
8c99fe2fab
commit
6ded9c40ab
2 changed files with 69 additions and 49 deletions
|
@ -111,51 +111,9 @@ func (s *SignerClientHandler) ResponseData(ctx context.Context, in <-chan []byte
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil
|
return nil
|
||||||
case frame := <-in:
|
case frame := <-in:
|
||||||
switch response.Announce.Code {
|
err := handleIncomingFrame(response, frame)
|
||||||
case messages.RespHealth:
|
if err != nil {
|
||||||
var resp messages.HealthResponse
|
return err
|
||||||
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
|
||||||
return fmt.Errorf("could not unmarshal health response data: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
response.Response = &resp
|
|
||||||
case messages.RespCAInfo:
|
|
||||||
var resp messages.CAInfoResponse
|
|
||||||
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
|
||||||
return fmt.Errorf("could not unmarshal CA info response data: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
response.Response = &resp
|
|
||||||
case messages.RespFetchCRL:
|
|
||||||
var resp messages.FetchCRLResponse
|
|
||||||
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
|
||||||
return fmt.Errorf("could not unmarshal fetch CRL response data: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
response.Response = &resp
|
|
||||||
case messages.RespSignCertificate:
|
|
||||||
var resp messages.SignCertificateResponse
|
|
||||||
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
|
||||||
return fmt.Errorf("could not unmarshal sign certificate response data: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
response.Response = &resp
|
|
||||||
case messages.RespSignOpenPGP:
|
|
||||||
var resp messages.SignOpenPGPResponse
|
|
||||||
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
|
||||||
return fmt.Errorf("could not unmarshal sign OpenPGP response data: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
response.Response = &resp
|
|
||||||
case messages.RespError:
|
|
||||||
var resp messages.ErrorResponse
|
|
||||||
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
|
||||||
return fmt.Errorf("could not unmarshal error response data: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
response.Response = &resp
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("unhandled response code %s", response.Announce.Code)
|
|
||||||
}
|
}
|
||||||
case <-time.After(s.config.ResponseDataTimeout):
|
case <-time.After(s.config.ResponseDataTimeout):
|
||||||
return protocol.ErrResponseDataTimeoutExpired
|
return protocol.ErrResponseDataTimeoutExpired
|
||||||
|
@ -164,6 +122,57 @@ func (s *SignerClientHandler) ResponseData(ctx context.Context, in <-chan []byte
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleIncomingFrame(response *protocol.Response, frame []byte) error {
|
||||||
|
switch response.Announce.Code {
|
||||||
|
case messages.RespHealth:
|
||||||
|
var resp messages.HealthResponse
|
||||||
|
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
||||||
|
return fmt.Errorf("could not unmarshal health response data: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Response = &resp
|
||||||
|
case messages.RespCAInfo:
|
||||||
|
var resp messages.CAInfoResponse
|
||||||
|
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
||||||
|
return fmt.Errorf("could not unmarshal CA info response data: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Response = &resp
|
||||||
|
case messages.RespFetchCRL:
|
||||||
|
var resp messages.FetchCRLResponse
|
||||||
|
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
||||||
|
return fmt.Errorf("could not unmarshal fetch CRL response data: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Response = &resp
|
||||||
|
case messages.RespSignCertificate:
|
||||||
|
var resp messages.SignCertificateResponse
|
||||||
|
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
||||||
|
return fmt.Errorf("could not unmarshal sign certificate response data: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Response = &resp
|
||||||
|
case messages.RespSignOpenPGP:
|
||||||
|
var resp messages.SignOpenPGPResponse
|
||||||
|
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
||||||
|
return fmt.Errorf("could not unmarshal sign OpenPGP response data: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Response = &resp
|
||||||
|
case messages.RespError:
|
||||||
|
var resp messages.ErrorResponse
|
||||||
|
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
||||||
|
return fmt.Errorf("could not unmarshal error response data: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Response = &resp
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unhandled response code %s", response.Announce.Code)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SignerClientHandler) HandleResponse(ctx context.Context, response *protocol.Response) error {
|
func (s *SignerClientHandler) HandleResponse(ctx context.Context, response *protocol.Response) error {
|
||||||
s.logger.WithField("response", response.Announce).Info("handled response")
|
s.logger.WithField("response", response.Announce).Info("handled response")
|
||||||
s.logger.WithField("response", response).Debug("full response")
|
s.logger.WithField("response", response).Debug("full response")
|
||||||
|
|
|
@ -548,7 +548,10 @@ func (d *LegacyDB) requestSignedOpenPGPKeys(ctx context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *LegacyDB) requestCerts(ctx context.Context, query string, rt responseType, recordFailureCallback func(ctx context.Context, rowID int)) error {
|
func (d *LegacyDB) requestCerts(
|
||||||
|
ctx context.Context, query string, rt responseType,
|
||||||
|
recordFailureCallback func(ctx context.Context, rowID int),
|
||||||
|
) error {
|
||||||
issuerID, ok := d.issuerIDs[rt]
|
issuerID, ok := d.issuerIDs[rt]
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("no known issuer id for type %s", rt)
|
return fmt.Errorf("no known issuer id for type %s", rt)
|
||||||
|
@ -608,7 +611,9 @@ func (d *LegacyDB) requestCerts(ctx context.Context, query string, rt responseTy
|
||||||
}
|
}
|
||||||
|
|
||||||
if csrBlock.Type != "CERTIFICATE REQUEST" {
|
if csrBlock.Type != "CERTIFICATE REQUEST" {
|
||||||
d.logger.WithFields(logrus.Fields{"id": csrID, "file_name": csrFileName, "pem_block_type": csrBlock.Type}).Warn("unhandled PEM block type")
|
d.logger.WithFields(
|
||||||
|
logrus.Fields{"id": csrID, "file_name": csrFileName, "pem_block_type": csrBlock.Type},
|
||||||
|
).Warn("unhandled PEM block type")
|
||||||
|
|
||||||
idsWithIssues = append(idsWithIssues, csrID)
|
idsWithIssues = append(idsWithIssues, csrID)
|
||||||
|
|
||||||
|
@ -700,6 +705,7 @@ func buildSignCertificateCommand(
|
||||||
if len(subjParts.Subject.Country) > 0 {
|
if len(subjParts.Subject.Country) > 0 {
|
||||||
signCertCommand.Country = subjParts.Subject.Country[0]
|
signCertCommand.Country = subjParts.Subject.Country[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
return signCertCommand
|
return signCertCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -789,28 +795,32 @@ func parseSubjectStringComponent(identifier, value string, res *x509.Certificate
|
||||||
|
|
||||||
func (d *LegacyDB) revokePersonalClientCerts(_ context.Context) error {
|
func (d *LegacyDB) revokePersonalClientCerts(_ context.Context) error {
|
||||||
logrus.Debug("not implemented")
|
logrus.Debug("not implemented")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *LegacyDB) revokePersonalServerCerts(_ context.Context) error {
|
func (d *LegacyDB) revokePersonalServerCerts(_ context.Context) error {
|
||||||
logrus.Debug("not implemented")
|
logrus.Debug("not implemented")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *LegacyDB) revokeOrganizationClientCerts(_ context.Context) error {
|
func (d *LegacyDB) revokeOrganizationClientCerts(_ context.Context) error {
|
||||||
logrus.Debug("not implemented")
|
logrus.Debug("not implemented")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *LegacyDB) revokeOrganizationServerCerts(_ context.Context) error {
|
func (d *LegacyDB) revokeOrganizationServerCerts(_ context.Context) error {
|
||||||
logrus.Debug("not implemented")
|
logrus.Debug("not implemented")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *LegacyDB) writeCertificate(prefix string, rowID int, signatureData []byte) (string, error) {
|
func (d *LegacyDB) writeCertificate(prefix string, rowID int, signatureData []byte) (string, error) {
|
||||||
crtDir := path.Join("..", "crt", prefix, strconv.Itoa(rowID/1000))
|
crtDir := path.Join("..", "crt", prefix, strconv.Itoa(rowID/1000))
|
||||||
|
|
||||||
err := os.MkdirAll(crtDir, 0o755)
|
err := os.MkdirAll(crtDir, 0o755) //nolint:gomnd
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("could not create directory: %w", err)
|
return "", fmt.Errorf("could not create directory: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -840,7 +850,7 @@ func (d *LegacyDB) recordCertificate(ctx context.Context, prefix, query string,
|
||||||
}
|
}
|
||||||
|
|
||||||
expiry := certificate.NotAfter
|
expiry := certificate.NotAfter
|
||||||
serial := certificate.SerialNumber.Text(16) //nolint:gomnd
|
serial := certificate.SerialNumber.Text(16)
|
||||||
|
|
||||||
pemData := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certBytes})
|
pemData := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certBytes})
|
||||||
|
|
||||||
|
@ -1084,6 +1094,7 @@ func (d *LegacyDB) sendNotificationEmail(ctx context.Context, e emailData) error
|
||||||
}
|
}
|
||||||
|
|
||||||
const smtpPort = 1025
|
const smtpPort = 1025
|
||||||
|
|
||||||
c, err := mail.NewClient("localhost", mail.WithPort(smtpPort))
|
c, err := mail.NewClient("localhost", mail.WithPort(smtpPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not create mail client: %w", err)
|
return fmt.Errorf("could not create mail client: %w", err)
|
||||||
|
|
Loading…
Reference in a new issue