According to the documentation on SecTrustSettingsSetTrustSettings
"When making changes to per-user trust settings, the user is prompted with an alert panel asking for authentication (user name and password or other credentials normally used for login). Therefore, it is not possible to modify per-user trust settings when not running in a GUI environment (that is, when the user is not logged in via the login window). When making changes to system-wide trust settings, the user is prompted with an alert panel asking for an administrator’s name and password unless the calling process is running as root, in which case no further authentication is needed."
And under SecTrustSettings.h it says
* Trust Settings are configurable by the user; they can apply on three levels
* (called domains):
*
* -- Per-user.
* -- Locally administered, system-wide. Administrator privileges are required
* to make changes to this domain.
* -- System. These Trust Settings are immutable and comprise the set of trusted
* root certificates supplied in Mac OS X.
As we can see, kSecTrustSettingsDomainAdmin
is the "system-wide" options that we should be using in SecTrustSettingsSetTrustSettings
but when I run the following code, I get a GUI prompt regardless.
SecKeychainRef keychain;
SecKeychainCopyDomainDefault(kSecPreferencesDomainSystem, &keychain);
SecCertificateRef test = SecCertificateCreateWithData(NULL, certData);
SecCertificateAddToKeychain(test, keychain);
SecTrustSettingsSetTrustSettings(test, kSecTrustSettingsDomainAdmin, NULL);
I am running the project as root via the xcode scheme.