-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for RFC 5280 4.2.1.10 CA Name Constraints
- Loading branch information
Showing
6 changed files
with
238 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,6 +255,49 @@ var validLocalConfigsWithCAConstraint = []string{ | |
} | ||
} | ||
}`, | ||
`{ | ||
"signing": { | ||
"default": { | ||
"usages": ["digital signature", "email protection"], | ||
"ca_constraint": { | ||
"is_ca": true, | ||
"max_path_len_zero": true, | ||
"permitted_dns_domains_critical": true, | ||
"permitted_dns_domains": [ | ||
".example.com" | ||
], | ||
"excluded_dns_domains": [ | ||
".example.com" | ||
], | ||
"permitted_ip_ranges": [ | ||
{ | ||
"IP": "192.168.0.0", | ||
"Mask": "//8AAA==" | ||
} | ||
], | ||
"excluded_ip_ranges": [ | ||
{ | ||
"IP": "172.16.0.0", | ||
"Mask": "//AAAA==" | ||
} | ||
], | ||
"permitted_email_addresses": [ | ||
"[email protected]" | ||
], | ||
"excluded_email_addresses": [ | ||
"[email protected]" | ||
], | ||
"permitted_uri_domains": [ | ||
".example.com" | ||
], | ||
"excluded_uri_domains": [ | ||
"host.hurzel.com" | ||
] | ||
}, | ||
"expiry": "8000h" | ||
} | ||
} | ||
}`, | ||
} | ||
|
||
var copyExtensionWantedlLocalConfig = ` | ||
|
@@ -443,6 +486,7 @@ func TestLoadFile(t *testing.T) { | |
"testdata/valid_config.json", | ||
"testdata/valid_config_auth.json", | ||
"testdata/valid_config_no_default.json", | ||
"testdata/valid_config_ca_constraints.json", | ||
"testdata/valid_config_auth_no_default.json", | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"signing": { | ||
"default": { | ||
"usages": [ | ||
"digital signature", | ||
"email protection" | ||
], | ||
"ca_constraint": { | ||
"is_ca": true, | ||
"max_path_len_zero": true, | ||
"permitted_dns_domains_critical": true, | ||
"permitted_dns_domains": [ | ||
".example.com" | ||
], | ||
"excluded_dns_domains": [ | ||
".example.com" | ||
], | ||
"permitted_ip_ranges": [ | ||
{ | ||
"IP": "192.168.0.0", | ||
"Mask": "//8AAA==" | ||
} | ||
], | ||
"excluded_ip_ranges": [ | ||
{ | ||
"IP": "172.16.0.0", | ||
"Mask": "//AAAA==" | ||
} | ||
], | ||
"permitted_email_addresses": [ | ||
"[email protected]" | ||
], | ||
"excluded_email_addresses": [ | ||
"[email protected]" | ||
], | ||
"permitted_uri_domains": [ | ||
".example.com" | ||
], | ||
"excluded_uri_domains": [ | ||
"host.hurzel.com" | ||
] | ||
}, | ||
"expiry": "8000h" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ import ( | |
"github.com/cloudflare/cfssl/helpers" | ||
"github.com/cloudflare/cfssl/log" | ||
"github.com/cloudflare/cfssl/signer" | ||
"github.com/google/certificate-transparency-go" | ||
ct "github.com/google/certificate-transparency-go" | ||
"github.com/zmap/zlint/v3/lint" | ||
) | ||
|
||
|
@@ -963,6 +963,119 @@ func TestCASignPathlen(t *testing.T) { | |
} | ||
} | ||
|
||
func TestCAConstraints(t *testing.T) { | ||
var caCerts = []string{testCaFile, testECDSACaFile} | ||
var caKeys = []string{testCaKeyFile, testECDSACaKeyFile} | ||
var interCSRs = []string{ecdsaInterCSR, rsaInterCSR} | ||
var interKeys = []string{ecdsaInterKey, rsaInterKey} | ||
var CAPolicy = &config.Signing{ | ||
Default: &config.SigningProfile{ | ||
Usage: []string{"cert sign", "crl sign"}, | ||
ExpiryString: "1h", | ||
Expiry: 1 * time.Hour, | ||
CAConstraint: config.CAConstraint{ | ||
IsCA: true, | ||
MaxPathLenZero: true, | ||
PermittedDNSDomainsCritical: true, | ||
PermittedDNSDomains: []string{".sub.cloudflare-inter.com"}, | ||
ExcludedDNSDomains: []string{".forbidden.cloudflare-inter.com"}, | ||
PermittedIPRanges: []*net.IPNet{{ | ||
IP: net.IP{0xc0, 0xa8, 0x0, 0x0}, | ||
Mask: net.IPMask{0xff, 0xff, 0x0, 0x0}}}, | ||
ExcludedIPRanges: []*net.IPNet{{ | ||
IP: net.IP{172, 16, 0x0, 0x0}, | ||
Mask: net.IPMask{0xff, 0xf0, 0x0, 0x0}}}, | ||
PermittedEmailAddresses: []string{"[email protected]"}, | ||
ExcludedEmailAddresses: []string{".illegal.com"}, | ||
PermittedURIDomains: []string{".example.com"}, | ||
ExcludedURIDomains: []string{"host.illegal.com"}}, | ||
}, | ||
} | ||
var hostname = "cloudflare-inter.com" | ||
// Each RSA or ECDSA root CA issues two intermediate CAs (one ECDSA and one RSA). | ||
// For each intermediate CA, use it to issue additional RSA and ECDSA intermediate CSRs. | ||
for i, caFile := range caCerts { | ||
caKeyFile := caKeys[i] | ||
s := newCustomSigner(t, caFile, caKeyFile) | ||
s.policy = CAPolicy | ||
for j, csr := range interCSRs { | ||
csrBytes, _ := ioutil.ReadFile(csr) | ||
certBytes, err := s.Sign(signer.SignRequest{Hosts: signer.SplitHosts(hostname), Request: string(csrBytes)}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
interCert, err := helpers.ParseCertificatePEM(certBytes) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
keyBytes, _ := ioutil.ReadFile(interKeys[j]) | ||
interKey, _ := helpers.ParsePrivateKeyPEM(keyBytes) | ||
interSigner := &Signer{ | ||
ca: interCert, | ||
priv: interKey, | ||
policy: CAPolicy, | ||
sigAlgo: signer.DefaultSigAlgo(interKey), | ||
} | ||
for _, anotherCSR := range interCSRs { | ||
anotherCSRBytes, _ := ioutil.ReadFile(anotherCSR) | ||
bytes, err := interSigner.Sign( | ||
signer.SignRequest{ | ||
Hosts: signer.SplitHosts(hostname), | ||
Request: string(anotherCSRBytes), | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
cert, err := helpers.ParseCertificatePEM(bytes) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if cert.SignatureAlgorithm != interSigner.SigAlgo() { | ||
t.Fatal("Cert Signature Algorithm does not match the issuer.") | ||
} | ||
if cert.MaxPathLen != 0 { | ||
t.Fatal("CA Cert Max Path is not zero.") | ||
} | ||
if cert.MaxPathLenZero != true { | ||
t.Fatal("CA Cert Max Path is not zero.") | ||
} | ||
if cert.PermittedDNSDomainsCritical != true { | ||
t.Fatal("CA Cert Permitted DNS Domains Critical is not true..") | ||
} | ||
if !reflect.DeepEqual(cert.PermittedDNSDomains, []string{".sub.cloudflare-inter.com"}) { | ||
t.Fatal("CA Cert Permitted DNS Domains is not equal.") | ||
} | ||
if !reflect.DeepEqual(cert.ExcludedDNSDomains, []string{".forbidden.cloudflare-inter.com"}) { | ||
t.Fatal("CA Cert Excluded DNS Domains is not equal.") | ||
} | ||
if !reflect.DeepEqual(cert.PermittedIPRanges, []*net.IPNet{{ | ||
IP: net.IP{0xc0, 0xa8, 0x0, 0x0}, | ||
Mask: net.IPMask{0xff, 0xff, 0x0, 0x0}}}) { | ||
t.Fatal("CA Cert Permitted IP Ranges is not equal.") | ||
} | ||
if !reflect.DeepEqual(cert.ExcludedIPRanges, []*net.IPNet{{ | ||
IP: net.IP{172, 16, 0x0, 0x0}, | ||
Mask: net.IPMask{0xff, 0xf0, 0x0, 0x0}}}) { | ||
t.Fatal("CA Cert Excluded IP Ranges is not equal.") | ||
} | ||
if !reflect.DeepEqual(cert.PermittedEmailAddresses, []string{"[email protected]"}) { | ||
t.Fatal("CA Cert Permitted Email Addresses is not equal.") | ||
} | ||
if !reflect.DeepEqual(cert.ExcludedEmailAddresses, []string{".illegal.com"}) { | ||
t.Fatal("CA Cert Excluded Email Addresses is not equal.") | ||
} | ||
if !reflect.DeepEqual(cert.PermittedURIDomains, []string{".example.com"}) { | ||
t.Fatal("CA Cert Permitted URI Domains is not equal.") | ||
} | ||
if !reflect.DeepEqual(cert.ExcludedURIDomains, []string{"host.illegal.com"}) { | ||
t.Fatal("CA Cert Excluded URI Domains is not equal.") | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
func TestNoWhitelistSign(t *testing.T) { | ||
csrPEM, err := ioutil.ReadFile(fullSubjectCSR) | ||
if err != nil { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters