TrustKit
3.0.4
TrustKit是一个开源框架,可以轻松在任何iOS 12+,MACOS 10.13+,TVOS 12+或WatchOS 4+应用程序中部署SSL公共密钥固定和报告;它支持Swift和Objective-C应用程序。
如果您需要在Android应用中固定/报告。我们还在https://github.com/datatheorem/trustkit-android上发布了Android的TrustKit 。
TrustKit提供以下功能:
在应用程序中部署SSL固定需要使用固定策略(域,主题公共密钥信息哈希和其他设置)初始化TrustKit 。
该策略可以在应用程序的Info.plist中配置。
另外,可以通过编程设置固定策略:
NSDictionary *trustKitConfig =
@{
kTSKSwizzleNetworkDelegates : @ NO ,
kTSKPinnedDomains : @{
@" www.datatheorem.com " : @{
kTSKExpirationDate : @" 2017-12-01 " ,
kTSKPublicKeyHashes : @[
@" HXXQgxueCIU5TTLHob/bPbwcKOKw6DkfsTWYHbxbqTY= " ,
@" 0SDf3cRToyZJaMsoS17oF72VMavLxj/N7WBNasNuiR8= "
],
kTSKEnforcePinning : @ NO ,
},
@" yahoo.com " : @{
kTSKPublicKeyHashes : @[
@" TQEtdMbmwFgYUifM4LDF+xgEtd0z69mPGmkp014d6ZY= " ,
@" rFjc3wG7lTZe43zeYTvPq8k4xdDEutCmIhI5dn4oCeE= " ,
],
kTSKIncludeSubdomains : @ YES
}
}};
[TrustKit initSharedInstanceWithConfiguration: trustKitConfig];该策略也可以在Swift应用程序中以编程方式设置:
let trustKitConfig = [
kTSKSwizzleNetworkDelegates : false ,
kTSKPinnedDomains : [
" yahoo.com " : [
kTSKExpirationDate : " 2017-12-01 " ,
kTSKPublicKeyHashes : [
" JbQbUG5JMJUoI6brnx0x3vZF6jilxsapbXGVfjhN8Fg= " ,
" WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18= "
] , ] ] ] as [ String : Any ]
TrustKit . initSharedInstance ( withConfiguration : trustKitConfig )初始化TrustKit后,可以从TrustKit Singleton中检索TSKPinningValidator实例,并可用于在应用程序网络委托中执行SSL固定验证。例如,在nsurlsessiondelegate中:
- ( void )URLSession:( NSURLSession *)session
task:( NSURLSessionTask *)task
didReceiveChallenge:( NSURLAuthenticationChallenge *)challenge
completionHandler:( void (^)( NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {
{
TSKPinningValidator *pinningValidator = [[TrustKit sharedInstance ] pinningValidator ];
// Pass the authentication challenge to the validator; if the validation fails, the connection will be blocked
if (![pinningValidator handleChallenge: challenge completionHandler: completionHandler])
{
// TrustKit did not handle this challenge: perhaps it was not for server trust
// or the domain was not pinned. Fall back to the default behavior
completionHandler ( NSURLSessionAuthChallengePerformDefaultHandling , nil );
}
}有关更多信息,请参阅“入门指南”。
TrustKit是数据定理和Yahoo的移动团队之间的联合劳动。有关详细信息,请参见AUTHORS 。
TrustKit根据MIT许可发布。有关详细信息,请参见LICENSE 。