使用Azure网站实例中的客户端证书

时间:2016-12-09 16:47:19

标签: c# wcf azure azure-web-sites

我有一个Azure网站实例,需要将 out 连接到使用客户端证书保护的其他地方运行的WCF服务。

Client -> Azure Website (MVC Controller) -> WCF Service (Not Azure) that requires Client Certificate

我已经提供了一个CER文件,当在本地安装时,我的网站可以连接到WCF服务。如何在Azure网站上安装/提供此证书?

我在研究时发现的所有文档都是关于在Azure中运行时保护WCF服务,并且需要安装带密码的PFX文件。我正在尝试相反的做法,将Azure网站的出站连接到第三方WCF服务。

1 个答案:

答案 0 :(得分:4)

自: https://azure.microsoft.com/en-us/blog/using-certificates-in-azure-websites-applications/

添加以下应用程序设置:

  • 应用程序设置名称:WEBSITE_LOAD_CERTIFICATES
  • 价值:*{CERT_THUMBPRINT}

然后,您可以从My商店获取证书:

X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = certStore.Certificates.Find(
                                 X509FindType.FindByThumbprint,
                                 // Replace below with yourcert's thumbprint
                                 "E661583E8FABEF4C0BEF694CBC41C28FB81CD870”,
                                 false);

现在,我认为您无法上传.cer.pfx似乎是App Service中唯一可接受的格式。

error_uploading_cer

或者只是在没有私钥的情况下从磁盘加载它。 这样你也可以加载.cer(DER可以工作,也可能是Base64):

// The path to the certificate.
string Certificate = @"d:\home\site\cert.cer";

// Load the certificate into an X509Certificate object.
X509Certificate cert = X509Certificate.CreateFromCertFile(Certificate);

// Print to console
string result = cert.ToString(true);
Console.WriteLine(result);

在App Service中工作得很好(这里它在Kudu console中运行):

loadCert_Kudu_screenshot

相关问题