Blame SOURCES/freeradius-EAP-PWD-curve-handling.patch

df082d
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
df082d
index 7f91e4b230..848ca2055e 100644
df082d
--- a/src/modules/rlm_eap/types/rlm_eap_pwd/eap_pwd.c
df082d
+++ b/src/modules/rlm_eap/types/rlm_eap_pwd/eap_pwd.c
df082d
@@ -373,11 +373,26 @@ int process_peer_commit (pwd_session_t *session, uint8_t *in, size_t in_len, BN_
df082d
 	data_len = BN_num_bytes(session->order);
df082d
 	BN_bin2bn(ptr, data_len, session->peer_scalar);
df082d
df082d
+	/* validate received scalar */
df082d
+	if (BN_is_zero(session->peer_scalar) ||
df082d
+	    BN_is_one(session->peer_scalar) ||
df082d
+	    BN_cmp(session->peer_scalar, session->order) >= 0) {
df082d
+		ERROR("Peer's scalar is not within the allowed range");
df082d
+		goto finish;
df082d
+	}
df082d
+
df082d
 	if (!EC_POINT_set_affine_coordinates_GFp(session->group, session->peer_element, x, y, bnctx)) {
df082d
 		DEBUG2("pwd: unable to get coordinates of peer's element");
df082d
 		goto finish;
df082d
 	}
df082d
df082d
+	/* validate received element */
df082d
+	if (!EC_POINT_is_on_curve(session->group, session->peer_element, bnctx) ||
df082d
+	    EC_POINT_is_at_infinity(session->group, session->peer_element)) {
df082d
+		ERROR("Peer's element is not a point on the elliptic curve");
df082d
+		goto finish;
df082d
+	}
df082d
+
df082d
 	/* check to ensure peer's element is not in a small sub-group */
df082d
 	if (BN_cmp(cofactor, BN_value_one())) {
df082d
 		if (!EC_POINT_mul(session->group, point, NULL, session->peer_element, cofactor, NULL)) {
df082d
@@ -391,6 +406,13 @@ int process_peer_commit (pwd_session_t *session, uint8_t *in, size_t in_len, BN_
df082d
 		}
df082d
 	}
df082d
df082d
+	/* detect reflection attacks */
df082d
+	if (BN_cmp(session->peer_scalar, session->my_scalar) == 0 ||
df082d
+	    EC_POINT_cmp(session->group, session->peer_element, session->my_element, bnctx) == 0) {
df082d
+		ERROR("Reflection attack detected");
df082d
+		goto finish;
df082d
+	}
df082d
+
df082d
 	/* compute the shared key, k */
df082d
 	if ((!EC_POINT_mul(session->group, K, NULL, session->pwe, session->peer_scalar, bnctx)) ||
df082d
 	    (!EC_POINT_add(session->group, K, K, session->peer_element, bnctx)) ||