Steven 11 月之前
父節點
當前提交
f803e6076d

+ 2 - 0
KulexiuForTeacher/KulexiuForTeacher.xcodeproj/project.pbxproj

@@ -719,6 +719,7 @@
 		BC7CFFD5281801A800CAEB21 /* CardBandBodyView.m in Sources */ = {isa = PBXBuildFile; fileRef = BC7CFFD4281801A800CAEB21 /* CardBandBodyView.m */; };
 		BC7CFFD7281801B700CAEB21 /* CardBandBodyView.xib in Resources */ = {isa = PBXBuildFile; fileRef = BC7CFFD6281801B700CAEB21 /* CardBandBodyView.xib */; };
 		BC7E770C2900DD8E00EB37AF /* HomeDragButton.m in Sources */ = {isa = PBXBuildFile; fileRef = BC7E770A2900DD8E00EB37AF /* HomeDragButton.m */; };
+		BC7FF6A22BEB71B70092E0DE /* client.p12 in Resources */ = {isa = PBXBuildFile; fileRef = BC3BF6242B9EAF1700831494 /* client.p12 */; };
 		BC81F0E529232C11004106AF /* CoursewareViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = BC81F0E429232C11004106AF /* CoursewareViewController.m */; };
 		BC81F0E929232D01004106AF /* CoursewareListCell.m in Sources */ = {isa = PBXBuildFile; fileRef = BC81F0E729232D01004106AF /* CoursewareListCell.m */; };
 		BC81F0EA29232D01004106AF /* CoursewareListCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = BC81F0E829232D01004106AF /* CoursewareListCell.xib */; };
@@ -7143,6 +7144,7 @@
 			isa = PBXResourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				BC7FF6A22BEB71B70092E0DE /* client.p12 in Resources */,
 				BC71D2002887FDD40010F14B /* img_9.png in Resources */,
 				BCC5840D28A9FA8100BAB4CF /* cloud_animation_4.png in Resources */,
 				BCC5840628A9FA8100BAB4CF /* cloud_animation_13.png in Resources */,

+ 1 - 1
KulexiuForTeacher/KulexiuForTeacher.xcodeproj/xcshareddata/xcschemes/KulexiuForTeacher.xcscheme

@@ -52,7 +52,7 @@
       </Testables>
    </TestAction>
    <LaunchAction
-      buildConfiguration = "DEV"
+      buildConfiguration = "TEST"
       selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
       selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
       launchStyle = "0"

+ 50 - 1
KulexiuForTeacher/KulexiuForTeacher/Module/Home/Income/Controller/IncomeCountViewController.m

@@ -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) {

+ 1 - 1
KulexiuForTeacher/KulexiuForTeacher/configuration/Config-dev.xcconfig

@@ -20,6 +20,6 @@ TXOfflinePushCertificateIDForAPNS = 39559
 APP_NAME = 酷乐秀学院-dev
 APP_BUNDLE_ID = com.Colexiu.KulexiuForTeacher-dev
 CONFIG_FLAG = DEV
-SSL_AUTH = NO
+SSL_AUTH = YES
 
 GCC_PREPROCESSOR_DEFINITIONS = $(inherited) REQUEST_DOMAIN='${REQUEST_DOMAIN}' ACCOMPANY_DOMAIN='${ACCOMPANY_DOMAIN}' SOCKET_DOMAIN='${SOCKET_DOMAIN}' WHITE_BOARD='${WHITE_BOARD}' JSPUSH_ENVIRONMENT='${JSPUSH_ENVIRONMENT}' SUBMIT_UUID='${SUBMIT_UUID}' CONFIG_TXSDKAPPID='${CONFIG_TXSDKAPPID}' TXOfflinePushCertificateIDForAPNS='${TXOfflinePushCertificateIDForAPNS}' APP_NAME='${APP_NAME}' APP_BUNDLE_ID='${APP_BUNDLE_ID}' SSL_AUTH='${SSL_AUTH}'

+ 1 - 1
KulexiuForTeacher/KulexiuForTeacher/configuration/Config-test.xcconfig

@@ -20,6 +20,6 @@ TXOfflinePushCertificateIDForAPNS = 39559
 APP_NAME = 酷乐秀学院-test
 APP_BUNDLE_ID = com.Colexiu.KulexiuForTeacher-test
 CONFIG_FLAG = TEST
-SSL_AUTH = NO
+SSL_AUTH = YES
 
 GCC_PREPROCESSOR_DEFINITIONS = $(inherited) REQUEST_DOMAIN='${REQUEST_DOMAIN}' ACCOMPANY_DOMAIN='${ACCOMPANY_DOMAIN}' SOCKET_DOMAIN='${SOCKET_DOMAIN}' WHITE_BOARD='${WHITE_BOARD}' JSPUSH_ENVIRONMENT='${JSPUSH_ENVIRONMENT}' SUBMIT_UUID='${SUBMIT_UUID}' CONFIG_TXSDKAPPID='${CONFIG_TXSDKAPPID}' TXOfflinePushCertificateIDForAPNS='${TXOfflinePushCertificateIDForAPNS}' APP_NAME='${APP_NAME}' APP_BUNDLE_ID='${APP_BUNDLE_ID}' SSL_AUTH='${SSL_AUTH}'