When verifying a signature of a message it is recommended to first validate the message with a SAML profile validator. This to ensure that the signature follows the standard for XML signatures. Afterwords the cryptography validation of the signatureis done by a SignatureValidator.
PS. This validation only performs a cryptographic validation of the signature. This means that it validates that the message has not been changed since it was signed. It does however not check that the certificate used for signing is trusted. To confirm the trust of the certificate in OpenSAML, a trust engine must be used in the validation.
The most common method to confirm the trust of a key is to compare it to the key recieved in SAML Metadata. This is generally done as a configuration step when setting up a SAML federation. This post gives more information on SAML Metadata
Here is a full example of the crytographic validation.
SAMLSignatureProfileValidator profileValidator = new SAMLSignatureProfileValidator(); profileValidator.validate(entityDescriptor.getSignature()); SignatureValidator sigValidator = new SignatureValidator(cred); sigValidator.validate(entityDescriptor.getSignature());SignatureValidator is instansiated with a credenial. in this case the credential basically contains the public key for the private key that was used to sign the message.
The credetial object can be obtained in a number of different ways. This post shows some methods in OpenSAML.
If the public key was sent in the message, it is very important to validate that you trust the key.
Further reading
My book, A Guide to OpenSAML, explains in detail how to use the security features of SAML and much more.
Is there an easy way to verify a SAML 2 response with the certificate inside the signed response? Or do I have to parse the XML on my own and get the credentials and feed to SignatureValidator?
ReplyDeleteThe OpenSAML documentation is really difficult to follow and the code examples includes lots of method calls not included in the examples(!)
I have not tried this and i do not have any good answer. Al I have is som hints and tips to help you search.
DeleteThere is something called a keyInfoCredentialResolver. This might help you to extrac the credentials needed to validate the signature.
You will need to validate that the key in the message is signed by a CA you trust. This i sdone using trust engines. There is a short incomplete chapter about it in the documentation.
https://wiki.shibboleth.net/confluence/display/OpenSAML/OSTwoUserManJavaTrust
If you figure it out, please post a comment telling me how you did it =)
Hi, have you figured out a way to use the credentials from within the XML as public key?
DeleteThanks for the reply. It's reassuring to hear it's not something very simple I'm overlooking.
ReplyDeleteI'll update these comments if I find a solution, but at the moment I'm probably just going to use an "out-of-band" metadata file instead.
Hi Erik, I know this was 5 years ago, but were you able to find a solution to this?
DeleteHey Stefan,
ReplyDeleteThank you for all your entries on OpenSAML - they certainly helped. Even so, I'm still having issues verifying the SAML signature. I posted the question on stackoverflow (http://stackoverflow.com/questions/17890642/opensaml-2-0-signature-validation-not-working) - do you have any suggestions?
Can you send me the whole request?
DeleteHi Stefan.
ReplyDeleteThank you very much for you posts about OpenSAML. I'm in the process of writing my own set of wrappers that pull the SAMLResponse from the header and perform my own validation based on:
- checking the conditions
- extracting the certificate from the assertion
- compare the thumbprint OR compare against the idp metadata
- verify the issuer
- extract the name ID and attributes
I'm wondering if you know of a wrapper library that does this work or if I should proceed creating my own?
I know there are many implementations that can do this. But those are more ready applications like OpenAM and not libraries.
DeleteThis can be done with OpenSAML but requires alot of own work.
Sorry I dont any such library. Pleas post a comment if you find one
Hi Stefan,
ReplyDeletehow can i get the public key from the assertion in java?
Is the key contained in a KeyInfo element? In that case use a keyInfoCredentialResolver
DeleteI bought your book but I cant find how to validade the XML in V3. I am using Configuration.getValidatorSuite(suiteId).validate(response); in V2 but in V3 I am not sure how to do it.
ReplyDeleteHi there, have a look on this post http://blog.samlsecurity.com/2016/08/verifying-signatures-with-opensaml-v3.html
DeleteHi Stefan,
ReplyDeleteWe have integrated SAML to our spring application. It Was working fine before it started giving "Validation of protocol message signature failed" error recently. I searched online but didnt get anything concrete. Can you help me with this.
Well, if you have not done any change in your system I would check with your IDP to ensure that they have not changed their signing key.
Delete