3

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

按照https://github.com/datatheorem/TrustKit中发布的指南,这些是我已经完成的步骤:

pod 'TrustKit'1) 使用和安装 TrustKit podpod install

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];

当我尝试做

 RNFetchBlob.fetch('GET', "https://www.datatheorem.com", {})    //tried using standard fetch() but gives same results
    .then(async(res) => {
        console.log('RES => ' ,res)
    })
    // Something went wrong:
    .catch((err) => {
        console.log('ERROR =>', err);
    })

它进入内部then并没有给出任何错误,而是以 200 状态代码响应(使用错误的哈希)。

否则,使用Android它可以正常工作,进入catch并说:

Error: Pin verification failed
4

2 回答 2

1

所以,我回到了这个并再次尝试并让它工作。我当前的代码与我前段时间发布的代码的唯一区别是我添加kTSKPublicKeyAlgorithms : @[kTSKAlgorithmRsa2048]到了一个特定的固定域中。

我已经按照我在问题中发布的相同步骤进行操作。最终AppDelegate看起来像:

在里面didFinishLaunchingWithOptions之前return YES,我补充说:

  [self initTrustKit];

然后在 i 的括号后didFinishLaunchingWithOptions添加:

- (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 返回并打印:ERROR => cancelled

于 2019-12-04T10:51:56.467 回答
0

我已经TrustKitInfo.plist. 我还注意到,即使你只有 1 PublicKeyHash,你也必须提供一个虚拟的,Trustkit以便在 iOS 应用程序中工作。

于 2019-12-28T06:19:49.860 回答