美文网首页iOS 开发iOS Developer
iOS HTTPS 自检证书请求服务器和WKWebView

iOS HTTPS 自检证书请求服务器和WKWebView

作者: 在这蓝色天空下 | 来源:发表于2017-01-09 15:52 被阅读132次

1、使用AFN3.0 HTTPS网络请求

    +(AFSecurityPolicy *)customSecurityPolicy{     //简单封装一下

    //2 设置证书模式
    NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"mnchip" ofType:@"cer"];

    NSData *cerDat = [NSData dataWithContentsOfFile:cerPath];

    AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];

    //允许自检证书
    securityPolicy.allowInvalidCertificates = YES;

    //域名与服务器一致
    securityPolicy.validatesDomainName = YES;

    securityPolicy.pinnedCertificates = [[NSSet alloc] initWithObjects:cerDat, nil];

    return securityPolicy;

    }

在有网络请求的地方:

******

    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    //添加证书
    [session setSecurityPolicy:[OperationHelper customSecurityPolicy]];

******

这样就可以了

2、关于WKWebView , 我是将Allow Arbitrary Loads in Web Content 置为 yes,然后正常使用,注意一点,要实现这个代理方法


    - (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler{

    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {

    NSURLCredential *card = [[NSURLCredential alloc]initWithTrust:challenge.protectionSpace.serverTrust];

    completionHandler(NSURLSessionAuthChallengeUseCredential,card);

    }}

@implementation NSURLRequest(DataController)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
    return YES;
}
@end

关于WKWebView就可以正常显示了

3、UIWebView 访问https 绕过证书验证的方法

在AppDelegate.m里面添加下面这些代码

@implementation NSURLRequest(DataController)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
    return YES;
}
@end

相关文章

  • iOS HTTPS 自检证书请求服务器和WKWebView

    1、使用AFN3.0 HTTPS网络请求 在有网络请求的地方: 这样就可以了 2、关于WKWebView , 我是...

  • IOS开发小记

    1.对服务器进行Https请求 -服务器:获取证书后需提供文件***.pem文件给IOS开发 -IOS开发:将得到...

  • iOS WKWebView信任Https请求(自签名证书)

    步骤如下:一、新建一个NSURLRequest的类别二、在这个类别中新增两个类方法,如下: 注:这两个方法是系统的...

  • HTTPS

    iOS客户端校验https网络请求证书 iOS开发 支持https请求以及https请求的抓包 NSURLConn...

  • iOS9 使用自签证证书实现HTTPS

    公司的服务器被人DDOS攻击了,后台改用自签证的证书,全部请求改用HTTPS. iOS的网络请求也需要全部改. 坑...

  • iOS SSL证书配置和HTTPS请求

    一、证书准备 1、证书转换 在服务器人员,给你发送的crt证书后,进到证书路径,执行下面语句 // openssl...

  • Flutter 自签名证书

    前言 Flutter项目中服务器使用了自签名证书,如果直接使用https请求或者wss请求的话会报证书签名错误。 ...

  • 2022-03-30

    iOS问题记录 WKWebView加载不受信任网页链接 实现WKWebView代理方法,调过证书校验 - (voi...

  • iOS 中 HTTPS 证书验证浅析

    iOS 中 HTTPS 证书验证浅析 一、HTTPS请求过程 下面看一个普通的HTTPS请求过程: 第一阶段:Cl...

  • 自签CA证书和签发证书

    生成CA根证书 生成服务私钥和证书请求 签发证书 查看证书 服务器导入CA证书

网友评论

    本文标题:iOS HTTPS 自检证书请求服务器和WKWebView

    本文链接:https://www.haomeiwen.com/subject/rbkhbttx.html