【问题标题】:Certificate not found when deploying IdentityServer 4 to Azure VM将 IdentityServer 4 部署到 Azure VM 时找不到证书
【发布时间】:2017-11-22 10:38:09
【问题描述】:

我在将 IdentityServer 4 (ASP.NET Core 1.1) 部署到 Azure VM (Windows Server 2012 R2) 时遇到此证书问题。

crit: IdentityServer4.Hosting.IdentityServerMiddleware[0]
      Unhandled exception: Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: The system cannot find the file specified
         at System.Security.Cryptography.CngKey.Open(String keyName, CngProvider provider, CngKeyOpenOptions openOptions)
         at System.Security.Cryptography.CngKey.Open(String keyName, CngProvider provider)
         at Internal.Cryptography.Pal.CertificatePal.GetPrivateKey[T](Func`2 createCsp, Func`2 createCng)
         at Internal.Cryptography.Pal.CertificatePal.GetRSAPrivateKey()

这将在本地开发计算机上运行,​​我无法弄清楚原因。我将证书安装在 VM 上的 My (Local Machine) store 上。

任何人都可以帮助解决这个问题。谢谢。

【问题讨论】:

    标签: azure .net-core identityserver4


    【解决方案1】:

    我在这里找到了解决方案:

    http://www.daves-blog.net/post/2014/06/16/X509Certificate-The-System-cannot-find-the-file-specified.aspx

    显然,我需要在应用程序池上启用加载用户配置文件。但是,错误现在变为:

    crit: IdentityServer4.Hosting.IdentityServerMiddleware[0]
      Unhandled exception: Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Keyset does not exist
         at System.Security.Cryptography.CngKey.Open(String keyName, CngProvider provider, CngKeyOpenOptions openOptions)
         at System.Security.Cryptography.CngKey.Open(String keyName, CngProvider provider)
         at Internal.Cryptography.Pal.CertificatePal.GetPrivateKey[T](Func`2 createCsp, Func`2 createCng)
         at Internal.Cryptography.Pal.CertificatePal.GetRSAPrivateKey()
    

    现在来看问题。

    好的,所以问题是读取证书的权限。我们所要做的只是转到证书并为 IIS_IUSRS 授予 Readonly)。

    现在可以了。

    【讨论】:

    • 如果有问题的证书只是一个内存证书并且没有安装在机器上的任何地方会发生什么?如果您要在容器内运行 IS4 并且使用应用程序部署证书会存在安全风险,我相信这是推荐的方法
    • 嗯,我的客户基础设施环境需要是这样的,所以他们可以轮换证书。我个人建议使用 AzureKeyVault 来存储带有 HSM 密钥的 PFX 以便于轮换,因此应用端将没有证书,即使它们有一天会移动到容器中。
    • 所以要让这个工作正常,您只需将证书放在与IIS_IUSRS 有权读取的运行代码相同的位置?
    • 所以您授予用户对证书存储的读取权限?你是怎么做到的?
    • @Ruskin 只是去证书商店。右键单击证书并选择所有任务 -> 管理私钥。我希望这会有所帮助。
    【解决方案2】:

    如果有人想知道如何让 IIS 用户访问证书

    1. 创建/购买证书。确保它有一个私钥。
    2. 将证书导入“本地计算机”帐户。最好使用证书 MMC。 确保选中“允许导出私钥”
    3. 基于此,IIS 7.5 应用程序池的标识使用以下之一。

      • IIS 7.5 网站在 ApplicationPoolIdentity 下运行。打开 MMC => 添加证书(本地计算机)管理单元 => 证书(本地计算机)=> 个人 => 证书 => 右键单击​​感兴趣的证书 => 所有任务 => 管理私钥 => 添加IIS AppPool\AppPoolName 和授予它Full control。将“AppPoolName”替换为您的应用程序池的名称(有时是 IIS_IUSRS
      • IIS 7.5 网站正在网络服务下运行。使用证书 MMC,将“网络服务”添加到“本地计算机\个人”中证书的完全信任中。
      • IIS 7.5 网站在“MyIISUser”本地计算机用户帐户下运行。使用证书 MMC,将“MyIISUser”(一个新的本地计算机用户帐户)添加到“本地计算机\个人”中证书的完全信任中。

    以上摘自here

    【讨论】:

    • 我同意上述观点,但有一个例外:在项目符号一中,Read 权限足以让应用程序池身份访问证书。
    猜你喜欢
    • 2020-08-23
    • 1970-01-01
    • 2013-09-17
    • 1970-01-01
    • 2017-06-25
    • 2019-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多