Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add trustAllServerCertificates property to ImageFetch #28

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions Sources/Objc/NImageFetch.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,19 @@ - (instancetype)init
return self;
}

#if defined(DEBUG) || defined(NOMATESTFLIGHT)

/* In DEBUG mode, blindly trust any server certificate */

- (void)URLSession:(NSURLSession *)session
didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler
{
NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
if (self.trustAllServerCertificates) {
completionHandler(NSURLSessionAuthChallengeUseCredential,
[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
} else {
completionHandler(NSURLSessionAuthChallengePerformDefaultHandling,
nil);
}
}

#endif

- (void)deactivateMemoryCache
{
self.isMemoryCacheDeactivated = YES;
Expand Down
3 changes: 3 additions & 0 deletions Sources/Objc/Public/NImageFetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ NS_SWIFT_NAME(ImageFetch)

@property (nonatomic, class, readonly) NImageFetch *sharedImageFetch;

/// Whether to blindly trust all server certificates.
@property (nonatomic) BOOL trustAllServerCertificates;

/** Start fetching the image specified by the URL request.
* @param request Request to fetch
* @return An NImageFetchTask, or nil if the image did need to be fetched (already in cache).
Expand Down