Blame SOURCES/0007-PAOS-Do-not-populate-Destination-attribute.patch

078269
From 1e85f1b2bd30c0d93b4a2ef37b35abeae3d15b56 Mon Sep 17 00:00:00 2001
078269
From: Dmitrii Shcherbakov <dmitrii.shcherbakov@canonical.com>
078269
Date: Fri, 28 Jun 2019 02:36:19 +0300
078269
Subject: [PATCH] PAOS: Do not populate "Destination" attribute
078269
078269
When ECP profile (saml-ecp-v2.0-cs01) is used with PAOS binding Lasso
078269
populates an AuthnRequest with the "Destination" attribute set to
078269
AssertionConsumerURL of an SP - this leads to IdP-side errors because
078269
the destination attribute in the request does not match the IdP URL.
078269
078269
The "Destination" attribute is mandatory only for HTTP Redirect and HTTP
078269
Post bindings when AuthRequests are signed per saml-bindings-2.0-os
078269
(sections 3.4.5.2 and 3.5.5.2). Specifically for PAOS it makes sense to
078269
avoid setting that optional attribute because an ECP decides which IdP
078269
to use, not the SP.
078269
078269
Fixes Bug: 34409
078269
License: MIT
078269
Signed-off-by: Dmitrii Shcherbakov <dmitrii.shcherbakov@canonical.com>
078269
---
078269
 lasso/saml-2.0/login.c   | 18 +++++++++---------
078269
 lasso/saml-2.0/profile.c | 10 +++++++++-
078269
 2 files changed, 18 insertions(+), 10 deletions(-)
078269
078269
diff --git a/lasso/saml-2.0/login.c b/lasso/saml-2.0/login.c
078269
index 6e8f7553..0d4bb1da 100644
078269
--- a/lasso/saml-2.0/login.c
078269
+++ b/lasso/saml-2.0/login.c
078269
@@ -222,7 +222,7 @@ _lasso_login_must_verify_signature(LassoProfile *profile) {
078269
 gint
078269
 lasso_saml20_login_build_authn_request_msg(LassoLogin *login)
078269
 {
078269
-	char *url = NULL;
078269
+	char *assertionConsumerServiceURL = NULL;
078269
 	gboolean must_sign = TRUE;
078269
 	LassoProfile *profile;
078269
 	LassoSamlp2AuthnRequest *authn_request;
078269
@@ -247,29 +247,29 @@ lasso_saml20_login_build_authn_request_msg(LassoLogin *login)
078269
 	}
078269
 
078269
 	if (login->http_method == LASSO_HTTP_METHOD_PAOS) {
078269
-
078269
 		/*
078269
 		 * PAOS is special, the url passed to build_request is the
078269
 		 * AssertionConsumerServiceURL of this SP, not the
078269
-		 * destination.
078269
+		 * destination IdP URL. This is done to fill paos:responseConsumerURL
078269
+		 * appropriately down the line in build_request_msg.
078269
+		 * See https://dev.entrouvert.org/issues/34409 for more information.
078269
 		 */
078269
 		if (authn_request->AssertionConsumerServiceURL) {
078269
-			url = authn_request->AssertionConsumerServiceURL;
078269
+			assertionConsumerServiceURL = authn_request->AssertionConsumerServiceURL;
078269
 			if (!lasso_saml20_provider_check_assertion_consumer_service_url(
078269
-					LASSO_PROVIDER(profile->server), url, LASSO_SAML2_METADATA_BINDING_PAOS)) {
078269
+					LASSO_PROVIDER(profile->server), assertionConsumerServiceURL, LASSO_SAML2_METADATA_BINDING_PAOS)) {
078269
 				rc = LASSO_PROFILE_ERROR_INVALID_REQUEST;
078269
 				goto cleanup;
078269
 			}
078269
 		} else {
078269
-			url = lasso_saml20_provider_get_assertion_consumer_service_url_by_binding(
078269
+			assertionConsumerServiceURL = lasso_saml20_provider_get_assertion_consumer_service_url_by_binding(
078269
 					LASSO_PROVIDER(profile->server), LASSO_SAML2_METADATA_BINDING_PAOS);
078269
-			lasso_assign_new_string(authn_request->AssertionConsumerServiceURL, url);
078269
+			lasso_assign_new_string(authn_request->AssertionConsumerServiceURL, assertionConsumerServiceURL);
078269
 		}
078269
 	}
078269
 
078269
-
078269
 	lasso_check_good_rc(lasso_saml20_profile_build_request_msg(profile, "SingleSignOnService",
078269
-				login->http_method, url));
078269
+				login->http_method, assertionConsumerServiceURL));
078269
 
078269
 cleanup:
078269
 	return rc;
078269
diff --git a/lasso/saml-2.0/profile.c b/lasso/saml-2.0/profile.c
078269
index 22a4e08c..85f535ae 100644
078269
--- a/lasso/saml-2.0/profile.c
078269
+++ b/lasso/saml-2.0/profile.c
078269
@@ -968,7 +968,15 @@ lasso_saml20_profile_build_request_msg(LassoProfile *profile, const char *servic
078269
 		made_url = url = get_url(provider, service, http_method_to_binding(method));
078269
 	}
078269
 
078269
-	if (url) {
078269
+
078269
+	// Usage of the Destination attribute on a request is mandated only
078269
+	// in "3.4.5.2" and "3.5.5.2" in saml-bindings-2.0-os for signed requests
078269
+	// and is marked as optional in the XSD schema otherwise.
078269
+	// PAOS is a special case because an SP does not select an IdP - ECP does
078269
+	// it instead. Therefore, this attribute needs to be left unpopulated.
078269
+	if (method == LASSO_HTTP_METHOD_PAOS) {
078269
+		lasso_release_string(((LassoSamlp2RequestAbstract*)profile->request)->Destination);
078269
+	} else if (url) {
078269
 		lasso_assign_string(((LassoSamlp2RequestAbstract*)profile->request)->Destination,
078269
 				url);
078269
 	} else {
078269
-- 
078269
2.20.1
078269