|
|
0719f5 |
From 8b8fd22a168860c5034822472d1fb5745f8fa0f5 Mon Sep 17 00:00:00 2001
|
|
|
0719f5 |
From: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
0719f5 |
Date: Wed, 16 Jun 2021 10:18:30 +0200
|
|
|
0719f5 |
Subject: [PATCH] Fix lasso_query_sign HMAC other than SHA1 (#54037)
|
|
|
0719f5 |
|
|
|
0719f5 |
The switch clause was using SHA1 digests for all digest types when
|
|
|
0719f5 |
signing. This obviously breaks verifying the signatures if HMAC-SHAXXX
|
|
|
0719f5 |
is used and XXX is something else than 1.
|
|
|
0719f5 |
---
|
|
|
0719f5 |
lasso/xml/tools.c | 35 +++++++++++++++++++++++------------
|
|
|
0719f5 |
tests/login_tests_saml2.c | 6 +++---
|
|
|
0719f5 |
2 files changed, 26 insertions(+), 15 deletions(-)
|
|
|
0719f5 |
|
|
|
0719f5 |
diff --git a/lasso/xml/tools.c b/lasso/xml/tools.c
|
|
|
0719f5 |
index 96d88a2c4..290fd55f2 100644
|
|
|
0719f5 |
--- a/lasso/xml/tools.c
|
|
|
0719f5 |
+++ b/lasso/xml/tools.c
|
|
|
0719f5 |
@@ -594,22 +594,20 @@ lasso_query_sign(char *query, LassoSignatureContext context)
|
|
|
0719f5 |
sigret_size = DSA_size(dsa);
|
|
|
0719f5 |
break;
|
|
|
0719f5 |
case LASSO_SIGNATURE_METHOD_HMAC_SHA1:
|
|
|
0719f5 |
+ md = EVP_sha1();
|
|
|
0719f5 |
+ sigret_size = EVP_MD_size(md);
|
|
|
0719f5 |
+ break;
|
|
|
0719f5 |
case LASSO_SIGNATURE_METHOD_HMAC_SHA256:
|
|
|
0719f5 |
+ md = EVP_sha256();
|
|
|
0719f5 |
+ sigret_size = EVP_MD_size(md);
|
|
|
0719f5 |
+ break;
|
|
|
0719f5 |
case LASSO_SIGNATURE_METHOD_HMAC_SHA384:
|
|
|
0719f5 |
+ md = EVP_sha384();
|
|
|
0719f5 |
+ sigret_size = EVP_MD_size(md);
|
|
|
0719f5 |
+ break;
|
|
|
0719f5 |
case LASSO_SIGNATURE_METHOD_HMAC_SHA512:
|
|
|
0719f5 |
- if ((rc = lasso_get_hmac_key(key, (void**)&hmac_key,
|
|
|
0719f5 |
- &hmac_key_length))) {
|
|
|
0719f5 |
- message(G_LOG_LEVEL_CRITICAL, "Failed to get hmac key (%s)", lasso_strerror(rc));
|
|
|
0719f5 |
- goto done;
|
|
|
0719f5 |
- }
|
|
|
0719f5 |
- g_assert(hmac_key);
|
|
|
0719f5 |
- md = EVP_sha1();
|
|
|
0719f5 |
+ md = EVP_sha512();
|
|
|
0719f5 |
sigret_size = EVP_MD_size(md);
|
|
|
0719f5 |
- /* key should be at least 128 bits long */
|
|
|
0719f5 |
- if (hmac_key_length < 16) {
|
|
|
0719f5 |
- critical("HMAC key should be at least 128 bits long");
|
|
|
0719f5 |
- goto done;
|
|
|
0719f5 |
- }
|
|
|
0719f5 |
break;
|
|
|
0719f5 |
default:
|
|
|
0719f5 |
g_assert_not_reached();
|
|
|
0719f5 |
@@ -645,6 +643,19 @@ lasso_query_sign(char *query, LassoSignatureContext context)
|
|
|
0719f5 |
case LASSO_SIGNATURE_METHOD_HMAC_SHA256:
|
|
|
0719f5 |
case LASSO_SIGNATURE_METHOD_HMAC_SHA384:
|
|
|
0719f5 |
case LASSO_SIGNATURE_METHOD_HMAC_SHA512:
|
|
|
0719f5 |
+ if ((rc = lasso_get_hmac_key(key, (void**)&hmac_key,
|
|
|
0719f5 |
+ &hmac_key_length))) {
|
|
|
0719f5 |
+ message(G_LOG_LEVEL_CRITICAL, "Failed to get hmac key (%s)", lasso_strerror(rc));
|
|
|
0719f5 |
+ goto done;
|
|
|
0719f5 |
+ }
|
|
|
0719f5 |
+ g_assert(hmac_key);
|
|
|
0719f5 |
+
|
|
|
0719f5 |
+ /* key should be at least 128 bits long */
|
|
|
0719f5 |
+ if (hmac_key_length < 16) {
|
|
|
0719f5 |
+ critical("HMAC key should be at least 128 bits long");
|
|
|
0719f5 |
+ goto done;
|
|
|
0719f5 |
+ }
|
|
|
0719f5 |
+
|
|
|
0719f5 |
HMAC(md, hmac_key, hmac_key_length, (unsigned char *)new_query,
|
|
|
0719f5 |
strlen(new_query), sigret, &siglen);
|
|
|
0719f5 |
status = 1;
|
|
|
0719f5 |
diff --git a/tests/login_tests_saml2.c b/tests/login_tests_saml2.c
|
|
|
0719f5 |
index e331c07a7..e1d78b5b1 100644
|
|
|
0719f5 |
--- a/tests/login_tests_saml2.c
|
|
|
0719f5 |
+++ b/tests/login_tests_saml2.c
|
|
|
0719f5 |
@@ -981,7 +981,7 @@ sso_initiated_by_sp(LassoServer *idp_context, LassoServer *sp_context, SsoCallba
|
|
|
0719f5 |
lasso_release_gobject(sp_login_context);
|
|
|
0719f5 |
}
|
|
|
0719f5 |
|
|
|
0719f5 |
-START_TEST(test07_sso_sp_with_hmac_sha1_signatures)
|
|
|
0719f5 |
+START_TEST(test07_sso_sp_with_hmac_sha256_signatures)
|
|
|
0719f5 |
{
|
|
|
0719f5 |
LassoServer *idp_context = NULL;
|
|
|
0719f5 |
LassoServer *sp_context = NULL;
|
|
|
0719f5 |
@@ -990,7 +990,7 @@ START_TEST(test07_sso_sp_with_hmac_sha1_signatures)
|
|
|
0719f5 |
|
|
|
0719f5 |
/* Create the shared key */
|
|
|
0719f5 |
key = lasso_key_new_for_signature_from_memory("xxxxxxxxxxxxxxxx", 16,
|
|
|
0719f5 |
- NULL, LASSO_SIGNATURE_METHOD_HMAC_SHA1, NULL);
|
|
|
0719f5 |
+ NULL, LASSO_SIGNATURE_METHOD_HMAC_SHA256, NULL);
|
|
|
0719f5 |
check_true(LASSO_IS_KEY(key));
|
|
|
0719f5 |
|
|
|
0719f5 |
/* Create an IdP context for IdP initiated SSO with provider metadata 1 */
|
|
|
0719f5 |
@@ -1640,7 +1640,7 @@ login_saml2_suite()
|
|
|
0719f5 |
tcase_add_test(tc_spSloSoap, test04_sso_then_slo_soap);
|
|
|
0719f5 |
tcase_add_test(tc_idpKeyRollover, test05_sso_idp_with_key_rollover);
|
|
|
0719f5 |
tcase_add_test(tc_spKeyRollover, test06_sso_sp_with_key_rollover);
|
|
|
0719f5 |
- tcase_add_test(tc_hmacSignature, test07_sso_sp_with_hmac_sha1_signatures);
|
|
|
0719f5 |
+ tcase_add_test(tc_hmacSignature, test07_sso_sp_with_hmac_sha256_signatures);
|
|
|
0719f5 |
tcase_add_test(tc_spLogin, test08_test_authnrequest_flags);
|
|
|
0719f5 |
tcase_add_test(tc_ecp, test09_ecp);
|
|
|
0719f5 |
tcase_add_test(tc_ecp, test10_ecp);
|
|
|
0719f5 |
--
|
|
|
0719f5 |
2.26.3
|
|
|
0719f5 |
|