Good morning!
Relatively new and inexperienced MAC admin, so please be gentle and feel free to talk to me like you're talking to a 5th grader!
In troubleshooting MDM communication with a large number of our Macs, the support tech I was working with suggested adding some EA's to assist in seeing what was going on. It definitely helped to identify and point us to a resolution, but one of them doesn't appear to be working the way I think it should? Note, that my background is mostly Windows enterprise, not any Bash, so I'm not sure exactly how to troubleshoot and resolve to get this particular EA to display what I want.
Here's what was provided:
#!/bin/bash
theIDs=$(security find-identity -v | awk '{print $3}' | tr -d '"' | grep -E '^[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}$')
echo "$theIDs"
if [ -z "$theIDs" ]; then
echo <result>"ERROR - No keychain identities matching a UUID found on this system.</result>"
exit 1
else
echo "At least one keychain identity found on this system, proceeding..."
fi
for i in $theIDs; do
info=$(security find-certificate -c "$i" | grep issu | awk '{print $4, $5, $6, $7}' | tr -d '"')
echo "$info"
if [[ "$info" == 'JSS BUILT-IN CERTIFICATE AUTHORITY' ]]; then
expiry=$(security find-certificate -c "$i" -p | openssl x509 -noout -enddate | cut -f2 -d"=")
echo "<result>$i;$expiry</result>"
exit 0
fi
done
echo "<result>ERROR - No keychain certificates matching an MDM profile were detected.</result>"
exit 1
So when I am parsing this out in my simple brain, I think it's:
1) Setting the environment to the Bash shell
2) Querying the security environment to get certificates, then it takes the 3rd value, which is a string, trims the quotes, and searches for values with the regular expression values (looking for a string with 8char-4char-4char-4char-12char. Displays that value.
3) If it doesn't find this certificate, then it displays an error.
4) Otherwise, it says it found at least one and proceeds.
5) Loops through as many certs as it found, pulls certain attributes, trims them, searches for the specific one related to MDM communication/identity and outputs the deets to the EA.
Problem: Even when pulled from machines that communicate correctly, this returns that there are no certificates found. I've tried running it (as is) in terminal on my test Mac, and it returns values for #1 and #2 above, but does NOT give me anything after that.
In searching through the forum, I found this, which looks similar, but has slight differences:
theIDs=$(security find-identity -v | awk '{print $3}' | tr -d '"' | grep -E '^[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}$')
if [[ -z "$theIDs" ]]
then
echo "<result>ERROR - No Keychain identities matching a UUID found on this system.</result>"
else
for i in $theIDs
do
info=$(security find-certificate -c "$i" | grep issu | awk '{print $6, $7, $8, $9}' | tr -d '"')
if [[ $info == *"BUILT-IN CERTIFICATE AUTHORITY"* ]]
then
expiry=$(security find-certificate -c "$i" -p | openssl x509 -noout -enddate | cut -f2 -d"=")
echo "<result>$theIDs + $expiry</result>"
fi
done
fi
Can anyone tell me what I'm doing wrong?
Thanks, and sorry for the long post!