Blame SOURCES/0006-Fix-ECP-signature-not-found-error-when-only-assertio.patch

e030e7
From 642182bdf49c9c93a86b093ad7335c8a7a5ae8cc Mon Sep 17 00:00:00 2001
e030e7
From: John Dennis <jdennis@redhat.com>
e030e7
Date: Wed, 9 Jan 2019 17:23:09 -0500
e030e7
Subject: [PATCH] Fix ECP signature not found error when only assertion is
e030e7
 signed (#26828)
e030e7
e030e7
With a SAML Authn Response either the message or the assertion
e030e7
contained in the response message or both can be signed. Most IdP's
e030e7
sign the message. This fixes a bug when processing an ECP authn
e030e7
response when only the assertion is signed.
e030e7
e030e7
lasso_saml20_profile_process_soap_response_with_headers() performs a
e030e7
signature check on the SAML message. A signature can also appear on
e030e7
the assertion which is checked by
e030e7
lasso_saml20_login_process_response_status_and_assertion() The problem
e030e7
occurred when the message was not signed and
e030e7
lasso_saml20_profile_process_soap_response_with_headers() returned
e030e7
LASSO_DS_ERROR_SIGNATURE_NOT_FOUND as an error code which is not
e030e7
actually an error because we haven't checked the signature on the
e030e7
assertion yet. We were returning the first
e030e7
LASSO_DS_ERROR_SIGNATURE_NOT_FOUND error when in fact the subsequent
e030e7
signature check in
e030e7
lasso_saml20_login_process_response_status_and_assertion() succeeded.
e030e7
e030e7
The ECP unit tests were enhanced to cover these cases.
e030e7
e030e7
The enhanced unit test revealed a problem in two switch statements
e030e7
operating on the return value of
e030e7
lasso_profile_get_signature_verify_hint() which were missing a case
e030e7
statement for LASSO_PROFILE_SIGNATURE_VERIFY_HINT_FORCE which caused
e030e7
an abort due to an unknown enumeration value.
e030e7
e030e7
Fixes Bug: 26828
e030e7
License: MIT
e030e7
Signed-off-by: John Dennis <jdennis@redhat.com>
e030e7
---
e030e7
 lasso/saml-2.0/login.c    | 29 ++++++++----
e030e7
 lasso/saml-2.0/profile.c  |  2 +
e030e7
 tests/login_tests_saml2.c | 97 +++++++++++++++++++++++++++++----------
e030e7
 3 files changed, 95 insertions(+), 33 deletions(-)
e030e7
e030e7
diff --git a/lasso/saml-2.0/login.c b/lasso/saml-2.0/login.c
e030e7
index 028ffb31..91ff302d 100644
e030e7
--- a/lasso/saml-2.0/login.c
e030e7
+++ b/lasso/saml-2.0/login.c
e030e7
@@ -1107,18 +1107,31 @@ lasso_saml20_login_process_paos_response_msg(LassoLogin *login, gchar *msg)
e030e7
 {
e030e7
 	LassoSoapHeader *header = NULL;
e030e7
 	LassoProfile *profile;
e030e7
-	int rc1, rc2;
e030e7
+	int rc;
e030e7
 
e030e7
 	lasso_null_param(msg);
e030e7
 
e030e7
 	profile = LASSO_PROFILE(login);
e030e7
 
e030e7
-	rc1 = lasso_saml20_profile_process_soap_response_with_headers(profile, msg, &header);
e030e7
+        /*
e030e7
+         * lasso_saml20_profile_process_soap_response_with_headers()
e030e7
+         * performs a signature check on the SAML message. A signature
e030e7
+         * can also appear on the assertion which is checked by
e030e7
+         * lasso_saml20_login_process_response_status_and_assertion()
e030e7
+         * (below). Therefore if the error is SIGNATURE_NOT_FOUND we
e030e7
+         * proceed because
e030e7
+         * lasso_saml20_login_process_response_status_and_assertion()
e030e7
+         * will test the signature on the assertion.
e030e7
+         */
e030e7
+	rc = lasso_saml20_profile_process_soap_response_with_headers(profile, msg, &header);
e030e7
+        if (rc != 0 && rc != LASSO_DS_ERROR_SIGNATURE_NOT_FOUND) {
e030e7
+            return rc;
e030e7
+        }
e030e7
 
e030e7
 	/*
e030e7
 	 * If the SOAP message contained a header check for the optional
e030e7
-     * paos:Response and ecp:RelayState elements, if they exist extract their
e030e7
-     * values into the profile.
e030e7
+	 * paos:Response and ecp:RelayState elements, if they exist extract their
e030e7
+	 * values into the profile.
e030e7
 	 */
e030e7
 	if (header) {
e030e7
 		GList *i = NULL;
e030e7
@@ -1142,12 +1155,8 @@ lasso_saml20_login_process_paos_response_msg(LassoLogin *login, gchar *msg)
e030e7
 		lasso_release_gobject(header);
e030e7
 	}
e030e7
 
e030e7
-	rc2 = lasso_saml20_login_process_response_status_and_assertion(login);
e030e7
-	if (rc1) {
e030e7
-		return rc1;
e030e7
-	}
e030e7
-	return rc2;
e030e7
-
e030e7
+	rc = lasso_saml20_login_process_response_status_and_assertion(login);
e030e7
+	return rc;
e030e7
 }
e030e7
 
e030e7
 /**
e030e7
diff --git a/lasso/saml-2.0/profile.c b/lasso/saml-2.0/profile.c
e030e7
index 8171e79e..22a4e08c 100644
e030e7
--- a/lasso/saml-2.0/profile.c
e030e7
+++ b/lasso/saml-2.0/profile.c
e030e7
@@ -398,6 +398,7 @@ lasso_saml20_profile_process_artifact_resolve(LassoProfile *profile, const char
e030e7
 
e030e7
 	switch (lasso_profile_get_signature_verify_hint(profile)) {
e030e7
 		case LASSO_PROFILE_SIGNATURE_VERIFY_HINT_MAYBE:
e030e7
+		case LASSO_PROFILE_SIGNATURE_VERIFY_HINT_FORCE:
e030e7
 			rc = profile->signature_status;
e030e7
 			break;
e030e7
 		case LASSO_PROFILE_SIGNATURE_VERIFY_HINT_IGNORE:
e030e7
@@ -1559,6 +1560,7 @@ lasso_saml20_profile_process_soap_response_with_headers(LassoProfile *profile,
e030e7
 			remote_provider, response_msg, "ID", LASSO_MESSAGE_FORMAT_SOAP);
e030e7
 	switch (lasso_profile_get_signature_verify_hint(profile)) {
e030e7
 		case LASSO_PROFILE_SIGNATURE_VERIFY_HINT_MAYBE:
e030e7
+		case LASSO_PROFILE_SIGNATURE_VERIFY_HINT_FORCE:
e030e7
 			rc = profile->signature_status;
e030e7
 			break;
e030e7
 		case LASSO_PROFILE_SIGNATURE_VERIFY_HINT_IGNORE:
e030e7
diff --git a/tests/login_tests_saml2.c b/tests/login_tests_saml2.c
e030e7
index 54c7fb63..e331c07a 100644
e030e7
--- a/tests/login_tests_saml2.c
e030e7
+++ b/tests/login_tests_saml2.c
e030e7
@@ -1090,42 +1090,42 @@ START_TEST(test08_test_authnrequest_flags)
e030e7
 	make_context(sp_context, "sp5-saml2", "", LASSO_PROVIDER_ROLE_IDP, "idp5-saml2", "")
e030e7
 
e030e7
 	block_lasso_logs;
e030e7
-	sso_initiated_by_sp2(idp_context, sp_context, 
e030e7
-			(SsoSettings) { 
e030e7
+	sso_initiated_by_sp2(idp_context, sp_context,
e030e7
+			(SsoSettings) {
e030e7
 				.use_assertion_consumer_service_idx = 1,
e030e7
 				.assertion_consumer_service_idx = 0,
e030e7
 				.stop_after_build_assertion = 1,
e030e7
 			});
e030e7
-	sso_initiated_by_sp2(idp_context, sp_context, 
e030e7
-			(SsoSettings) { 
e030e7
+	sso_initiated_by_sp2(idp_context, sp_context,
e030e7
+			(SsoSettings) {
e030e7
 				.assertion_consumer_service_url = "http://sp5/singleSignOnPost",
e030e7
 				.stop_after_build_assertion = 1,
e030e7
 			});
e030e7
-	sso_initiated_by_sp2(idp_context, sp_context, 
e030e7
-			(SsoSettings) { 
e030e7
+	sso_initiated_by_sp2(idp_context, sp_context,
e030e7
+			(SsoSettings) {
e030e7
 				.protocol_binding = LASSO_SAML2_METADATA_BINDING_ARTIFACT,
e030e7
 				.stop_after_build_assertion = 1,
e030e7
 			});
e030e7
-	sso_initiated_by_sp2(idp_context, sp_context, 
e030e7
-			(SsoSettings) { 
e030e7
+	sso_initiated_by_sp2(idp_context, sp_context,
e030e7
+			(SsoSettings) {
e030e7
 				.assertion_consumer_service_url = "http://sp5/singleSignOnPost",
e030e7
 				.protocol_binding = LASSO_SAML2_METADATA_BINDING_POST,
e030e7
 				.stop_after_build_assertion = 1,
e030e7
 			});
e030e7
-	sso_initiated_by_sp2(idp_context, sp_context, 
e030e7
-			(SsoSettings) { 
e030e7
+	sso_initiated_by_sp2(idp_context, sp_context,
e030e7
+			(SsoSettings) {
e030e7
 				.assertion_consumer_service_url = "http://sp5/singleSignOnArtifact",
e030e7
 				.protocol_binding = LASSO_SAML2_METADATA_BINDING_ARTIFACT,
e030e7
 				.stop_after_build_assertion = 1,
e030e7
 			});
e030e7
-	sso_initiated_by_sp2(idp_context, sp_context, 
e030e7
-			(SsoSettings) { 
e030e7
+	sso_initiated_by_sp2(idp_context, sp_context,
e030e7
+			(SsoSettings) {
e030e7
 				.assertion_consumer_service_url = "http://sp5/singleSignOnPostAndArtifact",
e030e7
 				.protocol_binding = LASSO_SAML2_METADATA_BINDING_ARTIFACT,
e030e7
 				.stop_after_build_assertion = 1,
e030e7
 			});
e030e7
-	sso_initiated_by_sp2(idp_context, sp_context, 
e030e7
-			(SsoSettings) { 
e030e7
+	sso_initiated_by_sp2(idp_context, sp_context,
e030e7
+			(SsoSettings) {
e030e7
 				.assertion_consumer_service_url = "http://sp5/singleSignOnPostAndArtifact",
e030e7
 				.protocol_binding = LASSO_SAML2_METADATA_BINDING_POST,
e030e7
 				.stop_after_build_assertion = 1,
e030e7
@@ -1278,7 +1278,9 @@ static void validate_idp_list(LassoEcp *ecp, EcpIdpListVariant ecpIDPListVariant
e030e7
 	check_str_equals((char*)g_list_nth(ecp->known_idp_entity_ids_supporting_ecp, 0)->data, "http://idp5/metadata");
e030e7
 }
e030e7
 
e030e7
-void test_ecp(EcpIdpListVariant ecpIDPListVariant)
e030e7
+void test_ecp(EcpIdpListVariant ecpIDPListVariant,
e030e7
+              LassoProfileSignatureHint signature_hint,
e030e7
+              LassoProfileSignatureVerifyHint signature_verify_hint)
e030e7
 {
e030e7
 	char *serviceProviderContextDump = NULL, *identityProviderContextDump = NULL;
e030e7
 	LassoServer *spContext = NULL, *ecpContext=NULL, *idpContext = NULL;
e030e7
@@ -1286,7 +1288,7 @@ void test_ecp(EcpIdpListVariant ecpIDPListVariant)
e030e7
 	LassoEcp *ecp = NULL;
e030e7
 	LassoSamlp2AuthnRequest *request = NULL;
e030e7
 	gboolean is_passive = FALSE;
e030e7
-    char *provider_name = NULL;
e030e7
+	char *provider_name = NULL;
e030e7
 	char *relayState = NULL;
e030e7
 	char *messageID = NULL;
e030e7
 	char *extracted_messageID = NULL;
e030e7
@@ -1296,7 +1298,7 @@ void test_ecp(EcpIdpListVariant ecpIDPListVariant)
e030e7
 	char *ecpPaosResponseMsg = NULL;
e030e7
 	char *spLoginDump = NULL;
e030e7
 	LassoSaml2Assertion *assertion;
e030e7
-    LassoSamlp2IDPList *idp_list = NULL;
e030e7
+	LassoSamlp2IDPList *idp_list = NULL;
e030e7
 
e030e7
 	/*
e030e7
 	 * SAML2 Profile for ECP (Section 4.2) defines these steps for an ECP
e030e7
@@ -1322,6 +1324,8 @@ void test_ecp(EcpIdpListVariant ecpIDPListVariant)
e030e7
 	spContext = lasso_server_new_from_dump(serviceProviderContextDump);
e030e7
 	spLoginContext = lasso_login_new(spContext);
e030e7
 	check_not_null(spLoginContext);
e030e7
+	lasso_profile_set_signature_hint(LASSO_PROFILE(spLoginContext), signature_hint);
e030e7
+	lasso_profile_set_signature_verify_hint(LASSO_PROFILE(spLoginContext), signature_verify_hint);
e030e7
 
e030e7
 	check_good_rc(lasso_login_init_authn_request(spLoginContext, "http://idp5/metadata",
e030e7
 												 LASSO_HTTP_METHOD_PAOS));
e030e7
@@ -1419,6 +1423,8 @@ void test_ecp(EcpIdpListVariant ecpIDPListVariant)
e030e7
 	idpContext = lasso_server_new_from_dump(identityProviderContextDump);
e030e7
 	idpLoginContext = lasso_login_new(idpContext);
e030e7
 	check_not_null(idpLoginContext);
e030e7
+	lasso_profile_set_signature_hint(LASSO_PROFILE(idpLoginContext), signature_hint);
e030e7
+	lasso_profile_set_signature_verify_hint(LASSO_PROFILE(idpLoginContext), signature_verify_hint);
e030e7
 
e030e7
 	/* Parse the ecpSoapRequestMsg */
e030e7
 	check_good_rc(lasso_login_process_authn_request_msg(idpLoginContext, ecpSoapRequestMsg));
e030e7
@@ -1465,7 +1471,7 @@ void test_ecp(EcpIdpListVariant ecpIDPListVariant)
e030e7
 	check_str_equals(ecp->relaystate, relayState);
e030e7
 	check_str_equals(ecp->issuer->content, "http://sp5/metadata");
e030e7
 	check_str_equals(ecp->provider_name, provider_name);
e030e7
-    check_equals(ecp->is_passive, is_passive);
e030e7
+	check_equals(ecp->is_passive, is_passive);
e030e7
 
e030e7
 	/* Validate ECP IdP list info */
e030e7
 	validate_idp_list(ecp, ecpIDPListVariant, idp_list);
e030e7
@@ -1480,6 +1486,8 @@ void test_ecp(EcpIdpListVariant ecpIDPListVariant)
e030e7
 	spContext = lasso_server_new_from_dump(serviceProviderContextDump);
e030e7
 	spLoginContext = lasso_login_new(spContext);
e030e7
 	check_not_null(spLoginContext);
e030e7
+	lasso_profile_set_signature_hint(LASSO_PROFILE(spLoginContext), signature_hint);
e030e7
+	lasso_profile_set_signature_verify_hint(LASSO_PROFILE(spLoginContext), signature_verify_hint);
e030e7
 
e030e7
 	/* Parse the ecpPaosResponseMsg */
e030e7
 	check_good_rc(lasso_login_process_paos_response_msg(spLoginContext, ecpPaosResponseMsg));
e030e7
@@ -1515,19 +1523,61 @@ void test_ecp(EcpIdpListVariant ecpIDPListVariant)
e030e7
 
e030e7
 START_TEST(test09_ecp)
e030e7
 {
e030e7
-	test_ecp(ECP_IDP_LIST_NONE);
e030e7
+	test_ecp(ECP_IDP_LIST_NONE,
e030e7
+		 LASSO_PROFILE_SIGNATURE_HINT_MAYBE,
e030e7
+		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_MAYBE);
e030e7
 }
e030e7
 END_TEST
e030e7
 
e030e7
 START_TEST(test10_ecp)
e030e7
 {
e030e7
-	test_ecp(ECP_IDP_LIST_ECP);
e030e7
+	test_ecp(ECP_IDP_LIST_ECP,
e030e7
+		 LASSO_PROFILE_SIGNATURE_HINT_MAYBE,
e030e7
+		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_MAYBE);
e030e7
 }
e030e7
 END_TEST
e030e7
 
e030e7
 START_TEST(test11_ecp)
e030e7
 {
e030e7
-	test_ecp(ECP_IDP_LIST_BOGUS);
e030e7
+	test_ecp(ECP_IDP_LIST_BOGUS,
e030e7
+		 LASSO_PROFILE_SIGNATURE_HINT_MAYBE,
e030e7
+		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_MAYBE);
e030e7
+}
e030e7
+END_TEST
e030e7
+
e030e7
+START_TEST(test12_ecp)
e030e7
+{
e030e7
+	/* Maybe Sign */
e030e7
+	test_ecp(ECP_IDP_LIST_NONE,
e030e7
+		 LASSO_PROFILE_SIGNATURE_HINT_MAYBE,
e030e7
+		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_MAYBE);
e030e7
+
e030e7
+	test_ecp(ECP_IDP_LIST_NONE,
e030e7
+		 LASSO_PROFILE_SIGNATURE_HINT_MAYBE,
e030e7
+		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_FORCE);
e030e7
+
e030e7
+	test_ecp(ECP_IDP_LIST_NONE,
e030e7
+		 LASSO_PROFILE_SIGNATURE_HINT_MAYBE,
e030e7
+		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_IGNORE);
e030e7
+
e030e7
+	/* Force Sign */
e030e7
+	test_ecp(ECP_IDP_LIST_NONE,
e030e7
+		 LASSO_PROFILE_SIGNATURE_HINT_FORCE,
e030e7
+		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_MAYBE);
e030e7
+
e030e7
+	test_ecp(ECP_IDP_LIST_NONE,
e030e7
+		 LASSO_PROFILE_SIGNATURE_HINT_FORCE,
e030e7
+		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_FORCE);
e030e7
+
e030e7
+	test_ecp(ECP_IDP_LIST_NONE,
e030e7
+		 LASSO_PROFILE_SIGNATURE_HINT_FORCE,
e030e7
+		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_IGNORE);
e030e7
+
e030e7
+	/* Forbid Sign */
e030e7
+	test_ecp(ECP_IDP_LIST_NONE,
e030e7
+		 LASSO_PROFILE_SIGNATURE_HINT_FORBID,
e030e7
+		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_IGNORE);
e030e7
+
e030e7
 }
e030e7
 END_TEST
e030e7
 
e030e7
@@ -1538,7 +1588,7 @@ void check_digest_method(G_GNUC_UNUSED LassoLogin *idp_login_context, LassoLogin
e030e7
 	lasso_release_string(dump)
e030e7
 }
e030e7
 
e030e7
-START_TEST(test12_sso_sp_with_rsa_sha256_signatures)
e030e7
+START_TEST(test13_sso_sp_with_rsa_sha256_signatures)
e030e7
 {
e030e7
 	LassoServer *idp_context = NULL;
e030e7
 	LassoServer *sp_context = NULL;
e030e7
@@ -1595,7 +1645,8 @@ login_saml2_suite()
e030e7
 	tcase_add_test(tc_ecp, test09_ecp);
e030e7
 	tcase_add_test(tc_ecp, test10_ecp);
e030e7
 	tcase_add_test(tc_ecp, test11_ecp);
e030e7
-	tcase_add_test(tc_spLogin, test12_sso_sp_with_rsa_sha256_signatures);
e030e7
+	tcase_add_test(tc_ecp, test12_ecp);
e030e7
+	tcase_add_test(tc_spLogin, test13_sso_sp_with_rsa_sha256_signatures);
e030e7
 	return s;
e030e7
 }
e030e7
 
e030e7
-- 
e030e7
2.20.1
e030e7