I have a really weird issue and at this point I cannot determine is it a Big Sur 11.1 or M1 issue or just some macOS settings issue.
Short description
programatically (from node, electron) I'd like to store x509 cert to keychain. I got the following error message:
I could reproduce this issue on:SecTrustSettingsSetTrustSettings: The authorization was denied since no user interaction was possible. (1)
a brand new mac mini with M1 chip and Big Sur 11.1
another brand new mac mini with M1 chip and Big Sur 11.1
a 2018 MacBook pro with Intel chip and Big Sur 11.1
2020 MacBook pro with intel i9 chip and Big Sur 11.1
2020 MacBook pro with intel i9 chip and Big Sur 11.0
How am I trying to store the cert
Code Block bash node test.js
test.js
Code Block javascript const { exec } = require('child_process') exec( `osascript -e 'do shell script "security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain /Users/kotapeter/ssl/testsite.local.crt" with prompt "Test APP wants to store SSL certification to keychain." with administrator privileges'`, (error, stdout, stderr) => { if (error) { console.log(error.stack) console.log(`Error code: ${error.code}`) console.log(`Signal received: ${error.signal}`) } console.log(`STDOUT: ${stdout}`) console.log(`STDERR: ${stderr}`) process.exit(1) } )
testsite.local.crt:
Code Block text -----BEGIN CERTIFICATE----- MIIDUzCCAjugAwIBAgIUD9xMnL73y7fuida5TXgmklLswsowDQYJKoZIhvcNAQEL BQAwGTEXMBUGA1UEAwwOdGVzdHNpdGUubG9jYWwwHhcNMjEwMTE3MTExODU1WhcN NDEwMTEyMTExODU1WjAZMRcwFQYDVQQDDA50ZXN0c2l0ZS5sb2NhbDCCASIwDQYJ KoZIhvcNAQEBBQADggEPADCCAQoCggEBANM08SDi06dvnyU1A6//BeEFd8mXsOpD QCbYEHX/Pz4jqaBYwVjD5pG7FkvDeUKZnEVyrsofjZ4Y1WAT8jxPMUi+jDlgNTiF jPVc4rA6hcGX6b70HjsCACmc8bZd+EU7gm4b5eL6exTsVzHc+lFz4eQFXgutYTL7 guDQE/gFHwqPkLvnfg3rgY31p3Hm/snL8NuD154iE9O1WuSxEjik65uOQaewZmJ9 ejJEuuEhMA8O9dXveJ71TMV5lqA//svDxBu3zXI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kJfTSEswgBKlQFJImxVA+bgKsEwUti1aBaIA2vyIYWDeV10 G8hlUDlxvVkfwCJoy5zz6joGGO/REhqOkMbFRPseA50u2NQVuK5C+avUXdcILJHN zp0nC5eZpP1TC++uCboJxo5TIdbLL7GRwQfffgALRBpK12Vijs195cc= -----END RSA PRIVATE KEY-----
What I've already found
If I run the following command from terminal It asks my password first in terminal and after that It asks my password again in OS password prompt.
Code Block bash sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain /Users/kotapeter/ssl/testsite.local.crt
It looks like I'm getting the above error message because osascript hides the second password asking dialog.
The cert always gets stored in keychain but when I get the error message the cert "Trust" value is not "Always Trust".
References
StackOverflow question: https://stackoverflow.com/questions/65699160/electron-import-x509-cert-to-local-keychain-macos-the-authorization-was-deni
opened issue on sudo-prompt electron package: https://github.com/jorangreef/sudo-prompt/issues/137
I’m going to close out this thread. Lemme explain my rationale…
The primary issue being discussed here is installing a root certificate without explicit approval from the user such that it’s trusted system wide. There are two different cases:
- Doing this programmatically
- Doing this from Terminal or from a shell script
For the programmatic case, there’s no supported solution. This isn’t a bug but a deliberate security hardening, as I explained in this post.
For the Terminal and shell script case, DevForums isn’t the right place to have that discussion because:
- Our focus here is primarily on APIs, not device management.
- Many of the workarounds suggested on this thread rely on implementation details, which is counter to the forums’ focus on APIs.
If you want to continue exploring device management options, I encourage you to pop over to the Apple Support Community, run by Apple Support, and specifically the Business and Education topic area.
Finally, there’s one very clear path forward here: Install the root certificate as a com.apple.security.root
payload using MDM. If you’re in a managed environment, that’s super easy. If not in a managed environment, consider whether making that switch is warranted.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"