77 "crypto/ecdsa"
88 "crypto/rand"
99 "crypto/rsa"
10- "crypto/sha256"
1110 "crypto/x509"
1211 "encoding/asn1"
1312 "encoding/hex"
@@ -37,8 +36,8 @@ import (
3736 corepb "github.com/letsencrypt/boulder/core/proto"
3837 csrlib "github.com/letsencrypt/boulder/csr"
3938 berrors "github.com/letsencrypt/boulder/errors"
40- "github.com/letsencrypt/boulder/features"
4139 "github.com/letsencrypt/boulder/goodkey"
40+ "github.com/letsencrypt/boulder/issuercerts"
4241 blog "github.com/letsencrypt/boulder/log"
4342 sapb "github.com/letsencrypt/boulder/sa/proto"
4443)
@@ -116,11 +115,9 @@ const (
116115type CertificateAuthorityImpl struct {
117116 rsaProfile string
118117 ecdsaProfile string
119- // A map from issuer cert common name to an internalIssuer struct
120- issuers map [string ]* internalIssuer
121118 // A map from issuer ID to internalIssuer
122- idToIssuer map [int64 ]* internalIssuer
123- // The common name of the default issuer cert
119+ idToIssuer map [issuercerts. ID ]* internalIssuer
120+ // The issuer that will be used for issuance (as opposed to OCSP signing)
124121 defaultIssuer * internalIssuer
125122 sa certificateStorage
126123 pa core.PolicyAuthority
@@ -166,11 +163,12 @@ func makeInternalIssuers(
166163 issuers []Issuer ,
167164 policy * cfsslConfig.Signing ,
168165 lifespanOCSP time.Duration ,
169- ) (map [string ]* internalIssuer , error ) {
166+ ) (map [issuercerts. ID ]* internalIssuer , error ) {
170167 if len (issuers ) == 0 {
171168 return nil , errors .New ("No issuers specified." )
172169 }
173- internalIssuers := make (map [string ]* internalIssuer )
170+ internalIssuers := make (map [issuercerts.ID ]* internalIssuer )
171+ cns := make (map [string ]bool )
174172 for _ , iss := range issuers {
175173 if iss .Cert == nil || iss .Signer == nil {
176174 return nil , errors .New ("Issuer with nil cert or signer specified." )
@@ -181,10 +179,11 @@ func makeInternalIssuers(
181179 }
182180
183181 cn := iss .Cert .Subject .CommonName
184- if internalIssuers [cn ] != nil {
182+ if cns [cn ] {
185183 return nil , errors .New ("Multiple issuer certs with the same CommonName are not supported" )
186184 }
187- internalIssuers [cn ] = & internalIssuer {
185+ id := issuercerts .FromCert (iss .Cert ).ID ()
186+ internalIssuers [id ] = & internalIssuer {
188187 cert : iss .Cert ,
189188 eeSigner : eeSigner ,
190189 ocspSigner : iss .Signer ,
@@ -193,16 +192,8 @@ func makeInternalIssuers(
193192 return internalIssuers , nil
194193}
195194
196- // idForIssuer generates a stable ID for an issuer certificate. This
197- // is used for identifying which issuer issued a certificate in the
198- // certificateStatus table.
199- func idForIssuer (cert * x509.Certificate ) int64 {
200- h := sha256 .Sum256 (cert .Raw )
201- return big .NewInt (0 ).SetBytes (h [:4 ]).Int64 ()
202- }
203-
204195// NewCertificateAuthorityImpl creates a CA instance that can sign certificates
205- // from a single issuer (the first first in the issuers slice), and can sign OCSP
196+ // from a single issuer (the first in the issuers slice), and can sign OCSP
206197// for any of the issuer certificates provided.
207198func NewCertificateAuthorityImpl (
208199 config ca_config.CAConfig ,
@@ -251,7 +242,7 @@ func NewCertificateAuthorityImpl(
251242 if err != nil {
252243 return nil , err
253244 }
254- defaultIssuer := internalIssuers [issuers [0 ].Cert . Subject . CommonName ]
245+ defaultIssuer := internalIssuers [issuercerts . FromCert ( issuers [0 ].Cert ). ID () ]
255246
256247 rsaProfile := config .RSAProfile
257248 ecdsaProfile := config .ECDSAProfile
@@ -301,7 +292,6 @@ func NewCertificateAuthorityImpl(
301292 ca = & CertificateAuthorityImpl {
302293 sa : sa ,
303294 pa : pa ,
304- issuers : internalIssuers ,
305295 defaultIssuer : defaultIssuer ,
306296 rsaProfile : rsaProfile ,
307297 ecdsaProfile : ecdsaProfile ,
@@ -319,9 +309,9 @@ func NewCertificateAuthorityImpl(
319309 signErrorCounter : signErrorCounter ,
320310 }
321311
322- ca .idToIssuer = make (map [int64 ]* internalIssuer )
323- for _ , ii := range ca . issuers {
324- id := idForIssuer (ii .cert )
312+ ca .idToIssuer = make (map [issuercerts. ID ]* internalIssuer )
313+ for _ , ii := range internalIssuers {
314+ id := issuercerts . FromCert (ii .cert ). ID ( )
325315 ca .idToIssuer [id ] = ii
326316 }
327317
@@ -433,48 +423,33 @@ var ocspStatusToCode = map[string]int{
433423func (ca * CertificateAuthorityImpl ) GenerateOCSP (ctx context.Context , req * caPB.GenerateOCSPRequest ) (* caPB.OCSPResponse , error ) {
434424 var issuer * internalIssuer
435425 var serial * big.Int
426+ if req .IssuerID == nil {
427+ return nil , fmt .Errorf ("no issuerID provided" )
428+ }
429+ if req .Serial == nil {
430+ return nil , fmt .Errorf ("no serial provided" )
431+ }
436432 // Once the feature is enabled we need to support both RPCs that include
437433 // IssuerID and those that don't as we still need to be able to update rows
438434 // that didn't have an IssuerID set when they were created. Once this feature
439435 // has been enabled for a full OCSP lifetime cycle we can remove this
440436 // functionality.
441- if features .Enabled (features .StoreIssuerInfo ) && req .IssuerID != nil {
442- serialInt , err := core .StringToSerial (* req .Serial )
443- if err != nil {
444- return nil , err
445- }
446- serial = serialInt
447- var ok bool
448- issuer , ok = ca .idToIssuer [* req .IssuerID ]
449- if ! ok {
450- return nil , fmt .Errorf ("This CA doesn't have an issuer cert with ID %d" , * req .IssuerID )
451- }
452- exists , err := ca .sa .SerialExists (ctx , & sapb.Serial {Serial : req .Serial })
453- if err != nil {
454- return nil , err
455- }
456- if ! * exists .Exists {
457- return nil , fmt .Errorf ("GenerateOCSP was asked to sign OCSP for certification with unknown serial %q" , * req .Serial )
458- }
459- } else {
460- cert , err := x509 .ParseCertificate (req .CertDER )
461- if err != nil {
462- ca .log .AuditErr (err .Error ())
463- return nil , err
464- }
465-
466- serial = cert .SerialNumber
467- cn := cert .Issuer .CommonName
468- issuer = ca .issuers [cn ]
469- if issuer == nil {
470- return nil , fmt .Errorf ("This CA doesn't have an issuer cert with CommonName %q" , cn )
471- }
472- err = cert .CheckSignatureFrom (issuer .cert )
473- if err != nil {
474- return nil , fmt .Errorf ("GenerateOCSP was asked to sign OCSP for cert " +
475- "%s from %q, but the cert's signature was not valid: %s." ,
476- core .SerialToString (cert .SerialNumber ), cn , err )
477- }
437+ serialInt , err := core .StringToSerial (* req .Serial )
438+ if err != nil {
439+ return nil , err
440+ }
441+ serial = serialInt
442+ var ok bool
443+ issuer , ok = ca .idToIssuer [issuercerts .ID (* req .IssuerID )]
444+ if ! ok {
445+ return nil , fmt .Errorf ("This CA doesn't have an issuer cert with ID %d" , * req .IssuerID )
446+ }
447+ exists , err := ca .sa .SerialExists (ctx , & sapb.Serial {Serial : req .Serial })
448+ if err != nil {
449+ return nil , err
450+ }
451+ if ! * exists .Exists {
452+ return nil , fmt .Errorf ("GenerateOCSP was asked to sign OCSP for certification with unknown serial %q" , * req .Serial )
478453 }
479454
480455 now := ca .clk .Now ().Truncate (time .Hour )
@@ -523,10 +498,16 @@ func (ca *CertificateAuthorityImpl) IssuePrecertificate(ctx context.Context, iss
523498 return nil , err
524499 }
525500
501+ // we currently only use one issuer, in the future when we support multiple
502+ // the issuer will need to be derived from issueReq
503+ issuerID := int64 (issuercerts .FromCert (ca .defaultIssuer .cert ).ID ())
504+
526505 status := string (core .OCSPStatusGood )
527506 ocspResp , err := ca .GenerateOCSP (ctx , & caPB.GenerateOCSPRequest {
528- CertDER : precertDER ,
529- Status : & status ,
507+ Serial : & serialHex ,
508+ CertDER : precertDER ,
509+ Status : & status ,
510+ IssuerID : & issuerID ,
530511 })
531512 if err != nil {
532513 err = berrors .InternalServerError (err .Error ())
@@ -535,17 +516,13 @@ func (ca *CertificateAuthorityImpl) IssuePrecertificate(ctx context.Context, iss
535516 }
536517
537518 req := & sapb.AddCertificateRequest {
538- Der : precertDER ,
539- RegID : & regID ,
540- Ocsp : ocspResp .Response ,
541- Issued : & nowNanos ,
519+ Der : precertDER ,
520+ RegID : & regID ,
521+ Ocsp : ocspResp .Response ,
522+ Issued : & nowNanos ,
523+ IssuerID : & issuerID ,
542524 }
543525
544- // we currently only use one issuer, in the future when we support multiple
545- // the issuer will need to be derived from issueReq
546- issuerID := idForIssuer (ca .defaultIssuer .cert )
547- req .IssuerID = & issuerID
548-
549526 _ , err = ca .sa .AddPrecertificate (ctx , req )
550527 if err != nil {
551528 ca .orphanCount .With (prometheus.Labels {"type" : "precert" }).Inc ()
0 commit comments