feat: validate responses encrypted with XML Encryption 1.1 - #13
Merged
Conversation
An IdP that encrypts with XML Encryption 1.1 puts an <xenc11:MGF> element
inside <xenc:EncryptionMethod>. That position is a wildcard whose
processContents is strict, so the element has to be declared somewhere in the
schema set; the set here carried XML Encryption 1.0 only. The result was that
the entire response failed schema validation -- before decryption was even
attempted -- with:
cvc-complex-type.2.4.c: ... no declaration found for element 'xenc11:MGF'
Invalid SAML Response. Not match the saml-schema-protocol-2.0.xsd
Nothing is wrong with such a message: the keys, the certificate and the
ciphertext are all fine, and the same response is accepted and decrypted once
schema validation is switched off. Current Keycloak encrypts this way by
default (xmlenc11#rsa-oaep with mgf1sha256, xmlenc11#aes256-gcm), so a service
provider asking for encrypted assertions could not accept its assertions at
all.
Adds the W3C XML Encryption 1.1 schema next to the ones already bundled and
compiles it into every schema set built here, rather than editing a published
schema to import it. The resolver also maps the 1.1 namespace to the local
copy, so a document that imports it is never fetched over the network.
The added test would pass just as well if validation had been loosened, so it
also asserts that an element that does not exist in the 1.1 namespace is still
refused. Without the schema the test fails on the response it is named for.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while verifying Fess 15.8's SAML SSO against a real IdP. Intended for the
release Fess 15.9 picks up, not for 15.8.
The problem
A service provider that asks for encrypted assertions cannot accept them from an
IdP that encrypts with XML Encryption 1.1. Current Keycloak does exactly that by
default:
http://www.w3.org/2009/xmlenc11#rsa-oaepfor key transport (with an<xenc11:MGF>child namingmgf1sha256) andxmlenc11#aes256-gcmfor content.<xenc:EncryptionMethod>ends in<any namespace="##other">whoseprocessContentsis strict, so anything carried there must be declared in theschema set. The set built here covers XML Encryption 1.0 only, so validation fails:
The response is refused in full, before decryption is attempted. Nothing about
it is malformed — the keys, certificate and ciphertext are all correct, and the same
response logs the user in once
wantXMLValidationis turned off. The message pointsat a malformed document rather than at an algorithm the schema set does not know, so
there is no path from the log to the cause.
The change
(
xenc-schema.xsd,xmldsig-core-schema.xsd, …). It carries the same W3Ccopyright header as its siblings and imports only xmldsig-core and XML Encryption
1.0, both of which are already present.
loadFromUrlbuilds, by passing both sources tonewSchema. Editing a published schema to add an<import>would work too, butkeeping the OASIS and W3C files byte-identical to what they publish seems worth
more than the one-line diff.
imports it is never fetched over the network — the same treatment every other
namespace here gets.
Tests
core415 → 416,toolkit92, all green.The new test uses a response whose
EncryptedKeycarries the<xenc11:MGF>elementan IdP actually emits. A test that only asserted "this now validates" would pass just
as well if validation had been loosened, so it also asserts that
<xenc11:NoSuchElement>— an element that does not exist in the 1.1 namespace — isstill refused. Against the previous
SchemaFactorythe test fails on the response itis named for.
What was measured, and what was not
Measured against a real IdP: an encrypted assertion refused with exactly the error
above while schema validation was on, and the same configuration logging in
successfully with it off — so decryption of RSA-OAEP/MGF1-SHA256 and AES-256-GCM
already works and schema validation was the only blocker. This PR is what removes
that blocker; the end-to-end run has not been repeated on top of this branch.