Skip to main content
Question

EA for checking if a certificate is installed.

  • April 11, 2014
  • 2 replies
  • 12 views

Forum|alt.badge.img+10

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

Forum|alt.badge.img+7
  • Contributor
  • November 21, 2014

Thank, Chris.

Much respect to the beard :)


SaltyCornelius
Forum|alt.badge.img+1

very useful!  many thanks!