首页 存档 技术 查看内容

基于OpenSSL自建CA和颁发SSL证书

2018-3-30 13:00 |来自: 互联网 543 0

摘要: “ 只推荐有价值的技术性文章 优才学院openssl是一个开源程序的套件、这个套件有三个部分组成:一是libcryto,这是一个具有通用功能的加密库,里面实现了众多的加密库;二是libssl,这个是实现ssl机制的,它是用于实 ...

只推荐有价值的技术性文章 优才学院

openssl是一个开源程序的套件、这个套件有三个部分组成:一是libcryto,这是一个具有通用功能的加密库,里面实现了众多的加密库;二是libssl,这个是实现ssl机制的,它是用于实现TLS/SSL的功能;三是openssl,是个多功能命令行工具,它可以实现加密解密,甚至还可以当CA来用,可以让你创建证书、吊销证书。

默认情况ubuntu和CentOS上都已安装好openssl。CentOS 6.x 上有关ssl证书的目录结构:


/etc/pki/CA/

newcerts 存放CA签署(颁发)过的数字证书(证书备份目录)

private 用于存放CA的私钥

crl 吊销的证书

/etc/pki/tls/

cert.pem 软链接到certs/ca-bundle.crt

certs/ 该服务器上的证书存放目录,可以房子自己的证书和内置证书

ca-bundle.crt 内置信任的证书

private 证书密钥存放目录

openssl.cnf openssl的CA主配置文件


  1. 颁发证书

1.1 修改CA的一些配置文件

CA要给别人颁发证书,首先自己得有一个作为根证书,我们得在一切工作之前修改好CA的配置文件、序列号、索引等等。

vi /etc/pki/tls/openssl.cnf


...

[ CA_default ]

dir = /etc/pki/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.

#unique_subject = no # Set to 'no' to allow creation of

# several ctificates with same subject.

new_certs_dir = $dir/newcerts # default place for new certs.

certificate = $dir/cacert.pem # The CA certificate

serial = $dir/serial # The current serial number

crlnumber = $dir/crlnumber # the current crl number

# must be commented out to leave a V1 CRL

crl = $dir/crl.pem # The current CRL

private_key = $dir/private/cakey.pem # The private key

RANDFILE = $dir/private/.rand # private random number file

...

default_days = 3650 # how long to certify for

...

# For the CA policy

[ policy_match ]

countryName = match

stateOrProvinceName = optional

localityName = optional

organizationName = optional

organizationalUnitName = optional

commonName = supplied

emailAddress = optional

...

[ req_distinguished_name ]

countryName = Country Name (2 letter code)

countryName_default = CN

countryName_min = 2

countryName_max = 2

stateOrProvinceName = State or Province Name (full name)

stateOrProvinceName_default = GD

...

[ req_distinguished_name ] 部分主要是颁证时一些默认的值,可以不动

一定要注意[ policy_match ]中的设定的匹配规则,是有可能因为证书使用的工具不一样,导致即使设置了csr中看起来有相同的countryName,stateOrProvinceName等,但在最终生成证书时依然报错:


Using configuration from /usr/lib/ssl/openssl.cnf

Check that the request matches the signature

Signature ok

The stateOrProvinceName field needed to be the same in the

CA certificate (GuangDong) and the request (GuangDong)

touch index.txt serial
在CA目录下创建两个初始文件:

1

2

# touch index.txt serial

# echo 01

声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

相关分类