Skip to content

Commit 95e5b07

Browse files
committed
crypto/x509: consider parents by Subject if AKID has no match
If a certificate somehow has an AKID, it should still chain successfully to a parent without a SKID, even if the latter is invalid according to RFC 5280, because only the Subject is authoritative. This reverts to the behavior before #29233 was fixed in 7701306. Roots with the right subject will still be shadowed by roots with the right SKID and the wrong subject, but that's been the case for a long time, and is left for a more complete fix in Go 1.13. Updates #30079 Change-Id: If8ab0179aca86cb74caa926d1ef93fb5e416b4bb Reviewed-on: https://go-review.googlesource.com/c/161097 Reviewed-by: Adam Langley <[email protected]>
1 parent aa161ad commit 95e5b07

File tree

2 files changed

+123
-2
lines changed

2 files changed

+123
-2
lines changed

src/crypto/x509/cert_pool.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,15 @@ func (s *CertPool) findPotentialParents(cert *Certificate) []int {
7171
if s == nil {
7272
return nil
7373
}
74+
75+
var candidates []int
7476
if len(cert.AuthorityKeyId) > 0 {
75-
return s.bySubjectKeyId[string(cert.AuthorityKeyId)]
77+
candidates = s.bySubjectKeyId[string(cert.AuthorityKeyId)]
78+
}
79+
if len(candidates) == 0 {
80+
candidates = s.byName[string(cert.RawIssuer)]
7681
}
77-
return s.byName[string(cert.RawIssuer)]
82+
return candidates
7883
}
7984

8085
func (s *CertPool) contains(cert *Certificate) bool {

src/crypto/x509/verify_test.go

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,19 @@ var verifyTests = []verifyTest{
386386

387387
errorCallback: expectHostnameError("not valid for any names"),
388388
},
389+
{
390+
// A certificate with an AKID should still chain to a parent without SKID.
391+
// See Issue 30079.
392+
leaf: leafWithAKID,
393+
roots: []string{rootWithoutSKID},
394+
currentTime: 1550000000,
395+
dnsName: "example",
396+
systemSkip: true,
397+
398+
expectedChains: [][]string{
399+
{"Acme LLC", "Acme Co"},
400+
},
401+
},
389402
}
390403

391404
func expectHostnameError(msg string) func(*testing.T, int, error) bool {
@@ -1679,6 +1692,109 @@ h7olHCpY9yMRiz0=
16791692
-----END CERTIFICATE-----
16801693
`
16811694

1695+
const (
1696+
rootWithoutSKID = `
1697+
Certificate:
1698+
Data:
1699+
Version: 3 (0x2)
1700+
Serial Number:
1701+
78:29:2a:dc:2f:12:39:7f:c9:33:93:ea:61:39:7d:70
1702+
Signature Algorithm: ecdsa-with-SHA256
1703+
Issuer: O = Acme Co
1704+
Validity
1705+
Not Before: Feb 4 22:56:34 2019 GMT
1706+
Not After : Feb 1 22:56:34 2029 GMT
1707+
Subject: O = Acme Co
1708+
Subject Public Key Info:
1709+
Public Key Algorithm: id-ecPublicKey
1710+
Public-Key: (256 bit)
1711+
pub:
1712+
04:84:a6:8c:69:53:af:87:4b:39:64:fe:04:24:e6:
1713+
d8:fc:d6:46:39:35:0e:92:dc:48:08:7e:02:5f:1e:
1714+
07:53:5c:d9:e0:56:c5:82:07:f6:a3:e2:ad:f6:ad:
1715+
be:a0:4e:03:87:39:67:0c:9c:46:91:68:6b:0e:8e:
1716+
f8:49:97:9d:5b
1717+
ASN1 OID: prime256v1
1718+
NIST CURVE: P-256
1719+
X509v3 extensions:
1720+
X509v3 Key Usage: critical
1721+
Digital Signature, Key Encipherment, Certificate Sign
1722+
X509v3 Extended Key Usage:
1723+
TLS Web Server Authentication
1724+
X509v3 Basic Constraints: critical
1725+
CA:TRUE
1726+
X509v3 Subject Alternative Name:
1727+
DNS:example
1728+
Signature Algorithm: ecdsa-with-SHA256
1729+
30:46:02:21:00:c6:81:61:61:42:8d:37:e7:d0:c3:72:43:44:
1730+
17:bd:84:ff:88:81:68:9a:99:08:ab:3c:3a:c0:1e:ea:8c:ba:
1731+
c0:02:21:00:de:c9:fa:e5:5e:c6:e2:db:23:64:43:a9:37:42:
1732+
72:92:7f:6e:89:38:ea:9e:2a:a7:fd:2f:ea:9a:ff:20:21:e7
1733+
-----BEGIN CERTIFICATE-----
1734+
MIIBbzCCARSgAwIBAgIQeCkq3C8SOX/JM5PqYTl9cDAKBggqhkjOPQQDAjASMRAw
1735+
DgYDVQQKEwdBY21lIENvMB4XDTE5MDIwNDIyNTYzNFoXDTI5MDIwMTIyNTYzNFow
1736+
EjEQMA4GA1UEChMHQWNtZSBDbzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABISm
1737+
jGlTr4dLOWT+BCTm2PzWRjk1DpLcSAh+Al8eB1Nc2eBWxYIH9qPirfatvqBOA4c5
1738+
ZwycRpFoaw6O+EmXnVujTDBKMA4GA1UdDwEB/wQEAwICpDATBgNVHSUEDDAKBggr
1739+
BgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MBIGA1UdEQQLMAmCB2V4YW1wbGUwCgYI
1740+
KoZIzj0EAwIDSQAwRgIhAMaBYWFCjTfn0MNyQ0QXvYT/iIFompkIqzw6wB7qjLrA
1741+
AiEA3sn65V7G4tsjZEOpN0Jykn9uiTjqniqn/S/qmv8gIec=
1742+
-----END CERTIFICATE-----
1743+
`
1744+
leafWithAKID = `
1745+
Certificate:
1746+
Data:
1747+
Version: 3 (0x2)
1748+
Serial Number:
1749+
f0:8a:62:f0:03:84:a2:cf:69:63:ad:71:3b:b6:5d:8c
1750+
Signature Algorithm: ecdsa-with-SHA256
1751+
Issuer: O = Acme Co
1752+
Validity
1753+
Not Before: Feb 4 23:06:52 2019 GMT
1754+
Not After : Feb 1 23:06:52 2029 GMT
1755+
Subject: O = Acme LLC
1756+
Subject Public Key Info:
1757+
Public Key Algorithm: id-ecPublicKey
1758+
Public-Key: (256 bit)
1759+
pub:
1760+
04:5a:4e:4d:fb:ff:17:f7:b6:13:e8:29:45:34:81:
1761+
39:ff:8c:9c:d9:8c:0a:9f:dd:b5:97:4c:2b:20:91:
1762+
1c:4f:6b:be:53:27:66:ec:4a:ad:08:93:6d:66:36:
1763+
0c:02:70:5d:01:ca:7f:c3:29:e9:4f:00:ba:b4:14:
1764+
ec:c5:c3:34:b3
1765+
ASN1 OID: prime256v1
1766+
NIST CURVE: P-256
1767+
X509v3 extensions:
1768+
X509v3 Key Usage: critical
1769+
Digital Signature, Key Encipherment
1770+
X509v3 Extended Key Usage:
1771+
TLS Web Server Authentication
1772+
X509v3 Basic Constraints: critical
1773+
CA:FALSE
1774+
X509v3 Authority Key Identifier:
1775+
keyid:C2:2B:5F:91:78:34:26:09:42:8D:6F:51:B2:C5:AF:4C:0B:DE:6A:42
1776+
1777+
X509v3 Subject Alternative Name:
1778+
DNS:example
1779+
Signature Algorithm: ecdsa-with-SHA256
1780+
30:44:02:20:64:e0:ba:56:89:63:ce:22:5e:4f:22:15:fd:3c:
1781+
35:64:9a:3a:6b:7b:9a:32:a0:7f:f7:69:8c:06:f0:00:58:b8:
1782+
02:20:09:e4:9f:6d:8b:9e:38:e1:b6:01:d5:ee:32:a4:94:65:
1783+
93:2a:78:94:bb:26:57:4b:c7:dd:6c:3d:40:2b:63:90
1784+
-----BEGIN CERTIFICATE-----
1785+
MIIBjTCCATSgAwIBAgIRAPCKYvADhKLPaWOtcTu2XYwwCgYIKoZIzj0EAwIwEjEQ
1786+
MA4GA1UEChMHQWNtZSBDbzAeFw0xOTAyMDQyMzA2NTJaFw0yOTAyMDEyMzA2NTJa
1787+
MBMxETAPBgNVBAoTCEFjbWUgTExDMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE
1788+
Wk5N+/8X97YT6ClFNIE5/4yc2YwKn921l0wrIJEcT2u+Uydm7EqtCJNtZjYMAnBd
1789+
Acp/wynpTwC6tBTsxcM0s6NqMGgwDgYDVR0PAQH/BAQDAgWgMBMGA1UdJQQMMAoG
1790+
CCsGAQUFBwMBMAwGA1UdEwEB/wQCMAAwHwYDVR0jBBgwFoAUwitfkXg0JglCjW9R
1791+
ssWvTAveakIwEgYDVR0RBAswCYIHZXhhbXBsZTAKBggqhkjOPQQDAgNHADBEAiBk
1792+
4LpWiWPOIl5PIhX9PDVkmjpre5oyoH/3aYwG8ABYuAIgCeSfbYueOOG2AdXuMqSU
1793+
ZZMqeJS7JldLx91sPUArY5A=
1794+
-----END CERTIFICATE-----
1795+
`
1796+
)
1797+
16821798
var unknownAuthorityErrorTests = []struct {
16831799
cert string
16841800
expected string

0 commit comments

Comments
 (0)