2020-06-22 openssl 私有CA證書頒發(fā)搭建

1 建立CA

[root@centos7localdomain ~]# cd /etc/pki/CA
[root@centos7localdomain CA]# (umask 077;openssl genrsa -out private/cakey.pem 4096)   #生成秘鑰文件 私鑰
Generating RSA private key, 4096 bit long modulus
...........................................++
...................................++
e is 65537 (0x10001)
[root@centos7localdomain CA]# tree
.
├── certs
├── crl
├── newcerts
└── private
    └── cakey.pem   私鑰
[root@centos7localdomain CA]# openssl req -new -x509 -key private/cakey.pem -out /etc/pki/CA/cacert.pem -days 3650 <<EOF
> cn                                  國家   #必須一致                                x509 自發(fā)簽證使用       -days 3650證書天數(shù) 默認一年                                                                           
> shanghai                       省份   #必須一致 
> shanghai                       城市
> et                                   公司   #必須一致 
> it                                    部門
> ca.et.com                      網(wǎng)址
> admin@qq.com            郵箱
> EOF
[root@centos7localdomain CA]# openssl x509 -in cacert.pem -noout -text   #查看證書內(nèi)容
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            db:11:ab:ab:44:97:96:14
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: C=cn, ST=shanghai, L=shanghai, O=et, OU=it, CN=ca.et.com/emailAddress=admin@qq.com
        Validity
            Not Before: Jun 22 01:25:48 2020 GMT
            Not After : Jun 20 01:25:48 2030 GMT
        Subject: C=cn, ST=shanghai, L=shanghai, O=et, OU=it, CN=ca.et.com/emailAddress=admin@qq.com
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (4096 bit)
                Modulus:
                    00:db:83:1f:0f:bd:22:01:35:dc:9c:3a:0e:dd:c6:
                    c7:65:54:b8:7d:b9:df:b5:39:e8:89:07:ad:80:e6:
                    18:10:fd:db:3b:cc:1e:c9:9f:89:0f:ec:c3:f8:15:
                    44:1a:69:a8:79:62:5b:86:46:43:fe:6f:94:c9:f4:
                    0f:3e:9a:f8:2d:ec:a9:9e:05:d7:70:5c:a5:a0:3d:
                    4b:e5:b1:a7:8a:7f:ab:e5:5d:bc:92:dc:4f:a6:73:
                    a6:09:76:2f:6c:d0:d3:b0:2e:1b:19:c2:e1:04:69:
                    3f:2d:87:07:8a:de:4c:80:04:c6:d1:c4:2d:b2:e8:
                    74:c1:3e:ba:e6:46:7a:99:68:d0:0e:25:72:ee:30:
                    52:13:10:9c:02:76:d4:c3:fc:57:0e:ad:56:d5:25:
                    98:d7:7a:82:31:53:63:90:8c:45:8d:96:c4:17:d2:

4 directories, 1 file
[root@centos7localdomain CA]# tree
.
├── cacert.pem  公鑰
├── certs
├── crl
├── newcerts
└── private
    └── cakey.pem  私鑰

4 directories, 2 files
[root@centos7localdomain CA]#touch /etc/pki/CA/index.txt
[root@centos7localdomain CA]#echo 0F > /etc/pki/CA/serial

2 申請

[root@localhost app]# (umask066;openssl genrsa -out app.key 2048) 用戶生成私鑰
bash: umask066: command not found...
Generating RSA private key, 2048 bit long modulus
..........................................+++
...................................+++
e is 65537 (0x10001)
[root@localhost app]# ls
app.key
[root@localhost app]#  openssl req -new  -key app.key -out app.csr  利用私鑰生成公鑰
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:shanghai
Locality Name (eg, city) [Default City]:shanghai
Organization Name (eg, company) [Default Company Ltd]:et
Organizational Unit Name (eg, section) []:fn
Common Name (eg, your name or your server's hostname) []:app
Email Address []:app@qq.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@localhost app]# ll
total 8
-rw-r--r--. 1 root root 1025 Jun 22 09:50 app.csr
-rw-r--r--. 1 root root 1679 Jun 22 09:45 app.key
[root@localhost app]# scp /data/app/app.csr 192.168.8.10:/data/ 將公鑰發(fā)送給CA服務(wù)器

3 頒發(fā)證書

[root@centos7localdomain CA]# openssl ca -in /data/app.csr -out /etc/pki/CA/certs/app.crt -days 100
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 31 (0x1f)
        Validity
            Not Before: Jun 22 02:27:32 2020 GMT
            Not After : Sep 30 02:27:32 2020 GMT
        Subject:
            countryName               = CN
            stateOrProvinceName       = shanghai
            organizationName          = et
            organizationalUnitName    = fn
            commonName                = app
            emailAddress              = app@qq.com
        X509v3 extensions:
            X509v3 Basic Constraints: 
                CA:FALSE
            Netscape Comment: 
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier: 
                BD:58:64:12:A1:5D:AA:01:69:A3:E6:BF:71:A4:14:C8:A5:A5:0C:7D
            X509v3 Authority Key Identifier: 
                keyid:AC:3B:3E:0C:A3:30:A0:2A:68:EC:6B:13:47:F1:66:10:C3:B9:41:7F

Certificate is to be certified until Sep 30 02:27:32 2020 GMT (100 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
[root@192 CA]# tree
.
├── cacert.pem
├── certs
│   └── app.crt
├── crl
├── index.txt
├── index.txt.attr
├── index.txt.old
├── newcerts
│   └── 1F.pem
├── private
│   └── cakey.pem
├── serial
└── serial.old
將生成的 app.crt或1F.pem發(fā)送給客戶端

用于更改默認選項 城市 省份 公司
vim /etc/pki/tls/openssl.cnf
# For the CA policy
[ policy_match ]
countryName     = match    必須相同 optional 可選
stateOrProvinceName = match
organizationName    = match
organizationalUnitName  = optional
commonName      = supplied
emailAddress        = optional
為用戶生成一個/多個證書文件
 vim /etc/pki/CA/index.txt.attr 
unique_subject = yes 一個 no 多個

4 證書吊銷

root@centos7localdomain app]# tree /etc/pki/CA/
/etc/pki/CA/
├── cacert.pem
├── certs
│   ├── app1.crt
│   ├── app2.crt
│   └── app.crt
├── crl
├── index.txt
├── index.txt.attr
├── index.txt.attr.old
├── index.txt.old
├── newcerts
│   ├── 00.pem
│   ├── 01.pem
│   └── 02.pem
├── private
│   └── cakey.pem
├── serial
└── serial.old

4 directories, 14 files
[root@centos7localdomain app]# openssl ca -revoke /etc/pki/CA/newcerts/02.pem 
Using configuration from /etc/pki/tls/openssl.cnf
Revoking Certificate 02.
Data Base Updated
[root@centos7localdomain app]# cat /etc/pki/CA/index.txt
V   230319031112Z       00  unknown /C=CN/ST=shanghai/O=et/OU=fn/CN=app/emailAddress=app@qq.com
V   230320104706Z       01  unknown /C=CN/ST=shanghai/O=et/OU=it/CN=www.app2.com/emailAddress=app@qq.com
R   230320105431Z   200623105942Z   02  unknown /C=CN/ST=shanghai/O=it/OU=fn/CN=www.it.vn/emailAddress=it@qq.com
指定第一個吊銷證書的編號,注意:第一次更新證書吊銷列表前赦颇,才需要執(zhí)行
echo 01 > /etc/pki/CA/crlnumber
更新證書吊銷列表
openssl ca -gencrl -out /etc/pki/CA/crl.pem
查看crl文件:
openssl crl -in /etc/pki/CA/crl.pem -noout -text
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末谤辜,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌宠能,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,734評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件鸭蛙,死亡現(xiàn)場離奇詭異川尖,居然都是意外死亡,警方通過查閱死者的電腦和手機藻糖,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,931評論 3 394
  • 文/潘曉璐 我一進店門淹冰,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人巨柒,你說我怎么就攤上這事樱拴∧埽” “怎么了?”我有些...
    開封第一講書人閱讀 164,133評論 0 354
  • 文/不壞的土叔 我叫張陵晶乔,是天一觀的道長珍坊。 經(jīng)常有香客問我,道長正罢,這世上最難降的妖魔是什么阵漏? 我笑而不...
    開封第一講書人閱讀 58,532評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮翻具,結(jié)果婚禮上履怯,老公的妹妹穿的比我還像新娘。我一直安慰自己裆泳,他們只是感情好叹洲,可當(dāng)我...
    茶點故事閱讀 67,585評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著工禾,像睡著了一般疹味。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上帜篇,一...
    開封第一講書人閱讀 51,462評論 1 302
  • 那天糙捺,我揣著相機與錄音,去河邊找鬼笙隙。 笑死洪灯,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的竟痰。 我是一名探鬼主播签钩,決...
    沈念sama閱讀 40,262評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼坏快!你這毒婦竟也來了铅檩?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,153評論 0 276
  • 序言:老撾萬榮一對情侶失蹤莽鸿,失蹤者是張志新(化名)和其女友劉穎昧旨,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體祥得,經(jīng)...
    沈念sama閱讀 45,587評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡兔沃,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,792評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了级及。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片乒疏。...
    茶點故事閱讀 39,919評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖饮焦,靈堂內(nèi)的尸體忽然破棺而出怕吴,到底是詐尸還是另有隱情窍侧,我是刑警寧澤,帶...
    沈念sama閱讀 35,635評論 5 345
  • 正文 年R本政府宣布转绷,位于F島的核電站伟件,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏暇咆。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,237評論 3 329
  • 文/蒙蒙 一丙曙、第九天 我趴在偏房一處隱蔽的房頂上張望爸业。 院中可真熱鬧,春花似錦亏镰、人聲如沸扯旷。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,855評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽钧忽。三九已至,卻和暖如春逼肯,著一層夾襖步出監(jiān)牢的瞬間耸黑,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,983評論 1 269
  • 我被黑心中介騙來泰國打工篮幢, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留大刊,地道東北人。 一個月前我還...
    沈念sama閱讀 48,048評論 3 370
  • 正文 我出身青樓三椿,卻偏偏與公主長得像缺菌,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子搜锰,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,864評論 2 354