I have been trying to implement SSL Pinning for a hybrid app using a plugin which builds the native code for the required functionality.
Inside the generated native project, the Objective-C code includes the following function to read certificate files (X.509 DER .cer
) from the www/certificates
location.
// AFSecurityPolicy.m
+ (NSSet *)certificatesInBundle:(NSBundle *)bundle {
NSArray *paths = [bundle pathsForResourcesOfType:@"cer" inDirectory:@"www/certificates"];
NSMutableSet *certificates = [NSMutableSet setWithCapacity:[paths count]];
for (NSString *path in paths) {
NSData *certificateData = [NSData dataWithContentsOfFile:path];
[certificates addObject:certificateData];
}
return [NSSet setWithSet:certificates];
}
But due to a known bug in the plugin, this location does not get created automatically (ideally, it should). As a workaround, I want to hardcode the .cer
certificate content to the above function.
How can I do that?
(A modified version of above code would be very helpful)
Sample certificates can be found here on Github.
Disclosure: I am very new to mobile programming and appreciate any sort of help in this regard.