接上文  ,上文提到了ssl的基本概念,以及相关密钥,证书的基本知识

下面 我们看看在 Linux 下 怎么利用openssl做一个CA服务器。

1.需要在自己的机器上面生成一对密钥(包含私钥和公钥)

在 /etc/pki/CA 目录下

  1. # openssl genrsa -out cakey.pem 1024  //生成一个1024位的 私钥
  2. # openssl rsa -in  cakey.pem -pubout -out cakey.pbkey.pem
  3.  //利用这个私钥生成一个公钥

2.利用私钥为CA生成自签证书

  1. # openssl req -new -key cacert.pem -out /cakey.srt -days s650 -x509 

3.创建必备文件和文件夹

  1. # mkdir -pv certs crl newcerts  //创建必备文件夹
  2. # touch index.txt serial   //创建必备文件
  3. # echo 01 > serial  //定义其实序列号

4.修改配置文件

 

  1. # vim /etc/pki/tls/openssl.cnf   

客户端:

1.生成私钥

 

  1. # openssl genrsa -out http.pki.pem 1024  

2.生成签署请求

  1. # openssl req -new -key http.pem -out  http.csr //利用私钥生成请求
  2. Country Name (2 letter code) [GB]:ZZ  //输入国家名
  3. State or Province Name (full name) [Berkshire]:HN  //州(省)
  4. Locality Name (eg, city) [Newbury]:ZZ  //市
  5. Organization Name (eg, company) [My Company Ltd]:Linux  //公司
  6. Organizational Unit Name (eg, section) []:TEC  //部门
  7. Common Name (eg, your name or your server's hostname) []:ca.a.com
  8. //服务器地址,这个一定要与自己的服务器地址对应
  9. Email Address []:root@ca.com  
  10.  
  11. Please enter the following 'extra' attributes  
  12. to be sent with your certificate request  
  13. A challenge password []:  
  14. An optional company name []: 

3.把这个请求发送给CA服务器,利用CA签署

  1. # openssl  ca -in http.csr -out http.crt 

这样一个CA服务器就搭建成功了

住:利用openssl.cnf配置文件修改生成请求时的默认参数

  1. # vim /etc/pki/tls/openssl.cnf