src/crypto/x509/verify.go | 2 +- src/crypto/x509/verify_test.go | 19 +++++++++++++++++++ diff --git a/src/crypto/x509/verify.go b/src/crypto/x509/verify.go index 345d434453c44b98b00be4899862c57d1c8973a1..56a1a1725cc3314b107f97885b2f8c421c9d4b88 100644 --- a/src/crypto/x509/verify.go +++ b/src/crypto/x509/verify.go @@ -899,7 +899,7 @@ hintCert *Certificate ) considerCandidate := func(certType int, candidate *Certificate) { - if alreadyInChain(candidate, currentChain) { + if candidate.PublicKey == nil || alreadyInChain(candidate, currentChain) { return } diff --git a/src/crypto/x509/verify_test.go b/src/crypto/x509/verify_test.go index 37f13f861f1b541fc10c98fe7a584618d33b2dcc..6d09d24da2389b9b47a064139f97da5e0d0f3826 100644 --- a/src/crypto/x509/verify_test.go +++ b/src/crypto/x509/verify_test.go @@ -2718,3 +2718,22 @@ }) } } + +func TestVerifyNilPubKey(t *testing.T) { + c := &Certificate{ + RawIssuer: []byte{1, 2, 3}, + AuthorityKeyId: []byte{1, 2, 3}, + } + opts := &VerifyOptions{} + opts.Roots = NewCertPool() + r := &Certificate{ + RawSubject: []byte{1, 2, 3}, + SubjectKeyId: []byte{1, 2, 3}, + } + opts.Roots.AddCert(r) + + _, err := c.buildChains([]*Certificate{r}, nil, opts) + if _, ok := err.(UnknownAuthorityError); !ok { + t.Fatalf("buildChains returned unexpected error, got: %v, want %v", err, UnknownAuthorityError{}) + } +}