生成ssl证书

http://blog.csdn.net/liuchunming033/article/details/48470575
https://segmentfault.com/a/1190000002569859
http://www.cnblogs.com/AloneSword/p/3809002.html

x509证书链

x509证书一般会用到三类文件,key,csr,crt。
Key是私用密钥,openssl格式,通常是rsa算法。
csr是证书请求文件,用于申请证书。在制作csr文件的时候,必须使用自己的私钥来签署申请,还可以设定一个密钥。
crt是CA认证后的证书文件(windows下面的csr,其实是crt),签署人用自己的key给你签署的凭证。

文件类型

.key格式:私有的密钥
.csr格式:证书签名请求(证书请求文件),含有公钥信息,certificate signing request的缩写
.crt格式:证书文件,certificate的缩写
.crl格式:证书吊销列表,Certificate Revocation List的缩写
.pem格式:用于导出,导入证书时候的证书的格式,有证书开头,结尾的格式
# 进入证书目录
cd /etc/pki/CA

# 生成CA私匙
openssl genrsa -out ca.key 2048

# 签发CA证书
openssl req -new -x509 -key ca.key -out ca.crt -days 3650

# 查看证书
openssl x509 -in ca.crt -text -noout

# 生成index.txt serial文件
touch serial index.txt
echo '01' > serial
# index.txt存放客户端证书信息 serial客户端证书编号

# 生成openldap服务器私匙
openssl genrsa -out openldap.key 2048  

# 生成openldap服务器请求签书证书
openssl req -new -key openldap.key -out openldap.csr -days 3650

# 签发openldap服务器证书  
openssl ca -cert ca.crt -keyfile ca.key -in openldap.csr -out openldap.crt -days 3650
[root@openldap-01 CA]# ll
total 44
-rw-r--r--  1 root root 1302 Sep 14 13:40 ca.crt
-rw-r--r--  1 root root 1675 Sep 14 13:17 ca.key
drwxr-xr-x. 2 root root    6 Jun 29  2015 certs
drwxr-xr-x. 2 root root    6 Jun 29  2015 crl
-rw-r--r--  1 root root   76 Sep 14 13:49 index.txt
-rw-r--r--  1 root root   21 Sep 14 13:49 index.txt.attr
-rw-r--r--  1 root root   21 Sep 14 13:42 index.txt.attr.old
-rw-r--r--  1 root root    0 Sep 14 13:49 index.txt.old
drwxr-xr-x. 2 root root   32 Sep 14 13:49 newcerts
-rw-r--r--  1 root root 4431 Sep 14 13:49 openldap.crt
-rw-r--r--  1 root root 1001 Sep 14 13:42 openldap.csr
-rw-r--r--  1 root root 1675 Sep 14 13:30 openldap.key
drwx------. 2 root root    6 Sep 14 13:17 private
-rw-r--r--  1 root root    3 Sep 14 13:49 serial
-rw-r--r--  1 root root    3 Sep 14 13:42 serial.old
原文地址:https://www.cnblogs.com/liujitao79/p/5848380.html