[精讚] [會員登入]
8447

[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

你可能感興趣的文章

[Rocky Linux] 安裝gitlab gitlab+docker compose+ nginx 安裝Gitlab並結合nginx當網頁伺服器

[Linux] 使用tarball安裝下載PERL的tar檔模組 在Linux下,perl下載的pm模組,不使用cpan的安裝方法

[LINUX] 利用 usermod 修改使用者的參數和資料 使用指令 usermod 修改使用者的參數和資料

[Centos7] 安裝phpMyAdmin Centos 7有新的方式可以安裝phpmyadmin,不必再採用過去的tarball安裝法。

SELinux 常用指令和檔案 在Redhat系列中,Centos5以後加入了selinux,他並沒有這麼可怕,不必每次看到Selinux ,就想把他

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

我有話要說

>>

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

訪客留言

[無留言]

隨機好文

[MAC] 截取螢幕畫面的方法 截取螢幕畫面的方法,在MAC中叫作螢幕快照,英文是screenshot

SELinux 常用指令和檔案 在Redhat系列中,Centos5以後加入了selinux,他並沒有這麼可怕,不必每次看到Selinux ,就想把他

安裝SPHINX支援中文 新版本的 sphinx 和舊版不同,網路上很多範例和教學是不能用的。此文是安裝和設定方法分享

[札記] 2016.7~12月札記 札記,只是札記

[AS3] 我做的唯一一個Flash As3遊戲UFO INVADSION [AS3] 我做的唯一一個Flash As3遊戲,是第一個也是最後一個,後來就沒再寫as3,不過as3還滿好玩的。