Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate x509.Certificate.Policies field #7940

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Populate x509.Certificate.Policies in all places
Reference: #7940 (review)
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
  • Loading branch information
Juneezee committed Jan 14, 2025
commit 4ad9f89b9fd9c3674d124b92610e5da3f3470d52
2 changes: 1 addition & 1 deletion cmd/ceremony/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func makeTemplate(randReader io.Reader, profile *certProfile, pubKey []byte, tbc

x509OID, err := x509.ParseOID(policyConfig.OID)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to parse %s as OID: %w", policyConfig.OID, err)
}
cert.Policies = append(cert.Policies, x509OID)
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/cert-checker/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
mrand "math/rand/v2"
"os"
"slices"
"sort"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -585,6 +584,9 @@ func TestIgnoredLint(t *testing.T) {
checker := newChecker(saDbMap, clock.NewFake(), pa, kp, time.Hour, testValidityDurations, blog.NewMock())
serial := big.NewInt(1337)

x509OID, err := x509.OIDFromInts([]uint64{1, 2, 3})
test.AssertNotError(t, err, "failed to create x509.OID")

template := &x509.Certificate{
Subject: pkix.Name{
CommonName: "CPU's Cool CA",
Expand All @@ -597,6 +599,7 @@ func TestIgnoredLint(t *testing.T) {
PolicyIdentifiers: []asn1.ObjectIdentifier{
{1, 2, 3},
},
Policies: []x509.OID{x509OID},
BasicConstraintsValid: true,
IsCA: true,
IssuingCertificateURL: []string{"http://aia.example.org"},
Expand Down Expand Up @@ -639,12 +642,12 @@ func TestIgnoredLint(t *testing.T) {
"zlint info: w_ct_sct_policy_count_unsatisfied Certificate had 0 embedded SCTs. Browser policy may require 2 for this certificate.",
"zlint error: e_scts_from_same_operator Certificate had too few embedded SCTs; browser policy requires 2.",
}
sort.Strings(expectedProblems)
slices.Sort(expectedProblems)

// Check the certificate with a nil ignore map. This should return the
// expected zlint problems.
_, problems := checker.checkCert(context.Background(), cert, nil)
sort.Strings(problems)
slices.Sort(problems)
test.AssertDeepEquals(t, problems, expectedProblems)

// Check the certificate again with an ignore map that excludes the affected
Expand Down
3 changes: 3 additions & 0 deletions issuance/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,16 @@ func (i *Issuer) requestValid(clk clock.Clock, prof *Profile, req *IssuanceReque
}

func (i *Issuer) generateTemplate() *x509.Certificate {
x509OID, _ := x509.OIDFromInts([]uint64{2, 23, 140, 1, 2, 1})

template := &x509.Certificate{
SignatureAlgorithm: i.sigAlg,
OCSPServer: []string{i.ocspURL},
IssuingCertificateURL: []string{i.issuerURL},
BasicConstraintsValid: true,
// Baseline Requirements, Section 7.1.6.1: domain-validated
PolicyIdentifiers: []asn1.ObjectIdentifier{{2, 23, 140, 1, 2, 1}},
Policies: []x509.OID{x509OID},
}

// TODO(#7294): Use i.crlURLBase and a shard calculation to create a
Expand Down
16 changes: 9 additions & 7 deletions issuance/cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import (
"github.com/letsencrypt/boulder/test"
)

var (
goodSKID = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
)
var goodSKID = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

func defaultProfile() *Profile {
p, _ := NewProfile(defaultProfileConfig())
Expand All @@ -33,7 +31,7 @@ func defaultProfile() *Profile {

func TestGenerateValidity(t *testing.T) {
fc := clock.NewFake()
fc.Set(time.Date(2015, time.June, 04, 11, 04, 38, 0, time.UTC))
fc.Set(time.Date(2015, time.June, 0o4, 11, 0o4, 38, 0, time.UTC))

tests := []struct {
name string
Expand All @@ -46,15 +44,15 @@ func TestGenerateValidity(t *testing.T) {
name: "normal usage",
backdate: time.Hour, // 90% of one hour is 54 minutes
validity: 7 * 24 * time.Hour,
notBefore: time.Date(2015, time.June, 04, 10, 10, 38, 0, time.UTC),
notBefore: time.Date(2015, time.June, 0o4, 10, 10, 38, 0, time.UTC),
notAfter: time.Date(2015, time.June, 11, 10, 10, 37, 0, time.UTC),
},
{
name: "zero backdate",
backdate: 0,
validity: 7 * 24 * time.Hour,
notBefore: time.Date(2015, time.June, 04, 11, 04, 38, 0, time.UTC),
notAfter: time.Date(2015, time.June, 11, 11, 04, 37, 0, time.UTC),
notBefore: time.Date(2015, time.June, 0o4, 11, 0o4, 38, 0, time.UTC),
notAfter: time.Date(2015, time.June, 11, 11, 0o4, 37, 0, time.UTC),
},
}

Expand Down Expand Up @@ -315,13 +313,17 @@ func TestGenerateTemplate(t *testing.T) {

actual := issuer.generateTemplate()

x509OID, err := x509.OIDFromInts([]uint64{2, 23, 140, 1, 2, 1})
test.AssertNotError(t, err, "failed to create x509.OID")

expected := &x509.Certificate{
BasicConstraintsValid: true,
SignatureAlgorithm: x509.SHA256WithRSA,
IssuingCertificateURL: []string{"http://issuer"},
OCSPServer: []string{"http://ocsp"},
CRLDistributionPoints: nil,
PolicyIdentifiers: []asn1.ObjectIdentifier{{2, 23, 140, 1, 2, 1}},
Policies: []x509.OID{x509OID},
}

test.AssertDeepEquals(t, actual, expected)
Expand Down
1 change: 1 addition & 0 deletions linter/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func makeIssuer(realIssuer *x509.Certificate, lintSigner crypto.Signer) (*x509.C
PermittedIPRanges: realIssuer.PermittedIPRanges,
PermittedURIDomains: realIssuer.PermittedURIDomains,
PolicyIdentifiers: realIssuer.PolicyIdentifiers,
Policies: realIssuer.Policies,
SerialNumber: realIssuer.SerialNumber,
Subject: realIssuer.Subject,
SubjectKeyId: realIssuer.SubjectKeyId,
Expand Down
Loading