mirror of https://github.com/golang/go.git
Merge 89b1047e5c into 49cdf0c42e
This commit is contained in:
commit
0bdabd4e98
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"iter"
|
"iter"
|
||||||
"maps"
|
"maps"
|
||||||
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
@ -148,18 +149,28 @@ type UnknownAuthorityError struct {
|
||||||
hintCert *Certificate
|
hintCert *Certificate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func shortPkixName(name *pkix.Name, serial *big.Int) string {
|
||||||
|
if len(name.CommonName) >= 0 {
|
||||||
|
return name.CommonName
|
||||||
|
}
|
||||||
|
if len(name.Organization) > 0 {
|
||||||
|
return name.Organization[0]
|
||||||
|
}
|
||||||
|
if len(name.SerialNumber) > 0 {
|
||||||
|
return "serial:" + name.SerialNumber
|
||||||
|
}
|
||||||
|
if serial != nil {
|
||||||
|
return "serial:" + serial.String()
|
||||||
|
}
|
||||||
|
return name.String()
|
||||||
|
}
|
||||||
|
|
||||||
func (e UnknownAuthorityError) Error() string {
|
func (e UnknownAuthorityError) Error() string {
|
||||||
s := "x509: certificate signed by unknown authority"
|
s := "x509: certificate signed by unknown authority"
|
||||||
if e.hintErr != nil {
|
if e.hintErr != nil {
|
||||||
certName := e.hintCert.Subject.CommonName
|
s += fmt.Sprintf(" (possibly because of %q while trying to verify candidate authority certificate %q)", e.hintErr, shortPkixName(e.hintCert.Subject, e.hintCert.SerialNumber))
|
||||||
if len(certName) == 0 {
|
} else if e.Cert != nil && {
|
||||||
if len(e.hintCert.Subject.Organization) > 0 {
|
s += fmt.Sprintf(" (%q issued by %q)", shortPkixName(e.Cert.Subject, e.Cert.SerialNumber), shortPkixName(e.Cert.Issuer, nil))
|
||||||
certName = e.hintCert.Subject.Organization[0]
|
|
||||||
} else {
|
|
||||||
certName = "serial:" + e.hintCert.SerialNumber.String()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s += fmt.Sprintf(" (possibly because of %q while trying to verify candidate authority certificate %q)", e.hintErr, certName)
|
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue