title: Swift: Add Certificate Authority root certificate
body: <p>We're attempting to follow the Apple <a href="https://developer.apple.com/library/ios/technotes/tn2232/_index.html#//apple_ref/doc/uid/DTS40012884-CH1-SECSELFSIGNEDCERTS" rel="nofollow">docs</a> for using your own certificate authority (CA): </p>
  
  <blockquote>
    <p>While a self-signed certificate is a reasonable approach during
    development, there is a better way: create your own certificate
    authority ... and have it issue a certificate for your test server.
    You can then ... hard-wire your certificate authority's root
    certificate into your app</p>
  </blockquote>
  
  <p>I haven't been able to figure out how to hard wire the CA root cert using Swift.  The paper mentions an <a href="https://developer.apple.com/library/ios/technotes/tn2232/_index.html#//apple_ref/doc/uid/DTS40012884-CH1-SECCUSTOMROOT" rel="nofollow">approach</a> but I haven't been able to translate this into Swift code:</p>
  
  <blockquote>
    <ol>
    <li>Get a copy of the remote peer's certificate ... </li>
    <li>Get the server
    certificate from the trust object (pass an index of 0 to
    SecTrustGetCertificateAtIndex) </li>
    <li>Get the data for that server
    certificate (SecCertificateCopyData) </li>
    <li>Compare this to the certificate
    data you got in step 1; if they match, you're talking to the correct
    peer</li>
    </ol>
  </blockquote>
  
  <p>How can you do this via Swift? </p>