19
19
20
20
#import < React/RCTBridge.h>
21
21
#import < React/RCTBundleURLProvider.h>
22
+ #import < React/RCTHTTPRequestHandler.h>
22
23
23
24
#import < UserNotifications/UserNotifications.h>
24
25
#import < RNCPushNotificationIOS.h>
25
26
27
+ #import < SDWebImage/SDWebImageDownloaderConfig.h>
28
+ #import < SDWebImage/SDWebImageDownloaderOperation.h>
29
+
30
+ #import < Security/Security.h>
31
+
32
+ // TODO: properly import the framework
33
+ extern NSString * StatusgoImageServerTLSCert ();
34
+
35
+ @interface StatusDownloaderOperation : SDWebImageDownloaderOperation
36
+ + (void )URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler;
37
+ @end
38
+
26
39
/*
27
40
#if DEBUG
28
41
#import <FlipperKit/FlipperClient.h>
@@ -45,7 +58,7 @@ static void InitializeFlipper(UIApplication *application) {
45
58
#endif
46
59
*/
47
60
48
- @implementation AppDelegate
61
+ @implementation AppDelegate
49
62
{
50
63
UIView *_blankView;
51
64
}
@@ -84,6 +97,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
84
97
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter ];
85
98
center.delegate = self;
86
99
100
+ SDWebImageDownloaderConfig.defaultDownloaderConfig .operationClass = [StatusDownloaderOperation class ];
101
+
87
102
return YES ;
88
103
}
89
104
@@ -124,7 +139,7 @@ - (void)applicationWillResignActive:(UIApplication *)application {
124
139
[UIView animateWithDuration: 0.5 animations: ^{
125
140
_blankView.alpha = 1 ;
126
141
}];
127
- }
142
+ }
128
143
}
129
144
130
145
- (void )applicationDidBecomeActive : (UIApplication *)application {
@@ -169,14 +184,67 @@ - (void)application:(UIApplication *)application didReceiveLocalNotification:(UI
169
184
- (void )userNotificationCenter : (UNUserNotificationCenter *)center willPresentNotification : (UNNotification *)notification withCompletionHandler : (void (^)(UNNotificationPresentationOptions options))completionHandler
170
185
{
171
186
NSDictionary *userInfo = notification.request .content .userInfo ;
172
-
187
+
173
188
NSString *notificationType = userInfo[@" notificationType" ]; // check your notification type
174
189
if (![notificationType isEqual: @" local-notification" ]) { // we silence all notifications which are not local
175
190
completionHandler (UNNotificationPresentationOptionNone );
176
191
return ;
177
192
}
178
-
193
+
179
194
completionHandler (UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge );
180
195
}
181
196
182
197
@end
198
+
199
+ @implementation StatusDownloaderOperation
200
+
201
+ + (void )URLSession : (NSURLSession *)session task : (NSURLSessionTask *)task didReceiveChallenge : (NSURLAuthenticationChallenge *)challenge completionHandler : (void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {
202
+ NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengeCancelAuthenticationChallenge ;
203
+ __block NSURLCredential *credential = nil ;
204
+
205
+ NSString *pemCert = StatusgoImageServerTLSCert ();
206
+ pemCert = [pemCert stringByReplacingOccurrencesOfString: @" -----BEGIN CERTIFICATE-----\n " withString: @" " ];
207
+ pemCert = [pemCert stringByReplacingOccurrencesOfString: @" \n -----END CERTIFICATE-----" withString: @" " ];
208
+ NSData *derCert = [[NSData alloc ] initWithBase64EncodedString: pemCert options: NSDataBase64DecodingIgnoreUnknownCharacters ];
209
+ SecCertificateRef certRef = SecCertificateCreateWithData (NULL , (__bridge_retained CFDataRef ) derCert);
210
+ CFArrayRef certArrayRef = CFArrayCreate (NULL , (void *)&certRef, 1 , NULL );
211
+ SecTrustSetAnchorCertificates (challenge.protectionSpace .serverTrust , certArrayRef);
212
+
213
+ SecTrustResultType trustResult;
214
+ SecTrustEvaluate (challenge.protectionSpace .serverTrust , &trustResult);
215
+
216
+ if ((trustResult == kSecTrustResultProceed ) || (trustResult == kSecTrustResultUnspecified )) {
217
+ disposition = NSURLSessionAuthChallengeUseCredential ;
218
+ credential = [NSURLCredential credentialForTrust: challenge.protectionSpace.serverTrust];
219
+ }
220
+
221
+ if (completionHandler) {
222
+ completionHandler (disposition, credential);
223
+ }
224
+ }
225
+
226
+ - (void )URLSession : (NSURLSession *)session task : (NSURLSessionTask *)task didReceiveChallenge : (NSURLAuthenticationChallenge *)challenge completionHandler : (void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {
227
+ if ([challenge.protectionSpace.authenticationMethod isEqualToString: NSURLAuthenticationMethodServerTrust ] &&
228
+ [challenge.protectionSpace.host isEqualToString: @" localhost" ]) {
229
+ [StatusDownloaderOperation URLSession: session task: task didReceiveChallenge: challenge completionHandler: completionHandler];
230
+ } else {
231
+ [super URLSession: session task: task didReceiveChallenge: challenge completionHandler: completionHandler];
232
+ }
233
+ }
234
+
235
+ @end
236
+
237
+ @implementation RCTHTTPRequestHandler (SelfSigned)
238
+
239
+ - (void )URLSession : (NSURLSession *)session task : (NSURLSessionTask *)task didReceiveChallenge : (NSURLAuthenticationChallenge *)challenge completionHandler : (void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {
240
+ if ([challenge.protectionSpace.authenticationMethod isEqualToString: NSURLAuthenticationMethodServerTrust ] &&
241
+ [challenge.protectionSpace.host isEqualToString: @" localhost" ]) {
242
+ [StatusDownloaderOperation URLSession: session task: task didReceiveChallenge: challenge completionHandler: completionHandler];
243
+ } else {
244
+ if (completionHandler) {
245
+ completionHandler (NSURLSessionAuthChallengePerformDefaultHandling , [NSURLCredential credentialForTrust: challenge.protectionSpace.serverTrust]);
246
+ }
247
+ }
248
+ }
249
+
250
+ @end
0 commit comments