Skip to content

Instantly share code, notes, and snippets.

@hatemzidi
Last active June 17, 2019 15:59
Show Gist options
  • Save hatemzidi/a7468c8f1ae7c6773e93cf62dfe83d41 to your computer and use it in GitHub Desktop.
Save hatemzidi/a7468c8f1ae7c6773e93cf62dfe83d41 to your computer and use it in GitHub Desktop.
# https://unix.stackexchange.com/a/487546
openssl s_client -showcerts -verify 5 -connect $HOST:$PORT < /dev/null | awk '/BEGIN/,/END/{ if(/BEGIN/){a++}; out="cert"a".crt"; print >out}' && for cert in *.crt; do newname=$(openssl x509 -noout -subject -in $cert | sed -n 's/^.*CN=\(.*\)$/\1/; s/[ ,.*]/_/g; s/__/_/g; s/^_//g;p').pem; mv $cert $newname; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment