[問題] mac可以略過server端SSL的憑證檢查嗎?
大家好
小弟在測試一台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://www.ptt.cc/bbs/MacDev/M.1397092627.A.EC2.html
→
04/10 09:48, , 1F
04/10 09:48, 1F
喔喔 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
→
04/10 14:11, , 2F
04/10 14:11, 2F
→
04/10 15:52, , 3F
04/10 15:52, 3F
→
04/10 15:53, , 4F
04/10 15:53, 4F
→
04/10 15:53, , 5F
04/10 15:53, 5F
經過多次測試
用 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
→
04/18 12:04, , 6F
04/18 12:04, 6F
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章