Exemplo n.º 1
0
    def test_x224_server_recvConnectionRequest_client_accept_ssl(self):
        """
        @summary:  unit test for X224Server.recvConnectionRequest function
                    test client doesn't support TLS case
        """
        class Transport(object):
            def send(self, data):
                if not isinstance(data, x224.ServerConnectionConfirm):
                    raise X224Test.X224_FAIL()
                if data.protocolNeg.code.value != x224.NegociationType.TYPE_RDP_NEG_FAILURE or data.protocolNeg.failureCode.value != x224.NegotiationFailureCode.SSL_REQUIRED_BY_SERVER:
                    raise X224Test.X224_FAIL()

            def close(self):
                raise X224Test.X224_PASS()

        message = x224.ClientConnectionRequestPDU()
        message.protocolNeg.selectedProtocol.value = x224.Protocols.PROTOCOL_HYBRID
        s = type.Stream()
        s.writeType(message)
        s.pos = 0

        layer = x224.Server(None, "key", "cert", True)
        layer._transport = Transport()
        layer.connect()

        self.assertRaises(X224Test.X224_PASS, layer.recv, s)
Exemplo n.º 2
0
    def __init__(self,
                 colorDepth,
                 privateKeyFileName=None,
                 certificateFileName=None):
        """
        @param privateKeyFileName: file contain server private key
        @param certficiateFileName: file that contain public key
        @param colorDepth: 15, 16, 24
        """
        self._isReady = False
        #list of observer
        self._serverObserver = []
        #build RDP protocol stack
        self._pduLayer = pdu_layer.Server(self)
        #secure layer
        self._secLayer = sec.Server(self._pduLayer)
        #multi channel service
        self._mcsLayer = mcs.Server(self._secLayer)
        #transport pdu layer
        self._x224Layer = x224.Server(self._mcsLayer, privateKeyFileName,
                                      certificateFileName, False)
        #transport packet (protocol layer)
        self._tpktLayer = tpkt.TPKT(self._x224Layer)

        #fastpath stack
        self._pduLayer.initFastPath(self._secLayer)
        self._secLayer.initFastPath(self._tpktLayer)
        #set color depth of session
        self.setColorDepth(colorDepth)
Exemplo n.º 3
0
    def test_x224_server_recvConnectionRequest_valid(self):
        """
        @summary:  unit test for X224Server.recvConnectionRequest function
        """
        global tls, connect_event
        tls = False
        connect_event = False

        class ServerTLSContext(object):
            def __init__(self, key, cert):
                pass

        x224.ServerTLSContext = ServerTLSContext

        class Transport(object):
            def __init__(self):
                class TLS(object):
                    def startTLS(self, context):
                        global tls
                        tls = True

                self.transport = TLS()

            def send(self, data):
                if not isinstance(data, x224.ServerConnectionConfirm):
                    raise X224Test.X224_FAIL()
                if data.protocolNeg.code.value != x224.NegociationType.TYPE_RDP_NEG_RSP or data.protocolNeg.selectedProtocol.value != x224.Protocols.PROTOCOL_SSL:
                    raise X224Test.X224_FAIL()

        class Presentation(object):
            def connect(self):
                global connect_event
                connect_event = True

        message = x224.ClientConnectionRequestPDU()
        message.protocolNeg.selectedProtocol.value = x224.Protocols.PROTOCOL_SSL | x224.Protocols.PROTOCOL_RDP
        s = type.Stream()
        s.writeType(message)
        s.pos = 0

        layer = x224.Server(Presentation(), "key", "cert")
        layer._transport = Transport()
        layer.connect()
        layer.recvConnectionRequest(s)

        self.assertTrue(tls, "TLS not started")
        self.assertTrue(connect_event, "connect event not forwarded")