作者donkeychen (Bad_To_The_Bone)
看板MacDev
标题[问题] mac可以略过server端SSL的凭证检查吗?
时间Thu Apr 10 09:17:05 2014
大家好
小弟在测试一台server
server端的SSL凭证因为还没申请过
所以先装假的凭证
如果用浏览器打https://网址 都会显示一个确认的页面
(chrome: 网站的安全性凭证不可靠)
(safari: safari无法验证 ...网站的识别身分)
目前遇到了两个问题 一个我靠改网址解决 另一个还没处理好
想跟大家请教有无绕道的方式
1.在SOAP方面
WSMethodInvocationCreate(网址, 方法, kWSSOAP2001Protocol)
如果网址给https:// 开头的
会取得 kCFStreamErrorDomainSSL 的错误
如果网址改成http://
就不用SSL了
2.有一个IBOutlet WebView
loadRequest 给的 NSURLRequest 无论用https:// 还是http://都不行
(由於该网址用浏览器 打http::// 都会被转成用https:// 不知道是否是因为这关系)
想请教一下是否有办法针对SSL的网址设定成不验证凭证的方式呢
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 210.59.147.226
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/MacDev/M.1397092627.A.EC2.html
1F:→ howdiun:willSendRequestForAuthenticationChallenge may help 04/10 09:48
喔喔 howdiun大大感谢
我刚查了一下
http://goo.gl/JMoaq0
这网页有人回答是实做这两个delegate
==============================================================================
- (BOOL)connection:(NSURLConnection *)connection
canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
return [protectionSpace.authenticationMethod
isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
[challenge.sender useCredential:[NSURLCredential
credentialForTrust:challenge.protectionSpace.serverTrust]
forAuthenticationChallenge:challenge];
[challenge.sender
continueWithoutCredentialForAuthenticationChallenge:challenge];
}
==============================================================================
如果针对用NSURLConnection的 应该我只要把这些拿来用
然後delegate:self 就可以
实测结果 有帮助 :) 一些用NSURLConnection的都正常了
只是对於
http://goo.gl/AJ0DXl
这种直接使用webview的我还是没有头绪
webview的class reference 网页
http://goo.gl/HYoqVq
找不着auth相关的东西>.<
※ 编辑: donkeychen (210.59.147.226), 04/10/2014 10:49:51
※ 编辑: donkeychen (210.59.147.226), 04/10/2014 12:00:50
2F:→ howdiun:用shouldStartLoadWithRequest抓给NSURLConnection读取 04/10 14:11
3F:→ donkeychen:大大我还没用 shouldStartLoadWithRequest 04/10 15:52
4F:→ donkeychen:只是光改NSURLConnection後 "有时"就可以了 04/10 15:53
5F:→ donkeychen:早上改完时还不能连 现在又可以 我确认看看^^; 谢谢唷 04/10 15:53
经过多次测试
用 NSURLRequest给WebView loadRequest时
真的是时而出现 时而失败
(失败时就是空白画面 成功就是有显示)
我找不到shouldStartLoadWithRequest的用法
在下面网址找到一个方式
http://goo.gl/8qz6B2
这边的解答的地方有注解
Please note: This API is currently unsupported, and should really only be
used in a safe testing environment. For further details, take a look at this
CocoaNetics article.
参考到
http://goo.gl/1gze29
但是我还是硬加 (下面红色的是多加的 没标色的是原本的code)
.h
=========================================================
@interface NSURLRequest (DummyInterface)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host;
+ (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host;
@end
.m
=========================================================
NSString* httpsURL = @"
https://__________";
NSURL* url = [NSURL URLWithString:httpsURL];
NSMutableURLRequest *request = [NSMultableURLRequest requestWithURL:url];
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
[myWebView loadRequest:request];
可以compile过
不知道是否为心理作用 目前为止都有显示
给大家参考
持续观察如果还是有失败会再来更新
谢谢
※ 编辑: donkeychen (210.59.147.226), 04/11/2014 14:59:30
※ 编辑: donkeychen (210.59.147.226), 04/11/2014 14:59:57
※ 编辑: donkeychen (210.59.147.226), 04/11/2014 15:00:30
※ 编辑: donkeychen (210.59.147.226), 04/11/2014 15:01:44
※ 编辑: donkeychen (210.59.147.226), 04/11/2014 15:02:23
6F:→ donkeychen:改这样後没有出问题...(目前为止) 04/18 12:04