Skip to content

Commit 9c20546

Browse files
committed
certstore_darwin: fix deprecation warnings
Corrects a number of deprecation warnings in the darwin code. This updates the go check to 1.25/1.26 which pins the minimum supported macOS version to 12.0 which corresponds with the macOS version required for those Security framework API changes.
1 parent d3fa046 commit 9c20546

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

certstore_darwin.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,25 @@ func (i *macIdentity) CertificateChain() ([]*x509.Certificate, error) {
160160
}
161161
defer C.CFRelease(C.CFTypeRef(trustRef))
162162

163-
var status C.SecTrustResultType
164-
if err := osStatusError(C.SecTrustEvaluate(trustRef, &status)); err != nil {
165-
return nil, err
163+
// Evaluate trust to populate the certificate chain; ignore the trust
164+
// result since we only need the chain structure, not trust validation.
165+
var cfTrustErr C.CFErrorRef
166+
C.SecTrustEvaluateWithError(trustRef, &cfTrustErr)
167+
if cfTrustErr != nilCFErrorRef {
168+
C.CFRelease(C.CFTypeRef(cfTrustErr))
166169
}
167170

168-
var (
169-
nchain = C.SecTrustGetCertificateCount(trustRef)
170-
chain = make([]*x509.Certificate, 0, int(nchain))
171-
)
171+
certChain := C.SecTrustCopyCertificateChain(trustRef)
172+
if certChain == nilCFArrayRef {
173+
return nil, errors.New("error getting certificate chain")
174+
}
175+
defer C.CFRelease(C.CFTypeRef(certChain))
176+
177+
nchain := C.CFArrayGetCount(certChain)
178+
chain := make([]*x509.Certificate, 0, int(nchain))
172179

173-
for i := C.CFIndex(0); i < nchain; i++ {
174-
// TODO: do we need to release these?
175-
chainCertref := C.SecTrustGetCertificateAtIndex(trustRef, i)
180+
for j := C.CFIndex(0); j < nchain; j++ {
181+
chainCertref := C.SecCertificateRef(C.CFArrayGetValueAtIndex(certChain, j))
176182
if chainCertref == nilSecCertificateRef {
177183
return nil, errors.New("nil certificate in chain")
178184
}

0 commit comments

Comments
 (0)