接上文 ,上文提到了ssl的基本概念,以及相关密钥,证书的基本知识
下面 我们看看在 Linux 下 怎么利用openssl做一个CA服务器。
1.需要在自己的机器上面生成一对密钥(包含私钥和公钥)
在 /etc/pki/CA 目录下
- # openssl genrsa -out cakey.pem 1024 //生成一个1024位的 私钥
- # openssl rsa -in cakey.pem -pubout -out cakey.pbkey.pem
- //利用这个私钥生成一个公钥
2.利用私钥为CA生成自签证书
- # openssl req -new -key cacert.pem -out /cakey.srt -days s650 -x509
3.创建必备文件和文件夹
- # mkdir -pv certs crl newcerts //创建必备文件夹
- # touch index.txt serial //创建必备文件
- # echo 01 > serial //定义其实序列号
4.修改配置文件
- # vim /etc/pki/tls/openssl.cnf
客户端:
1.生成私钥
- # openssl genrsa -out http.pki.pem 1024
2.生成签署请求
- # openssl req -new -key http.pem -out http.csr //利用私钥生成请求
- Country Name (2 letter code) [GB]:ZZ //输入国家名
- State or Province Name (full name) [Berkshire]:HN //州(省)
- Locality Name (eg, city) [Newbury]:ZZ //市
- Organization Name (eg, company) [My Company Ltd]:Linux //公司
- Organizational Unit Name (eg, section) []:TEC //部门
- Common Name (eg, your name or your server's hostname) []:ca.a.com
- //服务器地址,这个一定要与自己的服务器地址对应
- Email Address []:root@ca.com
- Please enter the following 'extra' attributes
- to be sent with your certificate request
- A challenge password []:
- An optional company name []:
3.把这个请求发送给CA服务器,利用CA签署
- # openssl ca -in http.csr -out http.crt
这样一个CA服务器就搭建成功了
住:利用openssl.cnf配置文件修改生成请求时的默认参数
- # vim /etc/pki/tls/openssl.cnf