We have to remove an old cert from all the Macs. We have the hash, so can identify computers that have the old cert. The cert might exist in /Library/Keychains/System.keychain or /Users/username/Library/Keychains/login.keychain or etc.
In order to list the current logged in user's keychain(s), a script would have to capture the current logged in username, and then run with admin rights, to blast the old cert from either or both keychains.
#!/bin/sh
# Find current logged in username
USER=`/usr/bin/stat -f "%Su" /dev/console`
# Pull list of keychains
/usr/bin/security list-keychains > /private/tmp/"$USER"_keychains.txt
# Prune the list down to just paths
/bin/cat /private/tmp/"$USER"_keychains.txt | tr -d """ | tr -d " " > /private/tmp/"$USER"_keychains1.txt
# Loop through each keychain and remove Cross Root Cert if it exists and send errors to /dev/null
for keychain in $(/bin/cat /private/tmp/"$USER"_keychains1.txt)
do
/usr/bin/security delete-certificate -Z XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX $keychain 2>/dev/null
done
exit 0
Curious if it would be possible to to rework this script, so we can run the command once for the computer, looping through all users? Not familiar enough with the security command to know if that's possible. If possible, would make more sense than running for each user.
TIA,
Don
