1

MPMoviewPlayerController のドキュメントで見たものから、NSURLCredentialStorage は NSURLConnection 認証チャレンジの代替として設定できます (これは、URL からリソースをロードするが、NSURLConnection を抽象化し、認証を処理するためのデリゲートを提供しない高レベルのクラスに役立ちます)課題)。これは、ブラウザーに証明書をインストールし、特定のアドレスが要求したときに必要な証明書を自動的に選択することに似ているようです。

これをテストするために、独自の認証局、サーバー証明書、およびクライアント証明書 (.p12 ファイル) をセットアップしました。https サーバーをセットアップし、別のマシンからブラウザーを使用してクライアント証明書を正常にテストしました。

次に、証明書を iPhone アプリに統合する必要があります。

p12 ファイルをバンドルし、アプリケーションの起動時にこれを行います。

NSString *thePath = [[NSBundle mainBundle] pathForResource:@"clientside" ofType:@"p12"];
NSData *PKCS12Data = [[NSData alloc] initWithContentsOfFile:thePath];
CFDataRef inPKCS12Data = (CFDataRef)PKCS12Data;    
SecIdentityRef identity;
SecTrustRef trust;
extractIdentityAndTrust(inPKCS12Data, &identity, &trust);

SecCertificateRef certificate = NULL;
SecIdentityCopyCertificate (identity, &certificate); 

const void *certs[] = {certificate};
CFArrayRef certArray = CFArrayCreate(kCFAllocatorDefault, certs, 1, NULL);

NSURLCredential *credential = [NSURLCredential credentialWithIdentity:identity certificates:(NSArray*)certArray persistence:NSURLCredentialPersistencePermanent];

NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
                                         initWithHost: @"myhostname"
                                         port: 443
                                         protocol: @"https"
                                         realm: nil
                                         authenticationMethod: NSURLAuthenticationMethodClientCertificate];

[[NSURLCredentialStorage sharedCredentialStorage]
 setDefaultCredential: credential
 forProtectionSpace: protectionSpace];

extractIdentityAndTrust 関数は、'Certificate, Key, and Trust Services Tasks for iOS' ドキュメント ページから単純にコピーしたものです (証明書のパスワードを自分のものに置き換えただけです)。

私が知る限り、身元と証明書は適切にロードされています。NSURLCredential オブジェクトをコンソールに出力すると、次のような結果が得られます<NSURLCredential: 0x140ea0>: (null)(これが良い兆候かどうかはわかりません)。

ただし、 setDefaultCredential を実行すると、多くの情報を提供せずにアプリがクラッシュします。

スタックトレースは次のようになります。

#0  0x350a41c8 in CFHash
#1  0x3515180c in __CFBasicHashStandardHashKey
#2  0x351534e4 in ___CFBasicHashFindBucket_Linear
#3  0x350a4000 in CFBasicHashFindBucket
#4  0x350a3ecc in CFDictionaryGetValue
#5  0x344a0df2 in URLCredentialStorage::setDefaultCredentialForProtectionSpace
#6  0x3446a5aa in CFURLCredentialStorageSetDefaultCredentialForProtectionSpace
#7  0x339ec79e in -[NSURLCredentialStorage setDefaultCredential:forProtectionSpace:]
#8  0x00002612 in -[AVPlayerExampleViewController awakeFromNib] at AVPlayerExampleViewController.m:84

資格情報に何かが設定されていないように見えます。

これを解決する方法についてのアイデアはありますか?

編集:

テストのために、Mail からファイルを開いて iPhone に証明書をインストールしました。Safari 経由で https 経由でページにアクセスできますが、アプリ経由ではアクセスできません。

機能する唯一のことは、保護されたドメイン上の任意のリソースへの NSURLConnection を開き、didReceiveAuthenticationChallenge に応答することです (上記のコードとまったく同じように資格情報をロードし、NSURLAuthenticationChallenge の送信者に直接送信するだけです)。私は本当により高いレベルのクラスを使用する必要があります。

4

1 に答える 1

4

NSURLCredentialStorage がユーザー名とパスワードの NSURLCredentials に対してのみ機能することは既知の問題のようです (証明書はサポートされていません)。残念ながら、ドキュメントにはこれについて何も言及されていません。

于 2010-11-15T12:05:15.910 に答える