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?
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.
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.
The user can then trust the certificate on the device by going to Settings > General > About > Certificate Trust Settings.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With