Skip to content

Commit eac26b8

Browse files
authored
Populate x509.Certificate.Policies field (#7940)
Populate the new x509.Certificate.Policies field everywhere we currently populate the x509.Certificate.PolicyIdentifiers field. This allows Go to use whichever field it prefers (go1.23 prefers PolicyIdentifiers, go1.24 prefers Policies) as the source of truth when serializing a certificate. Part of #7148
1 parent df23344 commit eac26b8

File tree

6 files changed

+31
-7
lines changed

6 files changed

+31
-7
lines changed

cmd/ceremony/cert.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,17 @@ func makeTemplate(randReader io.Reader, profile *certProfile, pubKey []byte, tbc
318318
}
319319

320320
for _, policyConfig := range profile.Policies {
321-
oid, err := parseOID(policyConfig.OID)
321+
asnOID, err := parseOID(policyConfig.OID)
322322
if err != nil {
323323
return nil, err
324324
}
325-
cert.PolicyIdentifiers = append(cert.PolicyIdentifiers, oid)
325+
cert.PolicyIdentifiers = append(cert.PolicyIdentifiers, asnOID)
326+
327+
x509OID, err := x509.ParseOID(policyConfig.OID)
328+
if err != nil {
329+
return nil, fmt.Errorf("failed to parse %s as OID: %w", policyConfig.OID, err)
330+
}
331+
cert.Policies = append(cert.Policies, x509OID)
326332
}
327333

328334
return cert, nil

cmd/ceremony/cert_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ func TestMakeTemplateRoot(t *testing.T) {
128128
test.AssertEquals(t, cert.IssuingCertificateURL[0], profile.IssuerURL)
129129
test.AssertEquals(t, cert.KeyUsage, x509.KeyUsageDigitalSignature|x509.KeyUsageCRLSign)
130130
test.AssertEquals(t, len(cert.PolicyIdentifiers), 2)
131+
test.AssertEquals(t, len(cert.Policies), 2)
131132
test.AssertEquals(t, len(cert.ExtKeyUsage), 0)
132133

133134
cert, err = makeTemplate(randReader, profile, pubKey, nil, intermediateCert)

cmd/cert-checker/main_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
mrand "math/rand/v2"
1919
"os"
2020
"slices"
21-
"sort"
2221
"strings"
2322
"sync"
2423
"testing"
@@ -585,6 +584,9 @@ func TestIgnoredLint(t *testing.T) {
585584
checker := newChecker(saDbMap, clock.NewFake(), pa, kp, time.Hour, testValidityDurations, blog.NewMock())
586585
serial := big.NewInt(1337)
587586

587+
x509OID, err := x509.OIDFromInts([]uint64{1, 2, 3})
588+
test.AssertNotError(t, err, "failed to create x509.OID")
589+
588590
template := &x509.Certificate{
589591
Subject: pkix.Name{
590592
CommonName: "CPU's Cool CA",
@@ -597,6 +599,7 @@ func TestIgnoredLint(t *testing.T) {
597599
PolicyIdentifiers: []asn1.ObjectIdentifier{
598600
{1, 2, 3},
599601
},
602+
Policies: []x509.OID{x509OID},
600603
BasicConstraintsValid: true,
601604
IsCA: true,
602605
IssuingCertificateURL: []string{"http://aia.example.org"},
@@ -639,12 +642,12 @@ func TestIgnoredLint(t *testing.T) {
639642
"zlint info: w_ct_sct_policy_count_unsatisfied Certificate had 0 embedded SCTs. Browser policy may require 2 for this certificate.",
640643
"zlint error: e_scts_from_same_operator Certificate had too few embedded SCTs; browser policy requires 2.",
641644
}
642-
sort.Strings(expectedProblems)
645+
slices.Sort(expectedProblems)
643646

644647
// Check the certificate with a nil ignore map. This should return the
645648
// expected zlint problems.
646649
_, problems := checker.checkCert(context.Background(), cert, nil)
647-
sort.Strings(problems)
650+
slices.Sort(problems)
648651
test.AssertDeepEquals(t, problems, expectedProblems)
649652

650653
// Check the certificate again with an ignore map that excludes the affected

issuance/cert.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,26 @@ func (i *Issuer) requestValid(clk clock.Clock, prof *Profile, req *IssuanceReque
304304
return nil
305305
}
306306

307+
// Baseline Requirements, Section 7.1.6.1: domain-validated
308+
var domainValidatedASN1OID = asn1.ObjectIdentifier{2, 23, 140, 1, 2, 1}
309+
var domainValidatedOID = func() x509.OID {
310+
x509OID, err := x509.OIDFromInts([]uint64{2, 23, 140, 1, 2, 1})
311+
if err != nil {
312+
// This should never happen, as the OID is hardcoded.
313+
panic(fmt.Errorf("failed to create OID using ints %v: %s", x509OID, err))
314+
}
315+
return x509OID
316+
}()
317+
307318
func (i *Issuer) generateTemplate() *x509.Certificate {
308319
template := &x509.Certificate{
309320
SignatureAlgorithm: i.sigAlg,
310321
OCSPServer: []string{i.ocspURL},
311322
IssuingCertificateURL: []string{i.issuerURL},
312323
BasicConstraintsValid: true,
313324
// Baseline Requirements, Section 7.1.6.1: domain-validated
314-
PolicyIdentifiers: []asn1.ObjectIdentifier{{2, 23, 140, 1, 2, 1}},
325+
PolicyIdentifiers: []asn1.ObjectIdentifier{domainValidatedASN1OID},
326+
Policies: []x509.OID{domainValidatedOID},
315327
}
316328

317329
return template

issuance/cert_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ func TestGenerateTemplate(t *testing.T) {
336336
IssuingCertificateURL: []string{"http://issuer"},
337337
OCSPServer: []string{"http://ocsp"},
338338
CRLDistributionPoints: nil,
339-
PolicyIdentifiers: []asn1.ObjectIdentifier{{2, 23, 140, 1, 2, 1}},
339+
PolicyIdentifiers: []asn1.ObjectIdentifier{domainValidatedASN1OID},
340+
Policies: []x509.OID{domainValidatedOID},
340341
}
341342

342343
test.AssertDeepEquals(t, actual, expected)

linter/linter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ func makeIssuer(realIssuer *x509.Certificate, lintSigner crypto.Signer) (*x509.C
195195
PermittedIPRanges: realIssuer.PermittedIPRanges,
196196
PermittedURIDomains: realIssuer.PermittedURIDomains,
197197
PolicyIdentifiers: realIssuer.PolicyIdentifiers,
198+
Policies: realIssuer.Policies,
198199
SerialNumber: realIssuer.SerialNumber,
199200
Subject: realIssuer.Subject,
200201
SubjectKeyId: realIssuer.SubjectKeyId,

0 commit comments

Comments
 (0)