使用TrustKit iOS在react本机应用程序中实现ssl固定

使用TrustKit iOS在react本机应用程序中实现ssl固定,ios,react-native,react-native-ios,trustkit,Ios,React Native,React Native Ios,Trustkit,我正在尝试在react本机应用程序(RN 0.60)中实现SSL固定,并使用Trustkit 以下是我所做的步骤: 1) 使用pod'TrustKit'和pod安装来安装TrustKit pod 2) 添加到我的AppDelegate.m这段代码中: #import <TrustKit/TrustKit.h> //inside didFinishLaunchingWithOptions NSDictionary *trustKitConfig = @{ kTSKSwi

我正在尝试在react本机应用程序(RN 0.60)中实现SSL固定,并使用Trustkit

以下是我所做的步骤:

1) 使用
pod'TrustKit'
pod安装来安装TrustKit pod

2) 添加到我的
AppDelegate.m
这段代码中:

#import <TrustKit/TrustKit.h>

//inside didFinishLaunchingWithOptions

NSDictionary *trustKitConfig =
  @{
    kTSKSwizzleNetworkDelegates: @YES,
    kTSKPinnedDomains: @{
        @"www.datatheorem.com" : @{
            kTSKEnforcePinning:@YES,
            kTSKIncludeSubdomains:@YES,
            //Using wrong hashes so it fails
            kTSKPublicKeyHashes : @[
                @"Ca5gV6n7OVx4AxtEaIk8NI9qyKBTtKJjwqullb/v9hh=",
                @"YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihh="
                ]
            }}};

  [TrustKit initSharedInstanceWithConfiguration:trustKitConfig];
它进入
,然后进入
,不给出任何错误,但以200状态码(使用错误的哈希)响应

否则,使用安卓系统,它可以正常工作,进入陷阱并说:

Error: Pin verification failed

所以,我回到这一点,并尝试了一遍,让它的工作。我当前的代码与我不久前发布的代码的唯一区别是,我在特定的固定域中添加了
kTSKPublicKeyAlgorithms:@[kTSKAlgorithmRsa2048]

我遵循了我在问题中发布的相同步骤。最后的
AppDelegate
如下所示:

didfishlaunchingwithoptions
中,在
返回YES
之前,我添加了:

  [self initTrustKit];
然后在
didfishlaunchingwithoptions的括号后,我添加了:

- (void)initTrustKit {
      NSDictionary *trustKitConfig =
  @{
    kTSKSwizzleNetworkDelegates: @YES,                    
    kTSKPinnedDomains : @{
            @"www.datatheorem.com" : @{
              kTSKEnforcePinning : @YES,
              kTSKIncludeSubdomains:@YES,
                    kTSKPublicKeyHashes : @[
                        @"Ca5gV6n7OVx4AxtEaIk8NI9qyKBTtKJjwqullb/v9hh=",
                        @"YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihh="
                            ],
              kTSKPublicKeyAlgorithms : @[kTSKAlgorithmRsa2048],
                    },
            }};
    [TrustKit initSharedInstanceWithConfiguration:trustKitConfig];
}

它在iOS中不起作用,返回到catch和printing中:
ERROR=>cancelled
我已经在
Info.plist中配置了
TrustKit

我还注意到,即使您只有1个
PublicKeyHash
,您也必须为
Trustkit
提供一个虚拟哈希,以便在iOS应用程序中工作。

在我发布的示例中,有2个哈希。我使用appDelegate方法,因为它(对我来说)比使用info.plist更可读。或者你在说别的什么?是的。你的例子是正确的。我的意思是,当我做我的项目时,我只放了1个散列,应用程序在构建时崩溃。在检查了几个小时后,发现应用程序由于缺少备份哈希而崩溃。只是想分享我的经验,必须提供2个哈希。您是否尝试在实现后运行Charles日志?它起作用了吗?
- (void)initTrustKit {
      NSDictionary *trustKitConfig =
  @{
    kTSKSwizzleNetworkDelegates: @YES,                    
    kTSKPinnedDomains : @{
            @"www.datatheorem.com" : @{
              kTSKEnforcePinning : @YES,
              kTSKIncludeSubdomains:@YES,
                    kTSKPublicKeyHashes : @[
                        @"Ca5gV6n7OVx4AxtEaIk8NI9qyKBTtKJjwqullb/v9hh=",
                        @"YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihh="
                            ],
              kTSKPublicKeyAlgorithms : @[kTSKAlgorithmRsa2048],
                    },
            }};
    [TrustKit initSharedInstanceWithConfiguration:trustKitConfig];
}