Skip to content

Instantly share code, notes, and snippets.

@able8
Created May 27, 2022 03:28
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 able8/104bf744138ef2e88461a0140a28667e to your computer and use it in GitHub Desktop.
Save able8/104bf744138ef2e88461a0140a28667e to your computer and use it in GitHub Desktop.
check SSL certificate and PGP key expiration date with shell
#!/bin/bash
# check TLS/SSL certificate expiration date
# openssl x509 -text -noout -in inputfile
# https://www.sslshopper.com/certificate-decoder.html
echo -e "\n## SSL Certificates List: \n\n| File Name | Valid From | Valid To | Comment |\n| --- | --- | --- | --- |" >> README.md
for file in $(find .); do
if test -f $file; then
if grep -q "\-BEGIN CERTIFICATE\-" $file; then
echo "checking: $file"
result=$(openssl x509 -text -noout -in $file)
validateFrom=$(echo "$result" | grep "Not Before" | sed "s/Not Before: //g")
validateTo=$(echo "$result" | grep "Not After" | sed "s/Not After : //g")
echo "| $file | $validateFrom | $validateTo | |" >> README.md
fi
fi
done
# Check PGP key expiration date
# gpg --show-keys inputFile
echo -e "\n## PGP Keys List: \n\n| File Name | Valid From | Valid To | Comment |\n| --- | --- | --- | --- |" >> README.md
for file in $(find .); do
if test -f $file; then
if grep -q "BEGIN PGP PUBLIC KEY BLOCK" $file; then
echo "checking: $file"
result=$(gpg --show-keys $file)
validateFrom=$(echo "$result" | awk '/pub/{print $3}')
validateTo=$(echo "$result" | awk '/pub/{print $5 $6}')
echo "| $file | $validateFrom | $validateTo | |" >> README.md
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment