قالب وردپرس درنا توس
Home / IOS Development / iOS – How can I send https request with .p12 certificate on lens c or fast

iOS – How can I send https request with .p12 certificate on lens c or fast



I have this quickly due to lack of time, I can't convert it to lens C right now, I hope you want to convert it yourself,

Enter the Delegate URL session even when setting the request, [19659003] fileprivate func SSLCertificateCreateTrustResult (_ serverTrust: SecTrust) -> SecTrustResultType {
leave certificate: SecCertificate = SecTrustGetCertificateAtIndex (serverTrust, 0)!
leave remoteCertificateData = CFBridgingRetain (SecCertificateCopyData)
was certName = "localServerCert"
if serverUrl.contains (find: "uniqueNameinURL") {
certName = "liveServerCert"
}
la cerPath: String = Bundle.main.path (forResource: certName, ofType: "der")!
la localCertificateData = NSData (contentOfFile: cerPath)!

leave certDataRef = localCertificateData as CFData
let cert = (SecCertificateCreateWithData (null, certDataRef))
leave certArrayRef = [cert] as CFArray
SecTrustSetAnchorCertificates (serverTrust, certArrayRef)
SecTrustSetAnchorCertificatesOnly (serverTrust, false)
la tillitResultat: SecTrustResultType = SecTrustResultType.invalid
return trustResult
}
func urlSession (_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Filled) {
if challenge.protectionSpace.authenticationMethod == (NSURLAuthenticationMethodServerTrust) {
la serverTrust: SecTrust = challenge.protectionSpace.serverTrust!
var localCertificateTrust = SSLCertificateCreateTrustResult (serverTrust)
SecTrustEvaluate (serverTrust, & localCertificateTrust)
if localCertificateTrust == SecTrustResultType.unspecified || localCertificateTrust == SecTrustResultType.proceed
{
leave ID: URLCredential = URLCredential (trust: serverTrust)
challenge.sender? .use (credentials, for: challenge)
completionHandler (URLSession.AuthChallengeDisposition.useCredential, URLCredential (trust: challenge.protectionSpace.serverTrust!))

} other {
leave properties = SecTrustCopyProperties (serverTrust)
completionHandler (URLSession.AuthChallengeDisposition.cancelAuthenticationChallenge, null)
}
}
else
{
completionHandler (URLSession.AuthChallengeDisposition.cancelAuthenticationChallenge, null);
}
}

OR You can follow the following URL

iOS: Before Installing SSL Keychain Certificate ̵

1; Programmatic


Source link