I´m maintaining a github project which aims at automating clean macOS installations, macOS customization (complete system preferences and more settings) and and updates to apps and the system.
https://github.com/tiiiecherle/osx_install_config
One of the script sets the preferences under system preferences - securtiy - privacy.
Every macOS app has a csreq which seems to be kind of a fingerprint / checksum for each app. Before macOS Mojave it was not needed to set the value explicitly and it was working to replace the csreq with a "?". For example allowing accessibility to the Terminal:
DATABASE_SYSTEM="/Library/Application Support/com.apple.TCC/TCC.db"
INPUT_SERVICE=kTCCServiceAccessibility
APP_ID=com.apple.Terminal
PERMISSION_GRANTED=1
APP_CSREQ=X'FADE0C000000003000000001000000060000000200000012636F6D2E6170706C652E5465726D696E616C000000000003'
### working, but no csreq
sudo sqlite3 "$DATABASE_SYSTEM" "REPLACE INTO access VALUES('"$INPUT_SERVICE"','"$APP_ID"',0,$PERMISSION_GRANTED,1,NULL,NULL,NULL,?,NULL,0,?);"
### working with csreq
sqlite3 "$DATABASE_USER" "REPLACE INTO access VALUES('"$INPUT_SERVICE"','"$APP_ID"',0,$PERMISSION_GRANTED,1,$APP_CSREQ,NULL,NULL,?,NULL,NULL,?);"
This still works, but macOS Mojave introduced some more security settings and for setting automation via command line correctly the csreqs of both apps, the automating, and the automated app, is needed, for example allowing Terminal to automate System Settings:
DATABASE_USER="/Users/"$USER"/Library/Application Support/com.apple.TCC/TCC.db"
SOURCE_APP_ID=com.apple.Terminal
SOURCE_APP_CSREQ=X'FADE0C000000003000000001000000060000000200000012636F6D2E6170706C652E5465726D696E616C000000000003'
PERMISSION_GRANTED=1
AUTOMATED_APP_ID=com.apple.systemevents
AUTOMATED_APP_CSREQ=X'FADE0C000000003400000001000000060000000200000016636F6D2E6170706C652E73797374656D6576656E7473000000000003'
sqlite3 "$DATABASE_USER" "REPLACE INTO access VALUES('kTCCServiceAppleEvents','"$SOURCE_APP_ID"',0,$PERMISSION_GRANTED,1,$SOURCE_APP_CSREQ,NULL,0,'"$AUTOMATED_APP_ID"',$AUTOMATED_APP_CSREQ,NULL,?);"
If the csreq is replaced with a questionmark "?", then the entry works, but does not show up in the GUI of the system preferences at all.
The System generates the csreq when you click allow when it asks for permissions and can be read from the database afterwards. To make correct entries via command line I would like to read / generate the correct csreq from the app on the command line without reading it from the tcc.db as it seems to change with every version of the app.
Thanks for any help in advance
Edit
A big thanks to Keith Johnson for the very good explanation and for solving the question for a big part. Following his answers I was able to implement the csreq in the new config file for my scripts.
https://github.com/tiiiecherle/osx_install_config/blob/master/_config_file/shellscriptsrc.sh
in the functions env_set_apps_security_permissions
and env_set_apps_automation_permissions
.
What I couldn't solve yet is getting the csreq for unsigned applets or droplets created with script editor or automator.
PATH_TO_APP="/Applications/brew_casks_update.app"
codesign --detached "$PATH_TO_APP".sig -s - "$PATH_TO_APP"
SOURCE_APP_CSREQ_STRING=$(codesign -d -r- --detached "$PATH_TO_APP".sig "$PATH_TO_APP")
echo "$SOURCE_APP_CSREQ_STRING" | csreq -r- -b /tmp/csreq.bin
Executable=/Applications/brew_casks_update.app/Contents/MacOS/applet error: invalid or corrupted code requirement(s) Requirement syntax error(s): line 2:1: unexpected end of file
If I add it manually and read the string from the database it has a valid csreq. The question would be fully solved if this could be figured out, too. That would be really nice.
Thanks