如何生成不会在浏览器中触发警告的自签名证书?

How to generate a self-signed certificate that does not trigger warnings in browsers?

我正在通过利用 openssl 的简单 PowerShell 脚本生成一个简单的自签名证书,然后在一个简单的 ASP.NET Core 2.0 应用程序中使用 pfx 证书来启用 HTTPS)

function New-SelfSignedCertificate([string] $BaseName = 'localhost', $CommonName = 'localhost', [UInt16] $DayCount, [string] $Pass = 'somepassword')
{
    &openssl req -new -x509 -newkey rsa:2048 -keyout "$BaseName.key" -out "$BaseName.cer" -days "$DayCount" -subj /CN="$CommonName" -passout "pass:$Pass"
    &openssl pkcs12 -export -password "pass:$Pass" -passin "pass:$Pass" -out "$BaseName.pfx" -inkey "$BaseName.key" -in "$BaseName.cer"
    Remove-Item -Path "$BaseName.key"
    Remove-Item -Path "$BaseName.cer"
    Remove-Item -Path '.rnd'
}

我的证书的问题是它会在每个浏览器上触发大量警告:Chrome、Opera、Firefox(例如 SEC_ERROR_UNKNOWN_ISSUER)、IE11(例如 DLG_FLAGS_INVALID_CA)和边缘(DLG_FLAGS_INVALID_CADLG_FLAGS_SEC_CERT_CN_INVALID),我可以在这一代做些什么来避免这些警告? (即除了手动将证书添加到受信任的根目录之外)

似乎无法识别颁发者,我的意思是如何在没有用户干预的情况下以浏览器会说的方式判断证书:"ok you can go to the Trusted Root Certificate Authorities."? (即在开发阶段寻求便利)。

is there anything I can do at the generation to avoid those warnings? (i.e. besides adding manually the certificate to the Trusted Root category)

要么你不理解信任证书背后的概念,要么我不理解你的问题。证书验证背后的主要思想是,浏览器将检测是否有黑客转移或拦截您的连接,以冒充某些受信任的站点或在中间人攻击期间嗅探敏感(加密)数据。

如果任何人都可以自动将 CA 或证书添加为受信任的浏览器,即无需通知用户,那么任何人都可以为任意网站创建证书(如 paypal.com、google.com..) 并在这样的攻击中使用它,而浏览器无法检测到该攻击。

I mean how can the certificate can be judged in way that the browser would say without a user intervention: "ok you can go to the Trusted Root Certificate Authorities."?

这不能通过证书本身以任何方式设置。只有 system/browser 的用户或管理员或开发人员可以决定是否应将新 CA 视为可信。