向CA申請證書

?實驗向CA申請證書

步驟:

  1. 建立Root CA

1)生成私鑰

2)自簽名證書

2.用戶或服務器

1)生成私鑰

2)生成證書申請文件

3)將申請文件發給CA

3.CA頒發證書

4.證書發送給客戶端

5.應用軟件使用證書

如:centos7當服務器,centos6客戶端 ,即centos6向centos7申請證書

第一:建立根CA

生成私鑰的文件放在哪,文件名叫啥,這不是能隨便寫的,它要求要配合CA搭建的一個重要配置文件,才能去實現,

/etc/pki/tls/openssl.cnf

1

1).創建私鑰文件 ,且必須放在private文件夾中,并且必須叫cakey.pem

[root@centos7 CA]# cd /etc/pki/CA

[root@centos7 CA]# ls

certs? crl? newcerts? private

[root@centos7 CA]# tree

.

├── certs

├── crl

├── newcerts

└── private

 

由上可看出,private文件夾已存在,所不用創建.

[root@centos7 CA]# (umask 077;openssl genrsa -out private/cakey.pem 4096)??? 析:加umask是為了安全,4096是指定私鑰位數,安全一點

[root@centos7 CA]# tree

.

├── certs

├── crl

├── newcerts

└── private

└── cakey.pem ??已生成。

2)給自己頒發證書:

[root@centos7 CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650

(國家,省,城市,公司名,部門,網站名,其它可不寫)

析:req是發申請,-new建立新申請,-x509表示自簽名證書,,-key私鑰文件private/cakey.pem ,-out 是從私鑰文件生成申請并自己給自己頒發證書生成文件,cacert.pem? ,-days是有效期是

[root@centos7 CA]# ls

cacert.pem ?certs? crl? newcerts? 2

[root@centos7 CA]# openssl x509 -in cacert.pem -noout –text? 用這個命令可以把它轉成普通文本查看內容,x509格式,-noout,-text不生成新文件只是在屏幕上顯示出來.,結果如下圖,可以看到,上步中所輸入的內容,國家,城市…..

2018-05-18_211423

[root@centos7 CA]# sz ?cacert.pem? 以widons圖形方式查看,在下載文件夾中,把后綴名pem 改成crt 。

打開后效果如下

2018-05-18_212406

但是雙擊會報錯。那就安裝證書

2018-05-18_212754

2018-05-18_212813

出現如下畫面則說明前面步驟是對的。

2018-05-18_212828

 

到控制面板的internet選項中,內容—-證書—–受信任的(下拉列表中可以看到剛magedu該證書沒有問題了)

自此第一大步結束?。?/strong>

第二步:從客戶端申請證書。centos6

假設這個服務是app服務,所以申請的證書給app應用程序來使用

  • 先生成私鑰:

[root@centos6 /data]$(umask 077;openssl genrsa -out app.key 1024 )

Generating RSA private key, 1024 bit long modulus

………………………++++++

………++++++

e is 65537 (0x10001)

析:文件名和目錄與CA的私鑰不能一樣。這里是放在當前/data下,叫pem或key后綴都可以.客戶端所以位數可以短點,這里只設置1024位。

2)利用私鑰文件來生成證書的申請文件:

[root@centos6 /data]$openssl req -new -key app.key -out app.csr

析:這里不用寫申請多少天,因為是頒發的說了算,這里也不用加-x509,因為這個是自簽名的意思。注意提交申請中,國家省公司名必須與CA中的一致。

[root@centos6 /data]$ls

app.csr? app.key

[root@centos6 /data]$scp app.csr 172.20.110.245 :/etc/pki/CA

回到centos7服務器上:開始審核用戶信息并頒發證書。頒發證書要用到/etc/pki/CA/index.tx?? /etc/pki/CA/serial這兩個文件,但現在這兩個文件還沒有,所以頒發證書時會報錯,如下

[root@centos7 CA]# openssl ca -in app.csr -out certs/app.crt -days 100

Using configuration from /etc/pki/tls/openssl.cnf

/etc/pki/CA/index.txt: No such file or directory

unable to open ‘/etc/pki/CA/index.txt’

139651304716176:error:02001002:system library:fopen:No such file or directory:bss_file.c:402:fopen(‘/etc/pki/CA/index.txt’,’r’)

139651304716176:error:20074002:BIO routines:FILE_CTRL:system lib:bss_file.c:404:

所以要先建index.txt文件。

[root@centos7 CA]# touch index.txt? 當頒發證書的時候它會自動把頒發完的結果,包括編號等信息寫到這個文件里。

[root@centos7 CA]# echo 0F > serial 指定編號隨便0F并創建文件serial

[root@centos7 CA]# cat serial

[root@centos7 CA]# openssl ca -in app.csr -out certs/app.crt -days 100確定確定

[root@centos7 CA]# ls

app.csr???? certs? index.txt?????? index.txt.old? private? serial.old

cacert.pem? crl??? index.txt.attr? newcerts?????? serial

[root@centos7 CA]# ll certs/app.crt? 這就是我們頒發的證書

-rw-r–r–. 1 root root 4966 May 18 22:25 certs/app.crt

[root@centos7 CA]# cat certs/app.crt

Certificate:

Data:

Version: 3 (0x2)

Serial Number: 15 (0xf)? 這個是編號不過轉成了10進制

Signature Algorithm: sha256WithRSAEncryption

Issuer: C=CN, ST=beijing, L=beijing, O=magedu, OU=M30, CN=www.magedu.com

Validity

Not Before: May 18 14:25:37 2018 GMT

Not After : Aug 26 14:25:37 2018 GMT

Subject: C=CN, ST=beijing, O=magedu, OU=M30, CN=app.magedu.com

Subject Public Key Info:

Public Key Algorithm: rsaEncryption

Public-Key: (1024 bit)

Modulus:

00:c2:cc:d0:df:cf:2d:25:bd:7a:5c:db:2c:ce:98:

[root@centos7 CA]# sz certs/app.crt 同樣可以傳到widow上查看。

3)將文件復制到客戶端就完事了。

[root@centos7 CA]# tree

.

├── app.csr

├── cacert.pem

├── certs

│?? └── app.crt

├── crl

├── index.txt? (這個文件會自動更新,它存放了給哪些證書頒發的狀態是什)

├── index.txt.attr

├── index.txt.old (這是之前的自動做奮份)

├── newcerts

│?? └── 0F.pem

├── private

│?? └── cakey.pem

├── serial

└── serial.old

[root@centos7 CA]# cat index.txt

V ??????180826142537Z?????????? 0F????? unknown /C=CN/ST=beijing/O=maged

[root@centos7 CA]# scp certs/app.crt 172.20.111.193:/data/

 

如何吊銷證書?

如果發現某證書有問題如何吊銷?如下,發現證書編號為10的有問題:[root@centos7 CA]# cat serial?? ?查看證書編號

10

[root@centos7 CA]# openssl ca -status 10?? 查看證書狀態

Using configuration from /etc/pki/tls/openssl.cnf

Serial 10 not present in db.

Error verifying serial 10!

1.[root@centos7 CA]# openssl? ca -revoke newcerts/0F.pem

Using configuration from /etc/pki/tls/openssl.cnf

Revoking Certificate 0F.

Data Base Updated

[root@centos7 CA]# cat index.txt

R (是吊銷狀態)????? 180826142537Z?? 180519013814Z?? 0F????? unknown /C=CN/ST=beijing/O=magedu/OU=M30/CN=app.magedu.com

[root@centos7 CA]# openssl ca -status 0F

Using configuration from /etc/pki/tls/openssl.cnf

0F=Revoked (R)

2.證書雖已吊銷,但得讓其它使用證書服務的人也知道這個證書吊銷了,即要發布到互聯網上。

1)發布到證書吊銷列表(CRL):但需要人為去創建吊銷列表文件,且它也需要一個證書列表的一個單獨的編號。且放在圖1 中那個文件夾下,/etc/pki/tls

[root@centos7 CA]# openssl ca -gnecrl -out crl.pem

析:-out是生成,這里的路徑一定要注意了。

[root@centos7 CA]# echo 20 > /etc/pki/CA/crlnumber

析:指定吊銷列表編號,可以隨便編

[root@centos7 CA]# openssl ca -gnecrl -out crl.pem

[root@centos7 CA]# cat crlnumber

20

 

本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/98845

(2)
單爆手單爆手
上一篇 2018-05-19
下一篇 2018-05-19

相關推薦

  • 腳本編程基礎環境設置

    ?程序:指令+數據?程序編程風格:過程式:以指令為中心,數據服務于指令對象式:以數據為中心,指令服務于數據?shell程序:提供了編程能力,解釋執行 ?計算機:運行二進制指令?編程語言:低級:匯編高級:編譯:高級語言–>編譯器–>目標代碼java,C#解釋:高級語言–>解釋器–>機器代碼…

    Linux筆記 2018-04-15
  • 第一周作業之:計算機的組成及其功能 | Linux發行版 | Linux哲學思想

    計算機組成 Linux發行版 Linux哲學思想

    2018-04-14
  • LAMP的實現

    php的兩種工作模式一種以模塊方式;一種以fcgi方式

    2018-06-23
  • Ansible使用介紹(一)基本概念及常用模塊

    隨著運維自動化經歷了從本地部署到基礎設施即服務(IaaS)、平臺即服務(PaaS)在到軟件即服務(SaaS)的發展階段,掌握多種自動化運維工具就成了運維人員必備技能之一,ansible就是目前國內使用比較廣泛的自動化運維工具之一。

    2018-05-29
  • linux 學習6

    1、簡述osi七層模型和TCP/IP五層模型 1、 osi七層模型 1、應用層:OSI 參考模型中最靠近用戶的一層,為計算機用戶提供應用接口,也為用戶直接提供各種網絡服務。我們常見應用層的網絡服務協議有:HTTP,HTTPS,FTP,POP3、SMTP等。 2、表示層:提供各種用于應用層數據的編碼和轉換功能,確保一個主機的應用層發送的數據能被另一個主機的應用…

    Linux筆記 2018-07-28
欧美性久久久久