Skip to content

Commit

Permalink
Fix #171 encountered with non-valid SSL certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyLB committed Aug 17, 2017
1 parent 9cc5e0a commit 77bb6cd
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 6 deletions.
12 changes: 11 additions & 1 deletion piwigo/Albums/Album List/AlbumTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#import "CategoriesData.h"
#import "MoveCategoryViewController.h"
#import "NetworkHandler.h"
#import <AFNetworking/AFImageDownloader.h>

@interface AlbumTableViewCell()

Expand Down Expand Up @@ -389,8 +390,17 @@ -(void)setupWithAlbumData:(PiwigoAlbumData*)albumData
else
{
NSString *URLRequest = [NetworkHandler getURLWithPath:[imageData.MediumPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] asPiwigoRequest:NO withURLParams:nil];

// Ensure that SSL certificates won't be rejected
AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
[policy setAllowInvalidCertificates:YES];
[policy setValidatesDomainName:NO];

AFImageDownloader *dow = [AFImageDownloader defaultInstance];
[dow.sessionManager setSecurityPolicy:policy];

[self.backgroundImage setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:URLRequest]]
placeholderImage:nil
placeholderImage:[UIImage imageNamed:@"placeholder"]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
albumData.categoryImage = image;
[weakSelf setupBgWithImage:image];
Expand Down
15 changes: 13 additions & 2 deletions piwigo/Albums/Album Pictures/AlbumImagesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#import "LocalAlbumsViewController.h"
#import "AlbumData.h"
#import "NetworkHandler.h"
#import <AFNetworking/AFImageDownloader.h>


@interface AlbumImagesViewController () <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, ImageDetailDelegate, CategorySortDelegate, CategoryCollectionViewCellDelegate>

Expand Down Expand Up @@ -350,8 +352,17 @@ -(void)downloadImage
UIImageView *dummyView = [UIImageView new];
__weak typeof(self) weakSelf = self;
NSString *URLRequest = [NetworkHandler getURLWithPath:[downloadingImage.ThumbPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] asPiwigoRequest:NO withURLParams:nil];
[dummyView setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:URLRequest]]
placeholderImage:nil

// Ensure that SSL certificates won't be rejected
AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
[policy setAllowInvalidCertificates:YES];
[policy setValidatesDomainName:NO];

AFImageDownloader *dow = [AFImageDownloader defaultInstance];
[dow.sessionManager setSecurityPolicy:policy];

[dummyView setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:URLRequest]]
placeholderImage:[UIImage imageNamed:@"placeholderImage"]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
weakSelf.downloadView.downloadImage = image;
} failure:nil];
Expand Down
9 changes: 9 additions & 0 deletions piwigo/Albums/Album Pictures/ImageCollectionViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "PiwigoImageData.h"
#import "Model.h"
#import "NetworkHandler.h"
#import <AFNetworking/AFImageDownloader.h>

@interface ImageCollectionViewCell()

Expand Down Expand Up @@ -153,6 +154,14 @@ -(void)setupWithImageData:(PiwigoImageData*)imageData
return;
}

// Ensure that any SSL certificate won't be rejected
AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
[policy setAllowInvalidCertificates:YES];
[policy setValidatesDomainName:NO];

AFImageDownloader *dow = [AFImageDownloader defaultInstance];
[dow.sessionManager setSecurityPolicy:policy];

// Download the image of the requested resolution (or get it from the cache)
switch ([Model sharedInstance].defaultThumbnailSize) {
case kPiwigoImageSizeSquare:
Expand Down
15 changes: 13 additions & 2 deletions piwigo/Albums/Image Detail/ImageDetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import "ImageUpload.h"
#import "ImageScrollView.h"
#import "AllCategoriesViewController.h"
#import <AFNetworking/AFImageDownloader.h>

@interface ImageDetailViewController () <UIPageViewControllerDataSource, UIPageViewControllerDelegate, ImagePreviewDelegate>

Expand Down Expand Up @@ -199,12 +200,22 @@ -(void)downloadImage
UIImageView *dummyView = [UIImageView new];
__weak typeof(self) weakSelf = self;
NSString *URLRequest = [NetworkHandler getURLWithPath:[self.imageData.ThumbPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] asPiwigoRequest:NO withURLParams:nil];

// Ensure that SSL certificates won't be rejected
AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
[policy setAllowInvalidCertificates:YES];
[policy setValidatesDomainName:NO];

AFImageDownloader *dow = [AFImageDownloader defaultInstance];
[dow.sessionManager setSecurityPolicy:policy];

[dummyView setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:URLRequest]]
placeholderImage:nil
placeholderImage:[UIImage imageNamed:@"placeholderImage"]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
weakSelf.downloadView.downloadImage = image;
} failure:nil];
if(!self.imageData.isVideo)

if(!self.imageData.isVideo)
{
[ImageService downloadImage:self.imageData
onProgress:^(NSProgress *progress) {
Expand Down
4 changes: 3 additions & 1 deletion piwigo/Albums/ImageService.m
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ +(NSURLSessionTask*)downloadImage:(PiwigoImageData*)image
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFImageResponseSerializer serializer];

// Ensure that SSL certificates won't be rejected
AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
[policy setAllowInvalidCertificates:YES];
[policy setValidatesDomainName:NO];
Expand Down Expand Up @@ -283,6 +284,7 @@ +(NSURLSessionTask*)downloadVideo:(PiwigoImageData*)video
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];

// Ensure that SSL certificates won't be rejected
AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
[policy setAllowInvalidCertificates:YES];
[policy setValidatesDomainName:NO];
Expand All @@ -291,7 +293,7 @@ +(NSURLSessionTask*)downloadVideo:(PiwigoImageData*)video
NSString *URLRequest = [NetworkHandler getURLWithPath:[video.fullResPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] asPiwigoRequest:NO withURLParams:nil];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:URLRequest]];

// replace .mp4 or .mv4 with .mov for compatibility with Photos.app
// Replace .mp4 or .mv4 with .mov for compatibility with Photos.app
NSString *fileName = video.fileName;
if (([[[video.fileName pathExtension] uppercaseString] isEqualToString:@"MP4"]) ||
([[[video.fileName pathExtension] uppercaseString] isEqualToString:@"M4V"])) {
Expand Down
2 changes: 2 additions & 0 deletions piwigo/Network/NetworkHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ +(NSURLSessionTask*)post:(NSString*)path
jsonResponseSerializer.acceptableContentTypes = jsonAcceptableContentTypes;
manager.responseSerializer = jsonResponseSerializer;

// Ensure that SSL certificates won't be rejected
AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
[policy setAllowInvalidCertificates:YES];
[policy setValidatesDomainName:NO];
Expand Down Expand Up @@ -118,6 +119,7 @@ +(NSURLSessionTask*)postMultiPart:(NSString*)path
jsonResponseSerializer.acceptableContentTypes = jsonAcceptableContentTypes;
manager.responseSerializer = jsonResponseSerializer;

// Ensure that SSL certificates won't be rejected
AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
[policy setAllowInvalidCertificates:YES];
[policy setValidatesDomainName:NO];
Expand Down

0 comments on commit 77bb6cd

Please sign in to comment.