Last active
September 23, 2021 10:39
-
-
Save chen-hongzhi/5719035 to your computer and use it in GitHub Desktop.
Add self-signed CA certificate to the system's keychain and make it trusted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SecCertificateRef cert = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)certData); | |
| status = SecCertificateAddToKeychain(cert, keychain); | |
| if (status == errSecDuplicateItem) { | |
| status = errSecSuccess; | |
| } | |
| if (status == errSecSuccess) { | |
| int allowErr = -2147409654; | |
| SecPolicyRef x509Policy = SecPolicyCreateBasicX509(); | |
| NSDictionary *x509Settings = @{ | |
| (id)kSecTrustSettingsPolicy : (__bridge id)x509Policy, | |
| (id)kSecTrustSettingsAllowedError : @(allowErr), | |
| (id)kSecTrustSettingsResult : @(kSecTrustSettingsResultTrustRoot) | |
| }; | |
| NSDictionary *otherSettings = @{ | |
| (id)kSecTrustSettingsAllowedError : @(allowErr), | |
| (id)kSecTrustSettingsResult : @(kSecTrustSettingsResultTrustRoot) | |
| }; | |
| CFArrayRef trustSettings = (__bridge CFArrayRef)@[x509Settings, otherSettings]; | |
| status = SecTrustSettingsSetTrustSettings(cert, kSecTrustSettingsDomainUser, trustSettings); | |
| CFRelease(x509Policy); | |
| } | |
| CFRelease(cert); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
has
secTrustSettingsSetTrustSettingsandkSecTrustSettingsDomainUserbeen deprecated in new versions? they don't seem to be recognized in my code although they are in Apple documentation.