Skip to content

Commit

Permalink
Addressing further deprecation warnings. (#797)
Browse files Browse the repository at this point in the history
Beyond the change in PR Swift 5.7 regex 'SecTrustGetCertificateAtIndex' was used in different other places too.

Signed-off-by: Tim Bert <[email protected]>
  • Loading branch information
timbms authored Sep 7, 2024
1 parent 3ed161e commit 13f63d0
Showing 1 changed file with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,13 @@ public class ClientCertificateManager {

let chainSize = SecTrustGetCertificateCount(trust)

if trustResult == .recoverableTrustFailure, chainSize > 1 {
trustResult = SecTrustResultType.proceed
let rootCA = SecTrustGetCertificateAtIndex(trust, chainSize - 1)
if trustResult == .recoverableTrustFailure, chainSize > 1,
let certificates = SecTrustCopyCertificateChain(trust) as? [SecCertificate] {
let rootCA = certificates[chainSize - 1]
let anchors = [rootCA]
os_log("Setting anchor for trust evaluation to %s", log: .default, type: .info, rootCA.debugDescription)
os_log("Setting anchor for trust evaluation to %s", log: .default, type: .info, SecCertificateCopySubjectSummary(rootCA)! as String)
SecTrustSetAnchorCertificates(trust, anchors as CFArray)
trustResult = SecTrustResultType.proceed
if #available(iOS 12.0, *) {
var trustError: CFError?
if SecTrustEvaluateWithError(trust, &trustError) != true {
Expand All @@ -316,13 +317,7 @@ public class ClientCertificateManager {
return nil
}

var certChain: [SecCertificate] = []
for ix in 0 ... chainSize - 1 {
guard let ct = SecTrustGetCertificateAtIndex(trust, ix) else { return nil }
if ct != cert {
certChain.append(ct)
}
}
return certChain
let certificates = SecTrustCopyCertificateChain(trust) as? [SecCertificate]
return certificates?.filter { $0 != cert }
}
}

0 comments on commit 13f63d0

Please sign in to comment.