2016-12-07 135 views
3

我需要從Azure函數訪問證書。從C#Azure函數內訪問證書

我按照Runtime error loading certificate in Azure Functions中列出的步驟操作,但沒有解決。

private static X509Certificate2 GetCertificate(string thumbprint, TraceWriter log) 
{ 
    X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser); 
    try 
    { 
     store.Open(OpenFlags.ReadOnly); 
     log.Info("Enumerating certificates"); 
     foreach (var cert in store.Certificates) { 
      log.Info(cert.Subject); 
     } 
     var col = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false); 
     if (col == null || col.Count == 0) 
     { 
      return null; 
     } 
     return col[0]; 
    } 
    finally 
    { 
     store.Close(); 
    } 

}

兩個證書,其中上傳到天青功能並加入設定WEBSITE_LOAD_CERTIFICATES以及和設置爲*或以所需的證書的thumpbrint,但沒有效果。

GetCertificate方法應打印商店中所有證書的列表,但商店爲空。

關於如何解決這個問題的任何線索?

+0

您是否嘗試過爲webjobs搜索類似的問題?因爲解決方案將是相同的 – 4c74356b41

+0

是的。他們都建議上述鏈接中概述的方法應該可行。但事實並非如此。 –

+0

當我使用Azure訪問證書時,我總是使用StoreLocation.LocalMachine。我沒有在函數中嘗試過,但是在其他WebApps和CloudService中,它與LocalMachine一起工作 – dave000

回答

3

客戶證書尚未支持我們的消費計劃,只在應用服務計劃。這由我們的回購here中的問題進行跟蹤。我們正在研究它 - 請遵循該問題的狀態。謝謝。