forked from redredgroovy/easy-ca
-
Notifications
You must be signed in to change notification settings - Fork 11
/
revoke-cert
executable file
·95 lines (77 loc) · 1.85 KB
/
revoke-cert
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# Derek Moore <derek.moore@gmail.com>
usage() {
echo "Usage: $0 -c CERT"
echo "Revokes a certificate issued by this CA"
echo
echo "Options:"
echo " -c CERT Path the the certificate file to be revoked"
echo
exit 2
}
CERT=
while getopts c: FLAG; do
case $FLAG in
c) CERT=${OPTARG} ;;
*) usage ;;
esac
done
if [ "${CERT}" == "" ]; then
usage
fi
BIN_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source ${BIN_DIR}/functions
source ${BIN_DIR}/defaults.conf
echo
echo "Revoking certificate '${CERT}'"
echo
if [ ! -f "${CERT}" ]; then
echo "Could not read certificate '${CERT}', exiting."
exit 1
fi
# Fully-qualify path to cert
CERT=$( fullpath ${CERT} )
pushd ${BIN_DIR}/.. > /dev/null
echo "Reason for revocation: "
echo
echo "1. unspecified"
echo "2. keyCompromise"
echo "3. CACompromise"
echo "4. affiliationChanged"
echo "5. superseded"
echo "6. cessationOfOperation"
echo "7. certificateHold"
echo
echo -n "Enter 1-7 [1]: "
read INDEX
[ -z "${INDEX}" ] && INDEX="1"
case $INDEX in
1) REASON="unspecified" ;;
2) REASON="keyCompromise" ;;
3) REASON="CACompromise" ;;
4) REASON="affiliationChanged" ;;
5) REASON="superseded" ;;
6) REASON="cessationOfOperation" ;;
7) REASON="certificateHold" ;;
8) echo "Unknown reason, exiting."; exit 1 ;;
esac
echo "You are about to revoke this certificate with reason '${REASON}'."
echo -n "Are you SURE you wish to continue? [y/N]: "
read SURE
if [ "${SURE}" != "y" -a "${SURE}" != "Y" ]; then
echo "Exiting."
exit 1
fi
# Revoke the certificate
openssl ca \
-config conf/ca.conf \
-revoke ${CERT} \
-crl_reason ${REASON}
# Regenerate the CRL
openssl ca -gencrl \
-config conf/ca.conf \
-out crl/ca.crl
popd > /dev/null
echo
echo "Server certificate revoked."
echo