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

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