我正在尝试在 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