Added in a property to handle invalid SSL certs
This commit is contained in:
parent
b5c48f13a1
commit
9ba4838862
2 changed files with 20 additions and 7 deletions
|
|
@ -105,6 +105,11 @@
|
||||||
*/
|
*/
|
||||||
@property (readonly, nonatomic, strong) NSError *error;
|
@property (readonly, nonatomic, strong) NSError *error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The flag to determine if the connection should accept an invalid SSL certificate. If `_AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_` is set, this property defaults to YES. Otherwise, this property defaults to NO.
|
||||||
|
*/
|
||||||
|
@property (nonatomic,assign) BOOL allowInvalidSSLCertificate;
|
||||||
|
|
||||||
///----------------------------
|
///----------------------------
|
||||||
/// @name Getting Response Data
|
/// @name Getting Response Data
|
||||||
///----------------------------
|
///----------------------------
|
||||||
|
|
|
||||||
|
|
@ -212,6 +212,11 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
self.outputStream = [NSOutputStream outputStreamToMemory];
|
self.outputStream = [NSOutputStream outputStreamToMemory];
|
||||||
|
|
||||||
self.state = AFOperationReadyState;
|
self.state = AFOperationReadyState;
|
||||||
|
|
||||||
|
//This ifdef has been added for backwards compatibility purposes
|
||||||
|
#ifdef _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_
|
||||||
|
self.allowInvalidSSLCertificate = YES;
|
||||||
|
#endif
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
@ -521,11 +526,10 @@ willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challe
|
||||||
- (BOOL)connection:(NSURLConnection *)connection
|
- (BOOL)connection:(NSURLConnection *)connection
|
||||||
canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
|
canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
|
||||||
{
|
{
|
||||||
#ifdef _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_
|
if(self.allowInvalidSSLCertificate &&
|
||||||
if ([protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
|
[protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (self.authenticationAgainstProtectionSpace) {
|
if (self.authenticationAgainstProtectionSpace) {
|
||||||
return self.authenticationAgainstProtectionSpace(connection, protectionSpace);
|
return self.authenticationAgainstProtectionSpace(connection, protectionSpace);
|
||||||
|
|
@ -539,12 +543,13 @@ canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
|
||||||
- (void)connection:(NSURLConnection *)connection
|
- (void)connection:(NSURLConnection *)connection
|
||||||
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
|
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
|
||||||
{
|
{
|
||||||
#ifdef _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_
|
|
||||||
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
|
if(self.allowInvalidSSLCertificate
|
||||||
|
&& [challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
|
||||||
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
|
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (self.authenticationChallenge) {
|
if (self.authenticationChallenge) {
|
||||||
self.authenticationChallenge(connection, challenge);
|
self.authenticationChallenge(connection, challenge);
|
||||||
|
|
@ -692,6 +697,7 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
self.error = [aDecoder decodeObjectForKey:@"error"];
|
self.error = [aDecoder decodeObjectForKey:@"error"];
|
||||||
self.responseData = [aDecoder decodeObjectForKey:@"responseData"];
|
self.responseData = [aDecoder decodeObjectForKey:@"responseData"];
|
||||||
self.totalBytesRead = [[aDecoder decodeObjectForKey:@"totalBytesRead"] longLongValue];
|
self.totalBytesRead = [[aDecoder decodeObjectForKey:@"totalBytesRead"] longLongValue];
|
||||||
|
self.allowInvalidSSLCertificate = [[aDecoder decodeObjectForKey:@"allowInvalidSSLCertificate"] boolValue];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
@ -716,6 +722,7 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
[aCoder encodeObject:self.error forKey:@"error"];
|
[aCoder encodeObject:self.error forKey:@"error"];
|
||||||
[aCoder encodeObject:self.responseData forKey:@"responseData"];
|
[aCoder encodeObject:self.responseData forKey:@"responseData"];
|
||||||
[aCoder encodeObject:[NSNumber numberWithLongLong:self.totalBytesRead] forKey:@"totalBytesRead"];
|
[aCoder encodeObject:[NSNumber numberWithLongLong:self.totalBytesRead] forKey:@"totalBytesRead"];
|
||||||
|
[aCoder encodeObject:[NSNumber numberWithBool:self.allowInvalidSSLCertificate] forKey:@"allowInvalidSSLCertificate"];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - NSCopying
|
#pragma mark - NSCopying
|
||||||
|
|
@ -729,6 +736,7 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
operation.authenticationChallenge = self.authenticationChallenge;
|
operation.authenticationChallenge = self.authenticationChallenge;
|
||||||
operation.cacheResponse = self.cacheResponse;
|
operation.cacheResponse = self.cacheResponse;
|
||||||
operation.redirectResponse = self.redirectResponse;
|
operation.redirectResponse = self.redirectResponse;
|
||||||
|
operation.allowInvalidSSLCertificate = self.allowInvalidSSLCertificate;
|
||||||
|
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue