openssl 配置文件:/etc/pki/tls/openssl.cnf
[root@localhost tmp]# cat /etc/pki/tls/openssl.cnf
该配置文件中以 “[配置段]”,的形式配置相关信息
====================openssl.cnf部分内容摘要=====================================
# OpenSSL example configuration file.
# This is mostly being used for generation of certificate requests.
######################################################################################
[ ca ] #CA相关配置段
default_ca = CA_default # The default ca section # 默认CA在[ CA_default ]配置
######################################################################################
[ CA_default ] # 默认当做CA的工作环境
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.颁发过的证书索引文件
new_certs_dir = $dir/newcerts # default place for new certs.
certificate = $dir/cacert.pem # The CA certificate指明CA的自签证书
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,CA自己的私钥
RANDFILE = $dir/private/.rand # private random number file
x509_extensions = usr_cert # The extentions to add to the cert
# Comment out the following two lines for the “traditional”
# (and highly broken) format.
name_opt = ca_default # Subject Name options
cert_opt = ca_default # Certificate field options
default_days = 365 # how long to certify for证书的默认有效期
default_crl_days= 30 # how long before next CRL默认声明有效期
default_md = sha256 # use SHA-256 by default默认的生成算法
preserve = no # keep passed DN ordering
####################################################################
[ req ] # 向CA证书签署发起注册请求相关属性
default_bits = 2048
default_md = sha256
default_keyfile = privkey.pem
distinguished_name = req_distinguished_name
attributes = req_attributes
x509_extensions = v3_ca # The extentions to add to the self signed cert
===============================================================================
openssl命令:
配置文件:/etc/pki/tls/openssl.cnf
构建私有CA:
1、在确定配置为CA的服务上生成一个自签证书,并为CA提供所需要的目录及文件即可;
步骤:
(1) 生成私钥;
# (umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 4096)
(2) 生成自签证书;
# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 3655
-new:生成新证书签署请求;
-x509:生成自签格式证书,专用于创建私有CA时;
-key:生成请求时用到的私有文件路径;
-out:生成的请求文件路径;如果自签操作将直接生成签署过的证书;
-days:证书的有效时长,单位是day;
(3) 为CA提供所需的目录及文件;
# mkdir -pv /etc/pki/CA/{certs,crl,newcerts}
# touch /etc/pki/CA/{serial,index.txt}
# echo 01 > /etc/pki/CA/serial
2、要用到证书进行安全通信的服务器,需要向CA请求签署证书:
步骤:(以httpd为例)
(1) 用到证书的主机生成私钥;
# mkdir /etc/httpd/ssl
# cd /etc/httpd/ssl
#(umask 077; openssl genrsa -out /etc/httpd/ssl/httpd.key 2048)
(2) 生成证书签署请求
#openssl req -new -key /etc/httpd/ssl/httpd.key -out /etc/httpd/ssl/httpd.csr -days 365
(3) 将请求通过可靠方式发送给CA主机;
(4) 在CA主机上签署证书;
# openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365
查看证书中的信息:
# openssl x509 -in /etc/pki/CA/certs/httpd.crt -noout -serial -subject
3、吊销证书:
步骤:
(1) 客户端获取要吊销的证书的serial(在使用证书的主机执行):
# openssl x509 -in /etc/pki/CA/certs/httpd.crt -noout -serial -subject
(2) CA主机吊销证书
先根据客户提交的serial和subject信息,对比其与本机数据库index.txt中存储的是否一致;
吊销:
# openssl ca -revoke /etc/pki/CA/newcerts/SERIAL.pem
其中的SERIAL要换成证书真正的序列号
(3) 生成吊销证书的吊销编号(第一次吊销证书时执行)
# echo 01 > /etc/pki/CA/crlnumber
(4) 更新证书吊销列表
# openssl ca -gencrl -out thisca.crl
查看crl文件:
# openssl crl -in /PATH/FROM/CRL_FILE.crl -noout -text