Como analisar uma solicitação de asserção SAML em .Net
Estou tentando implementar uma solução SAML SSO no .Net, mas estou tendo um problema ao analisar a asserçã
Tenho uma afirmação de amostra (parecebyte[]
dados como texto) e.p7b
Arquivo
Eu quero carregar as chaves do.p7b
e decodifique a asserção para um documento XM
té agora, acho que estou lendo as teclas corretament
// 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;
Então eu tento analisar a afirmação, eu tenho um problema:
// 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 the SAML data in an XML reader
var reader = XmlReader.Create(assertionPostStream);
// use the WS Security stuff to parse the reader
var securityToken = WSSecurityTokenSerializer.
DefaultInstance.ReadToken(reader, resolver) as SamlSecurityToken;
Essa última instrução gera uma exceção, afirmando que não pode analisar o conteúdo XM
Acho que isso significa que estou perdendo um passo para descriptografar a afirmação - obtendo obyte[]
como texto convertido em um documento XML no formato SAM
Alguém sabe como adicionar esta etapa? Estou perdendo outra coisa?