@@ -46,8 +46,15 @@ type lintCert *x509.Certificate
4646// template certificate signed by a given issuer and returns a *lintCert or an
4747// error. The lint certificate is linted prior to being returned. The public key
4848// from the just issued lint certificate is checked by the GoodKey package.
49- func issueLintCertAndPerformLinting (tbs , issuer * x509.Certificate , subjectPubKey crypto.PublicKey , signer crypto.Signer , skipLints []string ) (lintCert , error ) {
50- bytes , err := linter .Check (tbs , subjectPubKey , issuer , signer , skipLints )
49+ // When cross-signing, existing is the pre-existing certificate of the CA being
50+ // cross-signed, allowing the CP/CPS profile lints to check correspondence with
51+ // it; it is nil otherwise.
52+ func issueLintCertAndPerformLinting (tbs , issuer * x509.Certificate , subjectPubKey crypto.PublicKey , signer crypto.Signer , existing * x509.Certificate , skipLints []string ) (lintCert , error ) {
53+ lintConfig , err := linter.Config {}.WithExisting (existing )
54+ if err != nil {
55+ return nil , fmt .Errorf ("unable to create lint config: %w" , err )
56+ }
57+ bytes , err := linter .Check (tbs , subjectPubKey , issuer , signer , lintConfig , skipLints )
5158 if err != nil {
5259 return nil , fmt .Errorf ("certificate failed pre-issuance lint: %w" , err )
5360 }
@@ -66,8 +73,10 @@ func issueLintCertAndPerformLinting(tbs, issuer *x509.Certificate, subjectPubKey
6673// postIssuanceLinting performs post-issuance linting on the raw bytes of a
6774// given certificate with the same set of lints as
6875// issueLintCertAndPerformLinting. The public key is also checked by the GoodKey
69- // package.
70- func postIssuanceLinting (fc * x509.Certificate , skipLints []string ) error {
76+ // package. The issuer and existing certificates, when non-nil, are supplied to
77+ // the CP/CPS profile lints so that they can perform their correspondence
78+ // checks.
79+ func postIssuanceLinting (fc , issuer , existing * x509.Certificate , skipLints []string ) error {
7180 if fc == nil {
7281 return fmt .Errorf ("certificate was not provided" )
7382 }
@@ -77,7 +86,15 @@ func postIssuanceLinting(fc *x509.Certificate, skipLints []string) error {
7786 // lint. This should be treated as ZLint rejecting the certificate
7887 return fmt .Errorf ("unable to parse certificate: %s" , err )
7988 }
80- registry , err := linter .NewRegistry (skipLints )
89+ lintConfig , err := linter.Config {}.WithIssuer (issuer )
90+ if err != nil {
91+ return fmt .Errorf ("unable to create lint config: %s" , err )
92+ }
93+ lintConfig , err = lintConfig .WithExisting (existing )
94+ if err != nil {
95+ return fmt .Errorf ("unable to create lint config: %s" , err )
96+ }
97+ registry , err := linter .NewRegistryWithConfig (skipLints , lintConfig )
8198 if err != nil {
8299 return fmt .Errorf ("unable to create zlint registry: %s" , err )
83100 }
@@ -586,15 +603,15 @@ func rootCeremony(configBytes []byte) error {
586603 if err != nil {
587604 return fmt .Errorf ("failed to create certificate profile: %s" , err )
588605 }
589- lintCert , err := issueLintCertAndPerformLinting (template , template , keyInfo .key , signer , config .SkipLints )
606+ lintCert , err := issueLintCertAndPerformLinting (template , template , keyInfo .key , signer , nil , config .SkipLints )
590607 if err != nil {
591608 return err
592609 }
593610 finalCert , err := signAndWriteCert (template , template , lintCert , keyInfo .key , signer , config .Outputs .CertificatePath )
594611 if err != nil {
595612 return err
596613 }
597- err = postIssuanceLinting (finalCert , config .SkipLints )
614+ err = postIssuanceLinting (finalCert , nil , nil , config .SkipLints )
598615 if err != nil {
599616 return err
600617 }
@@ -631,7 +648,7 @@ func intermediateCeremony(configBytes []byte) error {
631648 return fmt .Errorf ("failed to create certificate profile: %s" , err )
632649 }
633650 template .AuthorityKeyId = issuer .SubjectKeyId
634- lintCert , err := issueLintCertAndPerformLinting (template , issuer , pub , signer , config .SkipLints )
651+ lintCert , err := issueLintCertAndPerformLinting (template , issuer , pub , signer , nil , config .SkipLints )
635652 if err != nil {
636653 return err
637654 }
@@ -646,7 +663,7 @@ func intermediateCeremony(configBytes []byte) error {
646663 if ! bytes .Equal (lintCert .RawTBSCertificate , finalCert .RawTBSCertificate ) {
647664 return fmt .Errorf ("mismatch between lintCert and finalCert RawTBSCertificate DER bytes: \" %x\" != \" %x\" " , lintCert .RawTBSCertificate , finalCert .RawTBSCertificate )
648665 }
649- err = postIssuanceLinting (finalCert , config .SkipLints )
666+ err = postIssuanceLinting (finalCert , issuer , nil , config .SkipLints )
650667 if err != nil {
651668 return err
652669 }
@@ -687,7 +704,7 @@ func crossCertCeremony(configBytes []byte) error {
687704 return fmt .Errorf ("failed to create certificate profile: %s" , err )
688705 }
689706 template .AuthorityKeyId = issuer .SubjectKeyId
690- lintCert , err := issueLintCertAndPerformLinting (template , issuer , pub , signer , config .SkipLints )
707+ lintCert , err := issueLintCertAndPerformLinting (template , issuer , pub , signer , toBeCrossSigned , config .SkipLints )
691708 if err != nil {
692709 return err
693710 }
@@ -748,7 +765,7 @@ func crossCertCeremony(configBytes []byte) error {
748765 if ! bytes .Equal (lintCert .RawTBSCertificate , finalCert .RawTBSCertificate ) {
749766 return fmt .Errorf ("mismatch between lintCert and finalCert RawTBSCertificate DER bytes: \" %x\" != \" %x\" " , lintCert .RawTBSCertificate , finalCert .RawTBSCertificate )
750767 }
751- err = postIssuanceLinting (finalCert , config .SkipLints )
768+ err = postIssuanceLinting (finalCert , issuer , toBeCrossSigned , config .SkipLints )
752769 if err != nil {
753770 return err
754771 }
0 commit comments