我正在将API SAML2.0用于ASP.net MVC,并且我使用openssl创建了专用和公用密钥文件,并对专用文件使用了密码。它生成了两个文件ca.key和cas.pem,我使用ca.key文件作为私钥,但出现此错误
其他信息:无法从文件D:\ Test Web Projects \ TestSaml \ TestSaml \ Certificates \ ca.key加载X.509证书。
我的用户登录到我的mvc应用程序时,登录过程与SAML无关。我只是对照我的数据库检查用户。我使用SAML2.0的原因是,我需要将我的用户引导进行付款过程到另一个外部页面,该页面是我的服务提供商。因此,一旦他们单击我页面上的按钮,便应将其重定向到其他网站。以下是我用来验证其工作原理的示例代码。
Web.config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<appSettings>
<add key="TargetURL" value="https://btat2.paybill.com/consumer/SSO/SSOLogin?clientId=ReadyCapital"/>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
Saml.config
<?xml version="1.0"?>
<SAMLConfiguration xmlns="urn:componentspace:SAML:2.0:configuration">
<IdentityProvider Name="https://TestSaml"
Description="Test Identity Provider"
LocalCertificateFile="Certificates\ca.key"
LocalCertificatePassword="readycapital"/>
<PartnerServiceProviders>
<!-- MVC example -->
<PartnerServiceProvider Name="urn:oasis:names:tc:SAML:2.0:assertion"
Description="MVC Example Service Provider"
SignSAMLResponse="true"
SignAssertion="false"
EncryptAssertion="true"
AssertionConsumerServiceUrl="http://www.paybill.com/V2/Test/Login.aspx"
PartnerCertificateFile="Certificates\btat2.cert"/>
</PartnerServiceProviders>
</SAMLConfiguration>
控制器
public ActionResult Index(Profile profile)
{
string targetUrl = WebConfigurationManager.AppSettings["TargetURL"];
string userName = "00373219101";// WebConfigurationManager.AppSettings["SubjectName"];
SAMLAttribute[] attributes = new SAMLAttribute[2];
SAMLAttribute attribute = new SAMLAttribute("UserEmailAddress", SAMLIdentifiers.AttributeNameFormats.Unspecified, null, string.Empty);
attributes[0] = attribute;
SAMLAttribute attribute2 = new SAMLAttribute("MiscellaneousData", SAMLIdentifiers.AttributeNameFormats.Unspecified, null, string.Empty);
attributes[1] = attribute2;
SAMLIdentityProvider.InitiateSSO(Response, userName, attributes, targetUrl);
}
答案 0 :(得分:1)
您是否检查了WebServer是否可以实际访问文件?也许使用Microsoft Windows Sysinternals Process Monitor并检查读取操作是否成功。
将独立的.key文件替换为.pfx文件,该文件既包含证书又包含私钥,并链接到IdentityProvider / @ LocalCertificateFile中的证书