2

我在从我的代码管理 Azure 证书时遇到了一些困难。事实上,我正在尝试使用 Azure REST 服务 API(例如创建 HTTP 请求)来从我的 Azure 网站了解我的服务状态。

它在本地调试中运行良好,但我的网络角色接缝对证书管理器有一些限制。贝娄是我所做的:

// this method stores a certificate from the resources
// to the local certificates manager
private X509Certificate2 StoreCertificate(Certificates certName)
{
    X509Certificate2 newCert = null;

    // get certificate from resources
    newCert = this.GetCertificateFromResources(certName);

    // store it into the local certificate manager
    if (newCert != null)
    {
        var store = new X509Store(
               StoreName.TrustedPeople,
               StoreLocation.LocalMachine
            );

        store.Open(OpenFlags.ReadWrite);
        store.Add(newCert);
    }

    // reset ref and try to load it from manager
    newCert = null;

    newCert = this.GetCertificate(certName);

    return newCert;
}

当我尝试添加证书时,会附加访问被拒绝错误。

任何想法 ?我可以将证书存储到 Azure VM 中吗?我应该使用特殊的位置来存储这些吗?

4

3 回答 3

1

为了节省其他开发人员的时间,这是我为解决主要问题所做的:

  1. 连接到部署 Web 角色的 VM:见那里
  2. 创建证书:见那里
  3. 最终使用证书管理器(mmc.exe)

然后可以从代码中获得证书。

于 2013-04-25T12:51:03.270 回答
1

好吧,我发现了很多东西:

  1. 我在网站中部署我的代码,因此我无法将证书添加到 Azure 中的共享 VM
  2. 我尝试在远程桌面会话中连接到 VM,并手动添加了证书。

即使在这种情况下,我在 InvalidOperationException 中有一个 (403) Forbidden 错误。

所以这是当前状态:

  • 已创建证书 (makecert) 并在托管我的 Web 角色的 VM 中手动添加(部署在服务中)
  • 此证书已上传到 Azure 帐户证书和 Azure 服务证书(部署我的 Web 角色的证书)
  • 此证书的指纹已添加到我的代码中,我可以在执行代码时访问证书

所以2个问题:

  1. 我应该对我的证书做些什么吗?
  2. 当我在 Azure 模拟器中本地尝试我的 Web 角色时,一切正常。在发布/部署步骤期间是否有要更新的特殊设置?

谢谢你的帮助。

于 2013-04-25T12:47:28.523 回答
1

您是否使用云服务(网络/工作者角色)?如果是这样,哪个操作系统系列?我已经看到一些报告说,对于使用 OS 系列 3 的工作角色,您需要以提升的权限运行该角色才能从本地证书存储读取证书。不确定这是否也适用于网络角色并添加到证书存储中。

是否也通过 Azure 管理门户(或通过 REST API 或 PowerShell)添加了服务证书?

于 2013-04-24T13:18:52.133 回答