向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 13:09
下一篇 2018-05-19 15:29

相關推薦

  • linux關于grep 與 正則表達式的那些事

    首先要記住的是: 正則表達式與通配符不一樣,它們表示的含義并不相同! 正則表達式只是一種表示法,只要工具支持這種表示法, 那么該工具就可以處理正則表達式的字符串。vim、grep、awk 、sed 都支持正則表達式,也正是因為由于它們支持正則,才顯得它們強grep (縮寫來自Globally search a Regular Expression and P…

    2018-04-08
  • vi命令的用法大全

    Vi有三種基本的工作模式:指令行模式、文本輸入模式、行末模式。他們的相互關系如所示。 指令模式(Command Mode) 下輸入 a、i、o進入文本輸入模式(Input Mode) 文本輸入模式(Input Mode) 下按ESC進入指令模式(Command Mode) 指令模式(Command Mode)下輸入:進入末行模式(Last line Mode…

    Linux筆記 2018-05-03
  • N31第一周

    一、計算機的組成及其功能。 計算機是由運算器、控制器、存儲器、輸入設備、輸出設備五大部件組成,每一個部分分別按照要求執行特定的基本功能。 運算器:運算器的主要功能是對數據進行各種運算。 控制器:控制器是整個計算機系統的控制中心,它指揮計算機各部分協調地工作,保證計算機按照預先規定的目標和步驟有條不紊的進行操作及處理。 存儲器:存儲器的主要功能是存儲程序和各種…

    2018-06-19
  • selinux 和 awk的使用

    selinux 和 awk的使用

    Linux筆記 2018-05-15
  • if語句、for語句練習

    單分支之if語句 語法: if測試條件1;then arg1 … else arg2 … fi 多分支if語句   語法: if 測試條件1 ;then arg1 … elif 測試條件2 ;then arg2 … elif 測試條件3 ;then arg3 … else arg4 fi …

    2018-04-15
欧美性久久久久