473,395 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How can Validate SAML Assertion in .NET

Hi All,

I am getting the valid SAML response from the vendor and I just want to validate SAML Assertion.

Below is the SAML response and I have mask few things with xxxxxxxxxxxxxxxxxxxxxx due to vendor concern.

Expand|Select|Wrap|Line Numbers
  1. <samlp:Response IssueInstant="" ID="gzRaMPjm98mgG0_s0ylFgO85wao" Version="2.0" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
  2. <saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">http://xxxxxxxxxx.com/</saml:Issuer>
  3. <samlp:Status>
  4. <samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
  5. </samlp:Status>
  6. <saml:Assertion Version="2.0" IssueInstant="6273" ID="wZT13pIVg8n60RZgGm_fWAhYNSP" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
  7. <saml:Issuer>http://xxxxxx.com/</saml:Issuer>
  8. <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
  9. <ds:SignedInfo>
  10. <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
  11. <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
  12. <ds:Reference URI="#wZT13pIVg8n60RZgGm_fWAhYNSP">
  13. <ds:Transforms>
  14. <ds:Transform Algorithm="http://www..w3.org/2000/09/xmldsig#enveloped-signature"/>
  15. <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
  16. </ds:Transforms>
  17. <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
  18. <ds:DigestValue>xxxxxxxxxxxxxxxxxxxxxxx</ds:DigestValue>
  19. </ds:Reference>
  20. </ds:SignedInfo>
  21. <ds:SignatureValue>
  22. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  23. </ds:SignatureValue>
  24. <ds:KeyInfo>
  25. <ds:X509Data>
  26. <ds:X509Certificate>
  27. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  28. </ds:X509Certificate>
  29. </ds:X509Data>
  30. <ds:KeyValue>
  31. <ds:RSAKeyValue>
  32. <ds:Modulus>
  33. xxxxxxxx
  34. </ds:Modulus>
  35. <ds:Exponent>xxx</ds:Exponent>
  36. </ds:RSAKeyValue>
  37. </ds:KeyValue>
  38. </ds:KeyInfo>
  39. </ds:Signature>
  40. <saml:Subject>
  41. <saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">staff</saml:NameID>
  42. <saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
  43. <saml:SubjectConfirmationData NotOnOrAfter=" " Recipient="https://xxxxxxxxx.com"/>
  44. </saml:SubjectConfirmation>
  45. </saml:Subject>
  46. <saml:Conditions NotOnOrAfter="" NotBefore="">
  47. <saml:AudienceRestriction>
  48. <saml:Audience>http://xxxxxxxxxxxxxxxx.com</saml:Audience>
  49. </saml:AudienceRestriction>
  50. </saml:Conditions>
  51. <saml:AuthnStatement AuthnInstant=" " SessionIndex="wZT13pIVg8n60RZgGm_fWAhYNSP">
  52. <saml:AuthnContext>
  53. <saml:AuthnContextClassRef></saml:AuthnContextClassRef>
  54. </saml:AuthnContext>
  55. </saml:AuthnStatement>
  56. <saml:AttributeStatement xmlns:xs="http://www.w3.org/2001/XMLSchema">
  57. <saml:Attribute NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic" Name="role">
  58. <saml:AttributeValue xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">http://xxxx.com/</saml:AttributeValue>
  59. </saml:Attribute>
  60. </saml:AttributeStatement>
  61. </saml:Assertion>
  62. </samlp:Response>
I have tried the below code in the .NET 3.5 web application and I am always getting the invalid signature message from the code. Please have a look in the code and suggest me.

Thanks in Advance.

Expand|Select|Wrap|Line Numbers
  1. XmlDocument doc = new XmlDocument();
  2.  
  3. doc.Load(Server.MapPath("SAML.xml"));
  4.  
  5. SignedXml signer = new CustomIdSignedXml(doc);
  6.  
  7. signer.AddReference(new Reference("#_d4559638-3abf-4433-9fad-b10f8a950351"));
  8. // _d4559638-3abf-4433-9fad-b10f8a950351 is used as reference to DigestMethod & DigestValue.
  9.  
  10. signer.SigningKey = new RSACryptoServiceProvider();
  11.  
  12. signer.ComputeSignature();
  13.  
  14. string s = signer.GetXml().OuterXml;
  15.  
  16. SignedXml verifier = new CustomIdSignedXml(doc);
  17.  
  18. verifier.LoadXml(signer.GetXml());
  19.  
  20. if (verifier.CheckSignature(signer.SigningKey))
  21.      Response.Write("Signature verified");
  22. else
  23.      Response.Write("Invalid signature");
Jun 30 '11 #1
0 1469

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mike Ash | last post by:
I inherited an existing application that needs some serious enhancement, though I am not fluent in the language it was developed in (PERL). I was hoping to migrate everything over to PHP, since I...
1
by: Robert Boyd | last post by:
Greetings, Has anyone worked with Python and SAML (the Security Assertion Markup Language, not Simple Algebraic Math Library)? I find very few references, most work has been done with Java. I...
2
by: jacksuyu | last post by:
For example the XML looks like: <SOAP-ENV:Body> <samlp:Response InResponseTo="abcd" IssueInstant="2005-02-03T20:18:06Z" MajorVersion="1" MinorVersion="0" ResponseID="abcd"> <samlp:Status>...
0
by: oliver.wulff | last post by:
Hi everybody Does there exist a SDK for SAML? It's much easier to call a .NET API instead of creating the XML structure by myself. Thank you very any hints Oliver
1
by: bp100a | last post by:
Does anyone know of a SAML api for C#? I know about the Java & C++ APIs at the OpenSAML site. /harry
1
by: Bob | last post by:
I'm doing a scoping study for a Single-Sign-On integration project with a client. The client's SSO interface is built on SAML 1.1 specification using Verisign TSIK, and needless to say, they have...
0
by: Lucas Tam | last post by:
Are there any open source SAML tool kits for .NET 1.1? I found SourceID's kit, but they seemed to have moved it to .NET 2.0 beta. Unfortunately I don't have a copy of VS.NET 2005 and I can't run...
10
by: Matthew Wilson | last post by:
Lately, I've been writing functions like this: def f(a, b): assert a in assert b in The point is that I'm checking the type and the values of the parameters.
0
by: rancedowner1234 | last post by:
I have successfully authenticated to a webservice that returns a SAML 1.0 token. I am using Visual Studio 2005 and WSE 3. How do I now parse out the SAML token so that I can send it to subsequent...
0
by: Marc Scheuner | last post by:
Folks, I'm trying to figure out what's going on in our ASP.NET 2.0 app here. We're using .NET 3.0 WCF to communicate with tons of external web services. So far, we've been using Forms...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.