修改openssl的配置文件:
#vi /usr/local/openssl/ssl/openssl.cnf
修改的内容如下:
####################################################################
[ ca ] default_ca = CA_default # The default ca section
####################################################################
[ CA_default ]
dir = /opt/CA # Where everything is kept
certs = $dir/certs # Where the 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/private/CAcert.pem # The CA certificate
serial = $dir/serial # The current serial number
crl = $dir/clr/crl.pem # The current CRL
private_key = $dir/private/CAkey.pem # The private key
RANDFILE = $dir/private/.rand # private random number file
其它部分你可以根据自己实际情况修改,反正openssl.cnf的注释非常详细,呵呵
ok,下面我们开始建立证书
第四,根证书建立
根证书是整个数字证书的基石,非常重要,是由CA证书(CAcert.pem)和私钥(CAkey.pem)组成,建立方法如下:
#openssl req -new -x509 -keyout /opt/CA/private/CAkey.pem -out /opt/CA/CAcert.pem -config /usr/local/ssl/openssl.cnf
Using configuration from /usr/local/ssl/openssl.cnf
Generating a 1024 bit private key
writing new private key to '/opt/CA/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 incorperated
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) [CN]:CN
State or Province Name (full name) [MA]:GD
Locality Name (eg, city) [Cambridge]:FS
Organization Name (eg, company) [The Open Group]:donotry.net
Organizational Unit Name (eg, section) [Research Institute]:donotry.net
Common Name (eg, YOUR name) [example.opengroup.org]:donotry.net
Email Address []:xk.leng@gmail.com
以上就是你建立根证书时候需要输入的信息,你可以根据自己的实际情况来填写。输入的那个密码不要忘了。
此时,就已经建立好了根证书CAcert.pem和私钥CAkey.pem。
第五,服务器证书建立
服务器证书建立也不难,具体如下:
生成服务器私钥和证书请求
#openssl req -new -keyout serverKey.pem -out serverReq.pem -days 1825
此时也需要输入一系列的类似于建立根证书时候输入的信息,大家按照自己实际情况输入就ok了。
接下来,就要给签证了,如下:
#cat serverReq.pem serverKey.pem > server.pem
#openssl ca -policy policy_anything -out servercert.pem -infiles server.pem
Using configuration from /opt/www/lib/ssleay.cnf
Enter PEM pass phrase: 这个是你刚才建立服务器证书时候输入的密码
Check that the request matches the signature
Signature ok
The Subjects Distinguished Name is as follows
countryName RINTABLE:'CN'
stateOrProvinceName RINTABLE:'GD'
localityName RINTABLE:'FS'
organizationName RINTABLE:'donotry.net'
organizationalUnitNameRINTABLE:'donotry.net'
commonName RINTABLE:'donotry.net'
emailAddress :IA5STRING:'xk.leng@gmail.com'
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
这样,我们就有了服务器证书servercert.pem和私钥serverKey.pem