Automate Trusting Certificates with AppleScript or Automator on macOS

applescriptautomatorkeychainmacos

I would like to know, if there is a way to make an Automator service or an Applescript that automatically trusts a root certificate. If possible without a prompt for password or Admin privileges. Could it be possible to do that maybe with tell application "Keychain Access"

or

do shell script "sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain <certificate>"

If possible without the sudo.

Best Answer

Undesirable Behaviour

There is no intended way to add trusted root certificates without requiring authorisation from the user or an administrator.

Any method that manages to add a trusted root certificate without confirming, at some stage, the credentials of the user would be considered a serious security bug.

What is the Risk?

Once a root certificate is trusted, it provides an automatic degree of trust for other certificates, applications, and content.

If a script, process, or tool could add trusted root certificates without authorisation, then it opens the possibly to perform malicious actions on a Mac – without the user knowing.