Skip to content

Commit

Permalink
Properly validate int ca lifetime error, add warning on leaf cert wit…
Browse files Browse the repository at this point in the history
…h basic constraints (hashicorp#20654)

* Ensure proper error message from CA validity period

Signed-off-by: Alexander Scheel <[email protected]>

* Add warning to issuance of leaf cert with basic constraints

Signed-off-by: Alexander Scheel <[email protected]>

* Add changelog entry

Signed-off-by: Alexander Scheel <[email protected]>

---------

Signed-off-by: Alexander Scheel <[email protected]>
  • Loading branch information
cipherboy authored May 19, 2023
1 parent 729e477 commit 9055b93
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
11 changes: 4 additions & 7 deletions builtin/logical/pki/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2532,7 +2532,7 @@ func TestBackend_Root_Idempotency(t *testing.T) {
}
}

func TestBackend_SignIntermediate_AllowedPastCA(t *testing.T) {
func TestBackend_SignIntermediate_AllowedPastCAValidity(t *testing.T) {
t.Parallel()
b_root, s_root := CreateBackendWithStorage(t)
b_int, s_int := CreateBackendWithStorage(t)
Expand All @@ -2550,6 +2550,7 @@ func TestBackend_SignIntermediate_AllowedPastCA(t *testing.T) {
_, err = CBWrite(b_root, s_root, "roles/test", map[string]interface{}{
"allow_bare_domains": true,
"allow_subdomains": true,
"allow_any_name": true,
})
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -2577,19 +2578,15 @@ func TestBackend_SignIntermediate_AllowedPastCA(t *testing.T) {
"csr": csr,
"ttl": "60h",
})
if err == nil {
t.Fatal("expected error")
}
require.ErrorContains(t, err, "that is beyond the expiration of the CA certificate")

_, err = CBWrite(b_root, s_root, "sign-verbatim/test", map[string]interface{}{
"common_name": "myint.com",
"other_sans": "1.3.6.1.4.1.311.20.2.3;utf8:[email protected]",
"csr": csr,
"ttl": "60h",
})
if err == nil {
t.Fatal("expected error")
}
require.ErrorContains(t, err, "that is beyond the expiration of the CA certificate")

resp, err = CBWrite(b_root, s_root, "root/sign-intermediate", map[string]interface{}{
"common_name": "myint.com",
Expand Down
6 changes: 6 additions & 0 deletions builtin/logical/pki/cert_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,12 @@ func signCert(b *backend,

if isCA {
creation.Params.PermittedDNSDomains = data.apiData.Get("permitted_dns_domains").([]string)
} else {
for _, ext := range csr.Extensions {
if ext.Id.Equal(certutil.ExtensionBasicConstraintsOID) {
warnings = append(warnings, "specified CSR contained a Basic Constraints extension that was ignored during issuance")
}
}
}

parsedBundle, err := certutil.SignCertificate(creation)
Expand Down
3 changes: 3 additions & 0 deletions changelog/20654.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:change
secrets/pki: Warning when issuing leafs from CSRs with basic constraints. In the future, issuance of non-CA leaf certs from CSRs with asserted IsCA Basic Constraints will be prohibited.
```

0 comments on commit 9055b93

Please sign in to comment.