相关疑难解决方法(0)

如何针对X509Certificate2Collection链验证X509Certificate2

我正在编写一个SAML 2.0响应解析器来处理ASP.Net中的POST身份验证(在C#和MVC中,但这不太相关).

所以我有一个.p7b要验证的文件,可以读入一个X509Certificate2Collection和一个示例断言 - 一个基本的64位编码的SAML响应.

理想情况下,我想使用内置的WSSecurityTokenSerializer,但失败了,所以我正在寻找一种有效的方法.

我正在直接读取XML:

// get the base 64 encoded SAML
string samlAssertionRaw = GetFromHttpRequest();

// load a new XML document
var assertion = new XmlDocument { PreserveWhitespace = true };
assertion.LoadXml(samlAssertionRaw);

// use a namespace manager to avoid the worst of xpaths
var ns = new XmlNamespaceManager(assertion.NameTable);
ns.AddNamespace("samlp", @"urn:oasis:names:tc:SAML:2.0:protocol");
ns.AddNamespace("saml", @"urn:oasis:names:tc:SAML:2.0:assertion");
ns.AddNamespace("ds", SignedXml.XmlDsigNamespaceUrl);

// get the signature XML node
var signNode = assertion.SelectSingleNode(
    "/samlp:Response/saml:Assertion/ds:Signature", ns);

// load the …
Run Code Online (Sandbox Code Playgroud)

.net x509certificate single-sign-on saml-2.0 pkcs#7

10
推荐指数
1
解决办法
8061
查看次数

如何在.Net中解析SAML断言请求

我正在尝试在.Net中实现SAML SSO解决方案,但我在解析断言时遇到问题.

我有一个示例断言(看起来像byte[]数据作为文本)和相应的.p7b文件.

我想从中加载密钥.p7b并将断言解密为XML文档.

到目前为止,我认为我正在正确读取键:

// get the key data
byte[] certificateData = System.IO.File.ReadAllBytes("myKeys.p7b");

// decode the keys
var cms = new SignedCms(SubjectIdentifierType.IssuerAndSerialNumber);
cms.Decode(certificateData);

var samlCertificates = cms.Certificates;
Run Code Online (Sandbox Code Playgroud)

然后我尝试解析我遇到问题的断言:

// we have a keychain of X509Certificate2s, we need a collection of tokens
var certificatesAsTokens =
    from X509Certificate2 cert in samlCertificates
    select new X509SecurityToken(cert) as SecurityToken;

// get a token resolver
var tokens = new ReadOnlyCollection<SecurityToken>(
    certificatesAsTokens.ToList());
var resolver = SecurityTokenResolver.CreateDefaultSecurityTokenResolver(
    tokens, true);

// get …
Run Code Online (Sandbox Code Playgroud)

.net saml x509certificate single-sign-on pkcs#7

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

.net ×2

pkcs#7 ×2

single-sign-on ×2

x509certificate ×2

saml ×1

saml-2.0 ×1