證書頒發機構不工作
如果我的理解是正確的,CA 就像一個父證書,用於驗證已由 CA 證書籤名的其他證書,而無需為 Web 服務(例如 FTP 伺服器、Web 伺服器、Nextcloud、OpenVPN)安裝多個伺服器證書伺服器等?
我正在嘗試創建一個 CA 證書,我可以將其分發到我的本地網路並通過 WAN 分發到朋友的網路上,以便當他們嘗試訪問我的一項服務時,可以安全地連接到該證書。例如,與其為我託管的每項服務提供多個證書,不如只給他們一個,即 CA 證書。
每個伺服器證書都由 CA 不經意地簽名,因此通過在他們的機器上安裝一個 CA 證書,這將自動驗證伺服器證書,因為它首先是使用 CA 簽名的。正確的?
問題是今天我嘗試將 CA 證書安裝到我的 Windows 客戶端 PC 上並嘗試通過 HTTPS 訪問我的 OpenMediaVault GUI,但我仍然收到不安全的警告螢幕。
下面的程式碼塊顯示了 CA 和伺服器證書的整個創建過程。我將包含目錄樹的螢幕截圖,以便您查看所有文件和文件夾。我還將包括配置文件的內容
我的指南
# Make OpenSSL Directory mkdir ~/Desktop/OpenSSL # Make Child Directories mkdir -p ~/Desktop/OpenSSL/{ca,configs,"csr's",keys} # Change Directory Into OpenSSL Directory cd ~/Desktop/OpenSSL # Create CA Certificate openssl req -x509 -newkey rsa:4096 -keyout ca/cakey.pem -out ca/cacert.pem -days 3650 -sha256 -nodes -config configs/ca_openssl.cnf # Create serial file echo '01' > serial # Create index.txt touch index.txt ## ### Create server certificates ### ## # OpenMediaVault openssl genrsa -out keys/OpenMediaVault.pem 4096 openssl req -new -key keys/OpenMediaVault.pem -config configs/openmediavault_openssl.cnf -out "csr's"/OpenMediaVault.csr # OpenWrt openssl genrsa -out keys/OpenWrt.pem 4096 openssl req -new -key keys/OpenWrt.pem -config configs/openwrt_openssl.cnf -out "csr's"/OpenWrt.csr ## ### Sign Server Certificates With CA ### ## # OpenMediaVault openssl x509 -req -CA ca/cacert.pem -CAkey ca/cakey.pem -in "csr's"/OpenMediaVault.csr -out certificates/OpenMediaVault.crt -extfile configs/openmediavault_openssl.cnf -extensions v3_req -CAserial serial # OpenWrt openssl x509 -req -CA ca/cacert.pem -CAkey ca/cakey.pem -in "csr's"/OpenWrt.csr -out certificates/OpenWrt.crt -extfile configs/openwrt_openssl.cnf -extensions v3_req -CAserial serial # Convert PEM to CRT openssl x509 -outform der -in ca/cacert.pem -out "My Custom CA".crt # Convert PEM to PKCS12 openssl pkcs12 -export -out certificate.pfx -inkey ca/cakey.pem -in ca/cacert.pem -certfile CACert.crt
‘ca_openssl.cnf’
[ ca ] default_ca = CA_default # The default ca section [ CA_default ] dir = ~/Desktop/"OpenSSL Certificates" certs = $dir/certs crl_dir = $dir/crl database = $dir/index.txt new_certs_dir = $dir/newcerts certificate = $dir/cacert.pem serial = $dir/serial crlnumber = $dir/crlnumber cr = $dir/crl.pem private_key = $dir/private/cakey.pem [ req ] # Don't prompt for the Domanin Name (DN). Use configured values instead. # This Saves having to type in your DN each time. prompt = no string_mask = default distinguished_name = req_distinguished_name x509_extensions = v3_ca # The size of the key in bits default_bits = 4096 [ req_distinguished_name ] countryName = GB stateOrProvinceName = SOME_PROVINCE localityName = SOME_CITY organizationName = domain organizationalUnitName = domain commonName = domain Certificate Authority emailAddress = user@domain.com [ v3_ca ] # Extensions added to the request basicConstraints = critical, CA:TRUE keyUsage = critical, keyCertSign, cRLSign
‘openmediavault_openssl.cnf’
[ req ] # Don't prompt for the Domanin Name (DN). Use configured values instead. # This Saves having to type in your DN each time. prompt = no string_mask = default distinguished_name = req_distinguished_name req_extensions = v3_req # The size of the key in bits default_bits = 4096 [ req_distinguished_name ] countryName = GB stateOrProvinceName = SOME_PROVINCE localityName = SOME_CITY organizationName = OpenMediaVault organizationalUnitName = OpenMediaVault commonName = OpenMediaVault.local [ v3_req ] # Extensions to add to a certificate request basicConstraints = CA:FALSE keyUsage = nonRepudiation, digitalSignature, keyEncipherment subjectAltName = @alternative_names [ alternative_names ] DNS.0 = domain.com IP.0 = 192.168.1.123
‘openwrt_openssl.cnf’
[ req ] # Don't prompt for the Domanin Name (DN). Use configured values instead. # This Saves having to type in your DN each time. prompt = no string_mask = default distinguished_name = req_distinguished_name req_extensions = v3_req # The size of the key in bits default_bits = 4096 [ req_distinguished_name ] countryName = GB stateOrProvinceName = SOME_PROVINCE localityName = SOME_CITY organizationName = OpenWrt organizationalUnitName = OpenWrt commonName = OpenWrt.local [ v3_req ] # Extensions to add to a certificate request basicConstraints = CA:FALSE keyUsage = nonRepudiation, digitalSignature, keyEncipherment subjectAltName = @alternative_names [ alternative_names ] DNS.0 = domain.com IP.0 = 192.168.1.1
我從“/certificates”目錄安裝了“OpenMediaVault.crt”,從“/keys”目錄安裝了“OpenMediaVault.pem”。
“certificate.pfx”文件是“我的指南”部分中最後一個命令的結果,並已導入 Windows certmgr。我使用帶有 Firefox 認證選項的“我的自定義 CA.crt”文件。
我究竟做錯了什麼?
非常感謝
將要
更新 1
我想我已經找到了問題的原因。當我訪問https://openmediavault.local(這是證書中設置的通用名稱)時,我收到此消息“證書僅對以下名稱有效:”我的螢幕上顯示的兩個(一個模糊了隱私)是我添加的subjectAltNames。為什麼替代名稱有效但 CN 無效?我從https://192.168.1.123訪問它,我的 Firefox 地址欄中有一個綠色掛鎖。
更新 2
只是為了讓您知道我將 CN 添加到 subjectAltName 中,並且一切正常。
作為與 OpenSSL 相關的一個附帶問題,我現在希望製作一些 OpenVPN 證書。使用 OpenSSL 製作的 CA 可以簽署我的 OpenVPN 證書嗎?
是的,如果存在 SAN(主題替代名稱)擴展,瀏覽器將不再查看 CN。這是在RFC 2818 部分中指定的。3.1,Chrome 大約在兩年前(Chrome 58)開始強制執行此操作,Firefox 大約在三年前(Firefox 48)對公開頒發的證書做了同樣的事情。我不知道 Firefox 是否還有私有 CA 的例外情況。(順便說一句,你自己調試這個問題做得很好!)
無論如何,您必須使用您想在 SubjectAltNames 中使用的所有名稱重新頒發您的證書。