From 288b6f8b85fc1a736ee1bc74d486a6530d030b9d Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sat, 28 Nov 2015 12:25:22 +0200 Subject: [PATCH] tests: Extended coverage for the EAP-SAKE attribute parser Signed-off-by: Jouni Malinen --- tests/hwsim/test_eap_proto.py | 91 +++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/tests/hwsim/test_eap_proto.py b/tests/hwsim/test_eap_proto.py index 5c11a1b20..b389c72af 100644 --- a/tests/hwsim/test_eap_proto.py +++ b/tests/hwsim/test_eap_proto.py @@ -477,6 +477,97 @@ def test_eap_proto_sake(dev, apdev): EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_IDENTITY, EAP_SAKE_AT_ANY_ID_REQ, 4) + idx += 1 + if ctx['num'] == idx: + logger.info("Test: Identity subtype with too short attribute header") + payload = struct.pack("B", EAP_SAKE_AT_ANY_ID_REQ) + return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'], + 4 + 1 + 3 + len(payload), + EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0, + EAP_SAKE_SUBTYPE_IDENTITY) + payload + + idx += 1 + if ctx['num'] == idx: + logger.info("Test: Identity subtype with AT_IV but not AT_ENCR_DATA") + payload = struct.pack("BB", EAP_SAKE_AT_IV, 2) + return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'], + 4 + 1 + 3 + len(payload), + EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0, + EAP_SAKE_SUBTYPE_IDENTITY) + payload + + idx += 1 + if ctx['num'] == idx: + logger.info("Test: Identity subtype with skippable and non-skippable unknown attribute") + payload = struct.pack("BBBB", 255, 2, 127, 2) + return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'], + 4 + 1 + 3 + len(payload), + EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0, + EAP_SAKE_SUBTYPE_IDENTITY) + payload + + idx += 1 + if ctx['num'] == idx: + logger.info("Test: Identity subtype: AT_RAND_P with invalid payload length") + payload = struct.pack("BB", EAP_SAKE_AT_RAND_P, 2) + return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'], + 4 + 1 + 3 + len(payload), + EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0, + EAP_SAKE_SUBTYPE_IDENTITY) + payload + + idx += 1 + if ctx['num'] == idx: + logger.info("Test: Identity subtype: AT_MIC_P with invalid payload length") + payload = struct.pack("BB", EAP_SAKE_AT_MIC_P, 2) + return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'], + 4 + 1 + 3 + len(payload), + EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0, + EAP_SAKE_SUBTYPE_IDENTITY) + payload + + idx += 1 + if ctx['num'] == idx: + logger.info("Test: Identity subtype: AT_PERM_ID_REQ with invalid payload length") + payload = struct.pack("BBBBBBBBBBBBBB", + EAP_SAKE_AT_SPI_S, 2, + EAP_SAKE_AT_SPI_P, 2, + EAP_SAKE_AT_ENCR_DATA, 2, + EAP_SAKE_AT_NEXT_TMPID, 2, + EAP_SAKE_AT_PERM_ID_REQ, 4, 0, 0, + EAP_SAKE_AT_PERM_ID_REQ, 2) + return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'], + 4 + 1 + 3 + len(payload), + EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0, + EAP_SAKE_SUBTYPE_IDENTITY) + payload + + idx += 1 + if ctx['num'] == idx: + logger.info("Test: Identity subtype: AT_PADDING") + payload = struct.pack("BBBBBB", + EAP_SAKE_AT_PADDING, 3, 0, + EAP_SAKE_AT_PADDING, 3, 1) + return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'], + 4 + 1 + 3 + len(payload), + EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0, + EAP_SAKE_SUBTYPE_IDENTITY) + payload + + idx += 1 + if ctx['num'] == idx: + logger.info("Test: Identity subtype: AT_MSK_LIFE") + payload = struct.pack(">BBLBBH", + EAP_SAKE_AT_MSK_LIFE, 6, 0, + EAP_SAKE_AT_MSK_LIFE, 4, 0) + return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'], + 4 + 1 + 3 + len(payload), + EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0, + EAP_SAKE_SUBTYPE_IDENTITY) + payload + + idx += 1 + if ctx['num'] == idx: + logger.info("Test: Identity subtype with invalid attribute length") + payload = struct.pack("BB", EAP_SAKE_AT_ANY_ID_REQ, 0) + return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'], + 4 + 1 + 3 + len(payload), + EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0, + EAP_SAKE_SUBTYPE_IDENTITY) + payload + idx += 1 if ctx['num'] == idx: logger.info("Test: Unknown subtype")