zoukankan      html  css  js  c++  java
  • iOS在https中验证CA签名

    - (void)URLSession:(NSURLSession *)session
    didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
     completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler
    {
        NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling;
        __block NSURLCredential *credential = nil;
    
        if (self.sessionDidReceiveAuthenticationChallenge) {
            disposition = self.sessionDidReceiveAuthenticationChallenge(session, challenge, &credential);
        } else {
            if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
                if ([self.securityPolicy evaluateServerTrust:challenge.protectionSpace.serverTrust forDomain:challenge.protectionSpace.host]) {
                    credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
                    SecTrustRef serverT = challenge.protectionSpace.serverTrust;
                    for (CFIndex index = 0; index < SecTrustGetCertificateCount(serverT); index++) {
                        SecCertificateRef secC = SecTrustGetCertificateAtIndex(serverT, index);
                        CFStringRef name;
                        SecCertificateCopyCommonName(secC, &name);
                        NSString *nameText = (__bridge NSString *)(name);
                        NSLog(@"\\%@",nameText);
                    }
                    
                    if (credential) {
                        disposition = NSURLSessionAuthChallengeUseCredential;
                    } else {
                        disposition = NSURLSessionAuthChallengePerformDefaultHandling;
                    }
                } else {
                    disposition = NSURLSessionAuthChallengeCancelAuthenticationChallenge;
                }
            } else {
                disposition = NSURLSessionAuthChallengePerformDefaultHandling;
            }
        }
    
        if (completionHandler) {
            completionHandler(disposition, credential);
        }
    }

    上述NSLog输出为以下字符串内容,从下到上

  • 相关阅读:
    正则与普通方法对字符串过滤的比较
    java基础练习笔记
    node.js-express路由基础+获取前端数据+rmvc架构开发
    解决powershell因为在此系统上禁止运行脚本"报错
    树、森林、二叉树的转换
    git提交代码时如何不提交node_modules文件
    node.js-静态资源目录搭建
    node.js路由基础
    sql server查询练习
    MYQL存储过程与事件
  • 原文地址:https://www.cnblogs.com/yuxiaoyiyou/p/12304664.html
Copyright © 2011-2022 走看看