title: How to use self signed certificate at iOS app
body: <p>Basically our iOS app needs to communicate with a server which has a self signed certificate for now. In my app, the https is failing with untrusted server certificate which is understandable. The error is like this:</p>
  
  <blockquote>
    <p>Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “my host name here” which could put your confidential information at risk." </p>
  </blockquote>
  
  <p>So I sent the self signed certificate via email to the iOS device and imported into the profiles and hoping that it would be used as part of root CA for https authentication. To my surprise, it is not and I am still getting the same error. I think that iOS would be default to use root CAs at keychain to validate the server certificate and from what I read, the imported certificate at profiles are at keychain as well. So I could not understand why my imported self signed certificate is not used as root CA. </p>
  
  <p>At this point, I don't really want to trust this self signed certificate via the coding like this <a href="http://codingfantasy.blogspot.com/2013/06/ios-authenticate-with-self-signed.html" rel="nofollow noreferrer">iOS authenticate HTTPS with self-signed certificate</a> or <a href="https://stackoverflow.com/questions/12049508/in-ios-how-to-connect-to-a-server-using-https-with-self-signed-certificate-on-t?rq=1">In iOS, how to connect to a server using https with self-signed certificate on the server?</a> since this won't work in customer case where they would install our server on their network and they could create their own self signed certificate.</p>
  
  <p>Somehow I didn't really get much information around this from searching. Could anyone shed some lights here and what I need to do to debug this? Thanks very much.</p>
  
  <p>Update on July 15: </p>
  
  <p>More update around this. I also tried to use configuration profile to add a self signed CA to root CA at the iOS device by following <a href="http://nat.guyton.net/2012/01/20/adding-trusted-root-certificate-authorities-to-ios-ipad-iphone/" rel="nofollow noreferrer">Adding Trusted Root Certificate Authorities to iOS </a>, from my testing on  6.0 iPad and iPhone, it doesn't work as well. So not sure if that only works on jail broken device or not.  In the end, I end up by allowing user to import a self signed certificate into the app. The app would load such imported certificate for certificate verification similar to this <a href="https://stackoverflow.com/questions/12049508/in-ios-how-to-connect-to-a-server-using-https-with-self-signed-certificate-on-t?rq=1">In iOS, how to connect to a server using https with self-signed certificate on the server?</a>. Hope that it would help others in this case. </p>