[英]How do I pull the thumbprint out of a SSL certificate FILE (not the windows cert store)?
[英]When trying to deserialize SAML tokens, can I read an SSL Cert from file instead of Certificate store
我想這樣的事情:
<microsoft.identityModel>
<service>
<serviceCertificate>
<certificateReference filename="App_Data/my.domain.com.crt" />
</serviceCertificate>
</service>
</microsoft.identityModel>
根據文檔 ,沒有。 要解密SAML令牌,WIF需要訪問證書的私鑰 。 通過將證書及其私鑰放在文件系統上(特別是在IIS管理的文件夾下 - 無論提供哪種保護)通常都是一個壞主意(tm)。 通過將證書放在證書庫中,您可以更嚴格地控制和管理對證書的訪問。
你可以,但正如Bobby建議你最好安裝在mahcine商店的證書。 實際上,當在Windows Azure上使用WIF部署應用程序時,這是一種解決方法,因為它不支持上傳證書。 這個限制早已不復存在。
我想到了。 在web.config中注釋掉這部分
<!--<serviceCertificate>
<certificateReference x509FindType="FindByThumbprint" findValue="" storeLocation="LocalMachine" storeName="My" />
</serviceCertificate>-->
將此代碼添加到global.asax
protected void Application_Start()
{
Microsoft.IdentityModel.Web.FederatedAuthentication.ServiceConfigurationCreated += new EventHandler
<Microsoft.IdentityModel.Web.Configuration.ServiceConfigurationCreatedEventArgs>(AttachCert);
}
protected void AttachCert(object sender, Microsoft.IdentityModel.Web.Configuration.ServiceConfigurationCreatedEventArgs e)
{
var filename = string.Format("{0}\\{1}\\{2}", System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, "App_Data\\certificates", "CERTNAME.pfx");
var cert = new System.Security.Cryptography.X509Certificates.X509Certificate2(filename, "YOURPASSWORD");
var _configuration = e.ServiceConfiguration;
_configuration.ServiceCertificate = cert;
var certificates = new List<System.IdentityModel.Tokens.SecurityToken> { new System.IdentityModel.Tokens.X509SecurityToken(
_configuration.ServiceCertificate) };
var encryptedSecurityTokenHandler =
(from handler in _configuration.SecurityTokenHandlers
where handler is Microsoft.IdentityModel.Tokens.EncryptedSecurityTokenHandler
select handler).First() as Microsoft.IdentityModel.Tokens.EncryptedSecurityTokenHandler;
_configuration.ServiceTokenResolver = encryptedSecurityTokenHandler.Configuration.ServiceTokenResolver =
System.IdentityModel.Selectors.SecurityTokenResolver.CreateDefaultSecurityTokenResolver(certificates.AsReadOnly(), false);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.