TLS 検証用の特定の CA 証明書を iOS 6 アプリケーションのキーチェーンに追加したいと考えています。証明書はアプリケーション バンドルに含まれています。いくつかの例で説明されているID (秘密鍵/証明書の組み合わせ)を追加したくありません。
このSecPKCS12Import
呼び出しはエラーを返しませんが、残念ながら証明書も返しません。
私の手順を再現できるように、例として Google 中間証明書 (「Google Internet Authority」) を取り上げ、ダウンロードした PEM 証明書に対して次のコマンドを実行しました。
.
#convert PEM certificate to PKCS12
openssl pkcs12 -export -in google.pem -nokeys -out google.p12 -passout "pass:google"
#verification
openssl pkcs12 -in google.p12 -passin "pass:google"
MAC verified OK
Bag Attributes: <No Attributes>
subject=/C=US/O=Google Inc/CN=Google Internet Authority
issuer=/C=US/O=Equifax/OU=Equifax Secure Certificate Authority
-----BEGIN CERTIFICATE-----
MIICsDCCAhmgAwIBAgIDFXfhMA0GCSqGSIb3DQEBBQUAME4xCzAJBgNVBAYTAlVT
MRAwDgYDVQQKEwdFcXVpZmF4MS0wKwYDVQQLEyRFcXVpZmF4IFNlY3VyZSBDZXJ0
[...]
ARlIjNvrPq86fpVg0NOTawALkSqOUMl3MynBQO+spR7EHcRbADQ/JemfTEh2Ycfl
vZqhEFBfurZkX0eTANq98ZvVfpg=
-----END CERTIFICATE-----
その後、次のコードが実行されたアプリケーションにファイルをバンドルしました。
NSMutableDictionary * options = [[[NSMutableDictionary alloc] init] autorelease];
[options setObject:@"google" forKey:(id)kSecImportExportPassphrase];
CFArrayRef items = NULL;
NSData *certData = [NSData dataWithContentsOfFile:[NSBundle pathForResource:@"google" ofType:@"p12" inDirectory:[[NSBundle mainBundle] bundlePath]]];
OSStatus result = SecPKCS12Import((CFDataRef)certData, (CFDictionaryRef)options, &items);
assert(result == errSecSuccess);
CFIndex count = CFArrayGetCount(items);
NSLog(@"Certificates found: %ld",count);
コンソールの結果出力は「Certificates found: 0」です。certData変数には正しいバイト数が入力され、提供されたパスワードを変更すると、結果がerrSecAuthFailedに変わります。
何が問題なのか分かりますか?