-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathx509client_process.sh
More file actions
executable file
·67 lines (58 loc) · 1.85 KB
/
x509client_process.sh
File metadata and controls
executable file
·67 lines (58 loc) · 1.85 KB
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
#!/bin/bash
SERVERNAME=mysecuredserver
CITY=Stockholm
REGION=Stockholm
COUNTRY_CODE=SE
KEY_SIZE=4096
# If you don't have openssl and need a way to
# generate passwords, flip these two lines.
# LC_ALL=C tr -dc A-Za-z0-9 < /dev/urandom | head -c32 > password_client
echo `openssl rand -base64 10` > password_client
export CLIENTPW=`cat password_client`
export CAPW=`cat password_server_$SERVERNAME`
# Create a JKS keystore that trusts the CA, with the default password.
keytool -import -v \
-alias $SERVERNAME\ca \
-file $SERVERNAME\ca.crt \
-keypass:env CLIENTPW \
-storepass:env CLIENTPW \
-keystore client.jks \
-noprompt
# Create another key pair that will act as the client.
keytool -genkeypair -v \
-alias client \
-keystore client.jks \
-dname "CN=client, OU=$SERVERNAME Dev, O=$SERVERNAME, L=$CITY, ST=$REGION, C=$COUNTRY_CODE" \
-keypass:env CLIENTPW \
-storepass:env CLIENTPW \
-keyalg RSA \
-keysize $KEY_SIZE
# Create a certificate signing request from the client certificate.
keytool -certreq -v \
-alias client \
-keypass:env CLIENTPW \
-storepass:env CLIENTPW \
-keystore client.jks \
-file client.csr
# Make the CA create a certificate chain saying that client is signed by the CA.
keytool -gencert -v \
-alias $SERVERNAME\ca \
-keypass:env CAPW \
-storepass:env CAPW \
-keystore $SERVERNAME\ca.jks \
-infile client.csr \
-outfile client.crt \
-ext EKU="clientAuth" \
-rfc
# Import the signed certificate back into client.jks. This is important, as JSSE won't send a client
# certificate if it can't find one signed by the ca presented in the CertificateRequest.
keytool -import -v \
-alias client \
-file client.crt \
-keystore client.jks \
-storetype JKS \
-storepass:env CLIENTPW
# List out the contents of client.jks just to confirm it.
keytool -list -v \
-keystore client.jks \
-storepass:env CLIENTPW