|
|
047f28 |
From: Antonio Torres <antorres@redhat.com>
|
|
|
047f28 |
Date: Fri, 09 Dec 2022
|
|
|
047f28 |
Subject: Fix information leakage in EAP-PWD
|
|
|
047f28 |
|
|
|
047f28 |
The EAP-PWD function compute_password_element() leaks information about the
|
|
|
047f28 |
password which allows an attacker to substantially reduce the size of an
|
|
|
047f28 |
offline dictionary attack.
|
|
|
047f28 |
|
|
|
047f28 |
Patch adapted from: https://github.com/FreeRADIUS/freeradius-server/commit/9e5e8f2f
|
|
|
047f28 |
|
|
|
047f28 |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2151702
|
|
|
047f28 |
Signed-off-by: Antonio Torres <antorres@redhat.com>
|
|
|
047f28 |
---
|
|
|
047f28 |
diff --git a/src/modules/rlm_eap/types/rlm_eap_pwd/eap_pwd.c b/src/modules/rlm_eap/types/rlm_eap_pwd/eap_pwd.c
|
|
|
047f28 |
index d94851c3aa..9f86b62114 100644
|
|
|
047f28 |
--- a/src/modules/rlm_eap/types/rlm_eap_pwd/eap_pwd.c
|
|
|
047f28 |
+++ b/src/modules/rlm_eap/types/rlm_eap_pwd/eap_pwd.c
|
|
|
047f28 |
@@ -39,6 +39,8 @@ USES_APPLE_DEPRECATED_API /* OpenSSL API has been deprecated by Apple */
|
|
|
047f28 |
#include <freeradius-devel/radiusd.h>
|
|
|
047f28 |
#include <freeradius-devel/modules.h>
|
|
|
047f28 |
|
|
|
047f28 |
+static uint8_t allzero[SHA256_DIGEST_LENGTH] = { 0x00 };
|
|
|
047f28 |
+
|
|
|
047f28 |
/* The random function H(x) = HMAC-SHA256(0^32, x) */
|
|
|
047f28 |
static void H_Init(HMAC_CTX *ctx)
|
|
|
047f28 |
{
|
|
|
047f28 |
@@ -114,15 +116,13 @@ int compute_password_element (pwd_session_t *session, uint16_t grp_num,
|
|
|
047f28 |
uint32_t *token)
|
|
|
047f28 |
{
|
|
|
047f28 |
BIGNUM *x_candidate = NULL, *rnd = NULL, *cofactor = NULL;
|
|
|
047f28 |
- HMAC_CTX *ctx = NULL;
|
|
|
047f28 |
+ EVP_MD_CTX *hmac_ctx;
|
|
|
047f28 |
+ EVP_PKEY *hmac_pkey;
|
|
|
047f28 |
uint8_t pwe_digest[SHA256_DIGEST_LENGTH], *prfbuf = NULL, ctr;
|
|
|
047f28 |
int nid, is_odd, primebitlen, primebytelen, ret = 0;
|
|
|
047f28 |
|
|
|
047f28 |
- ctx = HMAC_CTX_new();
|
|
|
047f28 |
- if (ctx == NULL) {
|
|
|
047f28 |
- DEBUG("failed allocating HMAC context");
|
|
|
047f28 |
- goto fail;
|
|
|
047f28 |
- }
|
|
|
047f28 |
+ MEM(hmac_ctx = EVP_MD_CTX_new());
|
|
|
047f28 |
+ MEM(hmac_pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, allzero, sizeof(allzero)));
|
|
|
047f28 |
|
|
|
047f28 |
switch (grp_num) { /* from IANA registry for IKE D-H groups */
|
|
|
047f28 |
case 19:
|
|
|
047f28 |
@@ -203,13 +203,12 @@ int compute_password_element (pwd_session_t *session, uint16_t grp_num,
|
|
|
047f28 |
* pwd-seed = H(token | peer-id | server-id | password |
|
|
|
047f28 |
* counter)
|
|
|
047f28 |
*/
|
|
|
047f28 |
- H_Init(ctx);
|
|
|
047f28 |
- H_Update(ctx, (uint8_t *)token, sizeof(*token));
|
|
|
047f28 |
- H_Update(ctx, (uint8_t const *)id_peer, id_peer_len);
|
|
|
047f28 |
- H_Update(ctx, (uint8_t const *)id_server, id_server_len);
|
|
|
047f28 |
- H_Update(ctx, (uint8_t const *)password, password_len);
|
|
|
047f28 |
- H_Update(ctx, (uint8_t *)&ctr, sizeof(ctr));
|
|
|
047f28 |
- H_Final(ctx, pwe_digest);
|
|
|
047f28 |
+ EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha256(), NULL, hmac_pkey);
|
|
|
047f28 |
+ EVP_DigestSignUpdate(hmac_ctx, (uint8_t *)token, sizeof(*token));
|
|
|
047f28 |
+ EVP_DigestSignUpdate(hmac_ctx, (uint8_t const *)id_peer, id_peer_len);
|
|
|
047f28 |
+ EVP_DigestSignUpdate(hmac_ctx, (uint8_t const *)id_server, id_server_len);
|
|
|
047f28 |
+ EVP_DigestSignUpdate(hmac_ctx, (uint8_t const *)password, password_len);
|
|
|
047f28 |
+ EVP_DigestSignUpdate(hmac_ctx, (uint8_t *)&ctr, sizeof(ctr));
|
|
|
047f28 |
|
|
|
047f28 |
BN_bin2bn(pwe_digest, SHA256_DIGEST_LENGTH, rnd);
|
|
|
047f28 |
if (eap_pwd_kdf(pwe_digest, SHA256_DIGEST_LENGTH, "EAP-pwd Hunting And Pecking",
|
|
|
047f28 |
@@ -282,7 +281,8 @@ int compute_password_element (pwd_session_t *session, uint16_t grp_num,
|
|
|
047f28 |
BN_clear_free(x_candidate);
|
|
|
047f28 |
BN_clear_free(rnd);
|
|
|
047f28 |
talloc_free(prfbuf);
|
|
|
047f28 |
- HMAC_CTX_free(ctx);
|
|
|
047f28 |
+ EVP_MD_CTX_free(hmac_ctx);
|
|
|
047f28 |
+ EVP_PKEY_free(hmac_pkey);
|
|
|
047f28 |
|
|
|
047f28 |
return ret;
|
|
|
047f28 |
}
|