下面列出的命令是我们经常使用的一些命令,但还有更多命令存在。查看 man 手册和文档以获取更多详细信息和信息。例如,我们将向您展示如何为您的 Apache Web 服务器和/或您自己的 CA 证书颁发机构创建证书,以便自行签署您的证书签名请求。
: 下面列出的所有命令都假定在/etc/ssl/目录下执行。
为您的 Apache 服务器创建一个受密码保护的 RSA 私钥。
[root@deep ]/ssl#openssl genrsa -des3 -out server.key 1024
|
Generating RSA private key, 1024 bit long modulus
......................+++++
.....+++++
e is 65537 (0x10001)
Enter PEM pass phrase:
Verifying password - Enter PEM pass phrase:
Please backup this server.key file and remember the pass-phrase you had to enter at a secure location.
|
使用服务器 RSA 私钥生成证书签名请求 CSR。
[root@deep ]/ssl# openssl req -new -key server.key -out server.csr
|
Using configuration from /etc/ssl/openssl.cnf
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.
There are quite a few 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) [CA]:
State or Province Name (full name) [Quebec]:
Locality Name (eg, city) [Montreal]:
Organization Name (eg, company) [Open Network Architecture]:
Organizational Unit Name (eg, section) [Internet Department]:
Common Name (eg, YOUR name) [www.openna.com]:
Email Address [admin@openna.com]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:.
An optional company name []:.
|
: 请确保在 OpenSSL 提示您输入CommonName(通用名称)时,输入服务器的 FQDN(完全限定域名),例如,当您为稍后通过https://www.mydomain.com/访问的网站生成 CSR 时,请输入www.mydomain.com在此处。
在生成证书签名请求;CSR 后,您有两个选择
第一个是将此证书发送给商业证书颁发机构 (CA),如 Verisign 或 Thawte 进行签名。您通常需要将 CSR 发布到 Web 表单中,支付签名费用,等待签名的证书并将其存储到server.crt文件中。结果是一个真正的证书,可以用于 Apache。
其次,您可以使用自己的 CA,现在必须通过此 CA 自己签署 CSR。此解决方案经济实惠,并允许组织托管自己的 CA 服务器并生成他们内部使用所需的任意数量的证书,而无需向商业 CA 支付任何费用。不幸的是,使用您自己的 CA 生成证书会在电子商务中引起问题,因为客户需要通过使用公认的商业 CA 对您的组织有一定的信任。
为您的 CA 创建 RSA 私钥。
[root@deep ]/ssl# openssl genrsa -des3 -out ca.key 1024
|
Generating RSA private key, 1024 bit long modulus
...........................+++++
............................................+++++
e is 65537 (0x10001)
Enter PEM pass phrase:
Verifying password - Enter PEM pass phrase:
Please backup this ca.key file and remember the pass-phrase you had to enter at a secure location.
|
创建自签名 CA 证书x509结构,使用 CA 的 RSA 密钥。
[root@deep ]/ssl# openssl req -new -x509 -days 365 -key ca.key -out ca.crt
|
Using configuration from /etc/ssl/openssl.cnf
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.
There are quite a few 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) [CA]:
State or Province Name (full name) [Quebec]:
Locality Name (eg, city) [Montreal]:
Organization Name (eg, company) [Open Network Architecture]:
Organizational Unit Name (eg, section) [Internet Department]:CA Marketing
Common Name (eg, YOUR name) [www.openna.com]:
Email Address [admin@openna.com]:
|
[root@deep ]/ssl# mv server.key private/
[root@deep ]/ssl# mv ca.key private/
[root@deep ]/ssl# mv ca.crt certs/
|
: 当使用-x509开关时,req 命令会创建自签名证书。
签署证书请求。我们创建并使用我们自己的证书颁发机构 - CA,准备用于签名的脚本,这是必需的,因为 openssl ca 命令有一些奇怪的要求,并且默认的 OpenSSL 配置不允许轻松地直接使用 openssl ca。名为sign.sh的脚本与软盘一起分发在 openssl 目录下。使用此脚本进行签名。现在,您可以利用此 CA 签署服务器 CSR,以便为 Apache Web 服务器创建真正的 SSL 证书,假设您已经手头有一个 server.csr
[root@deep ]/ssl# /usr/bin/sign.sh server.csr
|
CA signing: server.csr -> server.crt:
Using configuration from ca.config
Enter PEM pass phrase:
Check that the request matches the signature
Signature ok
The Subjects Distinguished Name is as follows
countryName :PRINTABLE:'CA'
stateOrProvinceName :PRINTABLE:'Quebec'
localityName :PRINTABLE:'Montreal'
organizationName :PRINTABLE:'Open Network Architecture'
organizationalUnitName :PRINTABLE:'Internet Department'
commonName :PRINTABLE:'www.openna.com'
emailAddress :IA5STRING:'admin@openna.com'
Certificate is to be certified until Dec 1 14:59:29 2000 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
CA verifying: server.crt <-> CA cert
server.crt: OK
|
这将签署 CSR 并生成 server.crt 文件。
[root@deep ]/ssl# mv server.crt certs/
|
SSLCertificateFile /etc/ssl/certs/server.crt |
[root@deep ]/ssl# rm -f server.csr
|
: 如果您在证书签名期间收到错误消息,则可能是因为当 OpenSSL 提示您输入CommonName(通用名称); 时,您为服务器输入了错误的 FQDN(完全限定域名)CommonName(通用名称)必须类似于my.domain.com而不是domain.com。此外,由于您同时生成证书和 CA 证书,因此至少有一条信息在两个文件之间有所不同很重要,否则您可能会在证书请求签名期间遇到问题。