Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>SAML responses come with a signature and a public key for that signature.</p> <p>You can use the public key to verify that the content of the SAML response matches the key - in other words - that response definitely came from someone who has the matching private key to the public key in the message, and the response hasn't been tampered with.</p> <p>I don't know what tech you're working with, but in .Net you can check it like this:</p> <pre class="lang-cs prettyprint-override"><code>// load a new XML document var assertion = new XmlDocument { PreserveWhitespace = true }; assertion.LoadXml("The SAML XML that you were sent"); // 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("asrt", @"urn:oasis:names:tc:SAML:2.0:assertion"); ns.AddNamespace("dsig", @"http://www.w3.org/2000/09/xmldsig#"); // get nodes down to the signature var responseNode = assertion.SelectSingleNode("/samlp:Response", ns); var assertionNode = responseNode.SelectSingleNode("asrt:Assertion", ns); var signNode = assertionNode.SelectSingleNode("dsig:Signature", ns); // load the XML signature var signedXml = new SignedXml(assertion.DocumentElement); signedXml.LoadXml(signNode as XmlElement); // get the certificate, basically: // signedXml.KeyInfo[0].Certificates[0] // ...but with added casting var certificate = GetFirstX509Certificate(signedXml); // check the key and signature match bool isSigned = signedXml.CheckSignature(certificate, true); </code></pre> <p>That just checks that the message is from who it says it is. You need an additional check that the message has come from someone that you trust, and this check is slower - it needs to include revocation and may need to verify a whole chain of certificates.</p> <p>Normally this will be a list of public keys that you would accept SAML responses from.</p> <p>Then you can check that this message hasn't been tampered with, and is from someone that you trust, so you can authorise the user details supplied in the SAML attributes supplied.</p> <p>You <em>could</em> already have the public key, meaning that the signature shouldn't need to include the public key again, but you could also have multiple possible known senders, or even a chain of known senders.</p> <p>For instance you may have two trusted providers - in either case you check that the message has not been tampered with before checking whether you trust either provider. If the key isn't in the signature the assertions can be a little smaller, but now you have to know in advance which identity provider the assertion has come from.</p> <p>So, really, there are two main reasons that the public key is in the signature:</p> <ol> <li>The tamper check is quicker than the identity check, and can be isolated if the public key is known.</li> <li>Multiple identities are much easier to support if the key is in the assertion.</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload