support 40bits and 56bits key on client side, bug on update keys
This commit is contained in:
@@ -29,7 +29,7 @@ import unittest
|
||||
import rdpy.core.const
|
||||
import rdpy.core.type
|
||||
|
||||
class ConstCase(unittest.TestCase):
|
||||
class ConstTest(unittest.TestCase):
|
||||
'''
|
||||
represent test case for all classes and function
|
||||
present in rdpy.base.const
|
||||
@@ -28,7 +28,7 @@ sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import unittest
|
||||
import rdpy.core.layer
|
||||
|
||||
class LayerCase(unittest.TestCase):
|
||||
class LayerTest(unittest.TestCase):
|
||||
"""
|
||||
@summary: represent test case for all classes and function
|
||||
present in rdpy.core.layer
|
||||
@@ -46,9 +46,9 @@ class LayerCase(unittest.TestCase):
|
||||
"""
|
||||
class TestConnect(rdpy.core.layer.Layer):
|
||||
def connect(self):
|
||||
raise LayerCase.LayerCaseException()
|
||||
raise LayerTest.LayerCaseException()
|
||||
|
||||
self.assertRaises(LayerCase.LayerCaseException, rdpy.core.layer.Layer(presentation = TestConnect()).connect)
|
||||
self.assertRaises(LayerTest.LayerCaseException, rdpy.core.layer.Layer(presentation = TestConnect()).connect)
|
||||
|
||||
def test_layer_automata_more_than_expected(self):
|
||||
"""
|
||||
@@ -57,11 +57,11 @@ class LayerCase(unittest.TestCase):
|
||||
class TestAutomata(rdpy.core.layer.RawLayer):
|
||||
def expectedCallBack(self, data):
|
||||
if data.dataLen() == 4:
|
||||
raise LayerCase.LayerCaseException()
|
||||
raise LayerTest.LayerCaseException()
|
||||
|
||||
t = TestAutomata()
|
||||
t.expect(4, t.expectedCallBack)
|
||||
self.assertRaises(LayerCase.LayerCaseException, t.dataReceived, "\x00\x00\x00\x00\x00")
|
||||
self.assertRaises(LayerTest.LayerCaseException, t.dataReceived, "\x00\x00\x00\x00\x00")
|
||||
|
||||
def test_layer_automata_less_than_expected(self):
|
||||
"""
|
||||
@@ -70,7 +70,7 @@ class LayerCase(unittest.TestCase):
|
||||
class TestAutomata(rdpy.core.layer.RawLayer):
|
||||
def expectedCallBack(self, data):
|
||||
if data.dataLen() == 4:
|
||||
raise LayerCase.LayerCaseException()
|
||||
raise LayerTest.LayerCaseException()
|
||||
|
||||
t = TestAutomata()
|
||||
t.expect(4, t.expectedCallBack)
|
||||
@@ -29,7 +29,7 @@ import unittest
|
||||
import rdpy.core.type
|
||||
from rdpy.core.error import InvalidSize
|
||||
|
||||
class TypeCase(unittest.TestCase):
|
||||
class TypeTest(unittest.TestCase):
|
||||
"""
|
||||
@summary: represent test case for all classes and function
|
||||
present in rdpy.network.type
|
||||
@@ -30,7 +30,7 @@ import rdpy.protocol.rdp.ber as ber
|
||||
import rdpy.core.type as type
|
||||
import rdpy.core.error as error
|
||||
|
||||
class BERCase(unittest.TestCase):
|
||||
class BERTest(unittest.TestCase):
|
||||
"""
|
||||
@summary: test case for ber layer (RDP)
|
||||
"""
|
||||
|
||||
79
test/test_protocol_rdp_lic.py
Normal file
79
test/test_protocol_rdp_lic.py
Normal file
@@ -0,0 +1,79 @@
|
||||
#
|
||||
# Copyright (c) 2014 Sylvain Peyrefitte
|
||||
#
|
||||
# This file is part of rdpy.
|
||||
#
|
||||
# rdpy is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
"""
|
||||
unit test for rdpy.protocol.rdp.lic automata
|
||||
"""
|
||||
|
||||
import os, sys
|
||||
# Change path so we find rdpy
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
|
||||
import unittest
|
||||
from rdpy.protocol.rdp import lic, sec
|
||||
import rdpy.core.type as type
|
||||
|
||||
class TestLic(unittest.TestCase):
|
||||
"""
|
||||
@summary: Test case for MCS automata
|
||||
"""
|
||||
|
||||
class LIC_PASS(Exception):
|
||||
"""
|
||||
@summary: for OK tests
|
||||
"""
|
||||
pass
|
||||
|
||||
class LIC_FAIL(Exception):
|
||||
"""
|
||||
@summary: for KO tests
|
||||
"""
|
||||
pass
|
||||
|
||||
def test_valid_client_licensing_error_message(self):
|
||||
l = lic.LicenseManager(None)
|
||||
s = type.Stream()
|
||||
s.writeType(lic.createValidClientLicensingErrorMessage())
|
||||
#reinit position
|
||||
s.pos = 0
|
||||
|
||||
self.assertTrue(l.recv(s), "Manager can retrieve valid case")
|
||||
|
||||
def test_new_license(self):
|
||||
class Transport(object):
|
||||
def __init__(self):
|
||||
self._state = False
|
||||
def sendFlagged(self, flag, message):
|
||||
if flag != sec.SecurityFlag.SEC_LICENSE_PKT:
|
||||
return
|
||||
s = type.Stream()
|
||||
s.writeType(message)
|
||||
s.pos = 0
|
||||
s.readType(lic.LicPacket(lic.ClientNewLicenseRequest()))
|
||||
self._state = True
|
||||
|
||||
t = Transport()
|
||||
l = lic.LicenseManager(t)
|
||||
|
||||
s = type.Stream()
|
||||
s.writeType(lic.LicPacket(lic.ServerLicenseRequest()))
|
||||
#reinit position
|
||||
s.pos = 0
|
||||
|
||||
self.assertFalse(l.recv(s) and t._state, "Bad message after license request")
|
||||
36
test/test_protocol_rdp_mcs.py
Normal file
36
test/test_protocol_rdp_mcs.py
Normal file
@@ -0,0 +1,36 @@
|
||||
#
|
||||
# Copyright (c) 2014 Sylvain Peyrefitte
|
||||
#
|
||||
# This file is part of rdpy.
|
||||
#
|
||||
# rdpy is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
"""
|
||||
unit test for rdpy.protocol.rdp.mcs automata
|
||||
"""
|
||||
|
||||
import os, sys
|
||||
# Change path so we find rdpy
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
|
||||
import unittest
|
||||
|
||||
class MCSTest(unittest.TestCase):
|
||||
"""
|
||||
@summary: test case for per layer (RDP)
|
||||
"""
|
||||
|
||||
def test_per_readLength(self):
|
||||
pass
|
||||
@@ -30,7 +30,7 @@ import rdpy.protocol.rdp.per as per
|
||||
import rdpy.core.type as type
|
||||
import rdpy.core.error as error
|
||||
|
||||
class PERCase(unittest.TestCase):
|
||||
class PERTest(unittest.TestCase):
|
||||
"""
|
||||
@summary: test case for per layer (RDP)
|
||||
"""
|
||||
|
||||
48
test/test_protocol_rdp_rc4.py
Normal file
48
test/test_protocol_rdp_rc4.py
Normal file
@@ -0,0 +1,48 @@
|
||||
#
|
||||
# Copyright (c) 2014 Sylvain Peyrefitte
|
||||
#
|
||||
# This file is part of rdpy.
|
||||
#
|
||||
# rdpy is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
"""
|
||||
unit test for rdpy.protocol.rdp.rc4 module
|
||||
"""
|
||||
|
||||
import os, sys
|
||||
# Change path so we find rdpy
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
|
||||
import unittest
|
||||
import rdpy.protocol.rdp.rc4 as rc4
|
||||
|
||||
|
||||
class RC4Test(unittest.TestCase):
|
||||
"""
|
||||
@summary: unit tests for rc4
|
||||
@see: http://fr.wikipedia.org/wiki/RC4
|
||||
"""
|
||||
|
||||
def test_rc4_key_plaintext(self):
|
||||
self.assertEqual("\xBB\xF3\x16\xE8\xD9\x40\xAF\x0A\xD3", rc4.crypt(rc4.RC4Key("Key"), "Plaintext"), "RC4 bad crypt")
|
||||
self.assertEqual("Plaintext", rc4.crypt(rc4.RC4Key("Key"), "\xBB\xF3\x16\xE8\xD9\x40\xAF\x0A\xD3"), "RC4 bad crypt")
|
||||
|
||||
def test_rc4_wiki_pedia(self):
|
||||
self.assertEqual("\x10\x21\xBF\x04\x20", rc4.crypt(rc4.RC4Key("Wiki"), "pedia"), "RC4 bad crypt")
|
||||
self.assertEqual("pedia", rc4.crypt(rc4.RC4Key("Wiki"), "\x10\x21\xBF\x04\x20"), "RC4 bad crypt")
|
||||
|
||||
def test_rc4_secret_attack_at_down(self):
|
||||
self.assertEqual("\x45\xA0\x1F\x64\x5F\xC3\x5B\x38\x35\x52\x54\x4B\x9B\xF5", rc4.crypt(rc4.RC4Key("Secret"), "Attack at dawn"), "RC4 bad crypt")
|
||||
self.assertEqual("Attack at dawn", rc4.crypt(rc4.RC4Key("Secret"), "\x45\xA0\x1F\x64\x5F\xC3\x5B\x38\x35\x52\x54\x4B\x9B\xF5"), "RC4 bad crypt")
|
||||
@@ -30,7 +30,7 @@ import rdpy.protocol.rdp.tpkt as tpkt
|
||||
import rdpy.core.type as type
|
||||
import rdpy.core.error as error
|
||||
|
||||
class TPKTCase(unittest.TestCase):
|
||||
class TPKTTest(unittest.TestCase):
|
||||
"""
|
||||
@summary: test case for tpkt layer (RDP)
|
||||
"""
|
||||
@@ -47,10 +47,10 @@ class TPKTCase(unittest.TestCase):
|
||||
"""
|
||||
class Presentation(object):
|
||||
def connect(self):
|
||||
raise TPKTCase.TPKT_PASS()
|
||||
raise TPKTTest.TPKT_PASS()
|
||||
|
||||
layer = tpkt.TPKT(Presentation(), None)
|
||||
self.assertRaises(TPKTCase.TPKT_PASS, layer.connect)
|
||||
layer = tpkt.TPKT(Presentation())
|
||||
self.assertRaises(TPKTTest.TPKT_PASS, layer.connect)
|
||||
|
||||
def test_tpkt_layer_recv(self):
|
||||
"""
|
||||
@@ -61,16 +61,16 @@ class TPKTCase(unittest.TestCase):
|
||||
pass
|
||||
def recv(self, data):
|
||||
data.readType(type.String("test_tpkt_layer_recv", constant = True))
|
||||
raise TPKTCase.TPKT_PASS()
|
||||
raise TPKTTest.TPKT_PASS()
|
||||
|
||||
message = type.String("test_tpkt_layer_recv")
|
||||
|
||||
s = type.Stream()
|
||||
s.writeType((type.UInt8(tpkt.Action.FASTPATH_ACTION_X224), type.UInt8(), type.UInt16Be(type.sizeof(message) + 4), message))
|
||||
|
||||
layer = tpkt.TPKT(Presentation(), None)
|
||||
layer = tpkt.TPKT(Presentation())
|
||||
layer.connect()
|
||||
self.assertRaises(TPKTCase.TPKT_PASS, layer.dataReceived, s.getvalue())
|
||||
self.assertRaises(TPKTTest.TPKT_PASS, layer.dataReceived, s.getvalue())
|
||||
|
||||
def test_tpkt_layer_recv_fastpath(self):
|
||||
"""
|
||||
@@ -79,18 +79,19 @@ class TPKTCase(unittest.TestCase):
|
||||
class FastPathLayer(tpkt.IFastPathListener):
|
||||
def setFastPathSender(self, fastPathSender):
|
||||
pass
|
||||
def recvFastPath(self, fastPathS):
|
||||
def recvFastPath(self, secFlag, fastPathS):
|
||||
fastPathS.readType(type.String("test_tpkt_layer_recv_fastpath", constant = True))
|
||||
raise TPKTCase.TPKT_PASS()
|
||||
raise TPKTTest.TPKT_PASS()
|
||||
|
||||
message = type.String("test_tpkt_layer_recv_fastpath")
|
||||
|
||||
s = type.Stream()
|
||||
s.writeType((type.UInt8(tpkt.Action.FASTPATH_ACTION_FASTPATH), type.UInt8(type.sizeof(message) + 2), message))
|
||||
|
||||
layer = tpkt.TPKT(None, FastPathLayer())
|
||||
layer = tpkt.TPKT(None)
|
||||
layer.initFastPath(FastPathLayer())
|
||||
layer.connect()
|
||||
self.assertRaises(TPKTCase.TPKT_PASS, layer.dataReceived, s.getvalue())
|
||||
self.assertRaises(TPKTTest.TPKT_PASS, layer.dataReceived, s.getvalue())
|
||||
|
||||
def test_tpkt_layer_recv_fastpath_ext_length(self):
|
||||
"""
|
||||
@@ -99,15 +100,16 @@ class TPKTCase(unittest.TestCase):
|
||||
class FastPathLayer(tpkt.IFastPathListener):
|
||||
def setFastPathSender(self, fastPathSender):
|
||||
pass
|
||||
def recvFastPath(self, fastPathS):
|
||||
def recvFastPath(self, secflag, fastPathS):
|
||||
fastPathS.readType(type.String("test_tpkt_layer_recv_fastpath_ext_length", constant = True))
|
||||
raise TPKTCase.TPKT_PASS()
|
||||
raise TPKTTest.TPKT_PASS()
|
||||
|
||||
message = type.String("test_tpkt_layer_recv_fastpath_ext_length")
|
||||
|
||||
s = type.Stream()
|
||||
s.writeType((type.UInt8(tpkt.Action.FASTPATH_ACTION_FASTPATH), type.UInt16Be((type.sizeof(message) + 3) | 0x8000), message))
|
||||
|
||||
layer = tpkt.TPKT(None, FastPathLayer())
|
||||
layer = tpkt.TPKT(None)
|
||||
layer.initFastPath(FastPathLayer())
|
||||
layer.connect()
|
||||
self.assertRaises(TPKTCase.TPKT_PASS, layer.dataReceived, s.getvalue())
|
||||
self.assertRaises(TPKTTest.TPKT_PASS, layer.dataReceived, s.getvalue())
|
||||
|
||||
@@ -30,7 +30,7 @@ import rdpy.protocol.rdp.x224 as x224
|
||||
import rdpy.core.type as type
|
||||
import rdpy.core.error as error
|
||||
|
||||
class X224Case(unittest.TestCase):
|
||||
class X224Test(unittest.TestCase):
|
||||
"""
|
||||
@summary: test case for x224 layer (RDP)
|
||||
"""
|
||||
@@ -54,7 +54,7 @@ class X224Case(unittest.TestCase):
|
||||
class Presentation(object):
|
||||
def recv(self, data):
|
||||
data.readType(type.String('test_x224_layer_recvData', constant = True))
|
||||
raise X224Case.X224_PASS()
|
||||
raise X224Test.X224_PASS()
|
||||
|
||||
layer = x224.X224Layer(Presentation())
|
||||
s = type.Stream()
|
||||
@@ -62,7 +62,7 @@ class X224Case(unittest.TestCase):
|
||||
#reinit position
|
||||
s.pos = 0
|
||||
|
||||
self.assertRaises(X224Case.X224_PASS, layer.recvData, s)
|
||||
self.assertRaises(X224Test.X224_PASS, layer.recvData, s)
|
||||
|
||||
def test_x224_layer_send(self):
|
||||
"""
|
||||
@@ -75,12 +75,12 @@ class X224Case(unittest.TestCase):
|
||||
s.pos = 0
|
||||
s.readType(x224.X224DataHeader())
|
||||
s.readType(type.String('test_x224_layer_send', constant = True))
|
||||
raise X224Case.X224_PASS()
|
||||
raise X224Test.X224_PASS()
|
||||
|
||||
layer = x224.X224Layer(None)
|
||||
layer._transport = Transport()
|
||||
|
||||
self.assertRaises(X224Case.X224_PASS, layer.send, type.String('test_x224_layer_send'))
|
||||
self.assertRaises(X224Test.X224_PASS, layer.send, type.String('test_x224_layer_send'))
|
||||
|
||||
def test_x224_client_connect(self):
|
||||
"""
|
||||
@@ -95,22 +95,22 @@ class X224Case(unittest.TestCase):
|
||||
s.readType(t)
|
||||
|
||||
if t.protocolNeg.code != x224.NegociationType.TYPE_RDP_NEG_REQ:
|
||||
raise X224Case.X224_FAIL()
|
||||
raise X224Test.X224_FAIL()
|
||||
|
||||
def nextAutomata(data):
|
||||
raise X224Case.X224_PASS()
|
||||
raise X224Test.X224_PASS()
|
||||
|
||||
layer = x224.Client(None)
|
||||
layer._transport = Transport()
|
||||
layer.recvConnectionConfirm = nextAutomata
|
||||
layer.connect()
|
||||
|
||||
self.assertRaises(X224Case.X224_PASS, layer.recv, type.String('\x01\x02'))
|
||||
self.assertRaises(X224Test.X224_PASS, layer.recv, type.String('\x01\x02'))
|
||||
|
||||
def test_x224_client_recvConnectionConfirm_negotiation_bad_protocol(self):
|
||||
"""
|
||||
@summary: unit test for X224Client.recvConnectionConfirm and sendConnectionRequest function
|
||||
Server ask another protocol than SSL
|
||||
Server ask another protocol than SSL or RDP
|
||||
"""
|
||||
message = x224.ServerConnectionConfirm()
|
||||
message.protocolNeg.selectedProtocol.value = x224.Protocols.PROTOCOL_HYBRID
|
||||
@@ -119,6 +119,19 @@ class X224Case(unittest.TestCase):
|
||||
s.pos = 0
|
||||
layer = x224.Client(None)
|
||||
self.assertRaises(error.InvalidExpectedDataException, layer.recvConnectionConfirm, s)
|
||||
|
||||
def test_x224_client_recvConnectionConfirm_negotiation_failure(self):
|
||||
"""
|
||||
@summary: unit test for X224Client.recvConnectionConfirm and sendConnectionRequest function
|
||||
check negotiation failure
|
||||
"""
|
||||
message = x224.ServerConnectionConfirm()
|
||||
message.protocolNeg.code.value = x224.NegociationType.TYPE_RDP_NEG_FAILURE
|
||||
s = type.Stream()
|
||||
s.writeType(message)
|
||||
s.pos = 0
|
||||
layer = x224.Client(None)
|
||||
self.assertRaises(error.RDPSecurityNegoFail, layer.recvConnectionConfirm, s)
|
||||
|
||||
def test_x224_client_recvConnectionConfirm_ok(self):
|
||||
"""
|
||||
@@ -141,7 +154,7 @@ class X224Case(unittest.TestCase):
|
||||
presentation_connect = True
|
||||
|
||||
def recvData(data):
|
||||
raise X224Case.X224_PASS()
|
||||
raise X224Test.X224_PASS()
|
||||
|
||||
message = x224.ServerConnectionConfirm()
|
||||
message.protocolNeg.selectedProtocol.value = x224.Protocols.PROTOCOL_SSL
|
||||
@@ -157,7 +170,7 @@ class X224Case(unittest.TestCase):
|
||||
|
||||
self.assertTrue(tls_begin, "TLS is not started")
|
||||
self.assertTrue(presentation_connect, "connect event is not forwarded")
|
||||
self.assertRaises(X224Case.X224_PASS, layer.recv, type.String('\x01\x02'))
|
||||
self.assertRaises(X224Test.X224_PASS, layer.recv, type.String('\x01\x02'))
|
||||
|
||||
def test_x224_server_recvConnectionRequest_invalid_old_client(self):
|
||||
"""
|
||||
@@ -199,9 +212,9 @@ class X224Case(unittest.TestCase):
|
||||
class Transport(object):
|
||||
def send(self, data):
|
||||
if not isinstance(data, x224.ServerConnectionConfirm):
|
||||
raise X224Case.X224_FAIL()
|
||||
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 X224Case.X224_FAIL()
|
||||
raise X224Test.X224_FAIL()
|
||||
|
||||
message = x224.ClientConnectionRequestPDU()
|
||||
message.protocolNeg.selectedProtocol.value = x224.Protocols.PROTOCOL_HYBRID
|
||||
@@ -239,9 +252,9 @@ class X224Case(unittest.TestCase):
|
||||
|
||||
def send(self, data):
|
||||
if not isinstance(data, x224.ServerConnectionConfirm):
|
||||
raise X224Case.X224_FAIL()
|
||||
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 X224Case.X224_FAIL()
|
||||
raise X224Test.X224_FAIL()
|
||||
|
||||
class Presentation(object):
|
||||
def connect(self):
|
||||
|
||||
Reference in New Issue
Block a user