Projet

Général

Profil

0001-Fix-ECP-signature-not-found-error-when-only-assertio.patch

Updated patch with MIT license tag - John Dennis, 10 janvier 2019 15:53

Télécharger (10,2 ko)

Voir les différences:

Subject: [PATCH] Fix ECP signature not found error when only assertion is
 signed
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit

With a SAML Authn Response either the message or the assertion
contained in the response message or both can be signed. Most IdP's
sign the message. This fixes a bug when processing an ECP authn
response when only the assertion is signed.

lasso_saml20_profile_process_soap_response_with_headers() performs a
signature check on the SAML message. A signature can also appear on
the assertion which is checked by
lasso_saml20_login_process_response_status_and_assertion() The problem
occurred when the message was not signed and
lasso_saml20_profile_process_soap_response_with_headers() returned
LASSO_DS_ERROR_SIGNATURE_NOT_FOUND as an error code which is not
actually an error because we haven't checked the signature on the
assertion yet. We were returning the first
LASSO_DS_ERROR_SIGNATURE_NOT_FOUND error when in fact the subsequent
signature check in
lasso_saml20_login_process_response_status_and_assertion() succeeded.

The ECP unit tests were enhanced to cover these cases.

The enhanced unit test revealed a problem in two switch statements
operating on the return value of
lasso_profile_get_signature_verify_hint() which were missing a case
statement for LASSO_PROFILE_SIGNATURE_VERIFY_HINT_FORCE which caused
an abort due to an unknown enumeration value.

Fixes Bug: 26828
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
 lasso/saml-2.0/login.c    | 29 ++++++++++------
 lasso/saml-2.0/profile.c  |  2 ++
 tests/login_tests_saml2.c | 69 ++++++++++++++++++++++++++++++++++-----
 3 files changed, 81 insertions(+), 19 deletions(-)
lasso/saml-2.0/login.c
1107 1107
{
1108 1108
	LassoSoapHeader *header = NULL;
1109 1109
	LassoProfile *profile;
1110
	int rc1, rc2;
1110
	int rc;
1111 1111

  
1112 1112
	lasso_null_param(msg);
1113 1113

  
1114 1114
	profile = LASSO_PROFILE(login);
1115 1115

  
1116
	rc1 = lasso_saml20_profile_process_soap_response_with_headers(profile, msg, &header);
1116
        /*
1117
         * lasso_saml20_profile_process_soap_response_with_headers()
1118
         * performs a signature check on the SAML message. A signature
1119
         * can also appear on the assertion which is checked by
1120
         * lasso_saml20_login_process_response_status_and_assertion()
1121
         * (below). Therefore if the error is SIGNATURE_NOT_FOUND we
1122
         * proceed because
1123
         * lasso_saml20_login_process_response_status_and_assertion()
1124
         * will test the signature on the assertion.
1125
         */
1126
	rc = lasso_saml20_profile_process_soap_response_with_headers(profile, msg, &header);
1127
        if (rc != 0 && rc != LASSO_DS_ERROR_SIGNATURE_NOT_FOUND) {
1128
            return rc;
1129
        }
1117 1130

  
1118 1131
	/*
1119 1132
	 * If the SOAP message contained a header check for the optional
1120
     * paos:Response and ecp:RelayState elements, if they exist extract their
1121
     * values into the profile.
1133
	 * paos:Response and ecp:RelayState elements, if they exist extract their
1134
	 * values into the profile.
1122 1135
	 */
1123 1136
	if (header) {
1124 1137
		GList *i = NULL;
......
1142 1155
		lasso_release_gobject(header);
1143 1156
	}
1144 1157

  
1145
	rc2 = lasso_saml20_login_process_response_status_and_assertion(login);
1146
	if (rc1) {
1147
		return rc1;
1148
	}
1149
	return rc2;
1150

  
1158
	rc = lasso_saml20_login_process_response_status_and_assertion(login);
1159
	return rc;
1151 1160
}
1152 1161

  
1153 1162
/**
lasso/saml-2.0/profile.c
398 398

  
399 399
	switch (lasso_profile_get_signature_verify_hint(profile)) {
400 400
		case LASSO_PROFILE_SIGNATURE_VERIFY_HINT_MAYBE:
401
		case LASSO_PROFILE_SIGNATURE_VERIFY_HINT_FORCE:
401 402
			rc = profile->signature_status;
402 403
			break;
403 404
		case LASSO_PROFILE_SIGNATURE_VERIFY_HINT_IGNORE:
......
1559 1560
			remote_provider, response_msg, "ID", LASSO_MESSAGE_FORMAT_SOAP);
1560 1561
	switch (lasso_profile_get_signature_verify_hint(profile)) {
1561 1562
		case LASSO_PROFILE_SIGNATURE_VERIFY_HINT_MAYBE:
1563
		case LASSO_PROFILE_SIGNATURE_VERIFY_HINT_FORCE:
1562 1564
			rc = profile->signature_status;
1563 1565
			break;
1564 1566
		case LASSO_PROFILE_SIGNATURE_VERIFY_HINT_IGNORE:
tests/login_tests_saml2.c
1278 1278
	check_str_equals((char*)g_list_nth(ecp->known_idp_entity_ids_supporting_ecp, 0)->data, "http://idp5/metadata");
1279 1279
}
1280 1280

  
1281
void test_ecp(EcpIdpListVariant ecpIDPListVariant)
1281
void test_ecp(EcpIdpListVariant ecpIDPListVariant,
1282
              LassoProfileSignatureHint signature_hint,
1283
              LassoProfileSignatureVerifyHint signature_verify_hint)
1282 1284
{
1283 1285
	char *serviceProviderContextDump = NULL, *identityProviderContextDump = NULL;
1284 1286
	LassoServer *spContext = NULL, *ecpContext=NULL, *idpContext = NULL;
......
1286 1288
	LassoEcp *ecp = NULL;
1287 1289
	LassoSamlp2AuthnRequest *request = NULL;
1288 1290
	gboolean is_passive = FALSE;
1289
    char *provider_name = NULL;
1291
	char *provider_name = NULL;
1290 1292
	char *relayState = NULL;
1291 1293
	char *messageID = NULL;
1292 1294
	char *extracted_messageID = NULL;
......
1296 1298
	char *ecpPaosResponseMsg = NULL;
1297 1299
	char *spLoginDump = NULL;
1298 1300
	LassoSaml2Assertion *assertion;
1299
    LassoSamlp2IDPList *idp_list = NULL;
1301
	LassoSamlp2IDPList *idp_list = NULL;
1300 1302

  
1301 1303
	/*
1302 1304
	 * SAML2 Profile for ECP (Section 4.2) defines these steps for an ECP
......
1322 1324
	spContext = lasso_server_new_from_dump(serviceProviderContextDump);
1323 1325
	spLoginContext = lasso_login_new(spContext);
1324 1326
	check_not_null(spLoginContext);
1327
	lasso_profile_set_signature_hint(LASSO_PROFILE(spLoginContext), signature_hint);
1328
	lasso_profile_set_signature_verify_hint(LASSO_PROFILE(spLoginContext), signature_verify_hint);
1325 1329

  
1326 1330
	check_good_rc(lasso_login_init_authn_request(spLoginContext, "http://idp5/metadata",
1327 1331
												 LASSO_HTTP_METHOD_PAOS));
......
1419 1423
	idpContext = lasso_server_new_from_dump(identityProviderContextDump);
1420 1424
	idpLoginContext = lasso_login_new(idpContext);
1421 1425
	check_not_null(idpLoginContext);
1426
	lasso_profile_set_signature_hint(LASSO_PROFILE(idpLoginContext), signature_hint);
1427
	lasso_profile_set_signature_verify_hint(LASSO_PROFILE(idpLoginContext), signature_verify_hint);
1422 1428

  
1423 1429
	/* Parse the ecpSoapRequestMsg */
1424 1430
	check_good_rc(lasso_login_process_authn_request_msg(idpLoginContext, ecpSoapRequestMsg));
......
1465 1471
	check_str_equals(ecp->relaystate, relayState);
1466 1472
	check_str_equals(ecp->issuer->content, "http://sp5/metadata");
1467 1473
	check_str_equals(ecp->provider_name, provider_name);
1468
    check_equals(ecp->is_passive, is_passive);
1474
	check_equals(ecp->is_passive, is_passive);
1469 1475

  
1470 1476
	/* Validate ECP IdP list info */
1471 1477
	validate_idp_list(ecp, ecpIDPListVariant, idp_list);
......
1480 1486
	spContext = lasso_server_new_from_dump(serviceProviderContextDump);
1481 1487
	spLoginContext = lasso_login_new(spContext);
1482 1488
	check_not_null(spLoginContext);
1489
	lasso_profile_set_signature_hint(LASSO_PROFILE(spLoginContext), signature_hint);
1490
	lasso_profile_set_signature_verify_hint(LASSO_PROFILE(spLoginContext), signature_verify_hint);
1483 1491

  
1484 1492
	/* Parse the ecpPaosResponseMsg */
1485 1493
	check_good_rc(lasso_login_process_paos_response_msg(spLoginContext, ecpPaosResponseMsg));
......
1515 1523

  
1516 1524
START_TEST(test09_ecp)
1517 1525
{
1518
	test_ecp(ECP_IDP_LIST_NONE);
1526
	test_ecp(ECP_IDP_LIST_NONE,
1527
		 LASSO_PROFILE_SIGNATURE_HINT_MAYBE,
1528
		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_MAYBE);
1519 1529
}
1520 1530
END_TEST
1521 1531

  
1522 1532
START_TEST(test10_ecp)
1523 1533
{
1524
	test_ecp(ECP_IDP_LIST_ECP);
1534
	test_ecp(ECP_IDP_LIST_ECP,
1535
		 LASSO_PROFILE_SIGNATURE_HINT_MAYBE,
1536
		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_MAYBE);
1525 1537
}
1526 1538
END_TEST
1527 1539

  
1528 1540
START_TEST(test11_ecp)
1529 1541
{
1530
	test_ecp(ECP_IDP_LIST_BOGUS);
1542
	test_ecp(ECP_IDP_LIST_BOGUS,
1543
		 LASSO_PROFILE_SIGNATURE_HINT_MAYBE,
1544
		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_MAYBE);
1545
}
1546
END_TEST
1547

  
1548
START_TEST(test12_ecp)
1549
{
1550
	/* Maybe Sign */
1551
	test_ecp(ECP_IDP_LIST_NONE,
1552
		 LASSO_PROFILE_SIGNATURE_HINT_MAYBE,
1553
		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_MAYBE);
1554
	
1555
	test_ecp(ECP_IDP_LIST_NONE,
1556
		 LASSO_PROFILE_SIGNATURE_HINT_MAYBE,
1557
		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_FORCE);
1558
	
1559
	test_ecp(ECP_IDP_LIST_NONE,
1560
		 LASSO_PROFILE_SIGNATURE_HINT_MAYBE,
1561
		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_IGNORE);
1562
	
1563
	/* Force Sign */
1564
	test_ecp(ECP_IDP_LIST_NONE,
1565
		 LASSO_PROFILE_SIGNATURE_HINT_FORCE,
1566
		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_MAYBE);
1567
	
1568
	test_ecp(ECP_IDP_LIST_NONE,
1569
		 LASSO_PROFILE_SIGNATURE_HINT_FORCE,
1570
		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_FORCE);
1571
	
1572
	test_ecp(ECP_IDP_LIST_NONE,
1573
		 LASSO_PROFILE_SIGNATURE_HINT_FORCE,
1574
		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_IGNORE);
1575
	
1576
	/* Forbid Sign */
1577
	test_ecp(ECP_IDP_LIST_NONE,
1578
		 LASSO_PROFILE_SIGNATURE_HINT_FORBID,
1579
		 LASSO_PROFILE_SIGNATURE_VERIFY_HINT_IGNORE);
1580

  
1531 1581
}
1532 1582
END_TEST
1533 1583

  
......
1538 1588
	lasso_release_string(dump)
1539 1589
}
1540 1590

  
1541
START_TEST(test12_sso_sp_with_rsa_sha256_signatures)
1591
START_TEST(test13_sso_sp_with_rsa_sha256_signatures)
1542 1592
{
1543 1593
	LassoServer *idp_context = NULL;
1544 1594
	LassoServer *sp_context = NULL;
......
1595 1645
	tcase_add_test(tc_ecp, test09_ecp);
1596 1646
	tcase_add_test(tc_ecp, test10_ecp);
1597 1647
	tcase_add_test(tc_ecp, test11_ecp);
1598
	tcase_add_test(tc_spLogin, test12_sso_sp_with_rsa_sha256_signatures);
1648
	tcase_add_test(tc_ecp, test12_ecp);
1649
	tcase_add_test(tc_spLogin, test13_sso_sp_with_rsa_sha256_signatures);
1599 1650
	return s;
1600 1651
}
1601 1652

  
1602
-