Skip to content

Instantly share code, notes, and snippets.

@gene1wood
Last active April 30, 2024 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gene1wood/6530100 to your computer and use it in GitHub Desktop.
Save gene1wood/6530100 to your computer and use it in GitHub Desktop.
Tool to show cert, key or CSR information for a file or site
#!/bin/bash
if [ -z "$1" ];then
echo "Showing certificate from clipboard"
FILENAME=$(mktemp)
trap "{ rm -f $FILENAME; }" EXIT
xclip -o > $FILENAME
elif [ -e "$1" ]; then
echo "Showing certificate file $1"
FILENAME="$1"
elif [ "${1:0:5}" = "https" ]; then
echo "Showing certificate for URL $1"
curl --insecure -v $1 2>&1 | awk 'BEGIN { cert=0 } /^\* SSL connection/ { cert=1 } /^\*/ { if (cert) print }'
else
echo "Showing certificate for domain name $1"
echo -n | openssl s_client -connect $1:443 | openssl x509 -text
fi
if [ -n "$FILENAME" ]; then
if grep -- ' PRIVATE KEY-' "$FILENAME" >/dev/null; then
action=rsa
elif grep -- '-BEGIN CERTIFICATE REQUEST-' "$FILENAME" >/dev/null; then
action=req
elif grep -- '-BEGIN CERTIFICATE-' "$FILENAME" >/dev/null; then
action=x509
elif grep -- '-BEGIN TRUSTED CERTIFICATE-' "$FILENAME" >/dev/null; then
action=x509
else
action=unknown
fi
if [ "$action" = "unknown" ]; then
echo "Couldn't detect the file type of $FILENAME"
exit 1
fi
echo -n | openssl $action -in "$FILENAME" -noout -text
fi
@gene1wood
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment