MHO*_*OOS 3 c# ssl azure ssl-certificate azure-web-sites
据我了解,如果有人不想使用自定义域名,而是打算使用Azure分配给网站的* .azurewebsite.net域,则HTTPS已通过Microsoft的证书启用(我知道这不是使用自定义域名是安全的)。我将如何以编程方式加载此证书。当前,我使用以下方法从本地计算机或Azure加载证书:
public static X509Certificate2 LoadFromStore(string certificateThumbprint,bool hostedOnAzure)
{
var s = certificateThumbprint;
var thumbprint = Regex.Replace(s, @"[^\da-zA-z]", string.Empty).ToUpper();
var store = hostedOnAzure ? new X509Store(StoreName.My, StoreLocation.CurrentUser) : new X509Store(StoreName.Root, StoreLocation.LocalMachine);
try
{
store.Open(OpenFlags.ReadOnly);
var certCollection = store.Certificates;
var signingCert = certCollection.Find(X509FindType.FindByThumbprint, thumbprint, false);
if (signingCert.Count == 0)
{
throw new FileNotFoundException(string.Format("Cert with thumbprint: '{0}' not found in certificate store. Also number of certificates in the sotre was {1}", thumbprint, store.Certificates.Count));
}
return signingCert[0];
}
finally
{
store.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
我认为罪魁祸首是以下代码行:
new X509Store(StoreName.My, StoreLocation.CurrentUser)
Run Code Online (Sandbox Code Playgroud)
因为当我遇到异常时,它会告诉我商店中没有证书,尽管我通过了正确的证书Thumbprint(我从Chrome手动获取了指纹)。
您将无法在WebApp中以编程方式访问此证书,因为该证书并未真正安装在Azure WebApp上。Azure WebApp的前端服务器执行“某种” SSL卸载,因此WebApp实际上永远无法访问此特定证书。为什么您确实要阅读此证书?
通常,如果有必要在WebApps的证书,您将安装客户端证书,并将其传递给服务身份验证中提到https://azure.microsoft.com/en-us/blog/using-certificates-in-azure- website-applications /和您可以通过编程方式访问的那些证书(同一文章中提到的代码段)
但是我不确定通过阅读服务器证书到底要实现什么目标
| 归档时间: |
|
| 查看次数: |
594 次 |
| 最近记录: |