Hi,
I have a custom CA on my device ( Server ). My iOS App gets the data from my device over https( with URLSession ). I've implememented this like in TN2232 described. My Code:
//Code start
if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust{
//TN2232: Custom certificate authority
//Step 1
let pathToCert = Bundle.main.path(forResource: "TrialRootCerSymantec", ofType: "der")
var localCertificate: NSData? = nil
do{
localCertificate = try NSData(contentsOfFile: pathToCert!)
}
//Step 2 and 3
let serverTrust = challenge.protectionSpace.serverTrust
let certificateServer = SecTrustGetCertificateAtIndex(serverTrust!, 0)
let cfData = CFDataCreate(kCFAllocatorDefault, localCertificate?.bytes.assumingMemoryBound(to: UInt8.self), (localCertificate?.length)!)
let anchorCert = SecCertificateCreateWithData(kCFAllocatorDefault, cfData!)
let certs:[CFTypeRef] = [anchorCert as CFTypeRef]
let certArrayRef: CFArray = CFBridgingRetain(certs as NSArray) as! CFArray
if(errSecSuccess == SecTrustSetAnchorCertificates(serverTrust!, certArrayRef)){
print("Status: \(errSecSuccess)")
}else{
print("Status: Error")
}
//Step 4
var result: SecTrustResultType = SecTrustResultType.invalid
let returnState: OSStatus = SecTrustEvaluate(serverTrust!, &result)
let isServerTrusted: Bool = (result == SecTrustResultType.unspecified || result == SecTrustResultType.proceed)
}
//Code end
The function SecTrustEvaluate returns -108...(returnState = -108 and result = 0).
What does mean error -108?
How can I fix this error?
Thanks!