Skip to content

Commit

Permalink
crypto/x509: fix mac cert error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
deejross committed Jul 21, 2022
1 parent 244c8b0 commit 319d415
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/crypto/x509/internal/macos/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func SecTrustEvaluateWithError(trustObj CFRef) error {
ret := syscall(abi.FuncPCABI0(x509_SecTrustEvaluateWithError_trampoline), uintptr(trustObj), uintptr(unsafe.Pointer(&errRef)), 0, 0, 0, 0)
if int32(ret) != 1 {
errStr := CFErrorCopyDescription(errRef)
err := fmt.Errorf("x509: %s", CFStringToString(errStr))
err := fmt.Errorf("%s", CFStringToString(errStr))
CFRelease(errRef)
CFRelease(errStr)
return err
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/x509/root_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate
// using TLS or OCSP for that.

if err := macOS.SecTrustEvaluateWithError(trustObj); err != nil {
return nil, err
return nil, CertificateInvalidError{Reason: NotTrusted, Detail: err.Error()}
}

chain := [][]*Certificate{{}}
Expand Down
6 changes: 6 additions & 0 deletions src/crypto/x509/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ const (
// CANotAuthorizedForExtKeyUsage results when an intermediate or root
// certificate does not permit a requested extended key usage.
CANotAuthorizedForExtKeyUsage
// NotTrusted results on Macs when a certificate is not trusted. This
// is needed to ensure we can properly catch this condition, otherwise
// it simply results in an `*error.ErrorString` type.
NotTrusted
)

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

0 comments on commit 319d415

Please sign in to comment.