ComponentSpace

Forums



'saml' is an undeclared prefix.


'saml' is an undeclared prefix.

Author
Message
sstewart
sstewart
New Member
New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)

Group: Awaiting Activation
Posts: 2, Visits: 22
Having a weird issue.  I have a SAML token with an encrypted assertion.   It parses XML just fine.  I can load it into SAMLResponse just fine.  I can pull off the EncryptedAssertion using SAMLResponse.GetEncryptedAssertion() just fine.

However when I call EncryptedAssertion.Decrypt() I get an exception:

Exception: ComponentSpace.SAML2.Exceptions.SAMLEncryptionException
  Message:   Failed to decrypt XML.

    Inner Exception:
  {
  Exception: System.Xml.XmlException
  Message:
 'saml' is an undeclared prefix. Line 1, position 2.
Stack Trace
 at System.Xml.XmlTextReaderImpl.Throw(Exception e)
 at System.Xml.XmlTextReaderImpl.Throw(String res, String arg, Int32 lineNo, Int32 linePos)
 at System.Xml.XmlTextReaderImpl.LookupNamespace(NodeData node)
 at System.Xml.XmlTextReaderImpl.ElementNamespaceLookup()
 at System.Xml.XmlTextReaderImpl.ParseAttributes()
 at System.Xml.XmlTextReaderImpl.ParseElement()
 at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
 at System.Xml.XmlTextReaderImpl.Read()
 at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
 at System.Xml.Xmldocument.Load(XmlReader reader)
 at ComponentSpace.SAML2.Utility.Xml.LoadDocument(String xmlText)
 at ComponentSpace.SAML2.Utility.XmlEncryption.Decrypt(XmlElement encryptedElement, XmlNodeList encryptedKeysNodeList, AsymmetricAlgorithm keyDecryptingKey, EncryptionMethod keyEncryptionMethod, EncryptionMethod dataEncryptionMethod)

  }
}

I did a ToXml().OuterXml on the EncryptedAssertion and sure enough the prefix is defined:

<saml:EncryptedAssertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">

I then did an Xmldocument.LoadXml() on the results of EncryptedAssertion.ToXml().OuterXml, and it loads just fine.

I've attached the token and the pfx file Base64 encrypted (Since pfx files aren't allowed to be attached here)

You can execute and re-create with the following code:

var xml = File.ReadAllText("workingEncrypted.xml");    
var doc = new XmlDocument();
doc.PreserveWhitespace = true;
doc.LoadXml(xml);

var pfx = File.ReadAllText("qa.pfx.txt");//base64 of the pfx file
var pfxBytes = Convert.FromBase64String(pfx);
var cert = new X509Certificate2(pfxBytes);

var response = new SAMLResponse(doc.DocumentElement);
var encryptedAssertion = response.GetEncryptedAssertion();
var assertion = encryptedAssertion.Decrypt(cert);//This line blows up.

Any ideas why I'm getting that exception?

Thanks!
Attachments
workingEncrypted.xml (1 view, 3.00 KB)
qa.pfx.txt (1 view, 2.00 KB)
ComponentSpace
ComponentSpace
ComponentSpace Development
ComponentSpace Development (4K reputation)ComponentSpace Development (4K reputation)ComponentSpace Development (4K reputation)ComponentSpace Development (4K reputation)ComponentSpace Development (4K reputation)ComponentSpace Development (4K reputation)ComponentSpace Development (4K reputation)ComponentSpace Development (4K reputation)ComponentSpace Development (4K reputation)

Group: Administrators
Posts: 2.9K, Visits: 9.4K
Thanks for including all that information. The exception could be more descriptive but is essentially correct. It's referring to the decrypted SAML assertion (see attached) which is missing the saml:xmlns declaration. You can enable SAML trace to see the decrypted string prior to the attempt to load it as an XmlDocument.

https://www.componentspace.com/Forums/17/Enabing-SAML-Trace   

Regards
ComponentSpace Development
Attachments
samlassertion.xml (1 view, 1.00 KB)
sstewart
sstewart
New Member
New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)

Group: Awaiting Activation
Posts: 2, Visits: 22
ComponentSpace - 8/27/2020
Thanks for including all that information. The exception could be more descriptive but is essentially correct. It's referring to the decrypted SAML assertion (see attached) which is missing the saml:xmlns declaration. You can enable SAML trace to see the decrypted string prior to the attempt to load it as an Xmldocument.

https://www.componentspace.com/Forums/17/Enabing-SAML-Trace   

OHHHHH! LOL! thank you so much.  You have no clue how long I stared at that encrypted assertion looking for typos in the namespace, the prefix, etc etc.  Since I couldn't decrypt it I couldn't see the problem LOL!  I will read up on SAML-Trace. That should be especially helpful.  Thank you so much for your prompt response!
ComponentSpace
ComponentSpace
ComponentSpace Development
ComponentSpace Development (4K reputation)ComponentSpace Development (4K reputation)ComponentSpace Development (4K reputation)ComponentSpace Development (4K reputation)ComponentSpace Development (4K reputation)ComponentSpace Development (4K reputation)ComponentSpace Development (4K reputation)ComponentSpace Development (4K reputation)ComponentSpace Development (4K reputation)

Group: Administrators
Posts: 2.9K, Visits: 9.4K
You're very welcome.

Regards
ComponentSpace Development
GO


Similar Topics


Execution: 0.000. 2 queries. Compression Enabled.
Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....









Forums, Documentation & Knowledge Base - ComponentSpace


Search