【问题标题】:Azure web service as a client to an external service, using a client-side certificateAzure Web 服务作为外部服务的客户端,使用客户端证书
【发布时间】:2014-08-17 21:10:10
【问题描述】:

我需要编写一个 Web 服务并将其托管在 Azure 中。该服务反过来使用来自外部站点的另一个服务。因此,我的 azure 托管服务是此外部托管服务的客户端。当我请求其他服务时,我需要在我的请求中包含客户端证书。

有没有人成功做到这一点?是否可以在 azure 的 Web 实例中安装证书?它会在实例重启后幸存下来吗?如果是这样,将不胜感激。

我从未使用过客户端证书(即使是在“真实”客户端上),所以如果这是一个新手问题,请原谅我。

【问题讨论】:

标签: web-services azure ssl


【解决方案1】:

将托管您的 webrole 的云服务中上传的证书(请参阅 Azure 门户中该云服务下的证书选项卡)将在该 webrole 的 VM 中可用。因此,您可以从证书存储中访问它并在进行外部 Web 服务调用时使用它。 这个 stackoverflow 帖子中给出了一个示例。 Accessing a web service and a HTTP interface using certificate authentication

【讨论】:

    【解决方案2】:

    您可以通过 azure 管理门户添加证书,一旦将您的应用程序部署到 VM 上,Azure 会将其添加到机器证书存储中,或者您可以将其保留在您的应用程序中,例如作为嵌入式资源并手动加载它与您的网络服务调用一起使用。像这样:

    private X509Certificate2 GetAuthCertificate()
        {            
            var assembly = Assembly.GetExecutingAssembly();
            Stream stream = null;
    
            var resources = assembly.GetManifestResourceNames();
            foreach (var resource in resources)
            {
                if (resource.EndsWith(certificateFilename))
                {
                    stream = assembly.GetManifestResourceStream(resource);
                    break;
                }
            }
    
            if (stream == null)
                throw new Exception("Certificate not found in embedded rersources");
    
            using (var ms = new MemoryStream())
            {
                stream.CopyTo(ms);
    
                var result = new X509Certificate2(ms.ToArray(), "password", X509KeyStorageFlags.Exportable);
                return result;
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2020-10-23
      • 1970-01-01
      • 1970-01-01
      • 2014-02-23
      • 2014-09-04
      • 1970-01-01
      • 2021-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多