gpt4 book ai didi

ios - 如何检查证书是否已安装并在 iOS 上受信任

转载 作者:行者123 更新时间:2023-12-03 20:47:53 26 4
gpt4 key购买 nike

我有一个应用程序,它提示用户下载并安装配置文件。该配置文件包含一个嵌入其中的根 CA。下载后,我想检查设备上是否安装了配置文件。
在浏览了 Apple Developer Forums 后,我意识到一种方法是检查嵌入在配置文件中的证书是否已安装并受到用户的信任。如果是,则隐式意味着(有异常(exception))配置文件是由用户安装的。
我经历了this link OP 有类似要求,但显然无法检测证书是否已安装。
有没有人有这样做的经验?

最佳答案

您不能使用 SecTrustEvaluateAsyncWithError识别证书是否已安装(受信任),例如:

// Load cert
guard let filePath = Bundle.main.path(forResource: "your_cert", ofType: "crt"),
let data = try? Data(contentsOf: URL(fileURLWithPath: filePath)),
let certificate = SecCertificateCreateWithData(nil, data as CFData)
else {
return
}

// Check
var secTrust: SecTrust?
if SecTrustCreateWithCertificates(certificate, SecPolicyCreateBasicX509(), &secTrust) == errSecSuccess, let trust = secTrust {
SecTrustEvaluateAsyncWithError(trust, .main) { trust, result, error in
print("Cert is", result ? "installed" : "not installed")
}
}

关于ios - 如何检查证书是否已安装并在 iOS 上受信任,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64737897/

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