SectRustevaluate()は、アプリケーションキーチェーンでルート証明書を探しますか?
質問
ドキュメントは次のように述べています。「リーフ証明書を確認するために必要なすべての証明書が信頼管理オブジェクトに含まれている場合、キーチェーン検索リスト(SectRustsetKeyChainsを参照)およびAnchor証明書のストア(SectRustStanchAthorcificatesを参照)の証明書の検索を検索します。 。」
ただし、iOSではsectRustSetKeyChains()は使用できないため、この関数がアプリケーションのキーチェーンでも表示されるかどうかは明らかではありません。
解決 3
Apple DevforumsのEskimo1はこれに答えたので:
- SectRustevaluate()は、アプリケーションキーチェーンでルート証明書を探しますか?
デフォルトではありません。ただし、キーチェーン(またはどこからでも)から証明書を取得し、SectRustSetanchOrCertificatesを使用してSectRustオブジェクトに適用することにより、これを実行するのは簡単です。
sectrustevaluation / will / keychainで中間証明書を見つけます。
他のヒント
あなたが投稿してからしばらく経っているように見えるので、まだ答えが必要かどうかはわかりません。あなたのユースケースが「私は打撃を受けています connection:didReceiveAuthenticationChallenge:
, 、そして私はそれを確認したいです ちょうど 証明書が評価されている場合、iOSビルトイントラストメソッドを使用するか、Foundation APIを介してもう少し作業を行うことができます。
#import <Security/Security.h>
#import <CommonCrypto/CommonDigest.h>
そこから、CERTの完全な配列を反復し、ChallengeのServer Trust ReferenceのSHA1のようなものと比較できます。
// way #1 - iOS built-in ================================================ //
SecTrustRef trust = challenge.protectionSpace.serverTrust;
CFIndex cnt = SecTrustGetCertificateCount(trust);
// way #2 - build it in yourself from a file ============================ //
OSErr err;
NSString *path = [[NSBundle mainBundle] pathForResource:@"my.cert"
ofType:@"der"];
NSData *derData = [NSData dataWithContentsOfFile:path];
SecCertificateRef myCert =
SecCertificateCreateWithData(NULL, (CFDataRef)derData);
CFMutableArrayRef array = CFArrayCreateMutable(NULL, 1, NULL);
CFArrayInsertValueAtIndex(array, 0, myCert);
err = SecTrustSetAnchorCertificates(trust, array);
if (err != errSecSuccess) {
// do something smarter here, obviously, logging would be a start
abort();
}
CFArrayRef certs = NULL;
err = SecTrustCopyCustomAnchorCertificates(trust, &certs);
if (err != errSecSuccess) {
// again, better choices needed
abort();
}
CFIndex cnt = CFArrayGetCount(certs);
// loop and compare 'em
for (int i = 0; i < cnt; i++) {
SecCertificateRef cert = SecTrustGetCertificateAtIndex(trust, i);
CFDataRef cdata = SecCertificateCopyData(cert);
NSData *data = [[NSData alloc] initWithData:(NSData *)cdata];
unsigned char digest_result[CC_SHA1_DIGEST_LENGTH];
CC_SHA1(data.bytes, data.length, digest_result);
// compare each byte with your in-code SHA1 bytes
if (allBytesMatch) {
NSURLCredential *cred = [NSURLCredential credentialForTrust:trust];
[challenge.sender useCredential:cred
forAuthenticationChallenge:challenge];
}
}
// don't forget to release & CFRelease all the alloc'ed stuff from above
それは今文書に書かれています:
注:この関数は、ユーザーのキーチェーン(またはiOSのアプリケーションキーチェーン)を検索しますが、中間証明書については、それらのキーチェーンがアンカー(root)証明書を検索しません。アンカー証明書を追加するには、SectRustSetanchOrCertificatesを呼び出す必要があります。
ソース: 文書化