这是一篇快速指南,使用 OpenSSL 来生成 CA ( 证书授权中心 )、 中级 CA 和 末端证书 。包括 OCSP、CRL 和 CA 颁发者 信息、具体颁发和失效日期。
我们将设置我们自己的 根 CA ,然后使用根 CA 生成一个示例的中级 CA,并使用中级 CA 签发最终用户证书。
根 CA
为根 CA 创建一个目录,并进入:
1 2 3
mkdir -p ~/SSLCA/root/ cd ~/SSLCA/root/
生成根 CA 的 8192 位长的 RSA 密钥:
1 2
openssl genrsa -out rootca.key 8192
输出类似如下:
1 2 3 4 5
Generating RSA private key, 8192 bit long modulus .........++ ....................................................................................................................++ e is 65537 (0x10001)
You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what iscalled a Distinguished Nameor a DN. There are quite a few fields but you can leave some blank Forsome fields there will be a defaultvalue, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:CN State or Province Name (fullname) [Some-State]:Beijing Locality Name (eg, city) []:Chaoyang dist. Organization Name (eg, company) [Internet Widgits Pty Ltd]:Linux.CN Organizational Unit Name (eg, section) []:Linux.CN CA Common Name (e.g. server FQDN or YOUR name) []:Linux.CN Root CA Email Address []:ca@linux.cn
You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what iscalled a Distinguished Nameor a DN. There are quite a few fields but you can leave some blank Forsome fields there will be a defaultvalue, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:CN State or Province Name (fullname) [Some-State]:Beijing Locality Name (eg, city) []:Chaoyang dist. Organization Name (eg, company) [Internet Widgits Pty Ltd]:Linux.CN Organizational Unit Name (eg, section) []:Linux.CN CA Common Name (e.g. server FQDN or YOUR name) []:Linux.CN Intermediate CA Email Address []:
Please enter the following'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []:
请确保中级 CA 的主题名(CN,Common Name)和根 CA 的不同。
使用根 CA 为你创建的中级 CA 的 CSR 签名:
1 2
openssl ca -batch -config ca.conf -notext -in intermediate1.csr -out intermediate1.crt
输出类似如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Using configuration from ca.conf Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows countryName :PRINTABLE:'CN' stateOrProvinceName :ASN.112:'Beijing' localityName :ASN.112:'chaoyang dist.' organizationName :ASN.112:'Linux.CN' organizationalUnitName:ASN.112:'Linux.CN CA' commonName :ASN.112:'Linux.CN Intermediate CA' Certificate is to be certified until Mar 3015:07:432017 GMT (730 days)
Write out database with 1 new entries Data Base Updated
You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what iscalled a Distinguished Nameor a DN. There are quite a few fields but you can leave some blank Forsome fields there will be a defaultvalue, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:CN State or Province Name (fullname) [Some-State]:Shanghai Locality Name (eg, city) []:Xuhui dist. Organization Name (eg, company) [Internet Widgits Pty Ltd]:Example Inc Organizational Unit Name (eg, section) []:IT Dept Common Name (e.g. server FQDN or YOUR name) []:example.com Email Address []:
Please enter the following'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []:
用1号中级 CA 签名最终用户的证书:
1 2 3
cd ~/SSLCA/intermediate1 openssl ca -batch -config ca.conf -notext -in ~/enduser-certs/enduser-example.com.csr -out ~/enduser-certs/enduser-example.com.crt
输出类似如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Using configuration from ca.conf Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows countryName :PRINTABLE:'CN' stateOrProvinceName :ASN.112:'Shanghai' localityName :ASN.112:'Xuhui dist.' organizationName :ASN.112:'Example Inc' organizationalUnitName:ASN.112:'IT Dept' commonName :ASN.112:'example.com' Certificate is to be certified until Mar 3015:18:262016 GMT (365 days)
Write out database with 1 new entries Data Base Updated
生成 CRL (包括 PEM 和 DER 两种格式):
1 2 3 4 5
cd ~/SSLCA/intermediate1/ openssl ca -config ca.conf -gencrl -keyfile intermediate1.key -cert intermediate1.crt -outintermediate1.crl.pem
openssl crl -inform PEM -inintermediate1.crl.pem -outform DER -outintermediate1.crl
每次使用该 CA 签名证书后都需要生成 CRL。
如果需要的话,你可以撤销revoke这个最终用户证书:
1 2 3
cd ~/SSLCA/intermediate1/ openssl ca -config ca.conf -revoke ~/enduser-certs/enduser-example.com.crt -keyfile intermediate1.key -cert intermediate1.crt
输出类似如下:
1 2 3 4
Usingconfigurationfrom ca.conf Revoking Certificate 1000. Data Base Updated