title: Alamofire - asymmetric cryptography with elliptic curve key (SSL pinning)
body: <p>I have a problem with connecting to server using Alamofire.</p>
  
  <p>I use this code (credits to cnoon):</p>
  
  <pre><code>class NetworkManager {    
      public static var manager : Alamofire.SessionManager = {
          // Create the server trust policies
          let serverTrustPolicies: [String: ServerTrustPolicy] = [
              "my.server.example.com/api": .pinCertificates(
                  certificates: ServerTrustPolicy.certificates(),
                  validateCertificateChain: true,
                  validateHost: true
              )
          ]
          // Create custom manager
          let configuration = URLSessionConfiguration.default
          configuration.httpAdditionalHeaders = Alamofire.SessionManager.defaultHTTPHeaders
          let man = Alamofire.SessionManager(
              configuration: URLSessionConfiguration.default,
              serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)
          )
          return man
      }()
  }
  </code></pre>
  
  <p>And I have these certificates which I converted to .der format:</p>
  
  <pre><code>client.cert.der
  ca.cert.der
  </code></pre>
  
  <p>And I have also this file with key - it is not a certificate, only the key:
  client.key.pem</p>
  
  <p>The content of file is (example):</p>
  
  <pre><code>-----BEGIN EC PARAMETERS-----
  AxxrtknPQXGLw==
  -----END EC PARAMETERS-----
  -----BEGIN EC PRIVATE KEY-----
  HFDHJBJDB7asjqojhJhhfehiHguegufbBIWhgfbibIUBbf+Hhifhie87nbGrztOIUb
  giGiGIGgzfwtUZTuio+hifegfiIUwzzUG768+HhifeihiI546banneeoPJnkienivbiBIFW
  HkGVi7d/HJihgfegui876gvejfbGUv/Zb7867798g
  -----END EC PRIVATE KEY-----
  </code></pre>
  
  <p>So the question is, how can I connect to the server using these two certificates, the key and Alamofire (if Alamofire cant use it, then it is not mandatory). </p>
  
  <p>EDIT:
  This is the response:</p>
  
  <blockquote>
    <p>2017-08-26 12:26:31.351511+0200 TestAppO2[79217:6915260] []
    nw_coretls_callback_handshake_message_block_invoke_3
    tls_handshake_continue: [-9812] 2017-08-26 12:26:31.351
    TestAppO2[79217:6915379] NSURLSession/NSURLConnection HTTP load failed
    (kCFStreamErrorDomainSSL, -9813) Response: nil
    Alamofire.DefaultDataResponse(request:
    Optional(<a href="https://my.server.example.com/api" rel="nofollow noreferrer">https://my.server.example.com/api</a>), response: nil, data:
    Optional(0 bytes), error: Optional(Error Domain=NSURLErrorDomain
    Code=-1202 "The certificate for this server is invalid. You might be
    connecting to a server that is pretending to be
    “<a href="https://my.server.example.com" rel="nofollow noreferrer">https://my.server.example.com</a>” which could put your confidential
    information at risk."
    UserInfo={NSURLErrorFailingURLPeerTrustErrorKey=, NSLocalizedRecoverySuggestion=Would you like to
    connect to the server anyway?, _kCFStreamErrorDomainKey=3,
    _kCFStreamErrorCodeKey=-9813, NSErrorPeerCertificateChainKey=(
        ""</p>
  </blockquote>