-
Notifications
You must be signed in to change notification settings - Fork 17
/
new_client_cert.sh
73 lines (56 loc) · 1.19 KB
/
new_client_cert.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
#!/bin/bash
hr="-------------------------------------------"
br=""
strength=1024
valid=365
message="Usage: sh new_client_cert.sh [client_name@yourdomain.com]"
if [ $# -ne 1 ];
then
echo $message
exit 2
fi
if [ $1 = "--help" ];
then
echo $message
exit 2
fi
if [ ! -d ./user/ ];
then
echo "Creating User folder: user/"
mkdir ./user/
mkdir ./user/keys/
mkdir ./user/requests/
mkdir ./user/certificates/
mkdir ./user/p12/
fi
export OPENSSL_CONF=./conf/client_openssl.cnf
user=$1
uk=./user/keys/$user.key
ur=./user/requests/$user.csr
uc=./user/certificates/$user.crt
up=./user/p12/$user.p12
echo $br
echo $hr
echo "CREATING CLIENT KEY"
echo $hr
openssl genrsa -des3 -out $uk $strength
echo $br
echo $hr
echo "CREATING CLIENT CERTIFICATE REQUEST"
echo $hr
openssl req -new -key $uk -out $ur
echo $br
echo $hr
echo "CA SIGNING AND ISSUING CLIENT CERTIFICATE"
echo $hr
openssl x509 -req -in $ur -out $uc -CA ./ca/ca.crt -CAkey ./ca/ca.key -CAcreateserial -days $valid
echo $br
echo $hr
echo "CREATING A PKCS#12 CERTIFICATE FOR BROWSER"
echo $hr
openssl pkcs12 -export -clcerts -in $uc -inkey $uk -out $up
echo $br
echo $hr
echo "DUMPING CERTIFICATE TO CONSOLE"
echo $hr
openssl x509 -in $uc -text -noout