ios – Why is Alamofire public pinning not working?


I’m making an attempt to carry out public key pinning utilizing Alamofire and Moya.

I’m constructing my very own customized Alamofire Session and passing it to my Moya supplier.
I’ve learn the documentation of Alamofire on find out how to carry out public key pinning which is summarized by these few strains of code:

let trustManager = ServerTrustManager(evaluators: ["": PublicKeysTrustEvaluator()])
return MySession(configuration: configuration, serverTrustManager: trustManager)

My understanding is that PublicKeysTrustEvaluator() will filter via all certificates present in Bundle.fundamental and extract the general public keys and carry out public key pinning towards the host. If not less than one succeeds, then the server belief is taken into account legitimate.

Right here is a few code from the Alamofire mission:

extension AlamofireExtension the place ExtendedType: Bundle {
    /// Returns all legitimate `cer`, `crt`, and `der` certificates within the bundle.
    public var certificates: [SecCertificate] {
        paths(forResourcesOfTypes: [".cer", ".CER", ".crt", ".CRT", ".der", ".DER"]).compactMap { path in
                let certificateData = strive? Knowledge(contentsOf: URL(fileURLWithPath: path)) as CFData,
                let certificates = SecCertificateCreateWithData(nil, certificateData) else { return nil }

            return certificates

    /// Returns all public keys for the legitimate certificates within the bundle.
    public var publicKeys: [SecKey] {

Why is Alamofire permitting the usage of .cer/.crt information if the perform SecCertificateCreateWithData solely expects DER codecs?

The perform paths is returning my .cer file however is empty as a result of this name SecCertificateCreateWithData at all times fails.

Ought to I convert my certificates to DER format?

If that’s the case, how ought to I do that?

The output of this name is just not being discovered by the perform paths(forResourcesOfTypes talked about above.

openssl x509 -outform der -in certificatename.pem -out certificatename.der


Leave a Reply