Regression: Certificates not getting fetched properly (#3992)

* Working now

* Point to repo

* Fix completions for servers without certs
This commit is contained in:
Diego Mello 2022-03-30 18:46:09 -03:00 committed by GitHub
parent 2af88a5544
commit f56bf819d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 687 additions and 237 deletions

View File

@ -23,7 +23,7 @@ index 602d51d..920d975 100644
public String getName() { public String getName() {
return "RNFetchBlob"; return "RNFetchBlob";
diff --git a/node_modules/rn-fetch-blob/ios/RNFetchBlobRequest.m b/node_modules/rn-fetch-blob/ios/RNFetchBlobRequest.m diff --git a/node_modules/rn-fetch-blob/ios/RNFetchBlobRequest.m b/node_modules/rn-fetch-blob/ios/RNFetchBlobRequest.m
index cdbe6b1..1699c6c 100644 index cdbe6b1..c0ce9bd 100644
--- a/node_modules/rn-fetch-blob/ios/RNFetchBlobRequest.m --- a/node_modules/rn-fetch-blob/ios/RNFetchBlobRequest.m
+++ b/node_modules/rn-fetch-blob/ios/RNFetchBlobRequest.m +++ b/node_modules/rn-fetch-blob/ios/RNFetchBlobRequest.m
@@ -15,6 +15,9 @@ @@ -15,6 +15,9 @@
@ -36,7 +36,7 @@ index cdbe6b1..1699c6c 100644
typedef NS_ENUM(NSUInteger, ResponseFormat) { typedef NS_ENUM(NSUInteger, ResponseFormat) {
UTF8, UTF8,
@@ -450,16 +453,107 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) { @@ -450,16 +453,108 @@ - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSen
} }
} }
@ -106,14 +106,14 @@ index cdbe6b1..1699c6c 100644
+ while (*utf8) [hex appendFormat:@"%02X", *utf8++ & 0x00FF]; + while (*utf8) [hex appendFormat:@"%02X", *utf8++ & 0x00FF];
+ +
+ return [[NSString stringWithFormat:@"%@", hex] lowercaseString]; + return [[NSString stringWithFormat:@"%@", hex] lowercaseString];
+} }
+
+-(void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler +-(void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
+{ +{
+ NSString *host = challenge.protectionSpace.host; + NSString *host = challenge.protectionSpace.host;
+ +
+ // Read the clientSSL info from MMKV + // Read the clientSSL info from MMKV
+ __block NSDictionary *clientSSL; + __block NSString *clientSSL;
+ SecureStorage *secureStorage = [[SecureStorage alloc] init]; + SecureStorage *secureStorage = [[SecureStorage alloc] init];
+ +
+ // https://github.com/ammarahm-ed/react-native-mmkv-storage/blob/master/src/loader.js#L31 + // https://github.com/ammarahm-ed/react-native-mmkv-storage/blob/master/src/loader.js#L31
@ -123,21 +123,22 @@ index cdbe6b1..1699c6c 100644
+ return; + return;
+ } + }
+ +
+ NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
+ NSData *cryptKey = [key dataUsingEncoding:NSUTF8StringEncoding]; + NSData *cryptKey = [key dataUsingEncoding:NSUTF8StringEncoding];
+ MMKV *mmkv = [MMKV mmkvWithID:@"default" cryptKey:cryptKey mode:MMKVMultiProcess]; + MMKV *mmkv = [MMKV mmkvWithID:@"default" cryptKey:cryptKey mode:MMKVMultiProcess];
+ clientSSL = [mmkv getObjectOfClass:[NSDictionary class] forKey:host]; + clientSSL = [mmkv getStringForKey:host];
+ +
+ NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]; + if ([clientSSL length] != 0) {
+ + NSData *data = [clientSSL dataUsingEncoding:NSUTF8StringEncoding];
+ if (clientSSL != (id)[NSNull null]) { + id dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
+ NSString *path = [clientSSL objectForKey:@"path"]; + NSString *path = [dict objectForKey:@"path"];
+ NSString *password = [clientSSL objectForKey:@"password"]; + NSString *password = [dict objectForKey:@"password"];
+ credential = [self getUrlCredential:challenge path:path password:password]; + credential = [self getUrlCredential:challenge path:path password:password];
+ } + }
+ +
+ completionHandler(NSURLSessionAuthChallengeUseCredential, credential); + completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
} +}
+
+// - (void) URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable credantial))completionHandler +// - (void) URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable credantial))completionHandler
+// { +// {
+// if ([[options valueForKey:CONFIG_TRUSTY] boolValue]) { +// if ([[options valueForKey:CONFIG_TRUSTY] boolValue]) {

895
yarn.lock

File diff suppressed because it is too large Load Diff