-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_SSL_request.sh
executable file
·79 lines (75 loc) · 1.29 KB
/
create_SSL_request.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
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
#!/bin/bash
usage()
{
echo "Usage $0 -e 'user@host.com' -o 'organization name' -c 'Country code' -s 'State code' -l 'Locality' [-p 'key pass' -d '/path/to/desired/folder' -u 'organizational unit']"
exit
}
while getopts "u:e:o:c:s:l:p:d:h?" opt; do
case $opt in
e)
EMAIL="$OPTARG"
;;
o)
ORG="$OPTARG"
;;
c)
COUNTRY="$OPTARG"
;;
s)
STATE="$OPTARG"
;;
l)
LOC="$OPTARG"
;;
p)
PASS="$OPTARG"
;;
d)
DESTDIR="$OPTARG"
;;
u)
OU="/OU=$OPTARG"
;;
h)
usage
;;
?)
usage
;;
esac
done
shift $(($OPTIND -1))
DN=$1
echo "loc=$LOC
email=$EMAIL
org=$ORG
country=$COUNTRY
state=$STATE
destdir=$DESTDIR
ou=$OU
dn=$DN"
if [[ ! $LOC || ! $EMAIL || ! $ORG || ! $COUNTRY || ! $STATE || ! $DN ]]
then
usage
fi
if [[ ! $PASS ]]
then
PASS=`pwgen -n 24`
echo "passphrase is $PASS"
fi
if [[ ! $DESTDIR ]]
then
DESTDIR=$DN
fi
if [[ ! -e $DESTDIR ]]
then
echo "Creating dir $DESTDIR"
mkdir -p $DESTDIR
fi
pushd $DESTDIR
echo $PASS >> passphrase
openssl genrsa -aes256 -passout pass:$PASS -out ${DN}.encrypt.key 2048
openssl rsa -in ${DN}.encrypt.key -passin pass:$PASS -out ${DN}.key
openssl req -new -sha256 -key ${DN}.key -out ${DN}.csr -subj "/CN=${DN}/emailAddress=$EMAIL/O=$ORG/C=$COUNTRY/ST=$STATE/L=$LOC"
popd
cat ${DESTDIR}/${DN}.csr