Skip to content

Instantly share code, notes, and snippets.

@trjh
Created March 11, 2022 12:20
Show Gist options
  • Select an option

  • Save trjh/fb523155a559bed4c3c769101da2e4c5 to your computer and use it in GitHub Desktop.

Select an option

Save trjh/fb523155a559bed4c3c769101da2e4c5 to your computer and use it in GitHub Desktop.
macaddcert.sh -- pull TLS cert from a URL and add it to trusted keystore
#!/bin/bash
# add the security certificate of a host to macos keychain
if [[ -z $1 ]]; then
echo USAGE: $0 hostname
exit
fi
host=$1
tmpfile=/tmp/${host}.pem
openssl x509 -in <(openssl s_client -connect ${host}:443 -prexit 2>/dev/null) > $tmpfile
if ! grep -q "END CERTIFICATE" $tmpfile; then
echo issue with openssl
exit
fi
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain $tmpfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment