|
@@ -10,7 +10,7 @@
|
|
|
#import <WebKit/WebKit.h>
|
|
|
#import "KSMutilDatePicker.h"
|
|
|
#import "IncomeCountBottomView.h"
|
|
|
-
|
|
|
+#import <KSToolLibrary/AuthChallengeManager.h>
|
|
|
// WKWebView 内存不释放的问题解决
|
|
|
@interface KSWeakWebViewScriptMessageDelegate : NSObject<WKScriptMessageHandler>
|
|
|
|
|
@@ -372,6 +372,55 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
+- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *_Nullable))completionHandler
|
|
|
+{
|
|
|
+ dispatch_queue_t queue = dispatch_queue_create("webViewChallengeQueue", NULL);
|
|
|
+ dispatch_async(queue, ^{
|
|
|
+ if (SSL_AUTH) {
|
|
|
+
|
|
|
+ NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling;
|
|
|
+ NSURLCredential *customCredential = nil;
|
|
|
+
|
|
|
+ if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
|
|
|
+ // 默认信任
|
|
|
+ customCredential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
|
|
|
+ disposition = NSURLSessionAuthChallengeUseCredential;
|
|
|
+ }
|
|
|
+ else if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodClientCertificate]) {
|
|
|
+ // client authentication
|
|
|
+ SecIdentityRef identity = NULL;
|
|
|
+ SecTrustRef trust = NULL;
|
|
|
+ if ([AuthChallengeManager extractIdentity:&identity andTrust:&trust filePath:CERT_PATH]) {
|
|
|
+ SecCertificateRef certificate = NULL;
|
|
|
+ SecIdentityCopyCertificate(identity, &certificate);
|
|
|
+ const void*certs[] = {certificate};
|
|
|
+ CFArrayRef certArray =CFArrayCreate(kCFAllocatorDefault, certs,1,NULL);
|
|
|
+ customCredential =[NSURLCredential credentialWithIdentity:identity certificates:(__bridge NSArray*)certArray persistence:NSURLCredentialPersistencePermanent];
|
|
|
+ disposition = NSURLSessionAuthChallengeUseCredential;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (completionHandler) {
|
|
|
+ completionHandler(disposition, customCredential);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
|
|
|
+ if (challenge.previousFailureCount == 0) {
|
|
|
+ NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
|
|
|
+ completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
|
|
|
+ } else {
|
|
|
+ completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
#pragma mark ---- lazying
|
|
|
- (WKWebView *)myWebView {
|
|
|
if (!_myWebView) {
|