Closed codearraydev closed 2 years ago
Hi
You need to put:
#import <TrustKit/TrustKit.h>
#import <TrustKit/TSKPinningValidator.h>
#import <TrustKit/TSKPinningValidatorCallback.h>
Out of and above:
#ifdef FB_SONARKIT_ENABLED
https://github.com/facebook/react-native/issues/28910#issuecomment-629680398
Hi All,
I am using TrustKit for SSL Pinning in my React Native App. It works fine when testing the App locally in Simulator and real devices. But upon Archiving the App. I get the follow errors
use of undeclared identifier kTS IncludeSubdomains use of undeclared identifier kTSKEnforcePinning use of undeclared identifier kTSKPublicKeyHashes use of undeclared identifier TrustKit
My Source code is given below
`
import "AppDelegate.h"
import <React/RCTBridge.h>
import <React/RCTBundleURLProvider.h>
import <React/RCTRootView.h>
ifdef FB_SONARKIT_ENABLED
import <FlipperKit/FlipperClient.h>
import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
import <TrustKit/TrustKit.h>
import <TrustKit/TSKPinningValidator.h>
import <TrustKit/TSKPinningValidatorCallback.h>
static void InitializeFlipper(UIApplication application) { FlipperClient client = [FlipperClient sharedClient]; SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]]; [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; [client addPlugin:[FlipperKitReactPlugin new]]; [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; [client start]; }
endif
@implementation AppDelegate
(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions {
ifdef FB_SONARKIT_ENABLED
InitializeFlipper(application);
endif
// Override TrustKit's logger method, useful for local debugging // void (^loggerBlock)(NSString ) = ^void(NSString message) // { // NSLog(@"TrustKit log: %@", message); // }; // [TrustKit setLoggerBlock:loggerBlock];
NSDictionary *trustKitConfig = @{ // Swizzling because we can't access the NSURLSession instance used in React Native's fetch method
[TrustKit initSharedInstanceWithConfiguration:trustKitConfig]; [TrustKit sharedInstance].pinningValidatorCallback = ^(TSKPinningValidatorResult result, NSString notedHostname, TKSDomainPinningPolicy *policy) { if (result.finalTrustDecision == TSKTrustEvaluationFailedNoMatchingPin) { NSLog(@"TrustKit certificate matching failed"); // Add more logging here. i.e. Sentry, BugSnag etc } };
RCTBridge bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; RCTRootView rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"indici_nz" initialProperties:nil];
if (@available(iOS 13.0, *)) { rootView.backgroundColor = [UIColor systemBackgroundColor]; } else { rootView.backgroundColor = [UIColor whiteColor]; }
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [UIViewController new]; rootViewController.view = rootView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; return YES; }
(NSURL )sourceURLForBridge:(RCTBridge )bridge {
if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
endif
}
@end
`