Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check the security of the SSL certificate in iOS?

I wanna check whether the SSL certificate is present in the URL also wants to check its version and validation type.

I have created a application where I am calling the NSURLConnection delegate methods to send request over a server.

Also used "canAuthenticateAgainstProtectionSpace" method, but this method is not getting called once the connection is established.

How do I achieve this?

like image 975
iLearner Avatar asked Feb 23 '12 11:02

iLearner


People also ask

How do I check my SSL certificate details?

To check an SSL certificate on any website, all you need to do is follow two simple steps. First, check if the URL of the website begins with HTTPS, where S indicates it has an SSL certificate. Second, click on the padlock icon on the address bar to check all the detailed information related to the certificate.

How do I view security certificates in Safari?

In the Safari app on your Mac, look for an encryption icon in the Smart Search field. An encryption icon indicates that the website uses the HTTPS protocol, has a digital identity certificate, and encrypts information. To view the website's certificate, click the icon. A gray lock icon indicates a standard certificate.

How do I trust certificates in iOS 15?

The user can then trust the certificate on the device by going to Settings > General > About > Certificate Trust Settings.


1 Answers

iOS does not give you very granular access to certificate information. You have two choices: private APIs or build your own evaluator with OpenSSL.

You can see the private certificate functions in the opensource code. The version is available from SecCertificateVersion(). I'm not certain what you mean by "validation type" here.

To do this with OpenSSL, you can get the DER data with SecCertificateCopyData() and then parse everything yourself.

I suggest opening a radar (bugreporter.apple.com) on this issue. The lack of access to basic information about the certificate is a serious problem.

If you're looking for sample code that extracts the certificate from the NSURLConnection, see the Chapter 11 sample code from iOS:PTL:

- (void)connection:(NSURLConnection *)connection
  willSendRequestForAuthenticationChallenge:
  (NSURLAuthenticationChallenge *)challenge
{
  NSURLProtectionSpace *protSpace = challenge.protectionSpace;
  SecTrustRef trust = protSpace.serverTrust;
  ...
    SecCertificateRef cert = SecTrustGetCertificateAtIndex(trust, 0);
  ...

At this point, cert holds your leaf certificate.

like image 199
Rob Napier Avatar answered Nov 15 '22 00:11

Rob Napier