Sometime I'm getting crashes from firebase: Index 1 beyond bounds [0..0] but in my app I'm checking if serverTrust contains any certificates. Any idea why? position 0 is leaf, position 1 is intermediate and 2 is root. here is code:
guard challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust else {
return false
}
guard let serverTrust = challenge.protectionSpace.serverTrust else {
return false
}
var secResult: SecTrustResultType = .invalid
let status = SecTrustEvaluate(serverTrust, &secResult)
guard status == errSecSuccess else {
return false
}
let position = 1
if SecTrustGetCertificateCount(serverTrust) < 1 { return false }
guard let rootCertificate = SecTrustGetCertificateAtIndex(serverTrust, position) else {
return false
}
do {
let localCert = try Certificate.cert()
let serverCert = SecCertificateCopyData(rootCertificate) as Data
return serverCert == localCert
} catch {
return false
}