如何讓openssl生成的SSL證書被瀏覽器認可


1. 使用openssl生成證書,我使用的是kali自帶的openssl模塊

也可以從官網下載openssl —— https://www.openssl.org/source/

生成命令如下,其中:/C=CN(國家縮寫)/ST=(省份)/L=(城市)/O=(組織名稱):

openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -subj "/C=CN/ST=ZheJiang/L=HangZhou/O=MJY" -keyout CA-private.key -out CA-certificate.crt -reqexts v3_req -extensions v3_ca


openssl genrsa -out private.key 2048


openssl req -new -key private.key -subj "/C=CN/ST=ZheJiang/L=HangZhou/O=MJY/CN=127.0.0.1" -sha256 -out private.csr
#最后的 CN=IP地址或域名

生成ext文件:

#vim private.ext
#復制如下內容到private.ext文件中

[ req ]
default_bits        = 1024
distinguished_name  = req_distinguished_name
req_extensions      = san
extensions          = san
[ req_distinguished_name ]
countryName         = CN
stateOrProvinceName = Definesys
localityName        = Definesys
organizationName    = Definesys
[SAN]
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = IP:127.0.0.1

#其中ip后內容,改成自己需要的ip地址(服務器ip或者域名)
#最后使用 :wq 保存退出

生成CA證書

openssl x509 -req -days 3650 -in private.csr -CA CA-certificate.crt -CAkey CA-private.key -CAcreateserial -sha256 -out private.crt -extfile private.ext -extensions SAN

 

2. 復制證書至相應目錄,並添加證書路徑至Apache配置文件中,之后重啟Apache服務

  虛擬機中復制文件出來,如果使用的是virtual Box,需要點擊安裝增強功能,之后執行:sudo sh /media/cdrom0/VBoxLinuxAdditions.run

Listen 443
SSLStrictSNIVHostCheck off
SSLCipherSuite AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL
SSLProtocol all -SSLv2 -SSLv3
<VirtualHost *:443>
  DocumentRoot "D:\phpStudy\PHPTutorial\WWW" 
  ServerName 127.0.0.1        
  ServerAlias 127.0.0.1            
  <Directory "D:\phpStudy\PHPTutorial\WWW">  
    Options -Indexes -FollowSymLinks +ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
    Require all granted
  </Directory>
SSLEngine on
SSLCertificateFile "D:\phpStudy\PHPTutorial\Apache\conf\ssl\private.crt"  
SSLCertificateKeyFile "D:\phpStudy\PHPTutorial\Apache\conf\ssl\private.key"  
</VirtualHost>

如下兩行表示證書文件路徑

 

 3. 將CA證書導入受信任的根目錄中

 

 

 

 

 

 

 

4. 重啟瀏覽器后查看,最終結果:

 顯示安全,nice

 

5. windows系統上命令行添加根證書

powershell:需要以管理員身份運行
certutil
-addstore root D:\Desktop\ssl\CA-certificate.crt

cmd:
需要以管理員身份運行
powershell.exe certutil -addstore root D:\Desktop\ssl\CA-certificate.crt # 如果使用bat的話,需要使用證書的全路徑


bat實現:

  pushd %~dp0
  set pwd=%cd%
  powershell.exe certutil -addstore root %pwd%\CA-certificate.crt
  pause



 

 

參考文檔:

《解決https網站通過nginx+openssl自簽名證書訪問,在谷歌瀏覽器報不安全告警的問題》https://blog.csdn.net/u010425839/article/details/120755553

《Windows 通過命令行安裝根證書》https://88250.b3log.org/articles/2018/05/03/1525333052172.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM