iOS SSL 인증서 만료 처리

냠냠·2024년 5월 2일
0

iOS

목록 보기
4/9

webview 에서 서버와 통신시 서버 인증서가 만료 되었는지 확인하는 코드

- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
{
    SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
    CFDataRef exceptions = SecTrustCopyExceptions(serverTrust);
    SecTrustSetExceptions (serverTrust, exceptions);
    
    CFDictionaryRef currentListingRef = SecTrustCopyResult(serverTrust);
    NSDictionary *test = CFBridgingRelease(currentListingRef);
    
    CFRelease(exceptions);
    
    completionHandler (NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:serverTrust]);
}

test 변수 에서 TrustExpirationDate 를 체크하면 된다.

0개의 댓글