Created
March 11, 2022 12:20
-
-
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
This file contains hidden or 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 | |
| # 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