Q1: fooobar.com/questions/207715/... . , , .
Q2: - , ( ), , SHA1 MD5 , (, ).
, , NSURLConnectionDelegate NSURLConnectionDataDelegate ( )
:
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
NSLOG(@"connection canAuthaenticateAgainstProtectionSpace");
if (![Certificates verifyProtectionSpace:protectionSpace]) {
NSLOG(@"Bad Certificate, canceling request");
[connection cancel];
self.ended = true;
return false;
}
return true;
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
NSLOG(@"connection didReceiveAuthenticationChallenge");
if ([Certificates verifyProtectionSpace:challenge.protectionSpace]) {
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
} else {
[challenge.sender performDefaultHandlingForAuthenticationChallenge:challenge];
}
}