From: John Brandt <brandtwjohn@gmail.com>
To: iwd@lists.linux.dev
Cc: John Brandt <brandtwjohn@gmail.com>
Subject: [PATCH v2 06/18] sae: make sae_process_commit callable in AP mode
Date: Sun, 5 May 2024 17:30:29 -0700 [thread overview]
Message-ID: <20240506003518.320176-7-brandtwjohn@gmail.com> (raw)
In-Reply-To: <20240506003518.320176-1-brandtwjohn@gmail.com>
As an AP, the function sae_process_commit will pick the group offered by
the client. In a subsuquent commit the offered group will first be
verified before calling sae_process_commit. The AP will reply with a
Commit frame, calculate current keys, and move to the COMMITTED state.
---
src/sae.c | 67 ++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 47 insertions(+), 20 deletions(-)
diff --git a/src/sae.c b/src/sae.c
index 7787a390..7ba9b0eb 100644
--- a/src/sae.c
+++ b/src/sae.c
@@ -48,6 +48,8 @@ static bool debug;
#define SAE_SYNC_MAX 3
#define SAE_MAX_ASSOC_RETRY 3
+static bool sae_send_commit(struct sae_sm *sm, bool retry);
+
#define sae_debug(fmat, ...) \
({ \
if (debug) \
@@ -321,6 +323,21 @@ static ssize_t sae_cn(struct sae_sm *sm, uint16_t send_confirm,
return ret;
}
+static bool sae_check_reflection(struct sae_sm *sm)
+{
+ /*
+ * If they match those sent as part of the protocol instance's own
+ * SAE Commit message, the frame shall be silently discarded (because
+ * it is evidence of a reflection attack) and the t0 (retransmission)
+ * timer shall be set.
+ */
+ if ((sm->scalar && sm->p_scalar && l_ecc_scalars_are_equal(sm->scalar, sm->p_scalar)) ||
+ (sm->element && sm->p_element && l_ecc_points_are_equal(sm->element, sm->p_element)))
+ return false;
+
+ return true;
+}
+
static int sae_reject(struct sae_sm *sm, uint16_t transaction, uint16_t status)
{
uint8_t reject[6];
@@ -593,6 +610,10 @@ static int sae_build_commit(struct sae_sm *sm, const uint8_t *addr1,
l_ecc_scalar_free(mask);
+ /* ensure the scalar and element are different from peer */
+ if (!sae_check_reflection(sm))
+ return -EPROTO;
+
/*
* Several cases require retransmitting the same commit message. The
* anti-clogging code path requires this as well as the retransmission
@@ -799,9 +820,13 @@ static int sae_process_commit(struct sae_sm *sm, const uint8_t *from,
const uint8_t *frame, size_t len)
{
uint8_t *ptr = (uint8_t *) frame;
- unsigned int nbytes = l_ecc_curve_get_scalar_bytes(sm->curve);
+ unsigned int nbytes;
int r;
+ if (sm->handshake->authenticator && sae_set_group(sm, l_get_le16(frame)) < 0)
+ return -1;
+
+ nbytes = l_ecc_curve_get_scalar_bytes(sm->curve);
ptr += 2;
sm->p_scalar = l_ecc_scalar_new(sm->curve, ptr, nbytes);
@@ -821,28 +846,30 @@ static int sae_process_commit(struct sae_sm *sm, const uint8_t *from,
MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP);
}
- /*
- * If they match those sent as part of the protocol instance's own
- * SAE Commit message, the frame shall be silently discarded (because
- * it is evidence of a reflection attack) and the t0 (retransmission)
- * timer shall be set.
- */
- if (l_ecc_scalars_are_equal(sm->p_scalar, sm->scalar) ||
- l_ecc_points_are_equal(sm->p_element, sm->element)) {
- l_warn("peer scalar or element matched own, discarding frame");
- return -ENOMSG;
- }
-
sm->sc++;
- r = sae_calculate_keys(sm);
- if (r != 0)
- return r;
+ if (sm->handshake->authenticator) {
+ if (!sae_send_commit(sm, false))
+ return -EPROTO;
+
+ r = sae_calculate_keys(sm);
+ if (r != 0)
+ return r;
- if (!sae_send_confirm(sm))
- return -EPROTO;
+ sm->state = SAE_STATE_COMMITTED;
+ } else {
+ if (!sae_check_reflection(sm))
+ return -EPROTO;
- sm->state = SAE_STATE_CONFIRMED;
+ r = sae_calculate_keys(sm);
+ if (r != 0)
+ return r;
+
+ if (!sae_send_confirm(sm))
+ return -EPROTO;
+
+ sm->state = SAE_STATE_CONFIRMED;
+ }
return 0;
}
@@ -1013,7 +1040,7 @@ static int sae_verify_nothing(struct sae_sm *sm, uint16_t transaction,
/*
* TODO: This does not handle the transition from NOTHING -> CONFIRMED
* as this is only relevant to the AP or in Mesh mode which is not
- * yet supported.
+ * yet fully supported.
*/
if (transaction != SAE_STATE_COMMITTED)
return -EBADMSG;
--
2.45.0
next prev parent reply other threads:[~2024-05-06 0:48 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-06 0:30 [PATCH v2 00/18] Basic WPA3 support in AP mode John Brandt
2024-05-06 0:30 ` [PATCH v2 01/18] ap: ability to advertise PSK and SAE John Brandt
2024-05-06 0:30 ` [PATCH v2 02/18] ap: accept PSK/SAE in auth depending on config John Brandt
2024-05-07 15:07 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 03/18] unit: fix SAE unit tests John Brandt
2024-05-07 15:51 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 04/18] sae: add function sae_set_group John Brandt
2024-05-07 14:53 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 05/18] sae: refactor and add function sae_calculate_keys John Brandt
2024-05-07 15:13 ` Denis Kenzior
2024-05-06 0:30 ` John Brandt [this message]
2024-05-06 0:30 ` [PATCH v2 07/18] sae: verify offered group in AP mode John Brandt
2024-05-07 15:11 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 08/18] sae: support reception of Confirm frame by AP John Brandt
2024-05-07 15:51 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 09/18] ap: add support to handle SAE authentication John Brandt
2024-05-07 15:44 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 10/18] ap: enable start of 4-way HS after SAE John Brandt
2024-05-06 0:30 ` [PATCH v2 11/18] eapol: support PTK derivation with SHA256 John Brandt
2024-05-07 15:52 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 12/18] eapol: encrypt key data for AKM-defined ciphers John Brandt
2024-05-07 16:04 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 13/18] unit: add unit test for SAE AP mode John Brandt
2024-05-06 0:30 ` [PATCH v2 14/18] ap: move toward requiring MFP when using SAE John Brandt
2024-05-07 16:12 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 15/18] handshake: add functions to save and set IGTK John Brandt
2024-05-07 16:20 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 16/18] eapol: include IGTK in 4-way handshake as AP John Brandt
2024-05-07 16:20 ` Denis Kenzior
2024-05-06 0:30 ` [PATCH v2 17/18] ap: generate IGTK on startup if MFP is enabled John Brandt
2024-05-06 0:30 ` [PATCH v2 18/18] ap: propogate IGTK and RSC to handshake John Brandt
2024-05-07 16:23 ` [PATCH v2 00/18] Basic WPA3 support in AP mode Denis Kenzior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240506003518.320176-7-brandtwjohn@gmail.com \
--to=brandtwjohn@gmail.com \
--cc=iwd@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox