Skip to content

Commit a99746c

Browse files
vanhoefmalandekok
authored andcommitted
EAP-pwd: validate received scalar and element
When processing an EAP-pwd Commit frame, the peer's scalar and elliptic curve point were not validated. This allowed an adversary to bypass authentication, and impersonate any user. Fix this vulnerability by assuring the received scalar lies within the valid range, and by checking that the received element is not the point at infinity and lies on the elliptic curve being used.
1 parent 8fd2231 commit a99746c

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

  • src/modules/rlm_eap/types/rlm_eap_pwd

src/modules/rlm_eap/types/rlm_eap_pwd/eap_pwd.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,26 @@ int process_peer_commit(pwd_session_t *session, uint8_t *in, size_t in_len, BN_C
351351
data_len = BN_num_bytes(session->order);
352352
BN_bin2bn(ptr, data_len, session->peer_scalar);
353353

354+
/* validate received scalar */
355+
if (BN_is_zero(session->peer_scalar) ||
356+
BN_is_one(session->peer_scalar) ||
357+
BN_cmp(session->peer_scalar, session->order) >= 0) {
358+
ERROR("Peer's scalar is not within the allowed range");
359+
goto finish;
360+
}
361+
354362
if (!EC_POINT_set_affine_coordinates_GFp(session->group, session->peer_element, x, y, bn_ctx)) {
355363
ERROR("Unable to get coordinates of peer's element");
356364
goto finish;
357365
}
358366

367+
/* validate received element */
368+
if (!EC_POINT_is_on_curve(session->group, session->peer_element, bn_ctx) ||
369+
EC_POINT_is_at_infinity(session->group, session->peer_element)) {
370+
ERROR("Peer's element is not a point on the elliptic curve");
371+
goto finish;
372+
}
373+
359374
/* check to ensure peer's element is not in a small sub-group */
360375
if (BN_cmp(cofactor, BN_value_one())) {
361376
if (!EC_POINT_mul(session->group, point, NULL, session->peer_element, cofactor, NULL)) {
@@ -369,6 +384,13 @@ int process_peer_commit(pwd_session_t *session, uint8_t *in, size_t in_len, BN_C
369384
}
370385
}
371386

387+
/* detect reflection attacks */
388+
if (BN_cmp(session->peer_scalar, session->my_scalar) == 0 ||
389+
EC_POINT_cmp(session->group, session->peer_element, session->my_element, bn_ctx) == 0) {
390+
ERROR("Reflection attack detected");
391+
goto finish;
392+
}
393+
372394
/* compute the shared key, k */
373395
if ((!EC_POINT_mul(session->group, K, NULL, session->pwe, session->peer_scalar, bn_ctx)) ||
374396
(!EC_POINT_add(session->group, K, K, session->peer_element, bn_ctx)) ||

0 commit comments

Comments
 (0)