Minor refactoring and reformatting
This commit is contained in:
parent
07c9f6c358
commit
46559bd6ca
1 changed files with 7 additions and 7 deletions
|
|
@ -175,9 +175,9 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
|
|
||||||
+ (NSArray *)pinnedCertificates {
|
+ (NSArray *)pinnedCertificates {
|
||||||
static NSArray *_pinnedCertificates = nil;
|
static NSArray *_pinnedCertificates = nil;
|
||||||
static dispatch_once_t oncePredicate;
|
static dispatch_once_t onceToken;
|
||||||
|
|
||||||
dispatch_once(&oncePredicate, ^{
|
dispatch_once(&onceToken, ^{
|
||||||
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
|
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
|
||||||
NSArray *paths = [bundle pathsForResourcesOfType:@"cer" inDirectory:@"."];
|
NSArray *paths = [bundle pathsForResourcesOfType:@"cer" inDirectory:@"."];
|
||||||
NSMutableArray *certificates = [NSMutableArray array];
|
NSMutableArray *certificates = [NSMutableArray array];
|
||||||
|
|
@ -486,15 +486,15 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
#pragma mark - NSURLConnectionDelegate
|
#pragma mark - NSURLConnectionDelegate
|
||||||
|
|
||||||
#ifdef _AFNETWORKING_PIN_SSL_CERTIFICATES_
|
#ifdef _AFNETWORKING_PIN_SSL_CERTIFICATES_
|
||||||
-(void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
|
- (void)connection:(NSURLConnection *)connection
|
||||||
|
willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
|
||||||
{
|
{
|
||||||
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
|
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
|
||||||
SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
|
SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
|
||||||
SecCertificateRef certificate = SecTrustGetCertificateAtIndex(serverTrust, 0);
|
SecCertificateRef certificate = SecTrustGetCertificateAtIndex(serverTrust, 0);
|
||||||
NSData *remoteCertificateData = CFBridgingRelease(SecCertificateCopyData(certificate));
|
NSData *certificateData = (__bridge_transfer NSData *)SecCertificateCopyData(certificate);
|
||||||
|
|
||||||
NSArray *pinnedCertificates = [[self class] pinnedCertificates];
|
if ([[[self class] pinnedCertificates] containsObject:certificateData]) {
|
||||||
if ([pinnedCertificates containsObject:remoteCertificateData]) {
|
|
||||||
NSURLCredential *credential = [NSURLCredential credentialForTrust:serverTrust];
|
NSURLCredential *credential = [NSURLCredential credentialForTrust:serverTrust];
|
||||||
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
|
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue