Beispiel #1
0
    def test_send_incorrect_state_request(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("request")

        event = GreetingRequest((AUTH_TYPE["NO_AUTH"], ))
        with self.assertRaises(ProtocolError):
            conn.send(event)
Beispiel #2
0
    def test_send_incorrect_state_request(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("request")

        event = GreetingRequest((AUTH_TYPE["NO_AUTH"], ))
        with self.assertRaises(ProtocolError):
            conn.send(event)
Beispiel #3
0
    def test_send_incorrect_state_response(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("response")

        event = GreetingResponse(AUTH_TYPE["NO_AUTH"])
        with self.assertRaises(ProtocolError):
            conn.send(event)
Beispiel #4
0
    def test_send_incorrect_state_response(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("response")

        event = GreetingResponse(AUTH_TYPE["NO_AUTH"])
        with self.assertRaises(ProtocolError):
            conn.send(event)
Beispiel #5
0
    def test_send_greeting_response_with_unsupported_auth(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 5
        conn._conn._auth_methods = [AUTH_TYPE["NO_SUPPORT_AUTH_METHOD"]]

        event = GreetingResponse(AUTH_TYPE["NO_SUPPORT_AUTH_METHOD"])
        conn.send(event)
        self.assertEqual(conn._conn.state, "end")
Beispiel #6
0
    def test_send_greeting_response_with_valid_auth(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 5
        conn._conn._auth_methods = [AUTH_TYPE["USERNAME_PASSWD"]]

        event = GreetingResponse(AUTH_TYPE["USERNAME_PASSWD"])
        conn.send(event)
        self.assertEqual(conn._conn.state, "auth_inprogress")
Beispiel #7
0
    def test_send_greeting_response_with_unsupported_auth(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 5
        conn._conn._auth_methods = [AUTH_TYPE["NO_SUPPORT_AUTH_METHOD"]]

        event = GreetingResponse(AUTH_TYPE["NO_SUPPORT_AUTH_METHOD"])
        conn.send(event)
        self.assertEqual(conn._conn.state, "end")
Beispiel #8
0
    def test_send_greeting_response_socks4_with_incorrect_event_detail_verion(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 4
        conn._conn._port = 5580

        event = GreetingResponse(AUTH_TYPE["NO_AUTH"])
        with self.assertRaises(ProtocolError):
            conn.send(event)
Beispiel #9
0
    def test_send_greeting_response_with_valid_auth(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 5
        conn._conn._auth_methods = [AUTH_TYPE["USERNAME_PASSWD"]]

        event = GreetingResponse(AUTH_TYPE["USERNAME_PASSWD"])
        conn.send(event)
        self.assertEqual(conn._conn.state, "auth_inprogress")
Beispiel #10
0
    def test_send_greeting_response_socks4_with_incorrect_event_detail_port(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 4
        conn._conn._port = 5580

        event = Socks4Response(0x5a, "127.0.0.1", 5581)
        with self.assertRaises(ProtocolError):
            conn.send(event)
Beispiel #11
0
    def test_send_greeting_response_with_incorrect_event_detail_auth_type(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 5
        conn._conn._auth_methods = [AUTH_TYPE["NO_SUPPORT_AUTH_METHOD"]]

        event = GreetingResponse(AUTH_TYPE["NO_AUTH"])
        with self.assertRaises(ProtocolError):
            conn.send(event)
Beispiel #12
0
    def test_send_greeting_response_with_incorrect_event_detail_version(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 5
        conn._conn._auth_methods = [AUTH_TYPE["NO_SUPPORT_AUTH_METHOD"]]

        event = Socks4Response(0x5a, "127.0.0.1", 5580)
        with self.assertRaises(ProtocolError):
            conn.send(event)
Beispiel #13
0
    def test_send_greeting_response_socks4_with_incorrect_event_detail_port(
            self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 4
        conn._conn._port = 5580

        event = Socks4Response(0x5a, "127.0.0.1", 5581)
        with self.assertRaises(ProtocolError):
            conn.send(event)
Beispiel #14
0
    def test_send_greeting_response_socks4_with_incorrect_event_detail_verion(
            self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 4
        conn._conn._port = 5580

        event = GreetingResponse(AUTH_TYPE["NO_AUTH"])
        with self.assertRaises(ProtocolError):
            conn.send(event)
Beispiel #15
0
    def test_send_response_with_incorrect_event_detail_port(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("response")
        conn._conn._version = 5
        conn._conn._addr_type = ADDR_TYPE["IPV4"]
        conn._conn._addr = ipaddress.IPv4Address("127.0.0.1")
        conn._conn._port = 8080

        event = Response(RESP_STATUS["SUCCESS"], ADDR_TYPE["IPV4"], "127.0.0.1", 5580)
        with self.assertRaises(ProtocolError):
            conn.send(event)
Beispiel #16
0
    def test_send_response_with_incorrect_event_detail_port(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("response")
        conn._conn._version = 5
        conn._conn._addr_type = ADDR_TYPE["IPV4"]
        conn._conn._addr = ipaddress.IPv4Address("127.0.0.1")
        conn._conn._port = 8080

        event = Response(RESP_STATUS["SUCCESS"], ADDR_TYPE["IPV4"],
                         "127.0.0.1", 5580)
        with self.assertRaises(ProtocolError):
            conn.send(event)
Beispiel #17
0
    def test_send_in_greeting_request_socks4(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("greeting_request")

        event = Socks4Request(1, "127.0.0.1", 5580, "Johnny")
        data = conn.send(event)
        expected_data = struct.pack("!BBH4B6sB", 0x4, 0x1, 5580, 127, 0, 0, 1, "Johnny".encode("ascii"), 0)
        self.assertEqual(conn._conn.state, "greeting_response")
        self.assertEqual(data, expected_data)
Beispiel #18
0
    def test_send_in_request_request(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("request")

        event = Request(REQ_COMMAND["CONNECT"], ADDR_TYPE["IPV4"], u"127.0.0.1", 8080)
        data = conn.send(event)
        expected_data = struct.pack("!BBxB4BH", 0x5, 0x1, 0x1, 127, 0, 0, 1, 8080)
        self.assertEqual(conn._conn.state, "response")
        self.assertEqual(data, expected_data)
Beispiel #19
0
    def test_send_in_greeting_request(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("greeting_request")

        event = GreetingRequest((AUTH_TYPE["NO_AUTH"], ))
        data = conn.send(event)
        expected_data = struct.pack("!BBB", 0x5, 0x1, 0x00)
        self.assertEqual(conn._conn.state, "greeting_response")
        self.assertEqual(data, expected_data)
Beispiel #20
0
    def test_send_in_greeting_request(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("greeting_request")

        event = GreetingRequest((AUTH_TYPE["NO_AUTH"], ))
        data = conn.send(event)
        expected_data = struct.pack("!BBB", 0x5, 0x1, 0x00)
        self.assertEqual(conn._conn.state, "greeting_response")
        self.assertEqual(data, expected_data)
Beispiel #21
0
    def test_send_in_greeting_request_socks4(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("greeting_request")

        event = Socks4Request(1, "127.0.0.1", 5580, "Johnny")
        data = conn.send(event)
        expected_data = struct.pack("!BBH4B6sB", 0x4, 0x1, 5580, 127, 0, 0, 1,
                                    "Johnny".encode("ascii"), 0)
        self.assertEqual(conn._conn.state, "greeting_response")
        self.assertEqual(data, expected_data)
Beispiel #22
0
    def test_send_in_request_request(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("request")

        event = Request(REQ_COMMAND["CONNECT"], ADDR_TYPE["IPV4"],
                        u"127.0.0.1", 8080)
        data = conn.send(event)
        expected_data = struct.pack("!BBxB4BH", 0x5, 0x1, 0x1, 127, 0, 0, 1,
                                    8080)
        self.assertEqual(conn._conn.state, "response")
        self.assertEqual(data, expected_data)
Beispiel #23
0
    def test_send_greeting_response_no_auth(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 5
        conn._conn._auth_methods = [AUTH_TYPE["NO_AUTH"]]

        event = GreetingResponse(AUTH_TYPE["NO_AUTH"])
        data = conn.send(event)
        expected_data = struct.pack("!BB", 0x5, 0x0)

        self.assertEqual(conn._conn.state, "request")
        self.assertEqual(data, expected_data)
Beispiel #24
0
    def test_send_greeting_response_socks4(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 4
        conn._conn._port = 5580

        event = Socks4Response(0x5a, "127.0.0.1", 5580)
        data = conn.send(event)
        expected_data = struct.pack("!BBH4B", 0, 0x5a, 5580, 127, 0, 0, 1)

        self.assertEqual(conn._conn.state, "end")
        self.assertEqual(data, expected_data)
Beispiel #25
0
    def test_send_greeting_response_no_auth(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 5
        conn._conn._auth_methods = [AUTH_TYPE["NO_AUTH"]]

        event = GreetingResponse(AUTH_TYPE["NO_AUTH"])
        data = conn.send(event)
        expected_data = struct.pack("!BB", 0x5, 0x0)

        self.assertEqual(conn._conn.state, "request")
        self.assertEqual(data, expected_data)
Beispiel #26
0
    def test_send_greeting_response_socks4(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 4
        conn._conn._port = 5580

        event = Socks4Response(0x5a, "127.0.0.1", 5580)
        data = conn.send(event)
        expected_data = struct.pack("!BBH4B", 0, 0x5a, 5580, 127, 0, 0, 1)

        self.assertEqual(conn._conn.state, "end")
        self.assertEqual(data, expected_data)
Beispiel #27
0
    def test_send_response(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("response")
        conn._conn._version = 5
        conn._conn._addr_type = ADDR_TYPE["IPV4"]
        conn._conn._addr = ipaddress.IPv4Address("127.0.0.1")
        conn._conn._port = 8080

        event = Response(RESP_STATUS["SUCCESS"], ADDR_TYPE["IPV4"], "127.0.0.1", 8080)
        data = conn.send(event)
        expected_data = struct.pack("!BBxB4BH", 0x5, 0x0, 0x1, 127, 0, 0, 1, 8080)
        self.assertEqual(conn._conn.state, "end")
        self.assertEqual(data, expected_data)
Beispiel #28
0
    def test_send_response(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("response")
        conn._conn._version = 5
        conn._conn._addr_type = ADDR_TYPE["IPV4"]
        conn._conn._addr = ipaddress.IPv4Address("127.0.0.1")
        conn._conn._port = 8080

        event = Response(RESP_STATUS["SUCCESS"], ADDR_TYPE["IPV4"],
                         "127.0.0.1", 8080)
        data = conn.send(event)
        expected_data = struct.pack("!BBxB4BH", 0x5, 0x0, 0x1, 127, 0, 0, 1,
                                    8080)
        self.assertEqual(conn._conn.state, "end")
        self.assertEqual(data, expected_data)