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 。