EA for checking if a certificate is installed.

ctangora
Contributor III

Thought I would share this incase anybody else needed to see if they had a certificate installed on the local machine. The variables can be set to look for a specific name of a variable and the location where it should be installed.

Tested on 10.9 & 10.8

#!/bin/bash
## Used to check for a certificate & it's location.

# VARIABLES
cert_name="certname"
desired_keychain="/Library/Keychains/System.keychain"


if [[ `security find-certificate -c "$cert_name" $desired_keychain 2>/dev/null` ]]; then
    echo "<result>Installed</result>"
else
    cert_search=`security find-certificate -c "$cert_name" 2>/dev/null | grep "keychain:" | awk -F """ '{ print $2 }' 2>/dev/null`
    if [[ $cert_search ]]; then
        echo "<result>Non-System Keychain: $cert_search</result>"
    else
        echo "<result>Not Found</result>"
    fi
fi

exit 0
2 REPLIES 2

waqas
New Contributor III

Thank, Chris.

Much respect to the beard :)

SaltyCornelius
New Contributor II

very useful!  many thanks!