搜索
您的当前位置:首页正文

iOS 配置https

来源:知库网

要求

启用ATS必须符合以下标准,不满足条件的HTTPS证书,ATS都会拒绝链接:

  • 服务器所有的链接使用TLS1.2以上版本
  • HTTPS证书必须使用SHA 256以上哈希算法签名
  • HTTPS证书必须使用RAS 2048位或ECC 356位以上公钥算法
  • 使用前向加密技术

AFSecurityPolicy相关的配置

  • typedef NS_ENUM(NSUInteger, AFSSLPinningMode){
    AFSSLPinningModeNone,
    AFSSLPinningModePublicKey,
    AFSSLPinningModeCertificate,
    };
    

    AFSSLPinningModeNone: 代表客户端无条件地信任服务器端返回的证书。

    AFSSLPinningModePublicKey: 代表客户端会将服务器端返回的证书与本地保存的证书中,PublicKey的部分进行校验;如果正确,才继续进行。

    AFSSLPinningModeCertificate: 代表客户端会将服务器端返回的证书和本地保存的证书中的所有内容,包括PublicKey和证书部分,全部进行校验;如果正确,才继续进行。

  • allowInvalidCertificates 是否支持自建证书默认NO 改为YES

  • validatesDomainName 是否进行域名验证 默认YES 改为NO

客户端配置


  • 网络请求配置(AFN)

NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"UpopRsaCert" ofType:@"cer"];//证书的路径
NSData *certData = [NSData dataWithContentsOfFile:cerPath];
NSString *cerPath2 = [[NSBundle mainBundle] pathForResource:@"verify_sign_acp" ofType:@"cer"];//证书的路径
NSData *certData2 = [NSData dataWithContentsOfFile:cerPath2];
NSString *cerPath3 = [[NSBundle mainBundle] pathForResource:@"myWebsite" ofType:@"cer"];//证书的路径
NSData *certData3 = [NSData dataWithContentsOfFile:cerPath3];
NSSet *cerArray = [NSSet setWithObjects:certData,certData2,certData3, nil];
securityPolicy.pinnedCertificates = cerArray;
[httpManager setSecurityPolicy:securityPolicy];
Top