4 How to setup your own Certificate Authority
\r
5 ===========================================
\r
8 Note: this howto requires the openssl binary, as well as classic
\r
9 UNIX tools (cat, touch, echo). If you use Windows, please consider
\r
10 installing Cygwin -- see http://cygwin.com/
\r
13 1. Configure OpenSSL
\r
14 --------------------
\r
16 First of all, create sslconf.txt in the current directory
\r
17 (a basic example is provided at the end of this file).
\r
19 cat > sslconf.txt <<"EOF"
\r
20 [paste contents here]
\r
23 Then you need to create the database and a starting serial number:
\r
30 2. Generate the CA certificate
\r
31 ------------------------------
\r
33 openssl req -config sslconf.txt -days 3653 -x509 -newkey rsa:2048 \
\r
34 -set_serial 0 -text -keyout test-ca.key -out test-ca.crt
\r
37 3. Generate the private keys and certificate requests
\r
38 -----------------------------------------------------
\r
40 openssl genrsa -out server1.key 2048
\r
41 openssl genrsa -out server2.key 2048
\r
42 openssl genrsa -out client1.key 2048
\r
43 openssl genrsa -out client2.key 2048
\r
45 openssl req -config sslconf.txt -new -key server1.key -out server1.req
\r
46 openssl req -config sslconf.txt -new -key server2.key -out server2.req
\r
47 openssl req -config sslconf.txt -new -key client1.key -out client1.req
\r
48 openssl req -config sslconf.txt -new -key client2.key -out client2.req
\r
51 4. Issue and sign the certificates
\r
52 ----------------------------------
\r
54 openssl ca -config sslconf.txt -in server1.req -out server1.crt
\r
55 openssl ca -config sslconf.txt -in server2.req -out server2.crt
\r
56 openssl ca -config sslconf.txt -in client1.req -out client1.crt
\r
57 openssl ca -config sslconf.txt -in client2.req -out client2.crt
\r
60 5. To revoke a certificate and update the CRL
\r
61 ---------------------------------------------
\r
63 openssl ca -config sslconf.txt -revoke server1.crt
\r
64 openssl ca -config sslconf.txt -revoke client1.crt
\r
65 openssl ca -config sslconf.txt -gencrl -out crl.pem
\r
68 6. To display a certificate and verify its validity
\r
69 ---------------------------------------------------
\r
71 openssl x509 -in server2.crt -text -noout
\r
72 cat test-ca.crt crl.pem > ca_crl.pem
\r
73 openssl verify -CAfile ca_crl.pem -crl_check server2.crt
\r
77 7. To export a certificate into a .pfx file
\r
78 -------------------------------------------
\r
80 openssl pkcs12 -export -in client2.crt -inkey client2.key \
\r
84 ##================================================================
\r
85 ##============== Example OpenSSL configuration file ==============
\r
86 ##================================================================
\r
90 # /etc/ssl/openssl.conf
\r
91 # http://www.openssl.org/docs/apps/config.html
\r
92 # http://www.openssl.org/docs/apps/x509v3_config.html
\r
98 certificate = test-ca.crt
\r
99 private_key = test-ca.key
\r
103 new_certs_dir = newcerts
\r
104 default_crl_days = 60
\r
108 x509_extensions = v3_usr
\r
111 countryName = optional
\r
112 stateOrProvinceName = optional
\r
113 organizationName = match
\r
114 organizationalUnitName = optional
\r
115 commonName = supplied
\r
116 emailAddress = optional
\r
119 distinguished_name = my_req_dn
\r
120 x509_extensions = v3_ca
\r
123 countryName = Country Name..............
\r
124 countryName_min = 2
\r
125 countryName_max = 2
\r
126 stateOrProvinceName = State or Province Name....
\r
127 localityName = Locality Name.............
\r
128 0.organizationName = Organization Name.........
\r
129 organizationalUnitName = Org. Unit Name............
\r
130 commonName = Common Name (required)....
\r
131 commonName_max = 64
\r
132 emailAddress = Email Address.............
\r
133 emailAddress_max = 64
\r
136 basicConstraints = CA:TRUE
\r
137 subjectKeyIdentifier = hash
\r
138 authorityKeyIdentifier = keyid:always,issuer:always
\r
141 basicConstraints = CA:FALSE
\r
142 subjectKeyIdentifier = hash
\r
143 authorityKeyIdentifier = keyid,issuer
\r