美文网首页iOS Developer
iOS APP配置HTTPS流程

iOS APP配置HTTPS流程

作者: 南南总是懒懒 | 来源:发表于2017-02-24 15:39 被阅读0次

    一.准备工作

    申请一个 SSL 证书 ,可在沃通WoSign网站申请所需SSL证书类型。SSL证书按验证的类别可分:

    DV SSL证书(域名验证型):只验证域名所有权,适合个人网站、博客等站点使用;

    OV SSL证书(企业验证型):验证网站所属单位身份,适合企业级用户使用;

    EV SSL证书(扩展验证型):扩展验证网站所属单位身份,这种证书在浏览器中会显示醒目的绿色地址栏,可信度最高,适合需要用户高度信任的企业级用户使用。

    根据域名数量和域名类型选择对应的证书。

    二.AFN配置HTTPS

    1.项目中的网络交互都是基于AFN,要求AFN版本在3.0及其以上;

    2.代码部分

    设置AFN请求管理者的时候 添加 https ssl 验证。

    // 1.获得请求管理者

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

    // 2.加上这个函数,https ssl 验证。

    [manager setSecurityPolicy:[self customSecurityPolicy]];

    // https ssl 验证函数

    - (AFSecurityPolicy *)customSecurityPolicy {

    // 先导入证书

    NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"xxx" ofType:@"cer"];//证书的路径

    NSData *cerData = [NSData dataWithContentsOfFile:cerPath];

    // AFSSLPinningModeCertificate 使用证书验证模式

    AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];

    // allowInvalidCertificates 是否允许无效证书(也就是自建的证书),默认为NO

    //validatesDomainName 是否需要验证域名,默认为YES;

    3.关于证书

    从沃通获取到HTTPS证书后,会得到一个有密码的压缩包文件,使用for other server里面的domain.crt的证书文件即可。

    三.后台服务器配置HTTPS证书(Ngnix)

    从沃通证书文件压缩包中,打开其中的for Nginx 文件可以看到 2 个文件,包括公钥、私钥。

    打开Nginx安装目录下conf目录中的nginx.conf文件找到

    #HTTPS server

    #

    #server {

    #    listen      443;

    #    server_name  localhost;

    #    ssl                  on;

    #    ssl_certificate    cert.pem;

    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;

    #    ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;

    #  ssl_prefer_server_ciphers  on;

    #    location / {

    #        root  html;

    #        index  index.html index.htm;

    #    }

    #}

    将其修改为 :

    server {

    listen      443;

    server_name  localhost;

    ssl                  on;

    ssl_certificate    sslkey/public.cer;      (证书公钥)

    ssl_certificate_key    sslkey/private.key;      (证书私钥)

    ssl_session_timeout  5m;

    ssl_protocols  TLSv1 TLSv1.1TLSv1.2;

    ssl_ciphers ECDH:AESGCM:HIGH:!RC4:!DH:!MD5:!aNULL:!eNULL;

    ssl_prefer_server_ciphers  on;

    location / {

    root  html;

    index  index.html index.htm;

    }

    }

    保存退出,并重启Nginx。

    由此转载http://jingyan.baidu.com/article/1709ad806d5eba4634c4f088.html

    相关文章

      网友评论

        本文标题:iOS APP配置HTTPS流程

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