首页 文章

无法从Web应用程序访问Azure公共和私有证书

提问于
浏览
0

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

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/

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

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

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位置Root和私有商店LocalMachine location My

  • 在Azure上传时,两个证书都转到CurrentUserMy

有些证书需要在LocalMachine上才能工作吗?

2 回答

  • 0

    无法与权限 Build SSL / TLS安全通道的信任关系

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

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

    正如Swikruti Bose所说,您可以关注Bind an existing custom SSL来自定义SSL .

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

    如果可以使用Azure虚拟机或Cloud Service,您还可以使用Azure虚拟机或cloud Service .

  • 0

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

相关问题