Beispiel #1
0
 def test_struct_unpack_error_converts_to_message_parse_error(self):  # pylint: disable=invalid-name
     data = bytes.fromhex("01001000")
     try:
         MessageParser.eap_parse(
             data, MacAddress.from_string("00:00:00:12:34:56"))
     except MessageParseError as exception:
         self.assertIsInstance(exception.__cause__, struct.error)
         return
     self.fail()
Beispiel #2
0
def test_one_x_parse(data):
    """Tests the one_x_parse function
    Args:
        data: payload to parse"""
    try:
        MessageParser.one_x_parse(data,
                                  MacAddress.from_string("00:00:00:12:34:56"))
    except MessageParseError:
        # Ignore exceptions the parser intentionally throws, and are caught by the caller.
        pass
Beispiel #3
0
 def test_eapol_logoff_message_parses(self):
     packed_message = build_byte_string(
         "0180c2000003001906eab88c888e01020000")
     message = MessageParser.parse(packed_message)
     self.assertEqual(MacAddress.from_string("00:19:06:ea:b8:8c"),
                      message.src_mac)
     self.assertTrue(isinstance(message, EapolLogoffMessage))
Beispiel #4
0
 def test_ttls_message_parses(self):
     packed_message = bytes.fromhex("000000111101444444444444888e"
                                    "01000006016900061520")
     message = MessageParser.ethernet_parse(packed_message)[0]
     self.assertEqual(MacAddress.from_string("44:44:44:44:44:44"),
                      message.src_mac)
     self.assertEqual(105, message.message_id)
     self.assertIsInstance(message, TtlsMessage)
Beispiel #5
0
def test_radius_parse(data):
    """Tests the radiuse_parse function
    Args:
        data: payload to parse"""

    try:
        # The dict sets the packet ID for the known packet_id (test/fuzzer/radius_packet*.ex)
        #  to none. so no validation is done.
        MessageParser.radius_parse(data,
                                   "SECRET",
                                   radius_lifecycle=namedtuple(
                                       'RadiusLifecycle',
                                       'packet_id_to_request_authenticator')(
                                           NoneDict()))
    except MessageParseError:
        # Ignore exceptions the parser intentionally throws, and are caught by the caller.
        pass
Beispiel #6
0
 def test_success_message_parses(self):
     packed_message = build_byte_string(
         "0180c2000003001906eab88c888e0100000403ff0004")
     message = MessageParser.parse(packed_message)
     self.assertEqual(MacAddress.from_string("00:19:06:ea:b8:8c"),
                      message.src_mac)
     self.assertEqual(255, message.message_id)
     self.assertTrue(isinstance(message, SuccessMessage))
Beispiel #7
0
 def test_failure_message_parses(self):
     packed_message = bytes.fromhex(
         "0180c2000003001906eab88c888e0100000404ff0004")
     message = MessageParser.ethernet_parse(packed_message)[0]
     self.assertEqual(MacAddress.from_string("00:19:06:ea:b8:8c"),
                      message.src_mac)
     self.assertEqual(255, message.message_id)
     self.assertTrue(isinstance(message, FailureMessage))
Beispiel #8
0
 def test_legacy_nak_message_parses(self):
     packed_message = bytes.fromhex("0180c2000003000000111101888e"
                                    "01000006026800060315")
     message = MessageParser.ethernet_parse(packed_message)[0]
     self.assertEqual(MacAddress.from_string("00:00:00:11:11:01"),
                      message.src_mac)
     self.assertEqual(104, message.message_id)
     self.assertIsInstance(message, LegacyNakMessage)
Beispiel #9
0
 def test_identity_request_message_parses(self):  # pylint: disable=invalid-name
     packed_message = bytes.fromhex(
         "0180c2000003001906eab88c888e010000050101000501000000")
     message = MessageParser.ethernet_parse(packed_message)[0]
     self.assertEqual(MacAddress.from_string("00:19:06:ea:b8:8c"),
                      message.src_mac)
     self.assertEqual(1, message.message_id)
     self.assertEqual(Eap.REQUEST, message.code)
     self.assertEqual("", message.identity)
Beispiel #10
0
 def test_identity_request_message_parses(self):
     packed_message = build_byte_string(
         "0180c2000003001906eab88c888e010000050101000501000000")
     message = MessageParser.parse(packed_message)
     self.assertEqual(MacAddress.from_string("00:19:06:ea:b8:8c"),
                      message.src_mac)
     self.assertEqual(1, message.message_id)
     self.assertEqual(Eap.REQUEST, message.code)
     self.assertEqual("", message.identity)
Beispiel #11
0
 def test_peap_message_parses(self):
     packed_message = bytes.fromhex("000000111101444444444444888e"
                                    "010000b2026900b2190016030100a7010000a303038c8007fa4ffe8f11fbe62debce4a1385e70be51efe77b105d205d2dc9ae815a5000038c02cc030009fcca9cca8ccaac02bc02f009ec024c028006bc023c0270067c00ac0140039c009c0130033009d009c003d003c0035002f00ff01000042000b000403000102000a000a0008001d0017001900180016000000170000000d0020001e060106020603050105020503040104020403030103020303020102020203")  # pylint: disable=line-too-long
     message = MessageParser.ethernet_parse(packed_message)[0]
     self.assertEqual(MacAddress.from_string("44:44:44:44:44:44"),
                      message.src_mac)
     self.assertEqual(105, message.message_id)
     self.assertEqual(0, message.flags)
     self.assertIsInstance(message, PeapMessage)
Beispiel #12
0
 def test_identity_response_message_parses(self):  # pylint: disable=invalid-name
     packed_message = bytes.fromhex(
         "0180c2000003001422e9545e888e0100001102000011014a6f686e2e4d63477569726b"
     )
     message = MessageParser.ethernet_parse(packed_message)[0]
     self.assertEqual(MacAddress.from_string("00:14:22:e9:54:5e"),
                      message.src_mac)
     self.assertEqual(0, message.message_id)
     self.assertEqual(Eap.RESPONSE, message.code)
     self.assertEqual("John.McGuirk", message.identity)
Beispiel #13
0
 def test_identity_response_message_parses(self):
     packed_message = build_byte_string(
         "0180c2000003001422e9545e888e0100001102000011014a6f686e2e4d63477569726b"
     )
     message = MessageParser.parse(packed_message)
     self.assertEqual(MacAddress.from_string("00:14:22:e9:54:5e"),
                      message.src_mac)
     self.assertEqual(0, message.message_id)
     self.assertEqual(Eap.RESPONSE, message.code)
     self.assertEqual("John.McGuirk", message.identity)
Beispiel #14
0
 def test_md5_challenge_response_message_parses(self):  # pylint: disable=invalid-name
     packed_message = bytes.fromhex(
         "0180c2000003001422e9545e888e010000220201002204103a535f0ee8c6b34fe714aa7dad9a0e154a6f686e2e4d63477569726b")  # pylint: disable=line-too-long
     message = MessageParser.ethernet_parse(packed_message)[0]
     self.assertEqual(MacAddress.from_string("00:14:22:e9:54:5e"),
                      message.src_mac)
     self.assertEqual(1, message.message_id)
     self.assertEqual(Eap.RESPONSE, message.code)
     self.assertEqual(bytes.fromhex("3a535f0ee8c6b34fe714aa7dad9a0e15"),
                      message.challenge)
     self.assertEqual(b"John.McGuirk", message.extra_data)
Beispiel #15
0
 def test_md5_challenge_response_message_parses(self):
     packed_message = build_byte_string(
         "0180c2000003001422e9545e888e010000220201002204103a535f0ee8c6b34fe714aa7dad9a0e154a6f686e2e4d63477569726b"
     )
     message = MessageParser.parse(packed_message)
     self.assertEqual(MacAddress.from_string("00:14:22:e9:54:5e"),
                      message.src_mac)
     self.assertEqual(1, message.message_id)
     self.assertEqual(Eap.RESPONSE, message.code)
     self.assertEqual(build_byte_string("3a535f0ee8c6b34fe714aa7dad9a0e15"),
                      message.challenge)
     self.assertEqual(b"John.McGuirk", message.extra_data)
Beispiel #16
0
 def test_md5_challenge_request_message_parses(self):
     packed_message = build_byte_string(
         "0180c2000003001906eab88c888e01000016010100160410824788d693e2adac6ce15641418228cf0000"
     )
     message = MessageParser.parse(packed_message)
     self.assertEqual(MacAddress.from_string("00:19:06:ea:b8:8c"),
                      message.src_mac)
     self.assertEqual(1, message.message_id)
     self.assertEqual(Eap.REQUEST, message.code)
     self.assertEqual(build_byte_string("824788d693e2adac6ce15641418228cf"),
                      message.challenge)
     self.assertEqual(b"", message.extra_data)
Beispiel #17
0
 def test_md5_challenge_request_message_parses(self):  # pylint: disable=invalid-name
     packed_message = bytes.fromhex(
         "0180c2000003001906eab88c888e01000016010100160410824788d693e2adac6ce15641418228cf0000"
     )
     message = MessageParser.ethernet_parse(packed_message)[0]
     self.assertEqual(MacAddress.from_string("00:19:06:ea:b8:8c"),
                      message.src_mac)
     self.assertEqual(1, message.message_id)
     self.assertEqual(Eap.REQUEST, message.code)
     self.assertEqual(bytes.fromhex("824788d693e2adac6ce15641418228cf"),
                      message.challenge)
     self.assertEqual(b"", message.extra_data)
Beispiel #18
0
 def receive_eap_messages(self):
     """receive eap messages from supplicant forever."""
     while self.running():
         sleep(0)
         self.logger.info("waiting for eap.")
         packed_message = self.eap_socket.receive()
         self.logger.info("Received packed_message: %s",
                          str(packed_message))
         try:
             eap, dst_mac = MessageParser.ethernet_parse(packed_message)
         except MessageParseError as exception:
             self.logger.info(
                 "MessageParser.ethernet_parse threw exception.\n"
                 " packed_message: '%s'.\n"
                 " exception: '%s'.", packed_message, exception)
             continue
         self.send_eap_to_state_machine(eap, dst_mac)
Beispiel #19
0
 def receive_radius_messages(self):
     """receive RADIUS messages from RADIUS server forever."""
     while self.running():
         sleep(0)
         self.logger.info("waiting for radius.")
         packed_message = self.radius_socket.receive()
         try:
             radius = MessageParser.radius_parse(packed_message,
                                                 self.radius_secret,
                                                 self.radius_lifecycle)
         except MessageParseError as exception:
             self.logger.warning(
                 "MessageParser.radius_parse threw exception.\n"
                 " packed_message: '%s'.\n"
                 " exception: '%s'.", packed_message, exception)
             continue
         self.logger.info("Received RADIUS message: %s", str(radius))
         self.send_radius_to_state_machine(radius)
Beispiel #20
0
 def data(self):
     from chewie.message_parser import MessageParser  # pylint: disable=import-outside-toplevel
     return MessageParser.eap_parse(self._data_type.data(), None)
Beispiel #21
0
 def test_eapol_logoff_message_parses(self):  # pylint: disable=invalid-name
     packed_message = bytes.fromhex("0180c2000003001906eab88c888e01020000")
     message = MessageParser.ethernet_parse(packed_message)[0]
     self.assertEqual(MacAddress.from_string("00:19:06:ea:b8:8c"),
                      message.src_mac)
     self.assertTrue(isinstance(message, EapolLogoffMessage))
Beispiel #22
0
 def test_eapol_start_message_parses(self):
     packed_message = bytes.fromhex("0180c2000003001906eab88c888e01010000")
     message = MessageParser.ethernet_parse(packed_message)[0]
     self.assertEqual(MacAddress.from_string("00:19:06:ea:b8:8c"),
                      message.src_mac)
     self.assertTrue(isinstance(message, EapolStartMessage))