2.5.2. 设置您的 Own CA
要执行的子步骤
这部分论述了如何设置您自己的私有 CA。在为实际部署设置 CA 之前,请阅读 第 2.2.3 节 “私有证书颁发机构” 中的其他注释。
要设置您自己的 CA,请执行以下步骤:
在您的 PATH 中添加 bin 目录
在安全 CA 主机上,将 OpenSSL bin
目录添加到您的路径中:
Windows
> set PATH=OpenSSLDir\bin;%PATH%
UNIX
% PATH=OpenSSLDir/bin:$PATH; export PATH
此步骤使 openssl
实用程序可从命令行使用。
创建 CA 目录树
创建新目录 X509CA,以容纳新 CA。该目录用于保存与 CA 关联的所有文件。在 X509CA 目录下,创建以下目录层次结构:
|
|
|
|
复制并编辑 openssl.cnf 文件
将 OpenSSL 安装中的 openssl.cnf
示例复制到 X509CA 目录。
编辑 openssl.cnf
以反映 X509CA 目录的目录结构,并识别新 CA 使用的文件。
编辑 openssl.cnf
文件的 [CA_default]
部分,使其类似如下:
#############################################################
[ CA_default ]
dir = X509CA # Where CA files are kept
certs = $dir/certs # Where issued certs are kept
crl_dir = $dir/crl # Where the issued crl are kept
database = $dir/index.txt # Database index file
new_certs_dir = $dir/newcerts # Default place for new certs
certificate = $dir/ca/new_ca.pem # The CA certificate
serial = $dir/serial # The current serial number
crl = $dir/crl.pem # The current CRL
private_key = $dir/ca/new_ca_pk.pem # The private key
RANDFILE = $dir/ca/.rand
# Private random number file
x509_extensions = usr_cert # The extensions to add to the cert
...
此时您可以决定编辑 OpenSSL 配置的其他详情,请参阅 http://www.openssl.org/docs/。
初始化 CA 数据库
在 X509CA 目录中,初始化两个文件,串行
和 index.txt
。
Windows
要在 Windows 中初始化 串行
文件,请输入以下命令:
> echo 01 > serial
要创建空文件 index.txt
,在 Windows 的 X509CA 目录中从命令行启动 Windows Notepad,如下所示:
> notepad index.txt
为了响应带有文本的对话框,Cannot find text.txt 文件。您要创建新文件?
,点击 是,并关闭 Notepad。
UNIX
要在 UNIX 中初始化 串行
文件和 index.txt
文件,请输入以下命令:
% echo "01" > serial % touch index.txt
CA 使用这些文件来维护其证书文件数据库。
index.txt
文件最初必须完全为空,甚至不能包含空格。
创建自签名 CA 证书和私钥
openssl req -x509 -new -config X509CA/openssl.cnf -days 365 -out X509CA/ca/new_ca.pem -keyout X509CA/ca/new_ca_pk.pem
该命令提示您输入 CA 私钥的密码短语和 CA 可区分名称的详情。例如:
Using configuration from X509CA/openssl.cnf
Generating a 512 bit RSA private key
....++
.++
writing new private key to 'new_ca_pk.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. 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) []:IE
State or Province Name (full name) []:Co. Dublin
Locality Name (eg, city) []:Dublin
Organization Name (eg, company) []:Red Hat
Organizational Unit Name (eg, section) []:Finance
Common Name (eg, YOUR name) []:Gordon Brown
Email Address []:gbrown@redhat.com
CA 的安全性取决于私钥文件的安全性以及此步骤中使用的私钥密码短语。
您必须确保 CA 证书和私钥、new_ca.pem
和 new_ca_pk.pem
的文件名和位置与 openssl.cnf
中指定的值相同(请参阅前面的步骤)。
您现在已准备好使用您的 CA 签署证书。