Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Certificate information can be obtained using NSURLConnection delegate methods:</p> <pre><code>- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge </code></pre> <p>That is:</p> <pre><code>- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { BOOL result = [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]; NSLog(@"&lt;%p %@: %s line:%d&gt; Result:%s", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __PRETTY_FUNCTION__, __LINE__, (result == YES) ? "YES" : "NO"); return result; } - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { NSArray *trustedHosts = [NSArray arrayWithObject:@"encrypted.google.com"]; BOOL isAuthMethodServerTrust = [challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]; NSLog(@"&lt;%p %@: %s line:%d&gt; Result:%s", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __PRETTY_FUNCTION__, __LINE__, (isAuthMethodServerTrust == YES) ? "YES" : "NO"); if (isAuthMethodServerTrust) { if ([trustedHosts containsObject:challenge.protectionSpace.host]) { NSLog(@"&lt;%p %@: %s line:%d&gt; trustedHosts containsObject:challenge.protectionSpace.host", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __PRETTY_FUNCTION__, __LINE__); NSURLCredential* urlCredential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]; NSLog(@"&lt;%p %@: %s line:%d&gt; Url credential", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __PRETTY_FUNCTION__, __LINE__); [challenge.sender useCredential:urlCredential forAuthenticationChallenge:challenge]; //Code to verify certificate info SecTrustRef trustRef = [[challenge protectionSpace] serverTrust]; CFIndex count = SecTrustGetCertificateCount(trustRef); for (CFIndex i = 0; i &lt; count; i++) { SecCertificateRef certRef = SecTrustGetCertificateAtIndex(trustRef, i); CFStringRef certSummary = SecCertificateCopySubjectSummary(certRef); CFDataRef certData = SecCertificateCopyData(certRef); NSLog(@"&lt;%p %@: %s line:%d&gt; Certificate summary:%@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __PRETTY_FUNCTION__, __LINE__, (NSString*) certSummary); NSLog(@"&lt;%p %@: %s line:%d&gt; Certificate data:%@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __PRETTY_FUNCTION__, __LINE__, (NSString*) certData); CFRelease(certData); } } } } </code></pre> <p>This code gives you the following information related to "https://encrypted.google.com": In the "certSummary" NSString the issuer of the certificate. In the "certData" data of the certificate. The problem is that at present I do not know how extract information from a such data (expiration date, public key, ...), so any help will be welcomed.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload