Example #1
0
    def setUp(self):
        self.vncSocket = vncsocket.VncSocket()
        self.vncSocket.connect()

        # Protocol version
        msg = protocolversion.ProtocolVersion.unpack(self.vncSocket.receive())
        self.assertEqual(3, msg.major)
        self.assertEqual(8, msg.minor)
        msg = protocolversion.ProtocolVersion(3, 8)
        self.assertEqual(self.vncSocket.send(msg.pack()), None)

        # Security types
        msg = securitytypes.SecurityTypes.unpack(self.vncSocket.receive())
        self.assertTrue(0 != msg.number_of_security_types)

        # Selected type
        self.assertEqual(self.vncSocket.send('\x01'), None)

        # SecurityResult
        msg = securityresult.SecurityResult.unpack(self.vncSocket.receive())
        self.assertTrue(0 == msg.status)

        # ClientInit
        self.assertEqual(self.vncSocket.send('\xFF'), None)

        # ServerInit
        self.serverInit = serverinit.ServerInit.unpack(
            self.vncSocket.receive())
        self.assertFalse(self.serverInit.big_endian_flag)
        self.assertTrue(self.serverInit.true_colour_flag)
        self.assertTrue(
            self.serverInit.bits_per_pixel >= self.serverInit.depth)
Example #2
0
    def test1(self):
        """RFB handshaking phase: Normal case """

        vncSocket = vncsocket.VncSocket()
        vncSocket.connect()

        # Protocol version
        msg = protocolversion.ProtocolVersion.unpack(vncSocket.receive())
        self.assertEqual(3, msg.major)
        self.assertEqual(8, msg.minor)
        msg = protocolversion.ProtocolVersion(3, 8)
        self.assertEqual(vncSocket.send(msg.pack()), None)

        # Security types
        msg = securitytypes.SecurityTypes.unpack(vncSocket.receive())
        self.assertTrue(0 != msg.number_of_security_types)

        # Selected type
        self.assertEqual(vncSocket.send('\x01'), None)

        # SecurityResult
        msg = securityresult.SecurityResult.unpack(vncSocket.receive())
        self.assertTrue(0 == msg.status)

        # ClientInit
        self.assertEqual(vncSocket.send('\xFF'), None)

        # ServerInit
        msg = serverinit.ServerInit.unpack(vncSocket.receive())
        self.assertFalse(msg.big_endian_flag)
        self.assertTrue(msg.true_colour_flag)
        self.assertTrue(msg.bits_per_pixel >= msg.depth)
Example #3
0
    def test3(self):
        """RFB handshaking phase : Wrong security type"""

        vncSocket = vncsocket.VncSocket()
        vncSocket.connect()

        # Protocol version
        msg = protocolversion.ProtocolVersion.unpack(vncSocket.receive())
        self.assertEqual(3, msg.major)
        self.assertEqual(8, msg.minor)
        msg = protocolversion.ProtocolVersion(3, 8)
        self.assertEqual(vncSocket.send(msg.pack()), None)

        # Security types
        msg = securitytypes.SecurityTypes.unpack(vncSocket.receive())
        self.assertTrue(0 != msg.number_of_security_types)

        # Selected type
        self.assertEqual(vncSocket.send('\xFF'), None)

        # Security types
        data = vncSocket.receive()
        if 0 != len(data):
            # If some data before disconnect check it
            # SecurityResult
            msg = securityresult.SecurityResult.unpack(data)
            self.assertTrue(1 == msg.status)
            self.assertTrue(0 < msg.reason_length)

        # Must have disconnect
        self.assertTrue(0 == len(vncSocket.receive()))
Example #4
0
    def test5(self):
        """RFB handshaking phase: Smartass clienting send all at once"""

        vncSocket = vncsocket.VncSocket()
        vncSocket.connect()

        # Protocol version
        msg = protocolversion.ProtocolVersion.unpack(vncSocket.receive())
        self.assertEqual(3, msg.major)
        self.assertEqual(8, msg.minor)

        data = 'RFB 003.008\n\x01\xFF'
        self.assertEqual(vncSocket.send(data), None)

        # Security types
        msg = securitytypes.SecurityTypes.unpack(vncSocket.receive(2))
        self.assertTrue(0 != msg.number_of_security_types)

        # SecurityResult
        msg = securityresult.SecurityResult.unpack(vncSocket.receive(4))
        self.assertTrue(0 == msg.status)

        # ServerInit
        msg = serverinit.ServerInit.unpack(vncSocket.receive())
        self.assertFalse(msg.big_endian_flag)
        self.assertTrue(msg.true_colour_flag)
        self.assertTrue(msg.bits_per_pixel >= msg.depth)
Example #5
0
    def test4(self):
        """RFB handshaking phase: Stupid clienting send one byte at the time"""

        vncSocket = vncsocket.VncSocket()
        vncSocket.connect()

        # Protocol version
        msg = protocolversion.ProtocolVersion.unpack(vncSocket.receive())
        self.assertEqual(3, msg.major)
        self.assertEqual(8, msg.minor)

        data = 'RFB 003.008\n\x01\xFF'
        for i in range(len(data)):
            self.assertEqual(vncSocket.send(data[i]), None)
            time.sleep(0.01)

        # Security types
        msg = securitytypes.SecurityTypes.unpack(vncSocket.receive(2))
        self.assertTrue(0 != msg.number_of_security_types)

        # SecurityResult
        msg = securityresult.SecurityResult.unpack(vncSocket.receive(4))
        self.assertTrue(0 == msg.status)

        # ServerInit
        msg = serverinit.ServerInit.unpack(vncSocket.receive())
        self.assertFalse(msg.big_endian_flag)
        self.assertTrue(msg.true_colour_flag)
        self.assertTrue(msg.bits_per_pixel >= msg.depth)
Example #6
0
 def test2(self):
     """Tests re-connecting"""
     i = 0
     while i < 10:
         i += 1
         vncSocket = vncsocket.VncSocket()
         vncSocket.connect()
         data = vncSocket.receive(protocolversion.ProtocolVersion.getSize())
         self.assertIsNotNone(data)
Example #7
0
    def test1(self):
        """Benchmarks RFB handshaking phase"""
        tick = measurement.Measurement("Handshake", 40)
        i = 0
        while (i < tick.count):
            i += 1
            tick.start()

            vncSocket = vncsocket.VncSocket()
            vncSocket.connect()

            # Protocol version
            msg = protocolversion.ProtocolVersion.unpack(vncSocket.receive())
            self.assertIsNotNone(msg)
            msg = protocolversion.ProtocolVersion(3, 8)
            self.assertEqual(vncSocket.send(msg.pack()), None)

            # Security types
            msg = securitytypes.SecurityTypes.unpack(vncSocket.receive())
            self.assertIsNotNone(msg)

            # Selected type
            self.assertEqual(vncSocket.send('\x01'), None)

            # SecurityResult
            msg = securityresult.SecurityResult.unpack(vncSocket.receive())
            self.assertIsNotNone(msg)

            # ClientInit
            self.assertEqual(vncSocket.send('\xFF'), None)

            # ServerInit
            msg = serverinit.ServerInit.unpack(vncSocket.receive())
            self.assertIsNotNone(msg)

            tick.stop()

        tick.output()
Example #8
0
 def test1(self):
     """Tests TCP connection once"""
     vncSocket = vncsocket.VncSocket()
     vncSocket.connect()
     data = vncSocket.receive(protocolversion.ProtocolVersion.getSize())
     self.assertIsNotNone(data)