mirror of
https://github.com/golang/go
synced 2024-11-24 08:50:14 -07:00
crypto/x509: properly handle issuerUniqueID and subjectUniqueID
Fixes #51754 Change-Id: I3bfa15db3497de9fb82d6391d87fca1ae9ba6543 Reviewed-on: https://go-review.googlesource.com/c/go/+/394297 Trust: Roland Shoemaker <roland@golang.org> Run-TryBot: Roland Shoemaker <roland@golang.org> Auto-Submit: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
parent
ff6b6c61d7
commit
9a53b472b5
@ -941,10 +941,10 @@ func parseCertificate(der []byte) (*Certificate, error) {
|
||||
}
|
||||
|
||||
if cert.Version > 1 {
|
||||
if !tbs.SkipOptionalASN1(cryptobyte_asn1.Tag(1).Constructed().ContextSpecific()) {
|
||||
if !tbs.SkipOptionalASN1(cryptobyte_asn1.Tag(1).ContextSpecific()) {
|
||||
return nil, errors.New("x509: malformed issuerUniqueID")
|
||||
}
|
||||
if !tbs.SkipOptionalASN1(cryptobyte_asn1.Tag(2).Constructed().ContextSpecific()) {
|
||||
if !tbs.SkipOptionalASN1(cryptobyte_asn1.Tag(2).ContextSpecific()) {
|
||||
return nil, errors.New("x509: malformed subjectUniqueID")
|
||||
}
|
||||
if cert.Version == 3 {
|
||||
|
@ -3348,3 +3348,51 @@ func TestLargeOID(t *testing.T) {
|
||||
t.Fatalf("ParseCertificate to failed to parse certificate with large OID: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
const uniqueIDPEM = `-----BEGIN CERTIFICATE-----
|
||||
MIIFsDCCBJigAwIBAgIIrOyC1ydafZMwDQYJKoZIhvcNAQEFBQAwgY4xgYswgYgG
|
||||
A1UEAx6BgABNAGkAYwByAG8AcwBvAGYAdAAgAEYAbwByAGUAZgByAG8AbgB0ACAA
|
||||
VABNAEcAIABIAFQAVABQAFMAIABJAG4AcwBwAGUAYwB0AGkAbwBuACAAQwBlAHIA
|
||||
dABpAGYAaQBjAGEAdABpAG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BlAGIAUwBlAHIAdgBl
|
||||
AHIwHQYDVR0OBBYEFMAC3UR4FwAdGekbhMgnd6lMejtbMAsGA1UdDwQEAwIFoDAT
|
||||
BgNVHSUEDDAKBggrBgEFBQcDATAJBgNVHRMEAjAAMIG/BgNVHQEEgbcwgbSAFGfF
|
||||
6xihk+gJJ5TfwvtWe1UFnHLQoYGRMIGOMYGLMIGIBgNVBAMegYAATQBpAGMAcgBv
|
||||
AHMAbwBmAHQAIABGAG8AcgBlAGYAcgBvAG4AdAAgAFQATQBHACAASABUAFQAUABT
|
||||
ACAASQBuAHMAcABlAGMAdABpAG8AbgAgAEMAZQByAHQAaQBmAGkAYwBhAHQAaQBv
|
||||
AG4AIABBAHUAdABoAG8AcgBpAHQAeYIIcKhXEmBXr0IwDQYJKoZIhvcNAQEFBQAD
|
||||
ggEBABlSxyCMr3+ANr+WmPSjyN5YCJBgnS0IFCwJAzIYP87bcTye/U8eQ2+E6PqG
|
||||
Q7Huj7nfHEw9qnGo+HNyPp1ad3KORzXDb54c6xEoi+DeuPzYHPbn4c3hlH49I0aQ
|
||||
eWW2w4RslSWpLvO6Y7Lboyz2/Thk/s2kd4RHxkkWpH2ltPqJuYYg3X6oM5+gIFHJ
|
||||
WGnh+ojZ5clKvS5yXh3Wkj78M6sb32KfcBk0Hx6NkCYPt60ODYmWtvqwtw6r73u5
|
||||
TnTYWRNvo2svX69TriL+CkHY9O1Hkwf2It5zHl3gNiKTJVaak8AuEz/CKWZneovt
|
||||
yYLwhUhg3PX5Co1VKYE+9TxloiE=
|
||||
-----END CERTIFICATE-----`
|
||||
|
||||
func TestParseUniqueID(t *testing.T) {
|
||||
b, _ := pem.Decode([]byte(uniqueIDPEM))
|
||||
if b == nil {
|
||||
t.Fatalf("couldn't decode test certificate")
|
||||
}
|
||||
cert, err := ParseCertificate(b.Bytes)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseCertificate to failed to parse certificate with unique identifier id: %s", err)
|
||||
}
|
||||
if len(cert.Extensions) != 7 {
|
||||
t.Fatalf("unexpected number of extensions (probably because the extension section was not parsed): got %d, want 7", len(cert.Extensions))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user