'Turn off or bypass SSL Certificate Verification in Swift iOS

I have my server certificates expired.

I want to bypass or turn off certs verification from my swift iOS app so i can test app features.

I need this just for testing, not for production of live app. so none concerned for security.

How can i achieve this in Swift iOS.

I am using Alamofire library for network requests.

How to achieve this.



Solution 1:[1]

Put the below cod into info.plist file.

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

Solution 2:[2]

Try something like:

import Foundation
import Alamofire

class NetworkManager {

    static let shared = NetworkManager()

    var unsecure: SessionManager!
    var serverTrustPolicies: [String: ServerTrustPolicy] = ["unsecureSslHostname":.disableEvaluation]

    private init () {
        self.unsecure = { () -> SessionManager in
            let configuration = URLSessionConfiguration.default
            configuration.httpAdditionalHeaders = SessionManager.defaultHTTPHeaders
            return SessionManager(
                configuration: configuration,
                serverTrustPolicyManager: ServerTrustPolicyManager(policies: self.serverTrustPolicies)
            )
        }()
    }
}

After that NetworkManager.shared.unsecure will return Alamofire SessionManager which can be used for send request to hosts with unsecured SSL certificates.

Solution 3:[3]

use this for your session configuration:

let serverTrustPolicies: [String: ServerTrustPolicy] = ["untrustedServer.com": .disableEvaluation]
let servertrustManager = ServerTrustPolicyManager(policies: serverTrustPolicies)
sessionManager = SessionManager(configuration: configuration,serverTrustPolicyManager: servertrustManager)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sanjeev
Solution 2
Solution 3 abed