【问题标题】:Azure public and private certificate not accessible from web app无法从 Web 应用访问 Azure 公共和私有证书
【发布时间】:2018-06-04 04:17:00
【问题描述】:

我从第三方公司获取数据,他们给了我证书,以便我可以访问他们的服务。在本地设置时,它在将 .cer 和 .pfx 安装到我的证书存储中后工作。但是,当代码在我的 Azure Web 应用程序上运行时,我无法让它工作,它会导致错误:

Could not establish trust relationship for the SSL/TLS secure channel with authority

在授予我的应用程序池对公共根证书 (IIS AppPool\AppPoolName) 的访问权限之前,我最初在本地收到了这个特定错误。感觉就像我现在在 Azure 上遇到了同样的错误。该代码肯定会找到证书(否则会引发错误),但它似乎无权使用它们。

我已按照本指南在我的网络应用中安装证书:https://azure.microsoft.com/en-us/blog/using-certificates-in-azure-websites-applications/

我已将应用程序属性设置为导入所有证书:

这是我用来加载私有证书的代码:

var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
var certs = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);

if (certs == null || certs.Count == 0)
{
    ExceptionUtils.ThrowDataError("Private certificate could not be found");
}

store.Close();
return certs[0];

我也尝试将 .pfx 添加到 App_Data 文件夹并像这样加载它:

var certPath = HttpContext.Current.Server.MapPath("~/App_Data/cert.pfx");
var bankIdCert = new X509Certificate2(certPath, "password");

但它会导致相同的错误。也许这意味着它无法访问公共证书?目前工作的本地版本和 azure 版本之间的唯一区别是:

  • 在本地,公共证书存储在 LocalMachine location Root 中,私有证书存储在 LocalMachine location My 中
  • 在 Azure 上上传时,两个证书都转到 CurrentUserMy

某些证书是否需要在 LocalMachine 上才能工作?

【问题讨论】:

    标签: c# azure certificate azure-web-app-service


    【解决方案1】:

    无法为具有权限的 SSL/TLS 安全通道建立信任关系

    在您的情况下,SSL 证书验证失败的最主要原因是:

    URL 中使用的主机名与证书上的名称不匹配。 确保您使用的 URL 与证书“颁发给”字段上的 URL 相同e。

    正如 Swikruti Bose 提到的,您可以关注 Bind an existing custom SSL 来自定义 SSL。

    由于 azure WebApp 是 sandbox,我们无权在 Azure WebApp 中安装根 CA。

    如果可以使用 Azure 虚拟机或云服务,您也可以使用 Azure 虚拟机或cloud Service

    【讨论】:

      【解决方案2】:

      如果第三方 CA 尚未被信任,则可能会发生此错误。如果您的 Web 应用程序出现证书验证错误,您可以尝试使用自签名证书:https://docs.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-custom-ssl

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-12-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-06
        • 1970-01-01
        • 2011-01-31
        相关资源
        最近更新 更多