[精讚] [會員登入]
8436

[Centos7] SSL自簽憑證+APACHE+Selinux

SSL的自簽憑證

分享此文連結 //n.sfs.tw/11830

分享連結 [Centos7] SSL自簽憑證+APACHE+Selinux@新精讚
(文章歡迎轉載,務必尊重版權註明連結來源)
2019-10-25 11:51:00 最後編修
2017-09-26 14:06:16 By 張○○
 

自動目錄

SSL的自簽憑證,窮人SSL,雖然網頁會跳SSL不合法的警告,此文主要參考[1]提供的指令。

SSL的憑證信任鍊 trust china 是這樣: 根憑證機構(Root CA) =授權=> 中繼憑證機構(Intermedia CA) =授權=> 終端憑證機構(Endpoint CA)

  * CA就是授權機構 certificate authority

 

一、自簽Root CA

建立私鑰

# openssl genrsa  -out RootCA.key 2048

產生根憑證申請檔

# openssl req -new -key RootCA.key -out RootCA.req

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) [GB]:TW
State or Province Name (full name) [Berkshire]:Taiwan
Locality Name (eg, city) [Newbury]:Taichung
Organization Name (eg, company) [My Company Ltd]:Somewhere Co.Ltd.
Organizational Unit Name (eg, section) []:Sleep Dep.
Common Name (eg, your name or your server's hostname) []:hostname.example.com
Email Address []:<按ENTER>

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:<按ENTER>
An optional company name []:<按ENTER>

利用申請檔產生憑證檔

# openssl x509 -req -days 3650 -sha256 -extensions v3_ca -signkey RootCA.key -in RootCA.req -out RootCA.crt

產生憑證檔RootCA.crt

接下來要拿根憑證來簽發終端憑證,因為沒有中繼憑證,所以直接來作伺服器憑證,也就是終端憑證。

 

二、製作終端憑證(伺服器憑證)

建立伺服器私鑰

# openssl genrsa -out ServerCert.key 2048

同上,產生憑證申請檔

# openssl req -new -key ServerCert.key -out ServerCert.req
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) [GB]:TW
State or Province Name (full name) [Berkshire]:Taiwan
Locality Name (eg, city) [Newbury]:Taichung
Organization Name (eg, company) [My Company Ltd]:Eat Co.Ltd.
Organizational Unit Name (eg, section) []:Pizza Dep.
Common Name (eg, your name or your server's hostname) []:hostname.example.com
Email Address []:<按ENTER>
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:<按ENTER>
An optional company name []:<按ENTER>

Common Name 中可以使用 wildcard寫法,例如 *.example.com

產生流水號檔

# echo 1000 > RootCA.srl

產生憑證檔一樣簽十年

# openssl x509 -req -days 3650 -sha256 -extensions v3_req -CA RootCA.crt -CAkey RootCA.key -CAserial RootCA.srl -CAcreateserial -in ServerCert.req -out ServerCert.crt

 

三、SELINUX 及搬移

# chcon -u system_u -t cert_t ServerCert.key ServerCert.crt RootCA.crt

複製到指定的位置

# cp ServerCert.key /etc/pki/tls/private/

# cp *.crt /etc/pki/tls/certs

 

 

四、APACHE上設定

修改 /etc/httpd/conf.d/ssl.conf

# 註解這兩項
#SSLCertificateFile /etc/pki/tls/certs/localhost.crt
#SSLCertificateKeyFile /etc/pki/tls/private/localhost.key

# 修改
Listen 443
ServerName
hostname.example.com:443
SSLEngine on

# 加入這三項
SSLCertificateFile /etc/pki/tls/certs/ServerCert.crt
SSLCertificateKeyFile /etc/pki/tls/private/ServerCert.key
SSLCACertificateFile /etc/pki/tls/certs/RootCA.crt

其中ServerName要和上面設定的一樣

重新啟動 apache

# apachectl restart

 

錯誤排除

啟動失敗log檔在 /etc/httpd/logs/ssl_error_log 或是 /var/log/message 看你的設定。

[warn] RSA server certificate CommonName (CN) `somehost.example.com' does NOT match server name!?

  可能解法:你的 ServerCert.key 檔裡面設定的網域名稱和你的 ssl.conf中設定的名稱不一樣

[error] Unable to configure RSA server private key

  可能解法:你的 ServerCert.key 檔不正確,請檢查或重新建立

 

相關連結

[HTTPS] Ubuntu +SSL +正式的CA 設定

[SSL] 免費的SSL憑證(三個月)

[Centos7] HTTPS/SSL憑證的SELINUX設置

參考資料

[1] https://www.bear2little.net/wordpress/?p=401

[2] http://wiki.weithenn.org/cgi-bin/wiki.pl?SSL_Certificate-%E8%87%AA%E8%A1%8C%E7%94%A2%E7%94%9F_SSL_%E6%86%91%E8%AD%89 有原理說明

[3] https://en.wikipedia.org/wiki/Root_certificate

END

你可能感興趣的文章

[Centos8] 安裝及設定docker docker 是一個應用程式的容器,相對於vm是作業系統的容器。此篇整理基本安裝及設定。

PHP for sphinx 函式庫安裝 PECL/sphinx PHP>= 5.2.2 已經能原生支援 sphinx,可是預設的沒有裝,我們得自己裝才能用

[Centos7] 安裝 semanage (selinux工具程式) 安裝selinux的工具程式 semanage

安裝網頁套件管理程式 Bower 一個非常棒的Javascript套件管理程式bower,用完愛不釋手。

TFTP Server 安裝及使用 讓設備的網路設定檔或是韌體經由TFTP拷備出來,操作的方法

[Centos6] 安裝VNC連線程式 在Centos6桌上環境安裝VNC 連線程式

我有話要說

>>

限制:留言最高字數1000字。 限制:未登入訪客,每則留言間隔需超過10分鐘,每日最多5則留言。

訪客留言

[無留言]

隨機好文

使用Google尋找你的手機 這近發現google竟然可以用來找android的手機,而且不需要經過什麼設定或安裝軟體。

TFTP Server 安裝及使用 讓設備的網路設定檔或是韌體經由TFTP拷備出來,操作的方法

[JAVA] JWS, JWT, JWE, JOSE是什麼? [JAVA] JWS, JWT, JWE, JOSE是什麼?非常的複雜,儘量來搞清楚..

一個邏輯的錯誤刪了全部檔案的經驗 今天本來想做一件很簡單的事,但卻足足浪費我多一倍的時間,再加上刪掉我全部的檔案,原因只是因為我自己的邏輯錯誤。

魔球中小女孩唱的歌 The show 魔球中小女孩唱的歌 The show