Hi,
I'm writing application which use NSURLSession for https communication. It was all good until I change my app to run as root (using sudo). It is failing on the connection (SSL Error) and I suspect the fault is that it is not able to validate the server certificate. I install the relevant root certificate in the system keychain (beside login) but it did not help.
What I should do for root user to be able to use the certificates in system keychain ?
b.t.w - I'm running on macOS BigSur
My plan is to run it as service (using
sudo launchctl load).
Yeah, that’s what I suspected.
Given that, testing your program from Terminal using sudo is not a good idea. The issue here is that sudo switches the traditional BSD context to root but does not switch the security context. This mixed environment can cause all sorts of weird problems, especially when it comes to Security framework stuff like the keychain.
For more background on this, see the Execution Contents section of Technote 2083 Daemons and Agents.
The take-home message here is that, when testing a launchd daemon, always test it by loading it into the global context using sudo launchctl.
I decided to delete the root certificate and install it again.
It’s possible that the first time you set the trust settings for this root certificate, you only set them for your user and not globally.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"