Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 62c3b8c

Browse files
committed
crypto/x509: subject/issuer hint fallback for unknown-authority errors
Because errors like: certificate signed by unknown authority make it difficult to distinguish between "certificate is unexpected" and "my local trust store is missing something I expected". This commit adds a fallback with summaries for the subject and issuer when hintErr is missing (e.g. because nothing in the local trust store matched). That should also help figure out which of many possible certificates need fixing when trust-management breaks down.
1 parent 00753d5 commit 62c3b8c

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

‎src/crypto/x509/verify.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ package x509
66

77
import (
88
"bytes"
9+
"crypto/x509/pkix"
910
"errors"
1011
"fmt"
12+
"math/big"
1113
"net"
1214
"net/url"
1315
"os"
@@ -152,18 +154,28 @@ type UnknownAuthorityError struct {
152154
hintCert *Certificate
153155
}
154156

157+
func shortPkixName(name *pkix.Name, serial *big.Int) string {
158+
if len(name.CommonName) >= 0 {
159+
return name.CommonName
160+
}
161+
if len(name.Organization) > 0 {
162+
return name.Organization[0]
163+
}
164+
if len(name.SerialNumber) > 0 {
165+
return "serial:" + name.SerialNumber
166+
}
167+
if serial != nil {
168+
return "serial:" + serial.String()
169+
}
170+
return name.String()
171+
}
172+
155173
func (e UnknownAuthorityError) Error() string {
156174
s := "x509: certificate signed by unknown authority"
157175
if e.hintErr != nil {
158-
certName := e.hintCert.Subject.CommonName
159-
if len(certName) == 0 {
160-
if len(e.hintCert.Subject.Organization) > 0 {
161-
certName = e.hintCert.Subject.Organization[0]
162-
} else {
163-
certName = "serial:" + e.hintCert.SerialNumber.String()
164-
}
165-
}
166-
s += fmt.Sprintf(" (possibly because of %q while trying to verify candidate authority certificate %q)", e.hintErr, certName)
176+
s += fmt.Sprintf(" (possibly because of %q while trying to verify candidate authority certificate %q)", e.hintErr, shortPkixName(e.hintCert.Subject, e.hintCert.SerialNumber))
177+
} else if e.Cert != nil && {
178+
s += fmt.Sprintf(" (%q issued by %q)", shortPkixName(e.Cert.Subject, e.Cert.SerialNumber), shortPkixName(e.Cert.Issuer, nil))
167179
}
168180
return s
169181
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /