예제 #1
0
    def test_discard2(self):
        request = self.test_md5_challenge_request()

        message = Md5ChallengeMessage(
            self.src_mac, request.message_id + 10, Eap.RESPONSE,
            bytes.fromhex("3a535f0ee8c6b34fe714aa7dad9a0e15"), b"host1user")
        self.sm.event(EventMessageReceived(message, self.PORT_ID_MAC))
        self.assertEqual(self.sm.state, self.sm.IDLE2)
        self.assertEqual(self.eap_output_queue.qsize(), 0)
        self.assertEqual(self.radius_output_queue.qsize(), 0)
예제 #2
0
 def test_incorrect_challenge_received_moves_to_idle(self):
     txn_id = 123
     challenge = build_byte_string("01234567890abcdef01234567890abcdef")
     password = "******"
     id_string = struct.pack("B", txn_id)
     challenge_response = md5(id_string + password.encode() + challenge).digest()
     message = Md5ChallengeMessage(
         MacAddress.from_string("00:12:34:56:78:90"), self.state_machine.txn_id, Eap.RESPONSE, challenge_response, b"who cares")
     self.state_machine.event(EventMessageReceived(message))
     self.assertEqual(self.state_machine.state, "idle")
     self.assertEqual(self.state_machine.output_messages.qsize(), 1)
예제 #3
0
    def test_md5_challenge_response(self):
        self.test_md5_challenge_request()

        message = Md5ChallengeMessage(
            self.src_mac, 2, Eap.RESPONSE,
            bytes.fromhex("3a535f0ee8c6b34fe714aa7dad9a0e15"), b"host1user")
        self.sm.event(EventMessageReceived(message, self.PORT_ID_MAC))

        self.assertEqual(self.sm.state, self.sm.AAA_IDLE)
        self.assertEqual(self.eap_output_queue.qsize(), 0)
        self.assertEqual(self.radius_output_queue.qsize(), 1)
        self.assertIsInstance(self.radius_output_queue.get_nowait()[0],
                              Md5ChallengeMessage)
예제 #4
0
 def test_md5_challenge_response_message_packs(self):  # pylint: disable=invalid-name
     expected_packed_message = bytes.fromhex(
         "0180c2000003001422e9545e888e010000220201002204103a535f0ee8c6b34fe714aa7dad9a0e154a6f686e2e4d63477569726b")  # pylint: disable=line-too-long
     message = Md5ChallengeMessage(
         src_mac=MacAddress.from_string("00:14:22:e9:54:5e"),
         message_id=1,
         code=Eap.RESPONSE,
         challenge=bytes.fromhex("3a535f0ee8c6b34fe714aa7dad9a0e15"),
         extra_data=b"John.McGuirk")
     packed_message = MessagePacker.ethernet_pack(
         message, MacAddress.from_string("00:14:22:e9:54:5e"),
         MacAddress.from_string("01:80:c2:00:00:03"))
     self.assertEqual(expected_packed_message, packed_message)
예제 #5
0
 def test_md5_challenge_request_message_packs(self):
     expected_packed_message = build_byte_string(
         "0180c2000003001906eab88c888e01000016010100160410824788d693e2adac6ce15641418228cf"
     )
     message = Md5ChallengeMessage(
         src_mac=MacAddress.from_string("00:19:06:ea:b8:8c"),
         message_id=1,
         code=Eap.REQUEST,
         challenge=build_byte_string("824788d693e2adac6ce15641418228cf"),
         extra_data=b"")
     packed_message = MessagePacker.pack(
         message, MacAddress.from_string("01:80:c2:00:00:03"))
     self.assertEqual(expected_packed_message, packed_message)
예제 #6
0
    def test_md5_challenge_request(self):
        self.test_identity_response()

        eap_message = Md5ChallengeMessage(
            self.src_mac, 2, Eap.REQUEST,
            bytes.fromhex("74d3db089b727d9cc5774599e4a32a29"), b"host1user")
        self.sm.event(
            EventRadiusMessageReceived(eap_message,
                                       State.create(b"random state")))

        self.assertEqual(self.sm.state, self.sm.IDLE2)

        self.assertEqual(self.eap_output_queue.qsize(), 1)
        output = self.eap_output_queue.get_nowait()[0]
        self.assertIsInstance(output, Md5ChallengeMessage)

        self.assertEqual(self.radius_output_queue.qsize(), 0)
        return output
예제 #7
0
    def test_radius_packs_basic(self):
        """without extra_attributes or nas-port"""

        packed_message = bytes.fromhex("01bf005b0123456789abcdeffedcba9876543210010a62656e62757274741f1361613a62623a63633a64643a65653a66664f18021500160410824788d693e2adac6ce15641418228cf5012caadc1c7a3be07fe63fdf83a59ed18c2")  # pylint: disable=line-too-long

        src_mac = MacAddress.from_string("aa:bb:cc:dd:ee:ff")
        username = "******"
        radius_packet_id = 191
        request_authenticator = bytes.fromhex(
            "0123456789abcdeffedcba9876543210")
        state = None
        secret = "SUPERSECRET"
        challenge = bytes.fromhex("824788d693e2adac6ce15641418228cf")
        eap_message = Md5ChallengeMessage(src_mac, 21, Eap.RESPONSE, challenge,
                                          b'')
        packed_radius = MessagePacker.radius_pack(eap_message, src_mac,
                                                  username, radius_packet_id,
                                                  request_authenticator, state,
                                                  secret)
        self.assertEqual(packed_message, packed_radius)
예제 #8
0
    def test_radius_packs_with_nas_port(self):

        packed_message = bytes.fromhex("01bf00610123456789abcdeffedcba9876543210010a62656e62757274741f1361613a62623a63633a64643a65653a66660506000002a14f18021500160410824788d693e2adac6ce15641418228cf50121139bd192c46fe6d2a937d9573311b70")  # pylint: disable=line-too-long

        src_mac = MacAddress.from_string("aa:bb:cc:dd:ee:ff")
        username = "******"
        radius_packet_id = 191
        request_authenticator = bytes.fromhex(
            "0123456789abcdeffedcba9876543210")
        state = None
        secret = "SUPERSECRET"
        challenge = bytes.fromhex("824788d693e2adac6ce15641418228cf")
        eap_message = Md5ChallengeMessage(src_mac, 21, Eap.RESPONSE, challenge,
                                          b'')
        packed_radius = MessagePacker.radius_pack(eap_message,
                                                  src_mac,
                                                  username,
                                                  radius_packet_id,
                                                  request_authenticator,
                                                  state,
                                                  secret,
                                                  nas_port=0x02a1)
        self.assertEqual(packed_message, packed_radius)