[英]Get MOZILLA_PKIX_ERROR_CA_CERT_USED_AS_END_ENTITY with Self-Signed Certificate on FireFox
嘗試使用使用以下命令行創建的證書時出現主題錯誤:
openssl.exe req -x509 -nodes -sha256 -days 3650 -subj "/CN=mysite.local" -newkey rsa:2048 -keyout mysite.local.key -out mysite.local.crt
我在此站點上發現了另一個引用相同錯誤的問題:
看起來該證書具有值 cA: TRUE 的 basicConstraints 擴展。 我們不再允許 CA 證書充當最終實體證書。 該證書應該在沒有 basicConstraints 擴展的情況下重新生成。 這也在https://wiki.mozilla.org/SecurityEngineering/x509Certs中進行了解釋
我按照引用的鏈接並嘗試按照自簽名證書下的說明進行操作。 第 1 步奏效。 第 2 步給出了錯誤:忽略 -days; 不生成證書。
我在 Windows 10 Pro 上,使用 OpenSSL 1.1.1f 2020 年 3 月 31 日。我在 Z2567A5EC9705EB7AC2C984033E0618D 上的任何地方都沒有找到對該錯誤的任何引用。 有任何想法嗎?
關於來自 OP 的評論:“我正在嘗試設置 HTTPS 以在網絡上不同計算機上的前端和后端 API 服務器之間進行通信。這就是我試圖生成自簽名證書的原因。是有沒有更標准的方法來解決這個問題?”
您可以使用下面的腳本創建證書,將其導入 API 服務器上的受信任根存儲,並配置給定端口上的流量以使用證書進行加密(我認為是 SSL...)。 然后,從證書管理 GUI(管理計算機證書)中,您可以導出剛剛創建的證書並將其導入前端服務器。
編輯以反映 OP 對管道 output 問題的評論。
param(
[string] $certPass,
[string] $portForTraffic,
[string] $dnsName = '<HOST>.<DOMAIN>.<DOMAIN_SUFFIX>', # <== ex: server.contoso.com
[int] $certValidForDays = 365
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop";
#Requires -Version 5.0
[string] $certStoreLocation = 'Cert:\LocalMachine'
function CreateSelfSignedCert(
[Parameter(Mandatory=$true)]
[string] $dnsName,
[Parameter(Mandatory=$false)]
[string] $storeLocation = $certStoreLocation,
[Parameter(Mandatory=$false)]
[int] $certValidDays = $certValidForDays
){
$certificate = New-SelfSignedCertificate `
-DnsName $dnsName `
-CertStoreLocation "$storeLocation\My" `
-NotAfter $((Get-Date).AddDays($certValidDays)) `
-Verbose
$certThumbPrint = $certificate.Thumbprint
$returnObj = [PSCustomObject] @{
ThumbPrint = $certThumbPrint;
}
return $returnObj;
}
function ExportCert(
[Parameter(Mandatory=$true)]
[string] $certThumbPrint,
[Parameter(Mandatory=$true)]
[string] $certPass,
[Parameter(Mandatory=$true)]
[string] $workDir,
[Parameter(Mandatory=$false)]
[string] $storeLocation = $certStoreLocation
){
$certificatePath = "$storeLocation\My\$certThumbPrint"
$secureString = ConvertTo-SecureString -String $certPass -Force -AsPlainText
$tempDir = "$workDir\pfx_temp"
$pfxFilePath = "$tempDir\temp.pfx"
if( (Test-Path -Path $tempDir) -eq $false ){
New-Item -ItemType Directory -Path $tempDir -Verbose | Out-Null
}
# ...so export it...
$fileInfo = Export-PfxCertificate `
-FilePath $pfxFilePath `
-Cert $certificatePath `
-Password $secureString `
-Verbose
Write-Host "$fileInfo"
return $pfxFilePath
}
function ImportCertToRoot(
[Parameter(Mandatory=$true)]
[string] $pfxPath,
[Parameter(Mandatory=$true)]
[string] $certPass,
[Parameter(Mandatory=$false)]
[string] $storeLocation = $certStoreLocation
) {
$secureString = ConvertTo-SecureString -String $certPass -Force -AsPlainText
Write-Host "Attempting to import cert from: $pfxPath"
Import-PfxCertificate `
-FilePath $pfxPath `
-CertStoreLocation "$storeLocation\Root" `
-Password $secureString `
-Verbose | Out-Null
Remove-Item -Path $pfxPath -Force -Verbose
}
function ConfigureSslForPortOnHost(
[Parameter(Mandatory=$true)]
[string] $port,
[Parameter(Mandatory=$true)]
[string] $certThumbPrint
) {
Write-Host -ForegroundColor Yellow "Attempting to add ssl rule using NETSH. Using cert with thumbprint: $($certThumbPrint)"
Invoke-Expression "netsh http delete sslcert ipport=0.0.0.0:$port"
Invoke-Expression "netsh http add sslcert ipport=0.0.0.0:$port appid='{214124cd-d05b-4309-9af9-9caa44b2b74a}' certhash=$($certThumbPrint)"
}
# Create a self-signed cert
$cert = CreateSelfSignedCert -dnsName $dnsName
# Export the cert so we can later import it to the root store
$pfxPath = ExportCert -certThumbPrint $cert.ThumbPrint -certPass $certPass -workDir $PSScriptRoot
# Import cert to trusted root
ImportCertToRoot -pfxPath $pfxPath -certPass $certPass
# Ensure HTTP traffic to specified port on API server is encrypted
ConfigureSslForPortOnHost -port $portForTraffic -certThumbPrint $cert.ThumbPrint
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.