Skip to content

Commit 319d415

Browse files
author
Ross Peoples
committed
crypto/x509: fix mac cert error handling
1 parent 244c8b0 commit 319d415

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/crypto/x509/internal/macos/security.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func SecTrustEvaluateWithError(trustObj CFRef) error {
201201
ret := syscall(abi.FuncPCABI0(x509_SecTrustEvaluateWithError_trampoline), uintptr(trustObj), uintptr(unsafe.Pointer(&errRef)), 0, 0, 0, 0)
202202
if int32(ret) != 1 {
203203
errStr := CFErrorCopyDescription(errRef)
204-
err := fmt.Errorf("x509: %s", CFStringToString(errStr))
204+
err := fmt.Errorf("%s", CFStringToString(errStr))
205205
CFRelease(errRef)
206206
CFRelease(errStr)
207207
return err

src/crypto/x509/root_darwin.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate
5555
// using TLS or OCSP for that.
5656

5757
if err := macOS.SecTrustEvaluateWithError(trustObj); err != nil {
58-
return nil, err
58+
return nil, CertificateInvalidError{Reason: NotTrusted, Detail: err.Error()}
5959
}
6060

6161
chain := [][]*Certificate{{}}

src/crypto/x509/verify.go

+6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ const (
5656
// CANotAuthorizedForExtKeyUsage results when an intermediate or root
5757
// certificate does not permit a requested extended key usage.
5858
CANotAuthorizedForExtKeyUsage
59+
// NotTrusted results on Macs when a certificate is not trusted. This
60+
// is needed to ensure we can properly catch this condition, otherwise
61+
// it simply results in an `*error.ErrorString` type.
62+
NotTrusted
5963
)
6064

6165
// CertificateInvalidError results when an odd error occurs. Users of this
@@ -86,6 +90,8 @@ func (e CertificateInvalidError) Error() string {
8690
return "x509: issuer has name constraints but leaf doesn't have a SAN extension"
8791
case UnconstrainedName:
8892
return "x509: issuer has name constraints but leaf contains unknown or unconstrained name: " + e.Detail
93+
case NotTrusted:
94+
return "x509: " + e.Detail
8995
}
9096
return "x509: unknown error"
9197
}

0 commit comments

Comments
 (0)