Skip to content

Commit 99aef44

Browse files
authored
add test with cert issued by preissuer (#275)
1 parent 582a8ba commit 99aef44

File tree

2 files changed

+71
-7
lines changed

2 files changed

+71
-7
lines changed

internal/ct/chain_validation_test.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,6 @@ func chainFromPEMs(t *testing.T, pems ...string) [][]byte {
665665

666666
// Validate a chain including a pre-issuer.
667667
func TestPreIssuedCert(t *testing.T) {
668-
// TODO(phboneff): add a test to make sure that a pre-isser can't sign an end cert.
669668
rawChain := chainFromPEMs(t, []string{
670669
testdata.PreCertFromPreIntermediate,
671670
testdata.PreIntermediateFromRoot,
@@ -677,22 +676,34 @@ func TestPreIssuedCert(t *testing.T) {
677676
}
678677

679678
for _, tc := range []struct {
680-
desc string
681-
eku []x509.ExtKeyUsage
679+
desc string
680+
eku []x509.ExtKeyUsage
681+
chain [][]byte
682682
}{
683683
{
684-
desc: "no EKU specified",
684+
desc: "no EKU specified",
685+
chain: rawChain,
685686
}, {
686-
desc: "EKU ServerAuth",
687-
eku: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
687+
desc: "EKU ServerAuth",
688+
eku: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
689+
chain: rawChain,
690+
}, {
691+
// This shouldn't happen with production intermediates, but should
692+
// be transparently discoverable in CT logs if it ever happens, so
693+
// we allow them in.
694+
desc: "pre-intermediate issues end-cert",
695+
chain: chainFromPEMs(t, []string{
696+
testdata.CertFromPreIntermediate,
697+
testdata.PreIntermediateFromRoot,
698+
testdata.CACertPEM}...),
688699
},
689700
} {
690701
t.Run(tc.desc, func(t *testing.T) {
691702
opts := chainValidator{
692703
trustedRoots: roots,
693704
extKeyUsages: tc.eku,
694705
}
695-
chain, err := opts.validate(rawChain)
706+
chain, err := opts.validate(tc.chain)
696707
if err != nil {
697708
t.Fatalf("failed to ValidateChain: %v", err)
698709
}

internal/testdata/certificates.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,59 @@ var PreIntermediateFromRoot string
285285
//go:embed test_leaf_pre_cert_signed_by_pre_intermediate.pem
286286
var PreCertFromPreIntermediate string
287287

288+
// CertFromPreIntermediate is a cert issued by PreIntermediateFromRoot.
289+
// This is *NOT* a PreCert, as opposed to PreCertFromPreIntermediate.
290+
// These certs should not be a thing in the real world, and we only use
291+
// this one in tests.
292+
//
293+
// $ openssl x509 -in internal/testdata/test_leaf_cert_signed_by_pre_intermediate.pem -noout -text
294+
//
295+
// Data:
296+
//
297+
// Version: 3 (0x2)
298+
// Serial Number: 100 (0x64)
299+
// Signature Algorithm: ecdsa-with-SHA384
300+
// Issuer: C=GB, O=TrustFabric Transparency.dev Test Intermediate Test CA, CN=TrustFabric Transparency.dev Test Intermediate Test CA
301+
// Validity
302+
// Not Before: Dec 5 18:05:50 2024 GMT
303+
// Not After : Dec 5 18:05:50 2025 GMT
304+
// Subject: C=GB, ST=London, L=London, O=TrustFabric Transparency.dev Test, OU=TrustFabric, CN=test.transparency.dev
305+
// Subject Public Key Info:
306+
// Public Key Algorithm: id-ecPublicKey
307+
// Public-Key: (384 bit)
308+
// pub:
309+
// 04:46:10:60:6d:e5:70:0d:fa:8f:ea:8c:70:40:6e:
310+
// eb:dd:15:88:8a:6e:94:54:ac:f7:92:77:53:68:65:
311+
// c1:55:d4:c0:92:2e:b4:08:d9:07:50:d3:12:f4:fb:
312+
// 56:08:ff:38:32:41:35:6e:53:12:af:57:88:39:68:
313+
// 81:e0:1b:4c:82:4a:de:ac:52:d4:46:a7:a2:55:73:
314+
// 78:7a:fd:98:0f:bb:88:5b:bc:f6:7b:9a:77:49:11:
315+
// ec:e6:1b:f3:c3:76:4a
316+
// ASN1 OID: secp384r1
317+
// NIST CURVE: P-384
318+
// X509v3 extensions:
319+
// X509v3 Key Usage: critical
320+
// Digital Signature, Key Encipherment
321+
// X509v3 Extended Key Usage:
322+
// TLS Web Server Authentication
323+
// X509v3 Basic Constraints: critical
324+
// CA:FALSE
325+
// X509v3 Authority Key Identifier:
326+
// 1F:FE:3D:85:AC:F5:38:C7:90:1C:6C:EA:E7:5F:45:74:83:CC:95:39
327+
// X509v3 Subject Alternative Name:
328+
// DNS:test.transparency.dev
329+
// Signature Algorithm: ecdsa-with-SHA384
330+
// Signature Value:
331+
// 30:65:02:30:35:aa:8a:19:87:15:32:a8:a1:2f:a7:46:67:cb:
332+
// f5:ac:69:84:ef:2b:8d:e2:49:3f:a5:18:92:f6:e7:1d:b2:f2:
333+
// 91:76:99:3f:ea:f3:b7:ec:df:94:96:78:b5:54:d2:59:02:31:
334+
// 00:b0:11:91:9a:bb:6c:3b:f9:14:e4:1f:3e:b4:40:22:0b:46:
335+
// 45:2a:18:cf:7c:20:b3:a7:56:3c:f6:c2:e0:7c:47:8a:a4:fd:
336+
// bf:6b:a2:48:c7:1e:4c:f8:f4:8a:df:5b:14
337+
338+
//go:embed test_leaf_cert_signed_by_pre_intermediate.pem
339+
var CertFromPreIntermediate string
340+
288341
// Issuance chain 3
289342
// ================
290343
// The next section holds:

0 commit comments

Comments
 (0)