-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate.sh
executable file
·45 lines (40 loc) · 1.46 KB
/
generate.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
#!/usr/bin/env bash
rm -rf testfiles
mkdir -p testfiles
cd testfiles
# Generate a self signed certificate for the CA along with a key.
mkdir -p ca/private
chmod 700 ca/private
# NOTE: I'm using -nodes, this means that once anybody gets
# their hands on this particular key, they can become this CA.
openssl req \
-x509 \
-nodes \
-days 3650 \
-newkey rsa:4096 \
-keyout ca/private/ca_key.pem \
-out ca/ca_cert.pem \
-subj "/C=US/ST=Acme State/L=Acme City/O=Acme Inc./CN=example.com"
# Create server private key and certificate request
mkdir -p server/private
chmod 700 ca/private
openssl genrsa -out server/private/server_key.pem 4096
openssl req -new \
-key server/private/server_key.pem \
-out server/server.csr \
-subj "/C=US/ST=Acme State/L=Acme City/O=Acme Inc./CN=server.example.com"
# Create client private key and certificate request
mkdir -p client/private
chmod 700 client/private
openssl genrsa -out client/private/client_key.pem 4096
openssl req -new \
-key client/private/client_key.pem \
-out client/client.csr \
-subj "/C=US/ST=Acme State/L=Acme City/O=Acme Inc./CN=client.example.com"
# Generate certificates
openssl x509 -req -days 1460 -in server/server.csr \
-CA ca/ca_cert.pem -CAkey ca/private/ca_key.pem \
-CAcreateserial -out server/server_cert.pem
openssl x509 -req -days 1460 -in client/client.csr \
-CA ca/ca_cert.pem -CAkey ca/private/ca_key.pem \
-CAcreateserial -out client/client_cert.pem