Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
- Move profile.Subject() to inline where used
- Reorder if/else in cert.go
  • Loading branch information
andygabby committed Mar 10, 2021
1 parent 3416438 commit 6b1f8a1
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions cmd/ceremony/cert.go
Expand Up @@ -96,17 +96,7 @@ func (profile *certProfile) Subject() pkix.Name {
}

func (profile *certProfile) verifyProfile(ct certType) error {
if ct != requestCert {
if profile.NotBefore == "" {
return errors.New("not-before is required")
}
if profile.NotAfter == "" {
return errors.New("not-after is required")
}
if profile.SignatureAlgorithm == "" {
return errors.New("signature-algorithm is required")
}
} else {
if ct == requestCert {
if profile.NotBefore != "" {
return errors.New("not-before cannot be set for a CSR")
}
Expand All @@ -131,6 +121,16 @@ func (profile *certProfile) verifyProfile(ct certType) error {
if profile.KeyUsages != nil {
return errors.New("key-usages cannot be set for a CSR")
}
} else {
if profile.NotBefore == "" {
return errors.New("not-before is required")
}
if profile.NotAfter == "" {
return errors.New("not-after is required")
}
if profile.SignatureAlgorithm == "" {
return errors.New("signature-algorithm is required")
}
}
if profile.CommonName == "" {
return errors.New("common-name is required")
Expand Down Expand Up @@ -266,12 +266,11 @@ func makeTemplate(randReader io.Reader, profile *certProfile, pubKey []byte, ct
return nil, errors.New("at least one key usage must be set")
}

templateSubject := profile.Subject()
cert := &x509.Certificate{
SerialNumber: big.NewInt(0).SetBytes(serial),
BasicConstraintsValid: true,
IsCA: true,
Subject: templateSubject,
Subject: profile.Subject(),
OCSPServer: ocspServer,
CRLDistributionPoints: crlDistributionPoints,
IssuingCertificateURL: issuingCertificateURL,
Expand Down Expand Up @@ -341,9 +340,8 @@ func (fr *failReader) Read([]byte) (int, error) {
}

func generateCSR(profile *certProfile, signer crypto.Signer) ([]byte, error) {
csrSubject := profile.Subject()
csrDER, err := x509.CreateCertificateRequest(&failReader{}, &x509.CertificateRequest{
Subject: csrSubject,
Subject: profile.Subject(),
}, signer)
if err != nil {
return nil, fmt.Errorf("failed to create and sign CSR: %s", err)
Expand Down

0 comments on commit 6b1f8a1

Please sign in to comment.