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

Added support for setting CRL distribution point URI #67

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 7 additions & 2 deletions certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ type Certificate struct {
// If not set, the default value is current time in nanoseconds.
SerialNumber *big.Int `json:"-" hash:"-"`

// CRLDistributionPoint defines the URI for downloading the CRL for this certificate.
// Not set by default.
CRLDistributionPoints []string `json:"crl_distribution_points"`

// GeneratedCert is a pointer to the generated certificate and private key.
// It is automatically set after calling any of the Certificate functions.
GeneratedCert *tls.Certificate `json:"-" hash:"-"`
Expand Down Expand Up @@ -200,11 +204,11 @@ func (c *Certificate) WritePEM(certFile, keyFile string) error {
if err != nil {
return err
}
err = os.WriteFile(certFile, cert, 0600)
err = os.WriteFile(certFile, cert, 0o600)
if err != nil {
return err
}
err = os.WriteFile(keyFile, key, 0600)
err = os.WriteFile(keyFile, key, 0o600)
if err != nil {
return err
}
Expand Down Expand Up @@ -341,6 +345,7 @@ func (c *Certificate) Generate() error {
ExtKeyUsage: c.ExtKeyUsage,
BasicConstraintsValid: *c.IsCA,
IsCA: *c.IsCA,
CRLDistributionPoints: c.CRLDistributionPoints,
}

for _, san := range c.SubjectAltNames {
Expand Down
8 changes: 7 additions & 1 deletion certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func TestSubjectAltName(t *testing.T) {
input := Certificate{Subject: "CN=Joe", SubjectAltNames: []string{"DNS:host.example.com", "URI:http://www.example.com", "IP:1.2.3.4"}}
got, err := input.X509Certificate()
assert.Nil(t, err)
assert.Nil(t, err)
assert.Equal(t, "Joe", got.Subject.CommonName)
assert.Equal(t, "host.example.com", got.DNSNames[0])
assert.Equal(t, url.URL{Scheme: "http", Host: "www.example.com"}, *got.URIs[0])
Expand Down Expand Up @@ -423,3 +422,10 @@ func TestParallelCertificateLazyInitialization(t *testing.T) {

wg.Wait()
}

func TestCRLDistributionPoint(t *testing.T) {
input := Certificate{Subject: "CN=Joe", CRLDistributionPoints: []string{"http://example.com/crl.pem"}}
got, err := input.X509Certificate()
assert.Nil(t, err)
assert.Equal(t, []string{"http://example.com/crl.pem"}, got.CRLDistributionPoints)
}
2 changes: 2 additions & 0 deletions internal/manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ func TestParsingAllCertificateFields(t *testing.T) {
assert.Equal(t, expectedURL, got.URIs[0])
assert.True(t, got.IPAddresses[0].Equal(expectedIP))

assert.Equal(t, []string{"http://ca1.example.com/crl", "http://ca2.example.com/crl"}, got.CRLDistributionPoints)

// Check fields from second end-entity cert.
tlsCert, err = tls.LoadX509KeyPair(path.Join(dir, "ec-cert.pem"), path.Join(dir, "ec-cert-key.pem"))
assert.Nil(t, err)
Expand Down
3 changes: 3 additions & 0 deletions internal/manifest/testdata/certs-test-all-fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ issuer: cn=ca
ca: true
not_before: 2020-01-01T09:00:00Z
not_after: 2030-01-01T09:00:00Z
crl_distribution_points:
- http://ca1.example.com/crl
- http://ca2.example.com/crl
---
subject: cn=ec-cert
key_size: 256
Expand Down
Loading