how to pin ssl in react native project (ios)

58 Views Asked by At

i wanted to pin ssl to my backend server, i have genereted ssl key, i was following this tutorial https://www.callstack.com/blog/ssl-pinning-in-react-native-apps but after lunching app i have errors

Last Exception Backtrace:
0   CoreFoundation                         0x18049111c __exceptionPreprocess + 160
1   libobjc.A.dylib                        0x18008412c objc_exception_throw + 56
2   CoreFoundation                         0x180491038 -[NSException initWithCoder:] + 0
3   frontend                               0x10545410c parseTrustKitConfiguration + 892 (parse_configuration.m:76)
4   frontend                               0x105459208 -[TrustKit initWithConfiguration:sharedContainerIdentifier:isSingleton:] + 380 (TrustKit.m:146)
5   frontend                               0x105458e7c __74+[TrustKit initSharedInstanceWithConfiguration:sharedContainerIdentifier:]_block_invoke + 68 (TrustKit.m:101)
6   libdispatch.dylib                      0x18016cd3c _dispatch_client_callout + 16
7   libdispatch.dylib                      0x18016e530 _dispatch_once_callout + 28
8   frontend                               0x105458de4 _dispatch_once + 36 (once.h:86) [inlined]
9   frontend                               0x105458de4 +[TrustKit initSharedInstanceWithConfiguration:sharedContainerIdentifier:] + 236 (TrustKit.m:100)
10  frontend                               0x105458ce0 +[TrustKit initSharedInstanceWithConfiguration:] + 72 (TrustKit.m:91)
11  frontend                               0x104bab89c -[AppDelegate initTrustKit] + 612 (AppDelegate.mm:35)
12  frontend                               0x104bab568 -[AppDelegate application:didFinishLaunchingWithOptions:] + 72 (AppDelegate.mm:10)
13  UIKitCore                              0x1852eccfc -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 312
14  UIKitCore                              0x1852ee15c -[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 2788
15  UIKitCore                              0x1852f2c7c -[UIApplication _runWithMainScene:transitionContext:completion:] + 856
16  UIKitCore                              0x1849a07f4 -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 104
17  UIKitCore                              0x184eb85ec _UIScenePerformActionsWithLifecycleActionMask + 96
18  UIKitCore                              0x1849a10f4 __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke + 188
19  UIKitCore                              0x1849a0c68 -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 212
20  UIKitCore                              0x1849a0f4c -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 576
21  UIKitCore                              0x1849a0950 -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] + 244
22  UIKitCore                              0x1849aac24 __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke + 140
23  UIKitCore                              0x184db957c +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:fromCurrentState:actions:completion:] + 656
24  UIKitCore                              0x184ece7a0 _UISceneSettingsDiffActionPerformChangesWithTransitionContextAndCompletion + 196
25  UIKitCore                              0x1849aa930 -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] + 288
26  UIKitCore                              0x184808338 __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke.198 + 608
27  UIKitCore                              0x1848070e8 -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 208
28  UIKitCore                              0x184807fbc -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 220
29  UIKitCore                              0x1852f19ac -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 484
30  UIKitCore                              0x184de0cc4 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 260
31  FrontBoardServices                     0x186e03190 -[FBSScene _callOutQueue_didCreateWithTransitionContext:completion:] + 296
32  FrontBoardServices                     0x186e2c3d4 __92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke.82 + 224
33  FrontBoardServices                     0x186e0fd6c -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 160
34  FrontBoardServices                     0x186e2c14c __92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke + 284
35  libdispatch.dylib                      0x18016cd3c _dispatch_client_callout + 16
36  libdispatch.dylib                      0x180170c4c _dispatch_block_invoke_direct + 376
37  FrontBoardServices                     0x186e4fb24 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 44
38  FrontBoardServices                     0x186e4fa00 -[FBSMainRunLoopSerialQueue _targetQueue_performNextIfPossible] + 196
39  FrontBoardServices                     0x186e4fb58 -[FBSMainRunLoopSerialQueue _performNextFromRunLoopSource] + 24
40  CoreFoundation                         0x1803f1f18 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
41  CoreFoundation                         0x1803f1e60 __CFRunLoopDoSource0 + 172
42  CoreFoundation                         0x1803f15d0 __CFRunLoopDoSources0 + 232
43  CoreFoundation                         0x1803ebcb8 __CFRunLoopRun + 768
44  CoreFoundation                         0x1803eb5a4 CFRunLoopRunSpecific + 572
45  GraphicsServices                       0x18e9fbae4 GSEventRunModal + 160
46  UIKitCore                              0x1852f02e4 -[UIApplication _run] + 868
47  UIKitCore                              0x1852f3f5c UIApplicationMain + 124
48  frontend                               0x104babaf0 main + 96 (main.m:8)
49  dyld_sim                               0x107bd9544 start_sim + 20
50  dyld                                   0x107ca2058 start + 2224
51  ???                             0x1d0c000000000000 ???

this is my appDelegate.mm file:

#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <TrustKit/TrustKit.h>


@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [self initTrustKit];

  self.moduleName = @"main";
  //
  //
  self.initialProps = @{};

  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (void)initTrustKit {
      NSDictionary *trustKitConfig =
  @{
    kTSKSwizzleNetworkDelegates: @YES,                    
    kTSKPinnedDomains : @{
            @"myadress" : @{
              kTSKEnforcePinning : @YES,
              kTSKIncludeSubdomains:@YES,
                    kTSKPublicKeyHashes : @[
                        @"ssl1=",
                        @"ssl2="
                            ],
              //kTSKPublicKeyAlgorithms : @[kTSKAlgorithmRsa2048],
                    },
            }};
    [TrustKit initSharedInstanceWithConfiguration:trustKitConfig];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@".expo/.virtual-metro-entry"];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
@end

how can i fix it? public key is valid (base64). After lunching app errors are in the problem report window, I am lunching my app with the npm start, not expo

0

There are 0 best solutions below