From: Tim Kourt <tim.a.kourt@linux.intel.com>
To: iwd@lists.01.org
Subject: [PATCH 4/6] peap: Extend EAP Extensions to handle multiple TLVs
Date: Thu, 05 Dec 2019 13:13:52 -0800 [thread overview]
Message-ID: <20191205211354.19075-4-tim.a.kourt@linux.intel.com> (raw)
In-Reply-To: <20191205211354.19075-1-tim.a.kourt@linux.intel.com>
[-- Attachment #1: Type: text/plain, Size: 3838 bytes --]
The handler for EAP Extensions has been modified to support multiple
TLV types instead of the single Result TLV. This will allow to handle
the other TLVs such as Crypto-Binding TLV.
---
src/eap-peap.c | 90 ++++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 65 insertions(+), 25 deletions(-)
diff --git a/src/eap-peap.c b/src/eap-peap.c
index ed18c667..8cd73c82 100644
--- a/src/eap-peap.c
+++ b/src/eap-peap.c
@@ -111,6 +111,7 @@ static void eap_peap_phase2_complete(enum eap_result result, void *user_data)
*/
#define EAP_EXTENSIONS_HEADER_LEN 5
#define EAP_EXTENSIONS_TLV_HEADER_LEN 4
+#define EAP_EXTENSIONS_TLV_M_BIT_MASK 0x8000
enum eap_extensions_tlv_type {
/* Reserved = 0x0000, */
@@ -119,6 +120,8 @@ enum eap_extensions_tlv_type {
EAP_EXTENSIONS_TLV_TYPE_RESULT = 0x8003,
};
+#define TLV_RESULT_VAL_LEN 2
+
enum eap_extensions_result {
EAP_EXTENSIONS_RESULT_SUCCCESS = 1,
EAP_EXTENSIONS_RESULT_FAILURE = 2,
@@ -126,31 +129,15 @@ enum eap_extensions_result {
static int eap_extensions_handle_result_tlv(struct eap_state *eap,
const uint8_t *data,
- size_t data_len,
+ uint16_t tlv_value_len,
uint8_t *response)
{
struct peap_state *peap_state;
- uint16_t type;
- uint16_t len;
uint16_t result;
- if (data_len < EAP_EXTENSIONS_TLV_HEADER_LEN + 2)
- return -ENOENT;
-
- type = l_get_be16(data);
-
- if (type != EAP_EXTENSIONS_TLV_TYPE_RESULT)
- return -ENOENT;
-
- data += 2;
-
- len = l_get_be16(data);
-
- if (len != 2)
+ if (tlv_value_len != TLV_RESULT_VAL_LEN)
return -ENOENT;
- data += 2;
-
result = l_get_be16(data);
l_debug("result: %d", result);
@@ -169,11 +156,62 @@ static int eap_extensions_handle_result_tlv(struct eap_state *eap,
return -ENOENT;
}
- l_put_be16(EAP_EXTENSIONS_TLV_TYPE_RESULT,
- &response[EAP_EXTENSIONS_HEADER_LEN]);
- l_put_be16(2, &response[EAP_EXTENSIONS_HEADER_LEN + 2]);
- l_put_be16(result, &response[EAP_EXTENSIONS_HEADER_LEN +
- EAP_EXTENSIONS_TLV_HEADER_LEN]);
+ /* Build response Result TLV */
+
+ l_put_be16(EAP_EXTENSIONS_TLV_TYPE_RESULT, response);
+ response += 2;
+
+ l_put_be16(TLV_RESULT_VAL_LEN, response);
+ response += 2;
+
+ l_put_be16(result, response);
+
+ return result;
+}
+
+static int eap_extensions_process_tlvs(struct eap_state *eap,
+ const uint8_t *data,
+ size_t data_len,
+ uint8_t *response)
+{
+ uint16_t tlv_type;
+ uint16_t tlv_value_len;
+ int r;
+ int result = EAP_EXTENSIONS_RESULT_FAILURE;
+
+ while (data_len >= EAP_EXTENSIONS_TLV_HEADER_LEN) {
+ tlv_type = l_get_be16(data);
+ data += 2;
+
+ tlv_value_len = l_get_be16(data);
+ data += 2;
+
+ data_len -= EAP_EXTENSIONS_TLV_HEADER_LEN;
+
+ if (data_len < tlv_value_len)
+ return -ENOENT;
+
+ switch (tlv_type) {
+ case EAP_EXTENSIONS_TLV_TYPE_RESULT:
+ result = r = eap_extensions_handle_result_tlv(eap,
+ data, tlv_value_len, response);
+
+ response += EAP_EXTENSIONS_TLV_HEADER_LEN +
+ TLV_RESULT_VAL_LEN;
+ break;
+ default:
+ if (tlv_type & EAP_EXTENSIONS_TLV_M_BIT_MASK)
+ return -ENOENT;
+
+ break;
+ }
+
+ if (r < 0)
+ return r;
+
+ data += tlv_value_len;
+ data_len -= tlv_value_len;
+ }
return result;
}
@@ -185,8 +223,10 @@ static void eap_extensions_handle_request(struct eap_state *eap,
{
struct peap_state *peap_state;
uint8_t response[EAP_EXTENSIONS_HEADER_LEN +
- EAP_EXTENSIONS_TLV_HEADER_LEN + 2];
- int r = eap_extensions_handle_result_tlv(eap, pkt, len, response);
+ EAP_EXTENSIONS_TLV_HEADER_LEN +
+ TLV_RESULT_VAL_LEN];
+ int r = eap_extensions_process_tlvs(eap, pkt, len,
+ &response[EAP_EXTENSIONS_HEADER_LEN]);
if (r < 0)
return;
--
2.13.6
next prev parent reply other threads:[~2019-12-05 21:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-05 21:13 [PATCH 1/6] peap: Introduce PEAP state Tim Kourt
2019-12-05 21:13 ` [PATCH 2/6] peap: Delay key installation until success of Phase 2 Tim Kourt
2019-12-05 21:13 ` [PATCH 3/6] peap: Rename AVPs to TLVs Tim Kourt
2019-12-05 21:13 ` Tim Kourt [this message]
2019-12-09 7:46 ` [PATCH 4/6] peap: Extend EAP Extensions to handle multiple TLVs Denis Kenzior
2019-12-05 21:13 ` [PATCH 5/6] crypto: Add support for PRF+ SHA1 Tim Kourt
2019-12-09 7:47 ` Denis Kenzior
2019-12-05 21:13 ` [PATCH 6/6] peap: Add support for Crypto-Binding in PEAPv0 Tim Kourt
2019-12-09 8:00 ` Denis Kenzior
2019-12-09 7:40 ` [PATCH 1/6] peap: Introduce PEAP state 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=20191205211354.19075-4-tim.a.kourt@linux.intel.com \
--to=tim.a.kourt@linux.intel.com \
--cc=iwd@lists.01.org \
/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