Skip to content

Instantly share code, notes, and snippets.

@ys-qb
Created December 12, 2024 13:42
Show Gist options
  • Save ys-qb/c4eee7fb677949f630adc17decdcb1a4 to your computer and use it in GitHub Desktop.
Save ys-qb/c4eee7fb677949f630adc17decdcb1a4 to your computer and use it in GitHub Desktop.
adding descriptions into the public cert
#!/bin/bash
ARG1=$1
META_ONLY=false
NL=$'\n'
if [ "$ARG1" = "-m" ]; then
META_ONLY=true
elif [ "$ARG1" = "-h" ]; then
echo "Usage: $0 -hm"
echo " -m: meta only without cert"
echo " -h: help"
exit -1
fi
while IFS= read -r line || [ -n "$line" ]; do
if echo $line | grep "BEGIN CERTIFICATE" >/dev/null; then
A_CERT=$line
continue
fi
A_CERT="${A_CERT}${NL}${line}"
if echo $line | grep "END CERTIFICATE" >/dev/null; then
META=$(openssl x509 -noout -nocert -subject -startdate -enddate -serial <<<"$A_CERT")
[ "$META_ONLY" = true ] && A_CERT=
[ -n "$OUTPUT" ] && OUTPUT="${OUTPUT}${NL}"
OUTPUT="${OUTPUT}${META}${NL}${A_CERT}"
fi
done
echo "$OUTPUT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment