Linux搭建CA服務

什麼是CA認證?算法

CA認證,即CA認證機構,爲電子簽名相關各方提供真實性、可靠性驗證的行爲。數據庫

什麼是CA證書?服務器

證書實際是由證書籤證機關(CA)簽發的對用戶的公鑰的認證。app

CA證書類型?dom

  • 證書頒發機構自簽名證書
  • 服務器證書
  • 用戶證書

Linux系統如何搭建CA服務?ide

1.安裝相關工具:openssl
yum install openssl -y
2.openssl相關配置文件:/etc/pki/tls/openssl.cnf
指定默認使用的CA工具

[ ca ]
default_ca      = CA_default            # The default ca section
CA的相關配置
[ CA_default ]
dir             = /etc/pki/CA               ​    ​    ​    ​# Where everything is kept,CA的工做目錄
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,當前吊銷證書編號

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,隨機文件

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

policy          = policy_match    ​    ​    ​    ​    ​    ​#選擇使用的策略類型
\# For the CA policy
[ policy_match ]    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​#第一種策略
countryName             = match    ​    ​    ​    ​     ​#是否匹配國家
stateOrProvinceName     = match    ​    ​    ​    #是否匹配省

organizationName        = match    ​    ​    ​    ​  #是否匹配組織名稱
organizationalUnitName  = optional    ​    ​   #是否單元名稱
commonName              = supplied    ​    ​    ​  #通用名
emailAddress            = optional    ​    ​    ​    ​   #郵箱

# For the 'anything' policy
# At this point in time, you must list all acceptable 'object'
# types.
[ policy_anything ]
countryName             = optional
stateOrProvinceName     = optional
localityName            = optional
organizationName        = optional
organizationalUnitName  = optional
commonName              = supplied
emailAddress            = optional

3.建立CAthis

(1)建立索引數據庫文件和指定證書編號 ​ ​ ​3d

touch /etc/pki/CA/index.txt
echo 01 >/etc/pki/CA/serial

(2)CA自簽名證書code

生成私鑰:

(umask 077;openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)

生成自簽名證書:

openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 365

Linux搭建CA服務
(3)客戶端建立申請文件
生成客戶端私鑰:

(umask 066;openssl genrsa -out app.key 1024)

生成申請文件:

openssl req -new -key app.key -out app.csr

Linux搭建CA服務
將生成的申請文件發送到CA頒發服務器

scp app.csr 192.168.128.130:/etc/pki/CA/

(4)CA服務器爲客戶端頒發證書

openssl ca -in app.csr -out certs/app.crt -days 100

Linux搭建CA服務
(5)將生成的證書發送給申請的客戶端

scp certs/app.crt 192.168.128.129:

證書吊銷
生成吊銷證書序號文件

echo 01 >crlnumber

吊銷證書

openssl ca -revoke /etc/pki/CA/newcerts/01.pem

生成吊銷列表

openssl ca -gencrl -out /etc/pki/CA/crl.pem

注意事項:1.必需要提早建立證書數據庫引導文件/etc/pki/CA/index.txt2.指定證書編號,證書頒發完成後會自動更新證書序號

相關文章
相關標籤/搜索