2012-07-15 97 views
4

內加載證書例如我有希望呼叫的管理服務(例如REST API),並收集有關相關的服務信息的天青工作者角色。但是,當我嘗試加載我的證書時,它無法找到它。下面是我遵循的步驟:無法從Azure的輔助角色

我創建使用MakeCert證書,並通過門戶網站註冊它作爲我的管理證書

makecert -r -pe -a -n SHA1「CN = MyCnName」 -SS我-len 2048 -SP 「Microsoft增強RSA和AES加密提供」 -sy 24 MyCert.cer

2.安裝在我的本地計算機上的證書,一切工作正常。當在本地運行工作者角色時,我可以毫無問題地致電管理服務。

從我的計算機導出的證書,並通過門戶網站

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"); 
} 

有沒有例外,只是沒有發現證書。任何人都可以點亮我需要做的事情嗎?

回答

8

想通了這個問題。除了配置在門戶網站的證書,我需要添加證書的詳細信息(例如名稱,商店,和指紋)到Certificates選項卡下的Azure項目角色設置。

0

我有一個Web角色類似的問題,我已經申請一個解決方法。

  1. 連接與遠程桌面虛擬機在服務和 證書是在部署
  2. 列表項
  3. 複製你的證書或pfx您 虛擬機本地磁盤上(例如C:
  4. 點擊您的pfx或.cert文件和 將其安裝在特定證書存儲「受信任的人」)
  5. 運行您的服務,即使您配置爲在不同的上進行搜索商店,你會發現在信任的人

我不知道爲什麼我的Web角色試圖找到證書這個位置上,如果我強迫到「我的店」位置搜索,但搜索方法檢索信息值得信賴的人存儲

這個解決辦法的問題是,當你刪除部署的證書和任何其他配置都將灰飛煙滅。

這段代碼可以給你一些信息:

//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); 
     } 

    } 
}