Update
This commit is contained in:
1 parent
3530afb854
commit
6903fcff27
2146 files changed
+112256
-190703
No files matched your search
+18
-11
@@ -155,24 +155,31 @@ func (i *macIdentity) CertificateChain() ([]*x509.Certificate, error) {
|
||||
policy := C.SecPolicyCreateSSL(0, nilCFStringRef)
|
||||
|
||||
var trustRef C.SecTrustRef
|
||||
if err := osStatusError(C.SecTrustCreateWithCertificates(C.CFTypeRef(certRef), C.CFTypeRef(policy), &trustRef)); err != nil {
|
||||
osStatusResult := C.SecTrustCreateWithCertificates(C.CFTypeRef(certRef), C.CFTypeRef(policy), &trustRef)
|
||||
if err := osStatusError(osStatusResult); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer C.CFRelease(C.CFTypeRef(trustRef))
|
||||
|
||||
var status C.SecTrustResultType
|
||||
if err := osStatusError(C.SecTrustEvaluate(trustRef, &status)); err != nil {
|
||||
return nil, err
|
||||
// Evaluate trust to populate the certificate chain; ignore the trust
|
||||
// result since we only need the chain structure, not trust validation.
|
||||
var cfTrustErr C.CFErrorRef
|
||||
C.SecTrustEvaluateWithError(trustRef, &cfTrustErr)
|
||||
if cfTrustErr != nilCFErrorRef {
|
||||
// ignore the error since we only care about the chain, not trust validation.
|
||||
}
|
||||
|
||||
var (
|
||||
nchain = C.SecTrustGetCertificateCount(trustRef)
|
||||
chain = make([]*x509.Certificate, 0, int(nchain))
|
||||
)
|
||||
certChain := C.SecTrustCopyCertificateChain(trustRef)
|
||||
if certChain == nilCFArrayRef {
|
||||
return nil, errors.New("error getting certificate chain")
|
||||
}
|
||||
defer C.CFRelease(C.CFTypeRef(certChain))
|
||||
|
||||
for i := C.CFIndex(0); i < nchain; i++ {
|
||||
// TODO: do we need to release these?
|
||||
chainCertref := C.SecTrustGetCertificateAtIndex(trustRef, i)
|
||||
nchain := C.CFArrayGetCount(certChain)
|
||||
chain := make([]*x509.Certificate, 0, int(nchain))
|
||||
|
||||
for j := C.CFIndex(0); j < nchain; j++ {
|
||||
chainCertref := C.SecCertificateRef(C.CFArrayGetValueAtIndex(certChain, j))
|
||||
if chainCertref == nilSecCertificateRef {
|
||||
return nil, errors.New("nil certificate in chain")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user