无法从Azure辅助角色中加载证书实例

时间:2012-07-15 19:27:37

标签: azure azure-worker-roles

我有一个Azure Worker角色,我希望将其称为管理服务(例如REST API ),并收集有关相关服务的信息。但是,当我尝试加载我的证书时,它无法找到它。以下是我遵循的步骤:

1。我使用MakeCert创建了一个证书,并通过门户将其注册为我的管理证书

  

makecert -r -pe -a sha1 -n“CN = MyCnName”-ss My -len 2048   -sp“Microsoft增强型RSA和AES加密提供程序”-sy 24 MyCert.cer

2。在我的本地计算机上安装了证书,一切正常。在本地运行辅助角色时,我可以毫无问题地调用管理服务。

3. 从我的计算机导出证书,并通过门户网站在目标托管服务下注册导出的证书

4. 部署角色。角色启动时无法找到证书。

以下是我用来查找证书的代码摘录。

// Open the certificate store for the current user.
var certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser); // I also tried localmachine
certStore.Open(OpenFlags.ReadOnly);

// Find the certificate with the specified subject.
X509Certificate2Collection certCollection = certStore.Certificates.Find(
    X509FindType.FindBySubjectName,
    _myConfiguration.SubjectName,
    false);


if (certCollection == null || certCollection.Count < 1)
{
    // Find the certificate with the specified thumbprint.
    certCollection = certStore.Certificates.Find(
        X509FindType.FindByThumbprint,
        _myConfiguration.ThumbPrint,
        false);
}

// Close the certificate store.
certStore.Close();

// Check to see if a matching certificate was found.
if (certCollection.Count == 0)
{
    _logger.Warn("No certificate found");
}

没有例外,只是没有找到证书。任何人都可以解释我需要做什么吗?

2 个答案:

答案 0 :(得分:8)

找出问题...除了在门户网站中配置证书之外,我还需要将证书详细信息(例如名称,存储和指纹)添加到Azure项目角色设置中Certificates标签。

答案 1 :(得分:0)

我对网络角色有类似的问题,我已应用了一种解决方法。

  1. 将远程桌面连接到服务所在的VM 证书已部署
  2. 列表项
  3. 复制您的证书或pfx VM本地磁盘(例如C :)
  4. 点击您的pfx或.cert文件 将其安装在特定证书商店“Trusted People”上)
  5. 即使您配置了搜索其他服务,也可以运行您的服务 商店,你会找到值得信赖的人
  6. 我不知道为什么我的网络角色试图在这个位置找到证书,如果我强行搜索“我的商店”位置,但搜索方法从可信人员商店检索信息。

    此解决方法的问题是当您删除部署时,将删除证书和任何其他配置。

    这段代码可以为您提供一些信息:

    //the certificate must be in the Trusted People Store
    X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
    try
    {
        store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
       //Commented
       //Get the first available match from cert store
       //X509Certificate2 cert = store.Certificates.Find(X509FindType.FindBySubjectName,
                     // subjectname,
                     // false)
                     // .Cast<X509Certificate2>()
                     // .FirstOrDefault();
    
       X509Certificate2 cert = new X509Certificate2();
       foreach (var ct in store.Certificates)
       {
           //Logger.TraceInformation(string.Format("Cert found: Subject {0} Tumbprt:{1}", ct.FriendlyName, ct.Thumbprint));
           if (ct.SubjectName.Name.ToString().Contains("*.certnamexx.extensionxx"))
           {
               return new X509SecurityToken(ct);
           }
    
        }
    }