Aut*_*cat 5 ios react-native react-native-ios trustkit
我正在尝试在react-native应用程序(RN 0.60)中实现SSL固定,并且我正在使用Trustkit。
按照https://github.com/datatheorem/TrustKit中发布的指南,这些是我所做的步骤:
1) 使用pod 'TrustKit'和安装 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];
Run Code Online (Sandbox Code Playgroud)
当我尝试做的时候
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);
})
Run Code Online (Sandbox Code Playgroud)
它进入内部then并且不会给出任何错误,但以 200 状态代码响应(使用错误的哈希值)。
否则,使用Android它可以正常工作,进入catch并说:
Error: Pin verification failed
Run Code Online (Sandbox Code Playgroud)
所以,我又回到了这个问题并再次尝试并成功了。我当前的代码与我前段时间发布的代码的唯一区别是我kTSKPublicKeyAlgorithms : @[kTSKAlgorithmRsa2048]在特定的固定域中添加了代码。
我遵循了我在问题中发布的相同步骤。最终AppDelegate效果如下:
在didFinishLaunchingWithOptions之前return YES,我添加了:
[self initTrustKit];
Run Code Online (Sandbox Code Playgroud)
然后在 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];
}
Run Code Online (Sandbox Code Playgroud)
它在 iOS 中不起作用,返回捕获和打印:ERROR => cancelled