Skip to content

Commit 4aee0b5

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 4aee0b5

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

.github/workflows/test-macos-recent-go-versions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jobs:
44
test:
55
strategy:
66
matrix:
7-
go-version: ["1.20", "1.21", "1.x"]
7+
go-version: ["1.26", "1.25"]
88
# Doesn't work on Linux.
99
os: [macos-latest]
1010
runs-on: ${{ matrix.os }}

.github/workflows/test-windows-recent-go-versions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jobs:
44
test:
55
strategy:
66
matrix:
7-
go-version: ["1.20", "1.21", "1.x"]
7+
go-version: ["1.26", "1.25"]
88
# Doesn't work on Linux.
99
os: [windows-latest]
1010
runs-on: ${{ matrix.os }}

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+
return nil, errors.New("trust evaluation error")
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)