blob: 6f052115ccafa2aff20513f0e4e56909fbe7baaa [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001
2
3
4 How to setup your own Certificate Authority
5 ===========================================
6
7
8Note: this howto requires the openssl binary, as well as classic
9UNIX tools (cat, touch, echo). If you use Windows, please consider
10installing Cygwin -- see http://cygwin.com/
11
12
13 1. Configure OpenSSL
14 --------------------
15
16First of all, create sslconf.txt in the current directory
17(a basic example is provided at the end of this file).
18
19cat > sslconf.txt <<"EOF"
20[paste contents here]
21EOF
22
23Then you need to create the database and a starting serial number:
24
25touch index
26echo "01" > serial
27mkdir newcerts
28
29
30 2. Generate the CA certificate
31 ------------------------------
32
33openssl req -config sslconf.txt -days 3653 -x509 -newkey rsa:2048 \
34 -set_serial 0 -text -keyout test-ca.key -out test-ca.crt
35
36
37 3. Generate the private keys and certificate requests
38 -----------------------------------------------------
39
40openssl genrsa -out server1.key 2048
41openssl genrsa -out server2.key 2048
42openssl genrsa -out client1.key 2048
43openssl genrsa -out client2.key 2048
44
45openssl req -config sslconf.txt -new -key server1.key -out server1.req
46openssl req -config sslconf.txt -new -key server2.key -out server2.req
47openssl req -config sslconf.txt -new -key client1.key -out client1.req
48openssl req -config sslconf.txt -new -key client2.key -out client2.req
49
50
51 4. Issue and sign the certificates
52 ----------------------------------
53
54openssl ca -config sslconf.txt -in server1.req -out server1.crt
55openssl ca -config sslconf.txt -in server2.req -out server2.crt
56openssl ca -config sslconf.txt -in client1.req -out client1.crt
57openssl ca -config sslconf.txt -in client2.req -out client2.crt
58
59
60 5. To revoke a certificate and update the CRL
61 ---------------------------------------------
62
63openssl ca -config sslconf.txt -revoke server1.crt
64openssl ca -config sslconf.txt -revoke client1.crt
65openssl ca -config sslconf.txt -gencrl -out crl.pem
66
67
68 6. To display a certificate and verify its validity
69 ---------------------------------------------------
70
71openssl x509 -in server2.crt -text -noout
72cat test-ca.crt crl.pem > ca_crl.pem
73openssl verify -CAfile ca_crl.pem -crl_check server2.crt
74rm ca_crl.pem
75
76
77 7. To export a certificate into a .pfx file
78 -------------------------------------------
79
80openssl pkcs12 -export -in client2.crt -inkey client2.key \
81 -out client2.pfx
82
83
84##================================================================
85##============== Example OpenSSL configuration file ==============
86##================================================================
87
88# References:
89#
90# /etc/ssl/openssl.conf
91# http://www.openssl.org/docs/apps/config.html
92# http://www.openssl.org/docs/apps/x509v3_config.html
93
94[ ca ]
95default_ca = my_ca
96
97[ my_ca ]
98certificate = test-ca.crt
99private_key = test-ca.key
100database = index
101serial = serial
102
103new_certs_dir = newcerts
104default_crl_days = 60
105default_days = 730
106default_md = sha1
107policy = my_policy
108x509_extensions = v3_usr
109
110[ my_policy ]
111countryName = optional
112stateOrProvinceName = optional
113organizationName = match
114organizationalUnitName = optional
115commonName = supplied
116emailAddress = optional
117
118[ req ]
119distinguished_name = my_req_dn
120x509_extensions = v3_ca
121
122[ my_req_dn ]
123countryName = Country Name..............
124countryName_min = 2
125countryName_max = 2
126stateOrProvinceName = State or Province Name....
127localityName = Locality Name.............
1280.organizationName = Organization Name.........
129organizationalUnitName = Org. Unit Name............
130commonName = Common Name (required)....
131commonName_max = 64
132emailAddress = Email Address.............
133emailAddress_max = 64
134
135[ v3_ca ]
136basicConstraints = CA:TRUE
137subjectKeyIdentifier = hash
138authorityKeyIdentifier = keyid:always,issuer:always
139
140[ v3_usr ]
141basicConstraints = CA:FALSE
142subjectKeyIdentifier = hash
143authorityKeyIdentifier = keyid,issuer
144