0

I'm currently implementing TrustKit SSL Pinning on a React Native project.

Due to another library on my XCode project, which does already install TrustKit Cocoapod I am not be able to refer it directly anymore, that's why I'm trying to call it in a "private" manner, just like this example:

  // Disable TrustKit if it is present 
  Class TrustKit = NSClassFromString(@"TrustKit"); //Private calling
  if (TrustKit != nil)
  {
    // Override TrustKit's logger method, useful for local debugging
    void (^loggerBlock)(NSString *) = ^void(NSString *message)
    {
      NSLog(@"TrustKit log: %@", message);
    };

    SEL setLoggerBlock = sel_registerName("setLoggerBlock:");
    [TrustKit performSelector: setLoggerBlock withObject:loggerBlock];
    
    NSDictionary *trustKitConfig =
    @{
      kTSKSwizzleNetworkDelegates: @YES,// How to private consume this property
      kTSKPinnedDomains: @{
          @"*.apps.dev.js.com" : @{
              kTSKIncludeSubdomains: @YES, // Pin all subdomains
              kTSKEnforcePinning: @YES, // Block connections if pinning validation failed
              kTSKDisableDefaultReportUri: @YES,
              kTSKPublicKeyHashes: @[
                @"dz0GbS1i4LnBsJwhRw3iuZmVcgqpn+AlxSBRxUbOz0k=",
                @"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB=",
              ],
          },
      }
    };
    
    SEL setInitSharedInstanceWithConfiguration = sel_registerName("initSharedInstanceWithConfiguration:");
    [TrustKit performSelector: setInitSharedInstanceWithConfiguration withObject:trustKitConfig];
  }

I was able to execute TrustKit methods properly. However, I don't know how to handle trustKitConfig properties from the dictionary by private calling

Error screen: Use of undeclared identifier 'kTSK....'

Fonts
  • 67
  • 1
  • 5
  • Usually, if the other lib refers to TrusKit publicly you shouldn't have an issue, no conflict. If you can't, your issue is that it doesn't know the value of the constants `kTSK...` so why not redefine them, or put write directly their value. See https://github.com/datatheorem/TrustKit/blob/3e98aeb36aff65067cdae55bca7be7f1157deffb/TrustKit/TSKTrustKitConfig.m : `kTSKSwizzleNetworkDelegates: @YES,` => `@"TSKSwizzleNetworkDelegates": @YES,` etc. – Larme Oct 04 '21 at 14:57
  • 1
    "Due to another library on my XCode project, which does already install TrustKit Cocoapod I am not be able to refer it directly anymore." Can you explain what problem you're running into? CocoaPods specifically allows you to access sub-dependancies of your dependancies (in fact, that's a major reason for using CocoaPods, to coordinate multiple places in the code with the same dependancies). – Rob Napier Oct 04 '21 at 15:43
  • Thanks for the help so far. I am going to add more info on the description related to those two solutions mentioned – Fonts Oct 04 '21 at 17:57

1 Answers1

1

Thanks for the help, I was able to fix this issue by using string value @""

I had to remove the k letter from the beginning

NSDictionary *trustKitConfig =
    @{
      @"TSKSwizzleNetworkDelegates": @YES,// How to private consume this property
      @"TSKPinnedDomains": @{
          @"*.apps.atp.dev.jsafrasarasin.com" : @{
              @"TSKIncludeSubdomains": @YES, // Pin all subdomains
              @"TSKEnforcePinning": @YES, // Block connections if pinning validation failed
              @"TSKDisableDefaultReportUri": @YES,
              @"TSKPublicKeyHashes": @[
                @"dz0GbS1i4LnBsJwhRw3iuZmVcgqpn+AlxSBRxUbOz0k=",
                @"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB=",
              ],
          },
      }
    };
Fonts
  • 67
  • 1
  • 5