这些是关于使用 OpenSSL 生成证书授权(CA)、中间证书授权和末端证书的速记随笔,内容包括 OCSP、CRL 和 CA 颁发者信息,以及指定颁发和有效期限等。
我们将建立我们自己的根 CA,我们将使用根 CA 来生成一个中间 CA 的例子,我们将使用中间 CA 来签署末端用户证书。
根 CA
创建根 CA 授权目录并切换到该目录:
1 2 3
mkdir ~/SSLCA/root/ cd ~/SSLCA/root/
为我们的根 CA 生成一个8192位长的 SHA-256 RSA 密钥:
1 2
openssl genrsa -aes256 -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]:NL State or Province Name (fullname) [Some-State]:Zuid Holland Locality Name (eg, city) []:Rotterdam Organization Name (eg, company) [Internet Widgits Pty Ltd]:Sparkling Network Organizational Unit Name (eg, section) []:Sparkling CA Common Name (e.g. server FQDN or YOUR name) []:Sparkling Root CA Email Address []:
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]:NL State or Province Name (fullname) [Some-State]:Zuid Holland Locality Name (eg, city) []:Rotterdam Organization Name (eg, company) [Internet Widgits Pty Ltd]:Sparkling Network Organizational Unit Name (eg, section) []:Sparkling CA Common Name (e.g. server FQDN or YOUR name) []:Sparkling 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)和根 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:'NL' stateOrProvinceName :ASN.112:'Zuid Holland' localityName :ASN.112:'Rotterdam' organizationName :ASN.112:'Sparkling Network' organizationalUnitName:ASN.112:'Sparkling CA' commonName :ASN.112:'Sparkling 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]:NL State or Province Name (fullname) [Some-State]:Noord Holland Locality Name (eg, city) []:Amsterdam 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 []:
使用中间 CA 签署末端用户的 CSR:
1 2
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:'NL' stateOrProvinceName :ASN.112:'Noord Holland' localityName :ASN.112:'Amsterdam' 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
enduser-certs/enduser-example.com.crt: CN = example.com, ST = Noord Holland, C = NL, O = Example Inc, OU = IT Dept error 23 at 0 depth lookup:certificate revoked