How to check SSL certificate security in iOS?

I will check the weather that the SSL certificate is present in the URL, also wants to check its version and type of verification.

I created an application in which I call the NSURLConnection delegation methods to send a request around the server.

The "canAuthenticateAgainstProtectionSpace" method is also used, but this method is not called after the connection is established.

Can anyone tell me how to achieve this.

+6
source share
1 answer

iOS does not give you very detailed access to certificate information. You have two options: private APIs or creating your own evaluator using OpenSSL.

You can see the private functions of certificates in open source code . A version is available from SecCertificateVersion() . I'm not sure what you mean by "type of validation" here.

To do this using OpenSSL, you can get DER data using SecCertificateCopyData() , and then analyze everything yourself.

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

If you are looking for sample code that extracts a certificate from NSURLConnection , see the example code for chapter 11 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 is stored your certificate sheet.

+9
source

Source: https://habr.com/ru/post/909175/


All Articles