forked from mdscunningham/shell-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
certcheck.sh
executable file
·26 lines (22 loc) · 1.06 KB
/
certcheck.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
# +----+----+----+----+
# | | | | |
# Author: Mark David Scott Cunningham | M | D | S | C |
# +----+----+----+----+
# Created: 2017-06-27
# Updated: 2018-02-26
#
# Purpose: Check hashes of cert parts to confirm they match
#
HASH='md5'
case $1 in
md5|sha1|sha256|sha512) HASH=$1; echo -e "\nUsing $HASH method\n"; shift;;
-h|--help) echo -e "\nUsage: \n $0 [hash method] <certfile1> [<certfile2> <certfile3> ...]\n\n Valid Hash-Methods\n md5, sha1, sha256, sha512\n"; exit ;;
esac
for x in $@; do
case $x in
*.key) echo $(openssl rsa -noout -modulus -in $x | openssl $HASH | awk '{print $NF}') :: $(basename $x) ;;
*.csr) echo $(openssl req -noout -modulus -in $x | openssl $HASH | awk '{print $NF}') :: $(basename $x) ;;
*.crt) echo $(openssl x509 -noout -modulus -in $x | openssl $HASH | awk '{print $NF}') :: $(basename $x) ;;
esac
done