一个由匹配证书公钥的私钥签名的证书称为 自签名 证书。根证书颁发机构 (Root certification authority,CA) 证书就属于这一类。用户证书通常是由不同的私钥签名的,如 CA 的私钥。这构成了两证书链。验证用户证书为真涉及验证其证书中的签名,这需要 CA 的公钥。但在在可以使用 CA 的公钥之前,需要对封装的 CA 证书进行验证。因为 CA 证书是自签名的,所以用 CA 公钥验证证书。
用户证书需要用根 CA 的私钥签名。它可以用一个中介的私钥签名,这个私钥的证书是用 CA 的私钥签名的。这是一个三证书链的例子:用户证书、中介证书和 CA 证书。但是在链中可以有多个中介,因此证书链可以有任意的长度。
创建根证书 CA shell 脚本使创建根证书成为一项相对轻易的工作。首先,进入要存放 CA 数据的目录。 (我使用 temp/OpenSSL 目录。) 然后键入:
CA -newca
这会产生一个像清单 1 的对话框,它包括我在提示符下输入的示例信息:
清单 1. 创建根证书
$ CA.sh -newca CA certificate filename (or enter to create)
Making CA certificate ... Using configuration from C:/PROGRA~1/MKSTOO~1/etc/openssl/openssl.cnf Loading 'screen' into random state - done Generating a 1024 bit RSA private key ......++++++ ...++++++ writing new private key to './demoCA/private/./cakey.pem' Enter PEM pass phrase: Verifying passWord - Enter PEM pass phrase: ----- 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 is called a Distinguished Name or a DN. You will see a number of fields, but you can leave some blank. For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:UK State or Province Name (full name) [Some-State]:Hampshire Locality Name (e.g., city) []:Winchester Organization Name (e.g., company) [Internet Widgits Pty Ltd]:IBM UK Ltd Organizational Unit Name (e.g., section) []:JTC Common Name (e.g., YOUR name) []:Pauls Root Certificate Email Address []:Paul_Abbott@uk.ibm.com $
Using configuration from C:/PROGRA~1/MKSTOO~1/etc/openssl/openssl.cnf Loading 'screen' into random state - done Generating a 1024 bit RSA private key ......................++++++ ...++++++ writing new private key to 'newreq.pem' Enter PEM pass phrase: Verifying password - Enter PEM pass phrase: ----- 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 is called a Distinguished Name or a DN. You will see a number of fields, but you can leave some blank. For some fields there will be a default value. If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:UK State or Province Name (full name) [Some-State]:Hampshire Locality Name (e.g., city) []:Winchester Organization Name (e.g., company) [Internet Widgits Pty Ltd]:IBM Uk Ltd Organizational Unit Name (e.g., section) []:JET Common Name (e.g., YOUR name) []:Paul Abbott Email Address []:Paul_H_Abbott@uk.ibm.com
Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:qwerty An optional company name []: Request (and private key) is in newreq.pem
对请求签名 执行 CA -sign 命令会用包含在 private/cakey.pem 中的根 CA 的私钥签名请求。请求需要在一个名为 newreq.pem 的文件中,生成的证书写入到名为 newcert.pem 的文件中,这两个文件都在当前目录中。清单 3 显示了示例请求-签名对话框。
清单 3. 示例 -sign 对话框
$ CA.sh -sign Using configuration from C:/PROGRA~1/MKSTOO~1/etc/openssl/openssl.cnf Loading 'screen' into random state - done Enter PEM pass phrase: Check that the request matches the signature Signature ok The Subjects Distinguished Name is as follows countryName :PRINTABLE:'UK' stateOrProvinceName :PRINTABLE:'Hampshire' localityName :PRINTAB