Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
[Issue #1323] Making debugSecurityPolicy defaultSecurityPolicy
Browse files Browse the repository at this point in the history
Adding +securityPolicyWithPinningMode:

Removing securityPolicy property from UIImageView
  • Loading branch information
mattt committed Sep 18, 2013
1 parent 6ff88e9 commit 8208096
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 35 deletions.
2 changes: 1 addition & 1 deletion AFNetworking/AFSecurityPolicy.h
Expand Up @@ -62,7 +62,7 @@ typedef NS_ENUM(NSUInteger, AFSSLPinningMode) {
/**
*/
+ (instancetype)debugPolicy;
+ (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode;

///

Expand Down
17 changes: 8 additions & 9 deletions AFNetworking/AFSecurityPolicy.m
Expand Up @@ -145,19 +145,18 @@ + (NSArray *)defaultPinnedCertificates {
}

+ (instancetype)defaultPolicy {
AFSecurityPolicy *security = [[self alloc] init];
security.SSLPinningMode = AFSSLPinningModePublicKey;
security.pinnedCertificates = [[self class] defaultPinnedCertificates];
AFSecurityPolicy *securityPolicy = [[self alloc] init];
securityPolicy.SSLPinningMode = AFSSLPinningModeNone;
securityPolicy.allowInvalidCertificates = YES;

This comment has been minimized.

Copy link
@kcharwood

kcharwood Sep 18, 2013

Contributor

I disagree here. My opinion is default policy should be AFSSLPinningModeNone and it should NOT allow invalid certificates. I believe those are the sensible defaults.

This comment has been minimized.

Copy link
@getaaron

getaaron Sep 18, 2013

Contributor

@kcharwood Agreed; this would match the 1.3.x releases.


return security;
return securityPolicy;
}

+ (instancetype)debugPolicy {
AFSecurityPolicy *security = [[self alloc] init];
security.SSLPinningMode = AFSSLPinningModeNone;
security.allowInvalidCertificates = YES;
+ (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode {
AFSecurityPolicy *securityPolicy = [[self alloc] init];
securityPolicy.SSLPinningMode = pinningMode;

return security;
return securityPolicy;
}

#pragma mark -
Expand Down
5 changes: 0 additions & 5 deletions UIKit+AFNetworking/UIImageView+AFNetworking.h
Expand Up @@ -40,11 +40,6 @@
*/
@property (nonatomic, strong) AFImageResponseSerializer <AFURLResponseSerialization> * imageResponseSerializer;

/**
*/
@property (nonatomic, strong) AFSecurityPolicy *securityPolicy;


/**
Creates and enqueues an image request operation, which asynchronously downloads the image from the specified URL, and sets it the request is finished. Any previous image request for the receiver will be cancelled. If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.
Expand Down
20 changes: 0 additions & 20 deletions UIKit+AFNetworking/UIImageView+AFNetworking.m
Expand Up @@ -39,24 +39,19 @@ - (void)cacheImage:(UIImage *)image

static char kAFImageRequestOperationKey;
static char kAFResponseSerializerKey;
static char kAFSecurityPolicyKey;


@interface UIImageView (_AFNetworking)
@property (readwrite, nonatomic, strong, setter = af_setImageRequestOperation:) AFHTTPRequestOperation *af_imageRequestOperation;
@property (readwrite, nonatomic, strong, setter = af_setSecurityPolicy:) AFSecurityPolicy *af_securityPolicy;
@end

@implementation UIImageView (_AFNetworking)
@dynamic af_imageRequestOperation;
@dynamic af_securityPolicy;
@end

#pragma mark -

@implementation UIImageView (AFNetworking)
@dynamic imageResponseSerializer;
@dynamic securityPolicy;

+ (NSOperationQueue *)af_sharedImageRequestOperationQueue {
static NSOperationQueue *_af_sharedImageRequestOperationQueue = nil;
Expand Down Expand Up @@ -101,20 +96,6 @@ - (void)setImageResponseSerializer:(id <AFURLResponseSerialization>)serializer {
objc_setAssociatedObject(self, &kAFResponseSerializerKey, serializer, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (AFSecurityPolicy *)securityPolicy {
static AFSecurityPolicy *_af_defaultSecurityPolicy = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_af_defaultSecurityPolicy = [AFSecurityPolicy debugPolicy];
});

return objc_getAssociatedObject(self, &kAFSecurityPolicyKey) ?: _af_defaultSecurityPolicy;
}

- (void)setSecurityPolicy:(AFSecurityPolicy *)securityPolicy {
objc_setAssociatedObject(self, &kAFSecurityPolicyKey, securityPolicy, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

#pragma mark -

- (void)setImageWithURL:(NSURL *)url {
Expand Down Expand Up @@ -152,7 +133,6 @@ - (void)setImageWithURLRequest:(NSURLRequest *)urlRequest
__weak __typeof(self)weakSelf = self;
self.af_imageRequestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
self.af_imageRequestOperation.responseSerializer = self.imageResponseSerializer;
self.af_imageRequestOperation.securityPolicy = self.securityPolicy;
[self.af_imageRequestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
if ([[urlRequest URL] isEqual:[operation.request URL]]) {
Expand Down

0 comments on commit 8208096

Please sign in to comment.