![](/img/trans.png)
[英]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.