V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
andyL
V2EX  ›  iDev

**关于升级到 HTTPS 的讨论**

  •  1
     
  •   andyL ·
    lyleLH · 2016-12-13 16:50:40 +08:00 · 4725 次点击
    这是一个创建于 2662 天前的主题,其中的信息可能已经有所发展或是发生改变。

    背景

    服务端的老大看到 17 年 1 月 1 日 Apple 强制提审的 app 必须是 HTTPS 的安全连接的消息之后就开始准备替换到 HTTPS 环境了,这两天我们在测试环境着手升级。

    服务器端已经部署了 HTTPS 的测试环境

    我的网络基础并不好,只了解一些皮毛, iOS 这边我查了一些博文,获得了一些东拼西凑的知识点,同时发现很多博文的内容本身也是东拼西凑的

    实现

    现在我通过ATS 设置AFN 提供的安全设置

    • AFN 提供的安全设置
    	AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    	····
    	····
    	AFSecurityPolicy *securityPolicy = [AFSecurityPolicy defaultPolicy];
        securityPolicy.allowInvalidCertificates = YES;
        [manager setSecurityPolicy:securityPolicy];
        
    
    • ATS 设置
    <key>NSAppTransportSecurity</key>
    	<dict>
    		<key>NSAllowsArbitraryLoads</key>
    		<true/>
    		<key>NSExceptionDomains</key>
    		<dict>
    			<key>log.umsns.com</key>
    			<dict>
    				<key>NSIncludesSubdomains</key>
    				<true/>
    				<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
    				<true/>
    				<key>NSTemporaryExceptionMinimumTLSVersion</key>
    				<string>TLSv1.1</string>
    			</dict>
    			<key>sns.whalecloud.com</key>
    			<dict>
    				<key>NSIncludesSubdomains</key>
    				<true/>
    				<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
    				<true/>
    				<key>NSTemporaryExceptionMinimumTLSVersion</key>
    				<string>TLSv1.1</string>
    			</dict>
    			<key>qq.com</key>
    			<dict>
    				<key>NSIncludesSubdomains</key>
    				<true/>
    				<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
    				<true/>
    				<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
    				<false/>
    			</dict>
    			<key>sina.com.cn</key>
    			<dict>
    				<key>NSIncludesSubdomains</key>
    				<true/>
    				<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
    				<true/>
    				<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
    				<false/>
    			</dict>
    			<key>sinaimg.cn</key>
    			<dict>
    				<key>NSIncludesSubdomains</key>
    				<true/>
    				<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
    				<true/>
    				<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
    				<false/>
    			</dict>
    			<key>sinajs.cn</key>
    			<dict>
    				<key>NSIncludesSubdomains</key>
    				<true/>
    				<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
    				<true/>
    				<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
    				<false/>
    			</dict>
    			<key>sina.cn</key>
    			<dict>
    				<key>NSExceptionMinimumTLSVersion</key>
    				<string>TLSv1.0</string>
    				<key>NSIncludesSubdomains</key>
    				<true/>
    				<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
    				<false/>
    			</dict>
    			<key>weibo.cn</key>
    			<dict>
    				<key>NSExceptionMinimumTLSVersion</key>
    				<string>TLSv1.0</string>
    				<key>NSIncludesSubdomains</key>
    				<true/>
    				<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
    				<false/>
    			</dict>
    			<key>weibo.com</key>
    			<dict>
    				<key>NSExceptionMinimumTLSVersion</key>
    				<string>TLSv1.0</string>
    				<key>NSIncludesSubdomains</key>
    				<true/>
    				<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
    				<true/>
    				<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
    				<false/>
    			</dict>
    		</dict>
    

    结果

    iOS 端能正常发出 HTTPS 请求,测试的时候用 fiddle 和 Charles 等代理软件在不配置证书的情况下无法抓到 HTTPS 请求包内容,配置证书后才能看到明文的请求内容

    问题

    • 请问这样算是成功的升级到 HTTPS 了吗?
    • 如不是的话,满足苹果要求的 HTTPS 请求是什么样的呢?
    第 1 条附言  ·  2016-12-13 17:23:37 +08:00
    • 服务端使用的是腾讯云中申请的证书,免费版,但是属于非自建证书

    • 非自建证书,我本地的工程中没有导入该证书,所以没有和 Trust Object 进行对比的步骤

    • 目前 info.plist 文件中 NSAllowsArbitraryLoads 设置为 NO , HTTPS 请求也是可以成功的.(YES 也可以成功,据说设为 NO 是满足 Apple 要求的,设为 YES 就是允许 HTTP 请求)

    15 条回复    2016-12-21 13:48:16 +08:00
    andyL
        1
    andyL  
    OP
       2016-12-13 17:23:11 +08:00
    - 服务端使用的是腾讯云中申请的证书,免费版,但是属于非自建证书
    - 非自建证书,我本地的工程中没有导入该证书,所以没有和 Trust Object 进行对比的步骤
    - 目前 info.plist 文件中 NSAllowsArbitraryLoads 设置为 NO , HTTPS 请求也是可以成功的.(YES 也可以成功,据说设为 NO 是满足 Apple 要求的,设为 YES 就是允许 HTTP 请求)
    loveuqian
        2
    loveuqian  
       2016-12-13 17:40:20 +08:00
    我记得之前看到一个测试证书能否过 store 检核的测试网站
    好像是腾讯云的
    找不到了
    alex321
        3
    alex321  
       2016-12-13 17:43:49 +08:00   ❤️ 1
    caileijuve
        4
    caileijuve  
       2016-12-13 17:50:56 +08:00
    只要能通过 HTTPS 发送和请求到数据应该就可以了
    alex321
        5
    alex321  
       2016-12-13 17:51:45 +08:00
    @caileijuve 不行, ssl 协议版本有要求的。
    andyL
        6
    andyL  
    OP
       2016-12-13 17:52:06 +08:00
    @alex321 @loveuqian 这个检测我做过了,是通过了的。
    现在就是 iOS 客户端这边 这种做法不知道对不对
    alex321
        7
    alex321  
       2016-12-13 17:54:13 +08:00
    @andyL 等元旦吧。。这东西都是程序处理的,提交的时候如果有问题应该会有提示。
    andyL
        8
    andyL  
    OP
       2016-12-13 17:55:48 +08:00
    @alex321 确实, Apple 的审核标准目前并没有十分明确
    loveuqian
        9
    loveuqian  
       2016-12-13 17:58:10 +08:00
    @andyL
    不着急,我们的图片储存还没转到 HTTPS
    圣诞前再更一版,剩下的就看明年会怎么样了
    andyL
        10
    andyL  
    OP
       2016-12-13 18:02:08 +08:00
    @loveuqian 嗯,我们的图片存储也没有使用 HTTPS ,不过已经在弄了。
    814084764
        11
    814084764  
       2016-12-14 15:37:24 +08:00
    苹果的强迫症又发作了。
    ZernonHuang
        12
    ZernonHuang  
       2016-12-16 00:44:42 +08:00
    直接买一个受苹果信任的证书,客户端基本上不用做修改。
    andyL
        13
    andyL  
    OP
       2016-12-16 10:01:27 +08:00
    @ZernonHuang 是的,客户端只做了我提问中贴出的那些修改,以及 API 的 URL 前缀替换成带 HTTPS 的域名前缀。
    DingSoung
        14
    DingSoung  
       2016-12-20 19:07:27 +08:00
    HTTPS 好说,就是一些第三方 SDK 还得弄,比如微信 QQ 微博分享
    andyL
        15
    andyL  
    OP
       2016-12-21 13:48:16 +08:00
    @dingsoung 这些第三方的 SDK 已经全部更新过了,相信他们会跟进对 HTTPS 的支持的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1045 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 19:17 · PVG 03:17 · LAX 12:17 · JFK 15:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.