Last active
July 16, 2020 14:54
-
-
Save jijiechen/907f0600a25744e4dda518981ec388fb to your computer and use it in GitHub Desktop.
Trust ca cert on Linux based on hostname and port
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/sh | |
FULL_HOST=$1 | |
if [ -z "$FULL_HOST" ]; then | |
FULL_HOST=localhost:443 | |
fi | |
HOST=$(echo $FULL_HOST | cut -d ':' -f 1) | |
PORT=$(echo $FULL_HOST | cut -d ':' -f 2) | |
if [ "$HOST" = "$PORT" ]; then | |
PORT=443 | |
fi | |
mkdir /tmp/trusting-ca && openssl s_client -showcerts \ | |
-connect $HOST:$PORT -servername $HOST < /dev/null \ | |
| awk '/BEGIN/,/END/{ if(/BEGIN/){i++}; out="/tmp/trusting-ca/"i".crt"; print >out}' \ | |
&& mv /tmp/trusting-ca/$(ls /tmp/trusting-ca/ -1 | tail -1) /usr/local/share/ca-certificates/$HOST-ca.crt \ | |
&& rm -rf /tmp/trusting-ca | |
update-ca-certificates |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: