Skip to content

Commit 3638fb8

Browse files
authored
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.
2 parents d3fa046 + 2c26d2b commit 3638fb8

3 files changed

Lines changed: 20 additions & 13 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: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,24 +155,31 @@ func (i *macIdentity) CertificateChain() ([]*x509.Certificate, error) {
155155
policy := C.SecPolicyCreateSSL(0, nilCFStringRef)
156156

157157
var trustRef C.SecTrustRef
158-
if err := osStatusError(C.SecTrustCreateWithCertificates(C.CFTypeRef(certRef), C.CFTypeRef(policy), &trustRef)); err != nil {
158+
osStatusResult := C.SecTrustCreateWithCertificates(C.CFTypeRef(certRef), C.CFTypeRef(policy), &trustRef)
159+
if err := osStatusError(osStatusResult); err != nil {
159160
return nil, err
160161
}
161162
defer C.CFRelease(C.CFTypeRef(trustRef))
162163

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

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

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

0 commit comments

Comments
 (0)