簡體   English   中英

使用NSURLConnection的應用程序的iPhone自定義CA證書?

[英]iPhone Custom CA certificate for an application which uses NSURLConnection?

我有一個與許多不同站點通信的應用程序,每個站點都有自己的SSL證書,由我們自己的內部CA簽名。 這樣做可以防止我們為每個站點購買SSL證書(數百或數千),並且在每個站點上使用帶有共享密鑰的通配符證書時更安全。 因此,基本上使用CA證書是唯一的方法。

現在,我有一個mobileprovision文件,它將CA證書作為配置文件安裝在手機上。 如果我們的iPhone應用程序在獲得SSL證書錯誤時啟動,它將通過Safari重定向到此移動配置文件,系統將提示用戶安裝CA.

問題是我擔心Apple AppStore可能會拒絕我的應用程序(此時只是來自其他開發人員的一些反饋),我想研究其他方法來實現這一目標。

基本上我需要完成的是允許SSL連接,該連接將驗證將嵌入我的應用程序中的自定義CA證書。 這將使CA證書僅對我撥打的電話有效。 我使用標准的NSURLConnection方法來與服務進行通信。

這可能嗎? 有人可以告訴我如何加載CA(PEM的形式是什么?)並將其添加到我的應用程序的可信CA證書列表中? 如果那是不可能的,我還有其他選擇嗎? 只是信任所有證書並不是真正的選擇,我們希望防止中間人攻擊並且只信任我們的CA頒發的證書。

謝謝!

使用NSURLConnection的以下兩個委托方法訪問具有無效證書的任何站點

   - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
    {

            NSLog(@"canAuthenticateAgainstProtectionSpace");
        if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust]) {
            // Note: this is presently only called once per server (or URL?) until
            //       you restart the app
                NSLog(@"Authentication checking is doing");
            return YES; // Self-signed cert will be accepted
            // Note: it doesn't seem to matter what you return for a proper SSL cert
            //       only self-signed certs
        }
        return NO;
    }

    - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
    {
            NSLog(@"didReceiveAuthenticationChallenge");
        if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
        {
            [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
                NSLog(@"chalenging protection space authentication checking");
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM