Created
July 29, 2015 03:27
-
-
Save opragel/5b85354bcf3ce10b33f8 to your computer and use it in GitHub Desktop.
add_certificate_to_keychain_and_trust.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
KEYCHAIN_PATH="/Library/Keychains/System.keychain" | |
CERTIFICATE_CER_PATHS=( \ | |
"/private/tmp/my-certificate-1.cer" \ | |
"/private/tmp/my-certificate-2.cer" ) | |
for certificateCerPath in "${CERTIFICATE_CER_PATHS[@]}"; do | |
certificatePemPath="$certificateCerPath.pem" | |
openssl x509 -inform der -in "$certificateCerPath" -out "$certificatePemPath" | |
opensslVerifyResponse=$(openssl verify -CAfile "$certificatePemPath" "$certificatePemPath" | grep -o 'error.*at .*depth') | |
if [ "$opensslVerifyResponse" ]; then | |
security add-trusted-cert -d -r trustAsRoot -k "$KEYCHAIN_PATH" "$certificateCerPath" | |
else | |
security add-trusted-cert -d -r trustRoot -k "$KEYCHAIN_PATH" "$certificateCerPath" | |
fi | |
rm "$certificatePemPath" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment