gpt4 book ai didi

iphone - 客户端证书 iOS

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:20:19 25 4
gpt4 key购买 nike

我正在尝试提取一个 .p12 文件并将其用于针对我自己的服务器的双向身份验证。当我尝试编译时出现一些链接错误。错误指的是:

  • _kSecImportExport密码
  • _SecIdentityCopyCertificate
  • _kSecImportItemTrust
  • _SecPKCS12Import
  • _kSecImportItemIdentity

这是我用来提取 p12 文件的代码:

        -(void)clientCert   
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"torbix" ofType:@"p12"];
NSData *p12data = [NSData dataWithContentsOfFile:path];
CFDataRef inP12data = (CFDataRef)p12data;

SecIdentityRef myIdentity;
SecTrustRef myTrust;
OSStatus status = extractIdentityAndTrust(inP12data, &myIdentity, &myTrust);

SecCertificateRef myCertificate;
SecIdentityCopyCertificate(myIdentity, &myCertificate);
const void *certs[] = { myCertificate };
CFArrayRef certsArray = CFArrayCreate(NULL, certs, 1, NULL);

}
OSStatus extractIdentityAndTrust(CFDataRef inP12data, SecIdentityRef *identity, SecTrustRef *trust)
{
OSStatus securityError = errSecSuccess;

CFStringRef password = CFSTR("password");
const void *keys[] = { kSecImportExportPassphrase };
const void *values[] = { password };

CFDictionaryRef options = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL);

CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL);
securityError = SecPKCS12Import(inP12data, options, &items);

if (securityError == 0) {
CFDictionaryRef myIdentityAndTrust = CFArrayGetValueAtIndex(items, 0);
const void *tempIdentity = NULL;
tempIdentity = CFDictionaryGetValue(myIdentityAndTrust, kSecImportItemIdentity);
*identity = (SecIdentityRef)tempIdentity;
const void *tempTrust = NULL;
tempTrust = CFDictionaryGetValue(myIdentityAndTrust, kSecImportItemTrust);
*trust = (SecTrustRef)tempTrust;
}

if (options) {
CFRelease(options);
}

return securityError;
}

为什么会出现这些错误?

最佳答案

Security.framework 添加到您的项目中。

在目标的 Xcode 4.2+ 中,转到“Build Phases”选项卡,“Link BinariesWith Libraries”,单击“+”并添加“Security.framework”。

enter image description here

关于iphone - 客户端证书 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8428895/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com