diff --git a/SDWebImage/SDWebImageDownloader.h b/SDWebImage/SDWebImageDownloader.h index ae7cfd7..3d0921c 100644 --- a/SDWebImage/SDWebImageDownloader.h +++ b/SDWebImage/SDWebImageDownloader.h @@ -34,11 +34,11 @@ typedef enum * NSMutableURLRequest.HTTPShouldHandleCookies = YES; */ SDWebImageDownloaderHandleCookies = 1 << 5, - SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6 /** - * Enable this to allow untrusted SSL ceriticates. - * Useful for testing purposes. + * Enable to allow untrusted SSL ceriticates. + * Useful for testing purposes. Use with caution in production. */ + SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6 } SDWebImageDownloaderOptions; diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index da21082..e019600 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -371,13 +371,16 @@ return self.options & SDWebImageDownloaderContinueInBackground; } -- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { +- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace +{ return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]; } -- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { +- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge +{ BOOL trustAllCertificates = (self.options & SDWebImageDownloaderAllowInvalidSSLCertificates); - if (trustAllCertificates && [challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { + if (trustAllCertificates && [challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) + { [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; } diff --git a/SDWebImage/SDWebImageManager.h b/SDWebImage/SDWebImageManager.h index 39a11a7..688d457 100644 --- a/SDWebImage/SDWebImageManager.h +++ b/SDWebImage/SDWebImageManager.h @@ -52,11 +52,11 @@ typedef enum * NSMutableURLRequest.HTTPShouldHandleCookies = YES; */ SDWebImageHandleCookies = 1 << 6, - SDWebImageAllowInvalidSSLCertificates = 1 << 7 /** - * Enable this to allow untrusted SSL ceriticates. - * Useful for testing purposes. + * Enable to allow untrusted SSL ceriticates. + * Useful for testing purposes. Use with caution in production. */ + SDWebImageAllowInvalidSSLCertificates = 1 << 7 } SDWebImageOptions; typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType);