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

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