first packet in RDP basic security layer
This commit is contained in:
@@ -26,9 +26,9 @@ import sys, os, getopt, socket
|
||||
from PyQt4 import QtGui, QtCore
|
||||
from rdpy.ui.qt4 import RDPClientQt
|
||||
from rdpy.protocol.rdp import rdp
|
||||
from rdpy.base.error import RDPSecurityNegoFail
|
||||
from rdpy.core.error import RDPSecurityNegoFail
|
||||
|
||||
import rdpy.base.log as log
|
||||
import rdpy.core.log as log
|
||||
log._LOG_LEVEL = log.Level.INFO
|
||||
|
||||
class RDPClientQtFactory(rdp.ClientFactory):
|
||||
|
||||
@@ -31,7 +31,7 @@ Admin ----------------------|
|
||||
|
||||
import sys, os, getopt, json
|
||||
|
||||
from rdpy.base import log, error
|
||||
from rdpy.core import log, error
|
||||
from rdpy.protocol.rdp import rdp
|
||||
from rdpy.ui import view
|
||||
from twisted.internet import reactor
|
||||
|
||||
@@ -28,7 +28,7 @@ import sys, os, getopt
|
||||
from PyQt4 import QtCore, QtGui
|
||||
from rdpy.protocol.rdp import rdp
|
||||
from rdpy.ui.qt4 import RDPBitmapToQtImage
|
||||
import rdpy.base.log as log
|
||||
import rdpy.core.log as log
|
||||
from twisted.internet import task
|
||||
|
||||
#set log level
|
||||
|
||||
@@ -27,7 +27,7 @@ from PyQt4 import QtGui
|
||||
from rdpy.ui.qt4 import RFBClientQt
|
||||
from rdpy.protocol.rfb import rfb
|
||||
|
||||
import rdpy.base.log as log
|
||||
import rdpy.core.log as log
|
||||
log._LOG_LEVEL = log.Level.INFO
|
||||
|
||||
class RFBClientQtFactory(rfb.ClientFactory):
|
||||
|
||||
@@ -26,7 +26,7 @@ take screenshot of login page
|
||||
import sys, os, getopt
|
||||
from PyQt4 import QtCore, QtGui
|
||||
from rdpy.protocol.rfb import rfb
|
||||
import rdpy.base.log as log
|
||||
import rdpy.core.log as log
|
||||
from rdpy.ui.qt4 import qtImageFormatFromRFBPixelFormat
|
||||
from twisted.internet import task
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ Join RDPY design with twisted design
|
||||
RDPY use Layer Protocol design (like twisted)
|
||||
"""
|
||||
|
||||
from rdpy.base.error import CallPureVirtualFuntion
|
||||
from rdpy.core.error import CallPureVirtualFuntion
|
||||
|
||||
class IStreamListener(object):
|
||||
"""
|
||||
@@ -99,7 +99,7 @@ class LayerAutomata(Layer, IStreamListener):
|
||||
@param callback: a callable object
|
||||
"""
|
||||
if callback is None:
|
||||
callback = self.__class__.recv
|
||||
callback = lambda x:self.__class__.recv(self, x)
|
||||
|
||||
self.recv = callback
|
||||
|
||||
@@ -27,8 +27,8 @@ We are in python!
|
||||
import struct
|
||||
from copy import deepcopy
|
||||
from StringIO import StringIO
|
||||
from rdpy.base.error import InvalidExpectedDataException, InvalidSize, CallPureVirtualFuntion, InvalidValue
|
||||
import rdpy.base.log as log
|
||||
from rdpy.core.error import InvalidExpectedDataException, InvalidSize, CallPureVirtualFuntion, InvalidValue
|
||||
import rdpy.core.log as log
|
||||
|
||||
def sizeof(element):
|
||||
"""
|
||||
@@ -22,8 +22,8 @@ Basic Encoding Rules use in RDP.
|
||||
ASN.1 standard
|
||||
"""
|
||||
|
||||
from rdpy.network.type import UInt8, UInt16Be, UInt32Be, String
|
||||
from rdpy.base.error import InvalidExpectedDataException, InvalidSize
|
||||
from rdpy.core.type import UInt8, UInt16Be, UInt32Be, String
|
||||
from rdpy.core.error import InvalidExpectedDataException, InvalidSize
|
||||
|
||||
class BerPc(object):
|
||||
BER_PC_MASK = 0x20
|
||||
|
||||
@@ -22,10 +22,10 @@ Implement GCC structure use in RDP protocol
|
||||
http://msdn.microsoft.com/en-us/library/cc240508.aspx
|
||||
"""
|
||||
|
||||
from rdpy.network.type import UInt8, UInt16Le, UInt32Le, CompositeType, String, Stream, sizeof, FactoryType, ArrayType
|
||||
from rdpy.core.type import UInt8, UInt16Le, UInt32Le, CompositeType, String, Stream, sizeof, FactoryType, ArrayType
|
||||
import per, mcs
|
||||
from rdpy.base.error import InvalidExpectedDataException
|
||||
import rdpy.base.log as log
|
||||
from rdpy.core.error import InvalidExpectedDataException
|
||||
import rdpy.core.log as log
|
||||
|
||||
t124_02_98_oid = ( 0, 0, 20, 124, 0, 1 )
|
||||
|
||||
@@ -343,8 +343,8 @@ class RSAPublicKey(CompositeType):
|
||||
self.bitlen = UInt32Le()
|
||||
self.datalen = UInt32Le()
|
||||
self.pubExp = UInt32Le()
|
||||
self.modulus = String(readLen = lambda:(self.keylen - 8))
|
||||
self.padding = String("\x00" * 8, constant = True)
|
||||
self.modulus = String(readLen = UInt16Le(lambda:(self.keylen.value - 8)))
|
||||
self.padding = String(readLen = UInt8(8))
|
||||
|
||||
class ChannelDef(CompositeType):
|
||||
"""
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc241880.aspx
|
||||
"""
|
||||
|
||||
from rdpy.network.type import CompositeType, UInt8, UInt16Le, UInt32Le, String, sizeof, FactoryType, ArrayType, Stream
|
||||
from rdpy.base.error import InvalidExpectedDataException
|
||||
import rdpy.base.log as log
|
||||
from rdpy.core.type import CompositeType, UInt8, UInt16Le, UInt32Le, String, sizeof, FactoryType, ArrayType, Stream
|
||||
from rdpy.core.error import InvalidExpectedDataException
|
||||
import rdpy.core.log as log
|
||||
import rc4, sec
|
||||
|
||||
class MessageType(object):
|
||||
@@ -316,7 +316,7 @@ class LicenseManager(object):
|
||||
message.encryptedPreMasterSecret.blobData = String(self._preMasterSecret + "\x00" * 8)
|
||||
message.ClientMachineName.blobData = String(self._hostname + "\x00")
|
||||
message.ClientUserName.blobData = String(self._username + "\x00")
|
||||
self._transport.sendLicensePacket(LicPacket(message))
|
||||
self._transport.sendFlagged(sec.SecurityFlag.SEC_LICENSE_PKT, LicPacket(message))
|
||||
|
||||
def sendClientChallengeResponse(self):
|
||||
"""
|
||||
@@ -336,4 +336,4 @@ class LicenseManager(object):
|
||||
message.encryptedHWID.blobData.value = rc4.crypt(self._licenseKey, hwid)
|
||||
message.MACData.value = sec.macData(self._macSalt, serverChallenge + hwid)
|
||||
|
||||
self._transport.sendLicensePacket(LicPacket(message))
|
||||
self._transport.sendFlagged(sec.SecurityFlag.SEC_LICENSE_PKT, LicPacket(message))
|
||||
@@ -24,13 +24,13 @@ Each channel have a particular role.
|
||||
The main channel is the graphical channel.
|
||||
It exist channel for file system order, audio channel, clipboard etc...
|
||||
"""
|
||||
from rdpy.network.layer import LayerAutomata, IStreamSender, Layer
|
||||
from rdpy.network.type import sizeof, Stream, UInt8, UInt16Le, String
|
||||
from rdpy.base.error import InvalidExpectedDataException, InvalidValue, InvalidSize
|
||||
from rdpy.core.layer import LayerAutomata, IStreamSender, Layer
|
||||
from rdpy.core.type import sizeof, Stream, UInt8, UInt16Le, String
|
||||
from rdpy.core.error import InvalidExpectedDataException, InvalidValue, InvalidSize
|
||||
from rdpy.protocol.rdp.ber import writeLength
|
||||
import rdpy.base.log as log
|
||||
import rdpy.core.log as log
|
||||
|
||||
import ber, gcc, per, sec
|
||||
import ber, gcc, per
|
||||
|
||||
class Message(object):
|
||||
"""
|
||||
|
||||
@@ -16,19 +16,19 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from rdpy.base.error import InvalidExpectedDataException
|
||||
import rdpy.base.log as log
|
||||
from rdpy.core.error import InvalidExpectedDataException
|
||||
import rdpy.core.log as log
|
||||
|
||||
"""
|
||||
Definition of structure use for capabilities nego
|
||||
Use in PDU layer
|
||||
"""
|
||||
|
||||
from rdpy.network.type import CompositeType, String, UInt8, UInt16Le, UInt32Le, sizeof, ArrayType, FactoryType
|
||||
from rdpy.core.type import CompositeType, String, UInt8, UInt16Le, UInt32Le, sizeof, ArrayType, FactoryType
|
||||
|
||||
class CapsType(object):
|
||||
"""
|
||||
Different type of capabilities
|
||||
@summary: Different type of capabilities
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240486.aspx
|
||||
"""
|
||||
CAPSTYPE_GENERAL = 0x0001
|
||||
@@ -62,7 +62,7 @@ class CapsType(object):
|
||||
|
||||
class MajorType(object):
|
||||
"""
|
||||
Use in general capability
|
||||
@summary: Use in general capability
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240549.aspx
|
||||
"""
|
||||
OSMAJORTYPE_UNSPECIFIED = 0x0000
|
||||
@@ -76,7 +76,7 @@ class MajorType(object):
|
||||
|
||||
class MinorType(object):
|
||||
"""
|
||||
Use in general capability
|
||||
@summary: Use in general capability
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240549.aspx
|
||||
"""
|
||||
OSMINORTYPE_UNSPECIFIED = 0x0000
|
||||
@@ -92,7 +92,7 @@ class MinorType(object):
|
||||
|
||||
class GeneralExtraFlag(object):
|
||||
"""
|
||||
Use in general capability
|
||||
@summary: Use in general capability
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240549.aspx
|
||||
"""
|
||||
FASTPATH_OUTPUT_SUPPORTED = 0x0001
|
||||
@@ -107,7 +107,7 @@ class Boolean(object):
|
||||
|
||||
class OrderFlag(object):
|
||||
"""
|
||||
Use in order capability
|
||||
@summary: Use in order capability
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240556.aspx
|
||||
"""
|
||||
NEGOTIATEORDERSUPPORT = 0x0002
|
||||
@@ -118,7 +118,7 @@ class OrderFlag(object):
|
||||
|
||||
class Order(object):
|
||||
"""
|
||||
Drawing orders supported
|
||||
@summary: Drawing orders supported
|
||||
Use in order capability
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240556.aspx
|
||||
"""
|
||||
@@ -146,7 +146,7 @@ class Order(object):
|
||||
|
||||
class OrderEx(object):
|
||||
"""
|
||||
Extension orders
|
||||
@summary: Extension orders
|
||||
Use in order capability
|
||||
"""
|
||||
ORDERFLAGS_EX_CACHE_BITMAP_REV3_SUPPORT = 0x0002
|
||||
@@ -154,7 +154,7 @@ class OrderEx(object):
|
||||
|
||||
class InputFlags(object):
|
||||
"""
|
||||
Input flag use in input capability
|
||||
@summary: Input flag use in input capability
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240563.aspx
|
||||
"""
|
||||
INPUT_FLAG_SCANCODES = 0x0001
|
||||
@@ -168,7 +168,7 @@ class InputFlags(object):
|
||||
|
||||
class BrushSupport(object):
|
||||
"""
|
||||
Brush support of client
|
||||
@summary: Brush support of client
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240564.aspx
|
||||
"""
|
||||
BRUSH_DEFAULT = 0x00000000
|
||||
@@ -177,7 +177,7 @@ class BrushSupport(object):
|
||||
|
||||
class GlyphSupport(object):
|
||||
"""
|
||||
Use by glyph order
|
||||
@summary: Use by glyph order
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240565.aspx
|
||||
"""
|
||||
GLYPH_SUPPORT_NONE = 0x0000
|
||||
@@ -187,7 +187,7 @@ class GlyphSupport(object):
|
||||
|
||||
class OffscreenSupportLevel(object):
|
||||
"""
|
||||
Use to determine offscreen cache level supported
|
||||
@summary: Use to determine offscreen cache level supported
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240550.aspx
|
||||
"""
|
||||
FALSE = 0x00000000
|
||||
@@ -195,7 +195,7 @@ class OffscreenSupportLevel(object):
|
||||
|
||||
class VirtualChannelCompressionFlag(object):
|
||||
"""
|
||||
Use to determine virtual channel compression
|
||||
@summary: Use to determine virtual channel compression
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240551.aspx
|
||||
"""
|
||||
VCCAPS_NO_COMPR = 0x00000000
|
||||
@@ -204,7 +204,7 @@ class VirtualChannelCompressionFlag(object):
|
||||
|
||||
class SoundFlag(object):
|
||||
"""
|
||||
Use in sound capability to inform it
|
||||
@summary: Use in sound capability to inform it
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240552.aspx
|
||||
"""
|
||||
NONE = 0x0000
|
||||
@@ -212,7 +212,7 @@ class SoundFlag(object):
|
||||
|
||||
class CacheEntry(CompositeType):
|
||||
"""
|
||||
Use in capability cache exchange
|
||||
@summary: Use in capability cache exchange
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240566.aspx
|
||||
"""
|
||||
def __init__(self):
|
||||
@@ -223,7 +223,7 @@ class CacheEntry(CompositeType):
|
||||
|
||||
class Capability(CompositeType):
|
||||
"""
|
||||
A capability
|
||||
@summary: A capability
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240486.aspx
|
||||
"""
|
||||
def __init__(self, capability = None):
|
||||
@@ -236,7 +236,7 @@ class Capability(CompositeType):
|
||||
Closure for capability factory
|
||||
"""
|
||||
for c in [GeneralCapability, BitmapCapability, OrderCapability, BitmapCacheCapability, PointerCapability, InputCapability, BrushCapability, GlyphCapability, OffscreenBitmapCacheCapability, VirtualChannelCapability, SoundCapability, ControlCapability, WindowActivationCapability, FontCapability, ColorCacheCapability, ShareCapability]:
|
||||
if self.capabilitySetType.value == c._TYPE_:
|
||||
if self.capabilitySetType.value == c._TYPE_ and (self.lengthCapability.value - 4) > 0:
|
||||
return c(readLen = self.lengthCapability - 4)
|
||||
log.debug("unknown Capability type : %s"%hex(self.capabilitySetType.value))
|
||||
#read entire packet
|
||||
@@ -251,7 +251,7 @@ class Capability(CompositeType):
|
||||
|
||||
class GeneralCapability(CompositeType):
|
||||
"""
|
||||
General capability (protocol version and compression mode)
|
||||
@summary: General capability (protocol version and compression mode)
|
||||
client -> server
|
||||
server -> client
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240549.aspx
|
||||
@@ -274,7 +274,7 @@ class GeneralCapability(CompositeType):
|
||||
|
||||
class BitmapCapability(CompositeType):
|
||||
"""
|
||||
Bitmap format Capability
|
||||
@summary: Bitmap format Capability
|
||||
client -> server
|
||||
server -> client
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240554.aspx
|
||||
@@ -299,7 +299,7 @@ class BitmapCapability(CompositeType):
|
||||
|
||||
class OrderCapability(CompositeType):
|
||||
"""
|
||||
Order capability list all drawing order supported
|
||||
@summary: Order capability list all drawing order supported
|
||||
client -> server
|
||||
server -> client
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240556.aspx
|
||||
@@ -328,7 +328,7 @@ class OrderCapability(CompositeType):
|
||||
|
||||
class BitmapCacheCapability(CompositeType):
|
||||
"""
|
||||
Order use to cache bitmap very useful
|
||||
@summary: Order use to cache bitmap very useful
|
||||
client -> server
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240559.aspx
|
||||
"""
|
||||
@@ -351,7 +351,7 @@ class BitmapCacheCapability(CompositeType):
|
||||
|
||||
class PointerCapability(CompositeType):
|
||||
"""
|
||||
Use to indicate pointer handle of client
|
||||
@summary: Use to indicate pointer handle of client
|
||||
Paint by server or per client
|
||||
client -> server
|
||||
server -> client
|
||||
@@ -367,7 +367,7 @@ class PointerCapability(CompositeType):
|
||||
|
||||
class InputCapability(CompositeType):
|
||||
"""
|
||||
Use to indicate input capabilities
|
||||
@summary: Use to indicate input capabilities
|
||||
client -> server
|
||||
server -> client
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240563.aspx
|
||||
@@ -391,7 +391,7 @@ class InputCapability(CompositeType):
|
||||
|
||||
class BrushCapability(CompositeType):
|
||||
"""
|
||||
Use to indicate brush capability
|
||||
@summary: Use to indicate brush capability
|
||||
client -> server
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240564.aspx
|
||||
"""
|
||||
@@ -403,7 +403,7 @@ class BrushCapability(CompositeType):
|
||||
|
||||
class GlyphCapability(CompositeType):
|
||||
"""
|
||||
Use in font order
|
||||
@summary: Use in font order
|
||||
client -> server
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240565.aspx
|
||||
"""
|
||||
@@ -419,7 +419,7 @@ class GlyphCapability(CompositeType):
|
||||
|
||||
class OffscreenBitmapCacheCapability(CompositeType):
|
||||
"""
|
||||
use to cached bitmap in offscreen area
|
||||
@summary: use to cached bitmap in offscreen area
|
||||
client -> server
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240550.aspx
|
||||
"""
|
||||
@@ -433,7 +433,7 @@ class OffscreenBitmapCacheCapability(CompositeType):
|
||||
|
||||
class VirtualChannelCapability(CompositeType):
|
||||
"""
|
||||
use to determine virtual channel compression
|
||||
@summary: use to determine virtual channel compression
|
||||
client -> server
|
||||
server -> client
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240551.aspx
|
||||
@@ -447,7 +447,7 @@ class VirtualChannelCapability(CompositeType):
|
||||
|
||||
class SoundCapability(CompositeType):
|
||||
"""
|
||||
Use to exchange sound capability
|
||||
@summary: Use to exchange sound capability
|
||||
client -> server
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240552.aspx
|
||||
"""
|
||||
@@ -460,7 +460,7 @@ class SoundCapability(CompositeType):
|
||||
|
||||
class ControlCapability(CompositeType):
|
||||
"""
|
||||
client -> server but server ignore contents! Thanks krosoft for brandwidth
|
||||
@summary: client -> server but server ignore contents! Thanks krosoft for brandwidth
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240568.aspx
|
||||
"""
|
||||
_TYPE_ = CapsType.CAPSTYPE_CONTROL
|
||||
@@ -474,7 +474,7 @@ class ControlCapability(CompositeType):
|
||||
|
||||
class WindowActivationCapability(CompositeType):
|
||||
"""
|
||||
client -> server but server ignore contents! Thanks krosoft for brandwidth
|
||||
@summary: client -> server but server ignore contents! Thanks krosoft for brandwidth
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240569.aspx
|
||||
"""
|
||||
_TYPE_ = CapsType.CAPSTYPE_ACTIVATION
|
||||
@@ -488,7 +488,7 @@ class WindowActivationCapability(CompositeType):
|
||||
|
||||
class FontCapability(CompositeType):
|
||||
"""
|
||||
Use to indicate font support
|
||||
@summary: Use to indicate font support
|
||||
client -> server
|
||||
server -> client
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240571.aspx
|
||||
@@ -515,7 +515,7 @@ class ColorCacheCapability(CompositeType):
|
||||
|
||||
class ShareCapability(CompositeType):
|
||||
"""
|
||||
Use to advertise channel id of server
|
||||
@summary: Use to advertise channel id of server
|
||||
client -> server
|
||||
server -> client
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240570.aspx
|
||||
|
||||
@@ -22,9 +22,9 @@ Implement the main graphic layer
|
||||
|
||||
In this layer are managed all mains bitmap update orders end user inputs
|
||||
"""
|
||||
from rdpy.network.type import CompositeType, String, UInt8, UInt16Le, UInt32Le, sizeof, ArrayType, FactoryType
|
||||
from rdpy.base.error import InvalidExpectedDataException
|
||||
import rdpy.base.log as log
|
||||
from rdpy.core.type import CompositeType, String, UInt8, UInt16Le, UInt32Le, sizeof, ArrayType, FactoryType
|
||||
from rdpy.core.error import InvalidExpectedDataException
|
||||
import rdpy.core.log as log
|
||||
import caps, order
|
||||
|
||||
class PDUType(object):
|
||||
|
||||
@@ -23,13 +23,13 @@ Implement the main graphic layer
|
||||
In this layer are managed all mains bitmap update orders end user inputs
|
||||
"""
|
||||
|
||||
from rdpy.network.layer import LayerAutomata
|
||||
from rdpy.base.error import InvalidExpectedDataException, CallPureVirtualFuntion
|
||||
from rdpy.network.type import UInt16Le
|
||||
import rdpy.base.log as log
|
||||
from rdpy.core.layer import LayerAutomata
|
||||
from rdpy.core.error import InvalidExpectedDataException, CallPureVirtualFuntion
|
||||
from rdpy.core.type import UInt16Le
|
||||
import rdpy.core.log as log
|
||||
import rdpy.protocol.rdp.gcc as gcc
|
||||
import rdpy.protocol.rdp.tpkt as tpkt
|
||||
import lic, data, caps
|
||||
import data, caps
|
||||
|
||||
class PDUClientListener(object):
|
||||
"""
|
||||
@@ -112,7 +112,7 @@ class PDULayer(LayerAutomata):
|
||||
@summary: Send a PDU data to transport layer
|
||||
@param pduMessage: PDU message
|
||||
"""
|
||||
self._transport.send(data.PDU(self._transport.getUserId(), pduMessage))
|
||||
self._transport.send(data.PDU(self._transport._transport.getUserId(), pduMessage))
|
||||
|
||||
def sendDataPDU(self, pduData):
|
||||
"""
|
||||
@@ -133,17 +133,13 @@ class Client(PDULayer, tpkt.IFastPathListener):
|
||||
self._listener = listener
|
||||
#enable or not fast path
|
||||
self._fastPathSender = None
|
||||
self._licenceManager = lic.LicenseManager(self)
|
||||
|
||||
def connect(self):
|
||||
"""
|
||||
@summary: Connect message in client automata
|
||||
Send INfo packet (credentials)
|
||||
Wait License info
|
||||
"""
|
||||
self.sendInfoPkt()
|
||||
#next state is license info PDU
|
||||
self.setNextState(self.recvLicenceInfo)
|
||||
self._gccCore = self._transport._transport.getGCCClientSettings().getBlock(gcc.MessageType.CS_CORE)
|
||||
self.setNextState(self.recvDemandActivePDU)
|
||||
#check if client support fast path message
|
||||
self._clientFastPathSupported = False
|
||||
|
||||
@@ -160,23 +156,6 @@ class Client(PDULayer, tpkt.IFastPathListener):
|
||||
@note: implement tpkt.IFastPathListener
|
||||
"""
|
||||
self._fastPathSender = fastPathSender
|
||||
|
||||
def recvLicenceInfo(self, s):
|
||||
"""
|
||||
@summary: Read license info packet and check if is a valid client info
|
||||
Wait Demand Active PDU
|
||||
@param s: Stream
|
||||
"""
|
||||
#packet preambule
|
||||
securityFlag = UInt16Le()
|
||||
securityFlagHi = UInt16Le()
|
||||
s.readType((securityFlag, securityFlagHi))
|
||||
|
||||
if not (securityFlag.value & data.SecurityFlag.SEC_LICENSE_PKT):
|
||||
raise InvalidExpectedDataException("Waiting license packet")
|
||||
|
||||
if self._licenceManager.recv(s):
|
||||
self.setNextState(self.recvDemandActivePDU)
|
||||
|
||||
def recvDemandActivePDU(self, s):
|
||||
"""
|
||||
@@ -325,16 +304,9 @@ class Client(PDULayer, tpkt.IFastPathListener):
|
||||
if updateDataPDU.updateType.value == data.UpdateType.UPDATETYPE_BITMAP:
|
||||
self._listener.onUpdate(updateDataPDU.updateData.rectangles._array)
|
||||
|
||||
def sendLicensePacket(self, licPkt):
|
||||
"""
|
||||
@summary: send license packet
|
||||
@param licPktr: license packet
|
||||
"""
|
||||
self._transport.send((UInt16Le(data.SecurityFlag.SEC_LICENSE_PKT), UInt16Le(), licPkt))
|
||||
|
||||
def sendConfirmActivePDU(self):
|
||||
"""
|
||||
Send all client capabilities
|
||||
@summary: Send all client capabilities
|
||||
"""
|
||||
#init general capability
|
||||
generalCapability = self._clientCapabilities[caps.CapsType.CAPSTYPE_GENERAL].capability
|
||||
@@ -346,9 +318,9 @@ class Client(PDULayer, tpkt.IFastPathListener):
|
||||
|
||||
#init bitmap capability
|
||||
bitmapCapability = self._clientCapabilities[caps.CapsType.CAPSTYPE_BITMAP].capability
|
||||
bitmapCapability.preferredBitsPerPixel = self._transport.getGCCClientSettings().getBlock(gcc.MessageType.CS_CORE).highColorDepth
|
||||
bitmapCapability.desktopWidth = self._transport.getGCCClientSettings().getBlock(gcc.MessageType.CS_CORE).desktopWidth
|
||||
bitmapCapability.desktopHeight = self._transport.getGCCClientSettings().getBlock(gcc.MessageType.CS_CORE).desktopHeight
|
||||
bitmapCapability.preferredBitsPerPixel = self._gccCore.highColorDepth
|
||||
bitmapCapability.desktopWidth = self._gccCore.desktopWidth
|
||||
bitmapCapability.desktopHeight = self._gccCore.desktopHeight
|
||||
|
||||
#init order capability
|
||||
orderCapability = self._clientCapabilities[caps.CapsType.CAPSTYPE_ORDER].capability
|
||||
@@ -357,11 +329,11 @@ class Client(PDULayer, tpkt.IFastPathListener):
|
||||
#init input capability
|
||||
inputCapability = self._clientCapabilities[caps.CapsType.CAPSTYPE_INPUT].capability
|
||||
inputCapability.inputFlags.value = caps.InputFlags.INPUT_FLAG_SCANCODES | caps.InputFlags.INPUT_FLAG_MOUSEX | caps.InputFlags.INPUT_FLAG_UNICODE
|
||||
inputCapability.keyboardLayout = self._transport.getGCCClientSettings().getBlock(gcc.MessageType.CS_CORE).kbdLayout
|
||||
inputCapability.keyboardType = self._transport.getGCCClientSettings().getBlock(gcc.MessageType.CS_CORE).keyboardType
|
||||
inputCapability.keyboardSubType = self._transport.getGCCClientSettings().getBlock(gcc.MessageType.CS_CORE).keyboardSubType
|
||||
inputCapability.keyboardrFunctionKey = self._transport.getGCCClientSettings().getBlock(gcc.MessageType.CS_CORE).keyboardFnKeys
|
||||
inputCapability.imeFileName = self._transport.getGCCClientSettings().getBlock(gcc.MessageType.CS_CORE).imeFileName
|
||||
inputCapability.keyboardLayout = self._gccCore.kbdLayout
|
||||
inputCapability.keyboardType = self._gccCore.keyboardType
|
||||
inputCapability.keyboardSubType = self._gccCore.keyboardSubType
|
||||
inputCapability.keyboardrFunctionKey = self._gccCore.keyboardFnKeys
|
||||
inputCapability.imeFileName = self._gccCore.imeFileName
|
||||
|
||||
#make active PDU packet
|
||||
confirmActivePDU = data.ConfirmActivePDU()
|
||||
@@ -373,7 +345,7 @@ class Client(PDULayer, tpkt.IFastPathListener):
|
||||
"""
|
||||
send a synchronize PDU from client to server
|
||||
"""
|
||||
synchronizePDU = data.SynchronizeDataPDU(self._transport.getChannelId())
|
||||
synchronizePDU = data.SynchronizeDataPDU(self._transport._transport.getChannelId())
|
||||
self.sendDataPDU(synchronizePDU)
|
||||
|
||||
#ask for cooperation
|
||||
@@ -415,38 +387,16 @@ class Server(PDULayer, tpkt.IFastPathListener):
|
||||
def connect(self):
|
||||
"""
|
||||
Connect message for server automata
|
||||
Wait Info Packet
|
||||
"""
|
||||
self.setNextState(self.recvInfoPkt)
|
||||
self.sendDemandActivePDU()
|
||||
self.setNextState(self.recvConfirmActivePDU)
|
||||
|
||||
def setFastPathSender(self, fastPathSender):
|
||||
"""
|
||||
@param fastPathSender: tpkt.FastPathSender
|
||||
@note: implement tpkt.IFastPathListener
|
||||
"""
|
||||
self._fastPathSender = fastPathSender
|
||||
|
||||
def recvInfoPkt(self, s):
|
||||
"""
|
||||
Receive info packet from client
|
||||
Client credentials
|
||||
Send License valid error message
|
||||
Send Demand Active PDU
|
||||
Wait Confirm Active PDU
|
||||
@param s: Stream
|
||||
"""
|
||||
securityFlag = UInt16Le()
|
||||
securityFlagHi = UInt16Le()
|
||||
s.readType((securityFlag, securityFlagHi))
|
||||
|
||||
if not (securityFlag.value & data.SecurityFlag.SEC_INFO_PKT):
|
||||
raise InvalidExpectedDataException("Waiting info packet")
|
||||
|
||||
s.readType(self._info)
|
||||
#next state send error license
|
||||
self.sendLicensingErrorMessage()
|
||||
self.sendDemandActivePDU()
|
||||
self.setNextState(self.recvConfirmActivePDU)
|
||||
self._fastPathSender = fastPathSender
|
||||
|
||||
def recvConfirmActivePDU(self, s):
|
||||
"""
|
||||
@@ -573,12 +523,6 @@ class Server(PDULayer, tpkt.IFastPathListener):
|
||||
"""
|
||||
pass
|
||||
|
||||
def sendLicensingErrorMessage(self):
|
||||
"""
|
||||
Send a licensing error data
|
||||
"""
|
||||
self._transport.send((UInt16Le(data.SecurityFlag.SEC_LICENSE_PKT), UInt16Le(), lic.createValidClientLicensingErrorMessage()))
|
||||
|
||||
def sendDemandActivePDU(self):
|
||||
"""
|
||||
@summary: Send server capabilities server automata PDU
|
||||
@@ -601,7 +545,7 @@ class Server(PDULayer, tpkt.IFastPathListener):
|
||||
"""
|
||||
Send last synchronize packet from server to client
|
||||
"""
|
||||
synchronizePDU = data.SynchronizeDataPDU(self._transport.getChannelId())
|
||||
synchronizePDU = data.SynchronizeDataPDU(self._transport._transport.getChannelId())
|
||||
self.sendDataPDU(synchronizePDU)
|
||||
|
||||
#ask for cooperation
|
||||
|
||||
@@ -21,9 +21,9 @@
|
||||
GDI order structure
|
||||
"""
|
||||
|
||||
from rdpy.base import log
|
||||
from rdpy.base.error import InvalidExpectedDataException
|
||||
from rdpy.network.type import CompositeType, UInt8, String, FactoryType, SInt8, SInt16Le
|
||||
from rdpy.core import log
|
||||
from rdpy.core.error import InvalidExpectedDataException
|
||||
from rdpy.core.type import CompositeType, UInt8, String, FactoryType, SInt8, SInt16Le
|
||||
|
||||
class ControlFlag(object):
|
||||
"""
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
Per encoded function
|
||||
"""
|
||||
|
||||
from rdpy.network.type import UInt8, UInt16Be, UInt32Be, String
|
||||
from rdpy.base.error import InvalidValue, InvalidExpectedDataException
|
||||
from rdpy.core.type import UInt8, UInt16Be, UInt32Be, String
|
||||
from rdpy.core.error import InvalidValue, InvalidExpectedDataException
|
||||
|
||||
def readLength(s):
|
||||
"""
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
Use to manage RDP stack in twisted
|
||||
"""
|
||||
|
||||
from rdpy.network import layer
|
||||
from rdpy.base.error import CallPureVirtualFuntion, InvalidValue
|
||||
from rdpy.core import layer
|
||||
from rdpy.core.error import CallPureVirtualFuntion, InvalidValue
|
||||
import pdu.layer
|
||||
import pdu.data
|
||||
import pdu.caps
|
||||
import rdpy.base.log as log
|
||||
import rdpy.core.log as log
|
||||
import tpkt, x224, mcs, gcc, sec
|
||||
|
||||
class RDPClientController(pdu.layer.PDUClientListener):
|
||||
@@ -39,7 +39,7 @@ class RDPClientController(pdu.layer.PDUClientListener):
|
||||
#PDU layer
|
||||
self._pduLayer = pdu.layer.Client(self)
|
||||
#secure layer
|
||||
self._secLayer = sec.SecLayer(self._pduLayer)
|
||||
self._secLayer = sec.Client(self._pduLayer)
|
||||
#multi channel service
|
||||
self._mcsLayer = mcs.Client(self._secLayer)
|
||||
#transport pdu layer
|
||||
@@ -72,7 +72,7 @@ class RDPClientController(pdu.layer.PDUClientListener):
|
||||
"""
|
||||
@summary: Set particular flag in RDP stack to avoid wall-paper, theme, menu animation etc...
|
||||
"""
|
||||
self._pduLayer._info.extendedInfo.performanceFlags.value = pdu.data.PerfFlag.PERF_DISABLE_WALLPAPER | pdu.data.PerfFlag.PERF_DISABLE_MENUANIMATIONS | pdu.data.PerfFlag.PERF_DISABLE_CURSOR_SHADOW | pdu.data.PerfFlag.PERF_DISABLE_THEMING | pdu.data.PerfFlag.PERF_DISABLE_FULLWINDOWDRAG
|
||||
self._secLayer._info.extendedInfo.performanceFlags.value = sec.PerfFlag.PERF_DISABLE_WALLPAPER | sec.PerfFlag.PERF_DISABLE_MENUANIMATIONS | sec.PerfFlag.PERF_DISABLE_CURSOR_SHADOW | sec.PerfFlag.PERF_DISABLE_THEMING | sec.PerfFlag.PERF_DISABLE_FULLWINDOWDRAG
|
||||
|
||||
def setScreen(self, width, height):
|
||||
"""
|
||||
@@ -90,8 +90,8 @@ class RDPClientController(pdu.layer.PDUClientListener):
|
||||
@param username: username of session
|
||||
"""
|
||||
#username in PDU info packet
|
||||
self._pduLayer._info.userName.value = username
|
||||
self._pduLayer._licenceManager._username = username
|
||||
self._secLayer._info.userName.value = username
|
||||
self._secLayer._licenceManager._username = username
|
||||
|
||||
def setPassword(self, password):
|
||||
"""
|
||||
@@ -99,20 +99,20 @@ class RDPClientController(pdu.layer.PDUClientListener):
|
||||
@param password: password of session
|
||||
"""
|
||||
self.setAutologon()
|
||||
self._pduLayer._info.password.value = password
|
||||
self._secLayer._info.password.value = password
|
||||
|
||||
def setDomain(self, domain):
|
||||
"""
|
||||
@summary: Set the windows domain of session
|
||||
@param domain: domain of session
|
||||
"""
|
||||
self._pduLayer._info.domain.value = domain
|
||||
self._secLayer._info.domain.value = domain
|
||||
|
||||
def setAutologon(self):
|
||||
"""
|
||||
@summary: enable autologon
|
||||
"""
|
||||
self._pduLayer._info.flag |= pdu.data.InfoFlag.INFO_AUTOLOGON
|
||||
self._secLayer._info.flag |= sec.InfoFlag.INFO_AUTOLOGON
|
||||
|
||||
def setKeyboardLayout(self, layout):
|
||||
"""
|
||||
@@ -129,7 +129,7 @@ class RDPClientController(pdu.layer.PDUClientListener):
|
||||
@summary: set hostname of machine
|
||||
"""
|
||||
self._mcsLayer._clientSettings.getBlock(gcc.MessageType.CS_CORE).clientName.value = hostname[:15] + "\x00" * (15 - len(hostname))
|
||||
self._pduLayer._licenceManager._hostname = hostname
|
||||
self._secLayer._licenceManager._hostname = hostname
|
||||
|
||||
def setRDPBasicSecurity(self):
|
||||
"""
|
||||
@@ -332,8 +332,10 @@ class RDPServerController(pdu.layer.PDUServerListener):
|
||||
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._pduLayer)
|
||||
self._mcsLayer = mcs.Server(self._secLayer)
|
||||
#transport pdu layer
|
||||
self._x224Layer = x224.Server(self._mcsLayer, privateKeyFileName, certificateFileName)
|
||||
#transport packet (protocol layer)
|
||||
@@ -359,21 +361,21 @@ class RDPServerController(pdu.layer.PDUServerListener):
|
||||
@summary: Must be call after on ready event else always empty string
|
||||
@return: username send by client may be an empty string
|
||||
"""
|
||||
return self._pduLayer._info.userName.value
|
||||
return self._secLayer._info.userName.value
|
||||
|
||||
def getPassword(self):
|
||||
"""
|
||||
@summary: Must be call after on ready event else always empty string
|
||||
@return: password send by client may be an empty string
|
||||
"""
|
||||
return self._pduLayer._info.password.value
|
||||
return self._secLayer._info.password.value
|
||||
|
||||
def getDomain(self):
|
||||
"""
|
||||
@summary: Must be call after on ready event else always empty string
|
||||
@return: domain send by client may be an empty string
|
||||
"""
|
||||
return self._pduLayer._info.domain.value
|
||||
return self._secLayer._info.domain.value
|
||||
|
||||
def getCredentials(self):
|
||||
"""
|
||||
@@ -492,7 +494,8 @@ class ClientFactory(layer.RawLayerClientFactory):
|
||||
#retrieve controller
|
||||
x224Layer = tpktLayer._presentation
|
||||
mcsLayer = x224Layer._presentation
|
||||
pduLayer = mcsLayer._channels[mcs.Channel.MCS_GLOBAL_CHANNEL]
|
||||
secLayer = mcsLayer._channels[mcs.Channel.MCS_GLOBAL_CHANNEL]
|
||||
pduLayer = secLayer._presentation
|
||||
controller = pduLayer._listener
|
||||
controller.onClose()
|
||||
|
||||
@@ -534,7 +537,8 @@ class ServerFactory(layer.RawLayerServerFactory):
|
||||
#retrieve controller
|
||||
x224Layer = tpktLayer._presentation
|
||||
mcsLayer = x224Layer._presentation
|
||||
pduLayer = mcsLayer._channels[mcs.Channel.MCS_GLOBAL_CHANNEL]
|
||||
secLayer = mcsLayer._channels[mcs.Channel.MCS_GLOBAL_CHANNEL]
|
||||
pduLayer = secLayer._presentation
|
||||
controller = pduLayer._listener
|
||||
controller.onClose()
|
||||
|
||||
|
||||
@@ -21,9 +21,10 @@
|
||||
Some use full methods for security in RDP
|
||||
"""
|
||||
|
||||
import sha, md5, rsa, gcc, rc4
|
||||
from rdpy.network.type import CompositeType, Stream, UInt32Le, UInt16Le, String, sizeof
|
||||
from rdpy.network.layer import LayerAutomata, IStreamSender
|
||||
import sha, md5, rsa, gcc, rc4, lic
|
||||
from rdpy.core.type import CompositeType, Stream, UInt32Le, UInt16Le, String, sizeof, UInt8
|
||||
from rdpy.core.layer import LayerAutomata, IStreamSender
|
||||
from rdpy.core.error import InvalidExpectedDataException
|
||||
|
||||
class SecurityFlag(object):
|
||||
"""
|
||||
@@ -182,19 +183,6 @@ def bin2bn(b):
|
||||
for ch in b:
|
||||
l = (l<<8) | ord(ch)
|
||||
return l
|
||||
|
||||
def bn2bin(b):
|
||||
"""
|
||||
@summary: convert Big number to binary
|
||||
@param b: bignumber (long)
|
||||
@return: binary stream
|
||||
"""
|
||||
s = bytearray()
|
||||
i = (b.bit_length() + 7) / 8
|
||||
while i > 0:
|
||||
s.append((b >> ((i - 1) * 8)) & 0xff)
|
||||
i -= 1
|
||||
return s
|
||||
|
||||
class ClientSecurityExchangePDU(CompositeType):
|
||||
"""
|
||||
@@ -204,11 +192,12 @@ class ClientSecurityExchangePDU(CompositeType):
|
||||
def __init__(self):
|
||||
CompositeType.__init__(self)
|
||||
self.length = UInt32Le(lambda:(sizeof(self) - 4))
|
||||
self.encryptedClientRandom = String(readLen = self.length)
|
||||
self.encryptedClientRandom = String(readLen = UInt8(lambda:(self.length.value - 8)))
|
||||
self.padding = String("\x00" * 8, readLen = UInt8(8))
|
||||
|
||||
class RDPInfo(CompositeType):
|
||||
"""
|
||||
Client informations
|
||||
@summary: Client informations
|
||||
Contains credentials (very important packet)
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240475.aspx
|
||||
"""
|
||||
@@ -235,7 +224,7 @@ class RDPInfo(CompositeType):
|
||||
|
||||
class RDPExtendedInfo(CompositeType):
|
||||
"""
|
||||
Add more client informations
|
||||
@summary: Add more client informations
|
||||
"""
|
||||
def __init__(self, conditional):
|
||||
CompositeType.__init__(self, conditional = conditional)
|
||||
@@ -255,6 +244,9 @@ class SecLayer(LayerAutomata, IStreamSender):
|
||||
This layer is Transparent as possible for upper layer
|
||||
"""
|
||||
def __init__(self, presentation):
|
||||
"""
|
||||
@param presentation: Layer (generally pdu layer)
|
||||
"""
|
||||
LayerAutomata.__init__(self, presentation)
|
||||
self._info = RDPInfo(extendedInfoConditional = lambda:(self._transport.getGCCServerSettings().getBlock(gcc.MessageType.SC_CORE).rdpVersion.value == gcc.Version.RDP_VERSION_5_PLUS))
|
||||
self._enableEncryption = False
|
||||
@@ -264,49 +256,177 @@ class SecLayer(LayerAutomata, IStreamSender):
|
||||
def generateKeys(self):
|
||||
"""
|
||||
@see: http://msdn.microsoft.com/en-us/library/cc240785.aspx
|
||||
@return: finalHash(second128bit(sessionkey), sthird128bit(sessionkey))
|
||||
"""
|
||||
preMasterSecret = self._clientRandom[:24] + self._serverRandom[:24]
|
||||
masterSecret = generateMicrosoftKeyABBCCC(preMasterSecret, self._clientRandom, self._serverRandom)
|
||||
self._sessionKey = generateMicrosoftKeyXYYZZZ(masterSecret, self._clientRandom, self._serverRandom)
|
||||
self._macKey128 = self._sessionKey[:16]
|
||||
|
||||
return (finalHash(self._sessionKey[16:32], self._clientRandom, self._serverRandom), finalHash(self._sessionKey[32:48], self._clientRandom, self._serverRandom))
|
||||
|
||||
def readEncryptedPayload(self, s):
|
||||
"""
|
||||
@summary: decrypt basic RDP security payload
|
||||
@param s: {Stream} encrypted stream
|
||||
@return: {Stream} decrypted
|
||||
"""
|
||||
signature = String(readLen = UInt8(8))
|
||||
encryptedPayload = String()
|
||||
s.readType((signature, encryptedPayload))
|
||||
return Stream(rc4.crypt(self._decrypt, encryptedPayload.value))
|
||||
|
||||
def writeEncryptedPayload(self, data):
|
||||
"""
|
||||
@summary: sign and crypt data
|
||||
@param s: {Stream} raw stream
|
||||
@return: {Tuple} (signature, encryptedData)
|
||||
"""
|
||||
s = Stream()
|
||||
s.writeType(data)
|
||||
return (String(macData(self._macKey128, s.getvalue())[:8]), String(rc4.crypt(self._encrypt, s.getvalue())))
|
||||
|
||||
def recv(self, data):
|
||||
"""
|
||||
@summary: if basic RDP security layer is activate decrypt
|
||||
else pass to upper layer
|
||||
@param data : {Stream} input Stream
|
||||
"""
|
||||
if not self._enableEncryption:
|
||||
self._presentation.recv(data)
|
||||
return
|
||||
|
||||
securityFlag = UInt16Le()
|
||||
securityFlagHi = UInt16Le()
|
||||
data.readType((securityFlag, securityFlagHi))
|
||||
|
||||
if securityFlag.value & SecurityFlag.SEC_ENCRYPT:
|
||||
data = self.readEncryptedPayload(data)
|
||||
|
||||
self._presentation.recv(data)
|
||||
|
||||
def send(self, data):
|
||||
"""
|
||||
@summary: if basic RDP security layer is activate encrypt
|
||||
else pass to upper layer
|
||||
@param data: {Type | Tuple}
|
||||
"""
|
||||
if not self._enableEncryption:
|
||||
self._presentation.recv(data)
|
||||
self._transport.send(data)
|
||||
return
|
||||
|
||||
def sendFlag(self, flag, data):
|
||||
self.sendFlagged(SecurityFlag.SEC_ENCRYPT, data)
|
||||
|
||||
def sendFlagged(self, flag, data):
|
||||
"""
|
||||
@summary: explicit send flag method for particular packet
|
||||
(info packet or license packet)
|
||||
If encryption is enable apply it
|
||||
@param flag: {integer} security flag
|
||||
@param data: {Type | Tuple}
|
||||
"""
|
||||
if self._enableEncryption:
|
||||
flag |= SecurityFlag.SEC_ENCRYPT
|
||||
data = self.writeEncryptedPayload(data)
|
||||
self.__sendFlagged__(flag, data)
|
||||
|
||||
def __sendFlagged__(self, flag, data):
|
||||
"""
|
||||
@summary: format basic message of security layer
|
||||
"""
|
||||
self._transport.send((UInt16Le(flag), UInt16Le(), data))
|
||||
|
||||
class SecClient(SecLayer):
|
||||
class Client(SecLayer):
|
||||
"""
|
||||
@summary: Client side of security layer
|
||||
"""
|
||||
def __init__(self, presentation):
|
||||
SecLayer.__init__(self, presentation)
|
||||
self._licenceManager = lic.LicenseManager(self)
|
||||
|
||||
def connect(self):
|
||||
"""
|
||||
@summary: send client random
|
||||
"""
|
||||
if self._transport.getGCCClientSettings.getBlock(gcc.MessageType.CS_CORE).serverSelectedProtocol == 0:
|
||||
if self._transport.getGCCClientSettings().getBlock(gcc.MessageType.CS_CORE).serverSelectedProtocol == 0:
|
||||
#generate client random
|
||||
self._clientRandom = rsa.randnum.read_random_bits(128)
|
||||
self._clientRandom = rsa.randnum.read_random_bits(256)
|
||||
self._serverRandom = self._transport.getGCCServerSettings().getBlock(gcc.MessageType.SC_SECURITY).serverRandom.value
|
||||
self.generateKeys()
|
||||
|
||||
self._decrypt = finalHash(self._sessionKey[16:32], self._clientRandom, self._serverRandom)
|
||||
self._encrypt = finalHash(self._sessionKey[32:48], self._clientRandom, self._serverRandom)
|
||||
self._decrypt, self._encrypt = self.generateKeys()
|
||||
|
||||
#send client random encrypted with
|
||||
certificate = self._transport.getGCCServerSettings().getBlock(gcc.MessageType.SC_SECURITY).serverCertificate.certData
|
||||
serverPublicKey = rsa.PublicKey(bin2bn(certificate.PublicKeyBlob.modulus.value), certificate.PublicKeyBlob.pubExp.value)
|
||||
serverPublicKey = rsa.PublicKey(bin2bn(certificate.PublicKeyBlob.modulus.value[::-1]), certificate.PublicKeyBlob.pubExp.value)
|
||||
|
||||
message = ClientSecurityExchangePDU()
|
||||
message.encryptedClientRandom.value = rsa.encrypt(self._clientRandom, serverPublicKey)
|
||||
self.send(SecurityFlag.SEC_EXCHANGE_PKT, message)
|
||||
message.encryptedClientRandom.value = rsa.encrypt(self._clientRandom[::-1], serverPublicKey)[::-1]
|
||||
self.sendFlagged(SecurityFlag.SEC_EXCHANGE_PKT, message)
|
||||
|
||||
#now all messages must be encrypted
|
||||
self._enableEncryption = True
|
||||
|
||||
self.send(SecurityFlag.SEC_INFO_PKT, self._info)
|
||||
self._presentation.connect()
|
||||
self.sendFlagged(SecurityFlag.SEC_INFO_PKT, self._info)
|
||||
self.setNextState(self.recvLicenceInfo)
|
||||
|
||||
def recvLicenceInfo(self, s):
|
||||
"""
|
||||
@summary: Read license info packet and check if is a valid client info
|
||||
Wait Demand Active PDU
|
||||
@param s: Stream
|
||||
"""
|
||||
#packet preambule
|
||||
securityFlag = UInt16Le()
|
||||
securityFlagHi = UInt16Le()
|
||||
s.readType((securityFlag, securityFlagHi))
|
||||
|
||||
if not (securityFlag.value & SecurityFlag.SEC_LICENSE_PKT):
|
||||
raise InvalidExpectedDataException("Waiting license packet")
|
||||
|
||||
if securityFlag.value & SecurityFlag.SEC_ENCRYPT:
|
||||
s = self.readEncryptedPayload(s)
|
||||
|
||||
if self._licenceManager.recv(s):
|
||||
self.setNextState()
|
||||
#end of connection step of
|
||||
self._presentation.connect()
|
||||
|
||||
class Server(SecLayer):
|
||||
"""
|
||||
@summary: Client side of security layer
|
||||
"""
|
||||
def __init__(self, presentation):
|
||||
SecLayer.__init__(self, presentation)
|
||||
|
||||
def connect(self):
|
||||
"""
|
||||
@summary: init automata to wait info packet
|
||||
"""
|
||||
self.setNextState(self.recvInfoPkt)
|
||||
|
||||
def recvInfoPkt(self, s):
|
||||
"""
|
||||
@summary: receive info packet from client
|
||||
Client credentials
|
||||
Send License valid error message
|
||||
Send Demand Active PDU
|
||||
Wait Confirm Active PDU
|
||||
@param s: Stream
|
||||
"""
|
||||
securityFlag = UInt16Le()
|
||||
securityFlagHi = UInt16Le()
|
||||
s.readType((securityFlag, securityFlagHi))
|
||||
|
||||
if not (securityFlag.value & SecurityFlag.SEC_INFO_PKT):
|
||||
raise InvalidExpectedDataException("Waiting info packet")
|
||||
|
||||
s.readType(self._info)
|
||||
#next state send error license
|
||||
self.sendLicensingErrorMessage()
|
||||
#reinit state
|
||||
self.setNextState()
|
||||
self._presentation.connect()
|
||||
|
||||
def sendLicensingErrorMessage(self):
|
||||
"""
|
||||
@summary: Send a licensing error data
|
||||
"""
|
||||
self.sendFlagged(SecurityFlag.SEC_LICENSE_PKT, lic.createValidClientLicensingErrorMessage())
|
||||
@@ -22,9 +22,9 @@ Transport packet layer implementation
|
||||
|
||||
Use to build correct size packet and handle slow path and fast path mode
|
||||
"""
|
||||
from rdpy.network.layer import RawLayer
|
||||
from rdpy.network.type import UInt8, UInt16Be, sizeof
|
||||
from rdpy.base.error import CallPureVirtualFuntion
|
||||
from rdpy.core.layer import RawLayer
|
||||
from rdpy.core.type import UInt8, UInt16Be, sizeof
|
||||
from rdpy.core.error import CallPureVirtualFuntion
|
||||
|
||||
class Action(object):
|
||||
"""
|
||||
|
||||
@@ -24,9 +24,9 @@ This layer have main goal to negociate SSL transport
|
||||
RDP basic security is supported only on client side
|
||||
"""
|
||||
|
||||
from rdpy.network.layer import LayerAutomata, IStreamSender
|
||||
from rdpy.network.type import UInt8, UInt16Le, UInt16Be, UInt32Le, CompositeType, sizeof, String
|
||||
from rdpy.base.error import InvalidExpectedDataException, RDPSecurityNegoFail
|
||||
from rdpy.core.layer import LayerAutomata, IStreamSender
|
||||
from rdpy.core.type import UInt8, UInt16Le, UInt16Be, UInt32Le, CompositeType, sizeof, String
|
||||
from rdpy.core.error import InvalidExpectedDataException, RDPSecurityNegoFail
|
||||
|
||||
class MessageType(object):
|
||||
"""
|
||||
@@ -132,7 +132,7 @@ class X224Layer(LayerAutomata, IStreamSender):
|
||||
LayerAutomata.__init__(self, presentation)
|
||||
#default selectedProtocol is SSl
|
||||
#client requested selectedProtocol
|
||||
self._requestedProtocol = Protocols.PROTOCOL_RDP | Protocols.PROTOCOL_SSL
|
||||
self._requestedProtocol = Protocols.PROTOCOL_RDP
|
||||
#server selected selectedProtocol
|
||||
self._selectedProtocol = Protocols.PROTOCOL_SSL
|
||||
|
||||
|
||||
@@ -25,11 +25,11 @@ Implement Remote FrameBuffer protocol use in VNC client and server
|
||||
@todo: more encoding rectangle
|
||||
"""
|
||||
|
||||
from rdpy.network.layer import RawLayer, RawLayerClientFactory
|
||||
from rdpy.network.type import UInt8, UInt16Be, UInt32Be, SInt32Be, String, CompositeType
|
||||
from rdpy.base.error import InvalidValue, CallPureVirtualFuntion
|
||||
from rdpy.core.layer import RawLayer, RawLayerClientFactory
|
||||
from rdpy.core.type import UInt8, UInt16Be, UInt32Be, SInt32Be, String, CompositeType
|
||||
from rdpy.core.error import InvalidValue, CallPureVirtualFuntion
|
||||
from rdpy.protocol.rfb.pyDes import des
|
||||
import rdpy.base.log as log
|
||||
import rdpy.core.log as log
|
||||
|
||||
class ProtocolVersion(object):
|
||||
"""
|
||||
|
||||
@@ -26,10 +26,10 @@ QRemoteDesktop is a widget use for render in rdpy
|
||||
from PyQt4 import QtGui, QtCore
|
||||
from rdpy.protocol.rfb.rfb import RFBClientObserver
|
||||
from rdpy.protocol.rdp.rdp import RDPClientObserver
|
||||
from rdpy.base.error import CallPureVirtualFuntion
|
||||
from rdpy.core.error import CallPureVirtualFuntion
|
||||
import sys
|
||||
|
||||
import rdpy.base.log as log
|
||||
import rdpy.core.log as log
|
||||
import rle
|
||||
|
||||
class QAdaptor(object):
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
"""
|
||||
Fake widget
|
||||
"""
|
||||
from rdpy.base.error import CallPureVirtualFuntion
|
||||
from rdpy.core.error import CallPureVirtualFuntion
|
||||
from PyQt4 import QtGui, QtCore
|
||||
|
||||
|
||||
|
||||
3
setup.py
3
setup.py
@@ -15,8 +15,7 @@ setup(name='rdpy',
|
||||
url='https://github.com/citronneur/rdpy',
|
||||
packages=[
|
||||
'rdpy',
|
||||
'rdpy.base',
|
||||
'rdpy.network',
|
||||
'rdpy.core',
|
||||
'rdpy.protocol',
|
||||
'rdpy.protocol.rdp',
|
||||
'rdpy.protocol.rdp.pdu',
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#
|
||||
|
||||
"""
|
||||
unit test for rdpy.base.const module
|
||||
unit test for rdpy.core.const module
|
||||
"""
|
||||
|
||||
import os, sys
|
||||
@@ -26,8 +26,8 @@ import os, sys
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
|
||||
import unittest
|
||||
import rdpy.base.const
|
||||
import rdpy.network.type
|
||||
import rdpy.core.const
|
||||
import rdpy.core.type
|
||||
|
||||
class ConstCase(unittest.TestCase):
|
||||
'''
|
||||
@@ -38,19 +38,19 @@ class ConstCase(unittest.TestCase):
|
||||
'''
|
||||
test if type attributes decorator works
|
||||
'''
|
||||
@rdpy.base.const.TypeAttributes(rdpy.network.type.UInt16Le)
|
||||
@rdpy.core.const.TypeAttributes(rdpy.core.type.UInt16Le)
|
||||
class Test:
|
||||
MEMBER_1 = 1
|
||||
MEMBER_2 = 2
|
||||
|
||||
self.assertIsInstance(Test.MEMBER_1, rdpy.network.type.UInt16Le, "MEMBER_1 is not in correct type")
|
||||
self.assertIsInstance(Test.MEMBER_2, rdpy.network.type.UInt16Le, "MEMBER_2 is not in correct type")
|
||||
self.assertIsInstance(Test.MEMBER_1, rdpy.core.type.UInt16Le, "MEMBER_1 is not in correct type")
|
||||
self.assertIsInstance(Test.MEMBER_2, rdpy.core.type.UInt16Le, "MEMBER_2 is not in correct type")
|
||||
|
||||
def test_const(self):
|
||||
'''
|
||||
test if get on const class member generate new object each
|
||||
'''
|
||||
@rdpy.base.const.ConstAttributes
|
||||
@rdpy.core.const.ConstAttributes
|
||||
class Test:
|
||||
MEMBER_1 = 1
|
||||
MEMBER_2 = 2
|
||||
|
||||
@@ -26,12 +26,12 @@ import os, sys
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
|
||||
import unittest
|
||||
import rdpy.network.layer
|
||||
import rdpy.core.layer
|
||||
|
||||
class LayerCase(unittest.TestCase):
|
||||
"""
|
||||
@summary: represent test case for all classes and function
|
||||
present in rdpy.network.layer
|
||||
present in rdpy.core.layer
|
||||
"""
|
||||
|
||||
class LayerCaseException(Exception):
|
||||
@@ -44,17 +44,17 @@ class LayerCase(unittest.TestCase):
|
||||
"""
|
||||
@summary: test if connect event is send from transport to presentation
|
||||
"""
|
||||
class TestConnect(rdpy.network.layer.Layer):
|
||||
class TestConnect(rdpy.core.layer.Layer):
|
||||
def connect(self):
|
||||
raise LayerCase.LayerCaseException()
|
||||
|
||||
self.assertRaises(LayerCase.LayerCaseException, rdpy.network.layer.Layer(presentation = TestConnect()).connect)
|
||||
self.assertRaises(LayerCase.LayerCaseException, rdpy.core.layer.Layer(presentation = TestConnect()).connect)
|
||||
|
||||
def test_layer_automata_more_than_expected(self):
|
||||
"""
|
||||
@summary: test layer automata mechanism if data received is more than expected
|
||||
"""
|
||||
class TestAutomata(rdpy.network.layer.RawLayer):
|
||||
class TestAutomata(rdpy.core.layer.RawLayer):
|
||||
def expectedCallBack(self, data):
|
||||
if data.dataLen() == 4:
|
||||
raise LayerCase.LayerCaseException()
|
||||
@@ -67,7 +67,7 @@ class LayerCase(unittest.TestCase):
|
||||
"""
|
||||
@summary: test layer automata mechanism
|
||||
"""
|
||||
class TestAutomata(rdpy.network.layer.RawLayer):
|
||||
class TestAutomata(rdpy.core.layer.RawLayer):
|
||||
def expectedCallBack(self, data):
|
||||
if data.dataLen() == 4:
|
||||
raise LayerCase.LayerCaseException()
|
||||
|
||||
@@ -26,8 +26,8 @@ import os, sys
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
|
||||
import unittest
|
||||
import rdpy.network.type
|
||||
from rdpy.base.error import InvalidSize
|
||||
import rdpy.core.type
|
||||
from rdpy.core.error import InvalidSize
|
||||
|
||||
class TypeCase(unittest.TestCase):
|
||||
"""
|
||||
@@ -38,24 +38,24 @@ class TypeCase(unittest.TestCase):
|
||||
"""
|
||||
@summary: test if callable value with const ctor doesn't change value
|
||||
"""
|
||||
c = rdpy.network.type.CallableValue(5)
|
||||
c = rdpy.core.type.CallableValue(5)
|
||||
self.assertEqual(c.value, 5, "invalid callable const")
|
||||
|
||||
def test_callable_value_lambda(self):
|
||||
"""
|
||||
@summary: test if callable value with lambda ctor return dynamic value
|
||||
"""
|
||||
c = rdpy.network.type.CallableValue(lambda:5)
|
||||
c = rdpy.core.type.CallableValue(lambda:5)
|
||||
self.assertEqual(c.value, 5, "invalid callable lambda")
|
||||
|
||||
def test_type_write_conditional_true(self):
|
||||
"""
|
||||
@summary: test when write is obligatory call write function
|
||||
"""
|
||||
class TestType(rdpy.network.type.Type):
|
||||
class TestType(rdpy.core.type.Type):
|
||||
def __write__(self, s):
|
||||
raise Exception()
|
||||
s = rdpy.network.type.Stream()
|
||||
s = rdpy.core.type.Stream()
|
||||
self.assertRaises(Exception, s.writeType, TestType(conditional = lambda:True))
|
||||
|
||||
@unittest.expectedFailure
|
||||
@@ -63,20 +63,20 @@ class TypeCase(unittest.TestCase):
|
||||
"""
|
||||
@summary: test when write doesn't needed, doesn't call write function
|
||||
"""
|
||||
class TestType(rdpy.network.type.Type):
|
||||
class TestType(rdpy.core.type.Type):
|
||||
def __write__(self, s):
|
||||
raise Exception()
|
||||
s = rdpy.network.type.Stream()
|
||||
s = rdpy.core.type.Stream()
|
||||
self.assertRaises(Exception, s.writeType, TestType(conditional = lambda:False))
|
||||
|
||||
def test_type_read_conditional_true(self):
|
||||
"""
|
||||
@summary: test when read is obligatory call write function
|
||||
"""
|
||||
class TestType(rdpy.network.type.Type):
|
||||
class TestType(rdpy.core.type.Type):
|
||||
def __read__(self, s):
|
||||
raise Exception()
|
||||
s = rdpy.network.type.Stream()
|
||||
s = rdpy.core.type.Stream()
|
||||
self.assertRaises(Exception, s.readType, TestType(conditional = lambda:True))
|
||||
|
||||
@unittest.expectedFailure
|
||||
@@ -84,10 +84,10 @@ class TypeCase(unittest.TestCase):
|
||||
"""
|
||||
@summary: test when read doesn't needed, doesn't call read function
|
||||
"""
|
||||
class TestType(rdpy.network.type.Type):
|
||||
class TestType(rdpy.core.type.Type):
|
||||
def __read__(self, s):
|
||||
raise Exception()
|
||||
s = rdpy.network.type.Stream()
|
||||
s = rdpy.core.type.Stream()
|
||||
self.assertRaises(Exception, s.readType, TestType(conditional = lambda:False))
|
||||
|
||||
|
||||
@@ -95,106 +95,106 @@ class TypeCase(unittest.TestCase):
|
||||
"""
|
||||
@summary: test if sizeof of simple type is init value(4) when type is conditional true
|
||||
"""
|
||||
v = rdpy.network.type.SimpleType("I", 4, False, 0, conditional = lambda:True)
|
||||
self.assertEqual(rdpy.network.type.sizeof(v), 4, "invalid sizeof")
|
||||
v = rdpy.core.type.SimpleType("I", 4, False, 0, conditional = lambda:True)
|
||||
self.assertEqual(rdpy.core.type.sizeof(v), 4, "invalid sizeof")
|
||||
|
||||
def test_sizeof_conditional_false(self):
|
||||
"""
|
||||
@summary: test if sizeof of simple type is 0 when type is conditional false
|
||||
"""
|
||||
v = rdpy.network.type.SimpleType("I", 4, False, 0, conditional = lambda:False)
|
||||
self.assertEqual(rdpy.network.type.sizeof(v), 0, "invalid sizeof")
|
||||
v = rdpy.core.type.SimpleType("I", 4, False, 0, conditional = lambda:False)
|
||||
self.assertEqual(rdpy.core.type.sizeof(v), 0, "invalid sizeof")
|
||||
|
||||
def test_sizeof_list(self):
|
||||
"""
|
||||
@summary: test call sizeof on list of type
|
||||
"""
|
||||
v = [rdpy.network.type.UInt8(), rdpy.network.type.UInt16Le(), rdpy.network.type.UInt32Le()]
|
||||
self.assertEqual(rdpy.network.type.sizeof(v), 7, "invalid sizeof")
|
||||
v = [rdpy.core.type.UInt8(), rdpy.core.type.UInt16Le(), rdpy.core.type.UInt32Le()]
|
||||
self.assertEqual(rdpy.core.type.sizeof(v), 7, "invalid sizeof")
|
||||
|
||||
def test_sizeof_list_conditional(self):
|
||||
"""
|
||||
@summary: test call sizeof on list of type with one type hidden
|
||||
"""
|
||||
v = [rdpy.network.type.UInt8(), rdpy.network.type.UInt16Le(conditional = lambda:False), rdpy.network.type.UInt32Le()]
|
||||
self.assertEqual(rdpy.network.type.sizeof(v), 5, "invalid sizeof")
|
||||
v = [rdpy.core.type.UInt8(), rdpy.core.type.UInt16Le(conditional = lambda:False), rdpy.core.type.UInt32Le()]
|
||||
self.assertEqual(rdpy.core.type.sizeof(v), 5, "invalid sizeof")
|
||||
|
||||
def test_sizeof_tuple(self):
|
||||
"""
|
||||
@summary: test call sizeof on tuple of type
|
||||
"""
|
||||
v = [rdpy.network.type.UInt8(), rdpy.network.type.UInt16Le(), rdpy.network.type.UInt32Le()]
|
||||
self.assertEqual(rdpy.network.type.sizeof(v), 7, "invalid sizeof")
|
||||
v = [rdpy.core.type.UInt8(), rdpy.core.type.UInt16Le(), rdpy.core.type.UInt32Le()]
|
||||
self.assertEqual(rdpy.core.type.sizeof(v), 7, "invalid sizeof")
|
||||
|
||||
def test_sizeof_tuple_conditional(self):
|
||||
"""
|
||||
@summary: test call sizeof on tuple of type with one type hidden
|
||||
"""
|
||||
v = (rdpy.network.type.UInt8(), rdpy.network.type.UInt16Le(), rdpy.network.type.UInt32Le(conditional = lambda:False))
|
||||
self.assertEqual(rdpy.network.type.sizeof(v), 3, "invalid sizeof")
|
||||
v = (rdpy.core.type.UInt8(), rdpy.core.type.UInt16Le(), rdpy.core.type.UInt32Le(conditional = lambda:False))
|
||||
self.assertEqual(rdpy.core.type.sizeof(v), 3, "invalid sizeof")
|
||||
|
||||
def test_stream_write_uint8_type(self):
|
||||
"""
|
||||
@summary: test write uint8 in stream
|
||||
"""
|
||||
s = rdpy.network.type.Stream()
|
||||
s.writeType(rdpy.network.type.UInt8(1))
|
||||
s = rdpy.core.type.Stream()
|
||||
s.writeType(rdpy.core.type.UInt8(1))
|
||||
self.assertEqual(''.join(s.buflist), '\x01', "invalid stream write")
|
||||
|
||||
def test_stream_write_uint16Le_type(self):
|
||||
"""
|
||||
@summary: test write UInt16Le in stream
|
||||
"""
|
||||
s = rdpy.network.type.Stream()
|
||||
s.writeType(rdpy.network.type.UInt16Le(1))
|
||||
s = rdpy.core.type.Stream()
|
||||
s.writeType(rdpy.core.type.UInt16Le(1))
|
||||
self.assertEqual(''.join(s.buflist), '\x01\x00', "invalid stream write")
|
||||
|
||||
def test_stream_write_uint16Be_type(self):
|
||||
"""
|
||||
@summary: test write UInt16Be in stream
|
||||
"""
|
||||
s = rdpy.network.type.Stream()
|
||||
s.writeType(rdpy.network.type.UInt16Be(1))
|
||||
s = rdpy.core.type.Stream()
|
||||
s.writeType(rdpy.core.type.UInt16Be(1))
|
||||
self.assertEqual(''.join(s.buflist), '\x00\x01', "invalid stream write")
|
||||
|
||||
def test_stream_write_uint24Le_type(self):
|
||||
"""
|
||||
@summary: test write UInt24Le in stream
|
||||
"""
|
||||
s = rdpy.network.type.Stream()
|
||||
s.writeType(rdpy.network.type.UInt24Le(1))
|
||||
s = rdpy.core.type.Stream()
|
||||
s.writeType(rdpy.core.type.UInt24Le(1))
|
||||
self.assertEqual(''.join(s.buflist), '\x01\x00\x00', "invalid stream write")
|
||||
|
||||
def test_stream_write_uint24Be_type(self):
|
||||
"""
|
||||
@summary: test write uint24Be in stream
|
||||
"""
|
||||
s = rdpy.network.type.Stream()
|
||||
s.writeType(rdpy.network.type.UInt24Be(1))
|
||||
s = rdpy.core.type.Stream()
|
||||
s.writeType(rdpy.core.type.UInt24Be(1))
|
||||
self.assertEqual(''.join(s.buflist), '\x00\x00\x01', "invalid stream write")
|
||||
|
||||
def test_stream_write_uint32Le_type(self):
|
||||
"""
|
||||
@summary: test write UInt32Le in stream
|
||||
"""
|
||||
s = rdpy.network.type.Stream()
|
||||
s.writeType(rdpy.network.type.UInt32Le(1))
|
||||
s = rdpy.core.type.Stream()
|
||||
s.writeType(rdpy.core.type.UInt32Le(1))
|
||||
self.assertEqual(''.join(s.buflist), '\x01\x00\x00\x00', "invalid stream write")
|
||||
|
||||
def test_stream_write_uint32Be_type(self):
|
||||
"""
|
||||
@summary: test write UInt32Be in stream
|
||||
"""
|
||||
s = rdpy.network.type.Stream()
|
||||
s.writeType(rdpy.network.type.UInt32Be(1))
|
||||
s = rdpy.core.type.Stream()
|
||||
s.writeType(rdpy.core.type.UInt32Be(1))
|
||||
self.assertEqual(''.join(s.buflist), '\x00\x00\x00\x01', "invalid stream write")
|
||||
|
||||
def test_stream_read_uint8_type(self):
|
||||
"""
|
||||
@summary: test read UInt8 type from stream
|
||||
"""
|
||||
s = rdpy.network.type.Stream('\x01')
|
||||
t = rdpy.network.type.UInt8()
|
||||
s = rdpy.core.type.Stream('\x01')
|
||||
t = rdpy.core.type.UInt8()
|
||||
s.readType(t)
|
||||
self.assertEqual(t.value, 1, "invalid stream read value")
|
||||
self.assertEqual(s.dataLen(), 0, "not read all stream")
|
||||
@@ -203,8 +203,8 @@ class TypeCase(unittest.TestCase):
|
||||
"""
|
||||
@summary: test read UInt16Le type from stream
|
||||
"""
|
||||
s = rdpy.network.type.Stream('\x01\x00')
|
||||
t = rdpy.network.type.UInt16Le()
|
||||
s = rdpy.core.type.Stream('\x01\x00')
|
||||
t = rdpy.core.type.UInt16Le()
|
||||
s.readType(t)
|
||||
self.assertEqual(t.value, 1, "invalid stream read value")
|
||||
self.assertEqual(s.dataLen(), 0, "not read all stream")
|
||||
@@ -213,8 +213,8 @@ class TypeCase(unittest.TestCase):
|
||||
"""
|
||||
@summary: test read UInt16Be type from stream
|
||||
"""
|
||||
s = rdpy.network.type.Stream('\x00\x01')
|
||||
t = rdpy.network.type.UInt16Be()
|
||||
s = rdpy.core.type.Stream('\x00\x01')
|
||||
t = rdpy.core.type.UInt16Be()
|
||||
s.readType(t)
|
||||
self.assertEqual(t.value, 1, "invalid stream read value")
|
||||
self.assertEqual(s.dataLen(), 0, "not read all stream")
|
||||
@@ -223,8 +223,8 @@ class TypeCase(unittest.TestCase):
|
||||
"""
|
||||
@summary: test read UInt24Le type from stream
|
||||
"""
|
||||
s = rdpy.network.type.Stream('\x01\x00\x00')
|
||||
t = rdpy.network.type.UInt24Le()
|
||||
s = rdpy.core.type.Stream('\x01\x00\x00')
|
||||
t = rdpy.core.type.UInt24Le()
|
||||
s.readType(t)
|
||||
self.assertEqual(t.value, 1, "invalid stream read value")
|
||||
self.assertEqual(s.dataLen(), 0, "not read all stream")
|
||||
@@ -233,8 +233,8 @@ class TypeCase(unittest.TestCase):
|
||||
"""
|
||||
@summary: test read UInt24Be type from stream
|
||||
"""
|
||||
s = rdpy.network.type.Stream('\x00\x00\x01')
|
||||
t = rdpy.network.type.UInt24Be()
|
||||
s = rdpy.core.type.Stream('\x00\x00\x01')
|
||||
t = rdpy.core.type.UInt24Be()
|
||||
s.readType(t)
|
||||
self.assertEqual(t.value, 1, "invalid stream read")
|
||||
self.assertEqual(s.dataLen(), 0, "not read all stream")
|
||||
@@ -243,8 +243,8 @@ class TypeCase(unittest.TestCase):
|
||||
"""
|
||||
@summary: test read UInt32Le type from stream
|
||||
"""
|
||||
s = rdpy.network.type.Stream('\x01\x00\x00\x00')
|
||||
t = rdpy.network.type.UInt32Le()
|
||||
s = rdpy.core.type.Stream('\x01\x00\x00\x00')
|
||||
t = rdpy.core.type.UInt32Le()
|
||||
s.readType(t)
|
||||
self.assertEqual(t.value, 1, "invalid stream read value")
|
||||
self.assertEqual(s.dataLen(), 0, "not read all stream")
|
||||
@@ -253,8 +253,8 @@ class TypeCase(unittest.TestCase):
|
||||
"""
|
||||
@summary: test read UInt32Be type from stream
|
||||
"""
|
||||
s = rdpy.network.type.Stream('\x00\x00\x00\x01')
|
||||
t = rdpy.network.type.UInt32Be()
|
||||
s = rdpy.core.type.Stream('\x00\x00\x00\x01')
|
||||
t = rdpy.core.type.UInt32Be()
|
||||
s.readType(t)
|
||||
self.assertEqual(t.value, 1, "invalid stream read")
|
||||
self.assertEqual(s.dataLen(), 0, "not read all stream")
|
||||
@@ -264,9 +264,9 @@ class TypeCase(unittest.TestCase):
|
||||
@summary: test optional option in case of simple type reading
|
||||
"""
|
||||
#unsigned int case
|
||||
t = rdpy.network.type.SimpleType("I", 4, False, 0, optional = True)
|
||||
t = rdpy.core.type.SimpleType("I", 4, False, 0, optional = True)
|
||||
#empty stream
|
||||
s1 = rdpy.network.type.Stream()
|
||||
s1 = rdpy.core.type.Stream()
|
||||
s1.readType(t)
|
||||
self.assertEqual(t.value, 0, "invalid stream read optional value")
|
||||
|
||||
@@ -275,8 +275,8 @@ class TypeCase(unittest.TestCase):
|
||||
@summary: test conditional option in case of simple type reading and when condition is false (not read)
|
||||
"""
|
||||
#unsigned int case
|
||||
t = rdpy.network.type.SimpleType("I", 4, False, 0, conditional = lambda:False)
|
||||
s1 = rdpy.network.type.Stream("\x01\x00\x00\x00")
|
||||
t = rdpy.core.type.SimpleType("I", 4, False, 0, conditional = lambda:False)
|
||||
s1 = rdpy.core.type.Stream("\x01\x00\x00\x00")
|
||||
s1.readType(t)
|
||||
self.assertEqual(t.value, 0, "invalid stream read conditional value")
|
||||
|
||||
@@ -285,8 +285,8 @@ class TypeCase(unittest.TestCase):
|
||||
@summary: test conditional option in case of simple type reading and when condition is true (must be read)
|
||||
"""
|
||||
#unsigned int case
|
||||
t = rdpy.network.type.SimpleType("I", 4, False, 0, conditional = lambda:True)
|
||||
s1 = rdpy.network.type.Stream("\x01\x00\x00\x00")
|
||||
t = rdpy.core.type.SimpleType("I", 4, False, 0, conditional = lambda:True)
|
||||
s1 = rdpy.core.type.Stream("\x01\x00\x00\x00")
|
||||
s1.readType(t)
|
||||
self.assertEqual(t.value, 1, "invalid stream read conditional value")
|
||||
|
||||
@@ -294,13 +294,13 @@ class TypeCase(unittest.TestCase):
|
||||
"""
|
||||
@summary: test if constant constraint fail, the reading stream is correctly rollback
|
||||
"""
|
||||
class TestComposite(rdpy.network.type.CompositeType):
|
||||
class TestComposite(rdpy.core.type.CompositeType):
|
||||
def __init__(self):
|
||||
rdpy.network.type.CompositeType.__init__(self)
|
||||
self.padding = rdpy.network.type.UInt32Le(0)
|
||||
self.constraint = rdpy.network.type.UInt32Le(1, constant = True)
|
||||
rdpy.core.type.CompositeType.__init__(self)
|
||||
self.padding = rdpy.core.type.UInt32Le(0)
|
||||
self.constraint = rdpy.core.type.UInt32Le(1, constant = True)
|
||||
|
||||
s = rdpy.network.type.Stream("\x00\x00\x00\x00\x00\x00\x00\x00")
|
||||
s = rdpy.core.type.Stream("\x00\x00\x00\x00\x00\x00\x00\x00")
|
||||
try:
|
||||
s.readType(TestComposite())
|
||||
except Exception:
|
||||
@@ -313,19 +313,19 @@ class TypeCase(unittest.TestCase):
|
||||
@summary: test if constant constraint fail even in recurcive composite type,
|
||||
the reading stream is correctly rollback
|
||||
"""
|
||||
class TestSubComposite(rdpy.network.type.CompositeType):
|
||||
class TestSubComposite(rdpy.core.type.CompositeType):
|
||||
def __init__(self):
|
||||
rdpy.network.type.CompositeType.__init__(self)
|
||||
self.padding = rdpy.network.type.UInt32Le(0)
|
||||
self.constraint = rdpy.network.type.UInt32Le(1, constant = True)
|
||||
rdpy.core.type.CompositeType.__init__(self)
|
||||
self.padding = rdpy.core.type.UInt32Le(0)
|
||||
self.constraint = rdpy.core.type.UInt32Le(1, constant = True)
|
||||
|
||||
class TestComposite(rdpy.network.type.CompositeType):
|
||||
class TestComposite(rdpy.core.type.CompositeType):
|
||||
def __init__(self):
|
||||
rdpy.network.type.CompositeType.__init__(self)
|
||||
self.padding = rdpy.network.type.UInt32Le(0)
|
||||
rdpy.core.type.CompositeType.__init__(self)
|
||||
self.padding = rdpy.core.type.UInt32Le(0)
|
||||
self.recurcive = TestSubComposite()
|
||||
|
||||
s = rdpy.network.type.Stream("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
||||
s = rdpy.core.type.Stream("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
||||
try:
|
||||
s.readType(TestComposite())
|
||||
except Exception:
|
||||
@@ -338,19 +338,19 @@ class TypeCase(unittest.TestCase):
|
||||
@summary: test if constant constraint fail even in recurcive composite type,
|
||||
the reading stream is correctly rollback
|
||||
"""
|
||||
class TestSubComposite(rdpy.network.type.CompositeType):
|
||||
class TestSubComposite(rdpy.core.type.CompositeType):
|
||||
def __init__(self):
|
||||
rdpy.network.type.CompositeType.__init__(self)
|
||||
self.padding = rdpy.network.type.UInt32Le(0)
|
||||
self.constraint = rdpy.network.type.UInt32Le(1)
|
||||
rdpy.core.type.CompositeType.__init__(self)
|
||||
self.padding = rdpy.core.type.UInt32Le(0)
|
||||
self.constraint = rdpy.core.type.UInt32Le(1)
|
||||
|
||||
class TestComposite(rdpy.network.type.CompositeType):
|
||||
class TestComposite(rdpy.core.type.CompositeType):
|
||||
def __init__(self):
|
||||
rdpy.network.type.CompositeType.__init__(self)
|
||||
self.padding = rdpy.network.type.UInt32Le(0)
|
||||
rdpy.core.type.CompositeType.__init__(self)
|
||||
self.padding = rdpy.core.type.UInt32Le(0)
|
||||
self.recurcive = TestSubComposite()
|
||||
|
||||
s = rdpy.network.type.Stream("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
||||
s = rdpy.core.type.Stream("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
||||
try:
|
||||
s.readType(TestComposite())
|
||||
except Exception:
|
||||
@@ -364,12 +364,12 @@ class TypeCase(unittest.TestCase):
|
||||
if total stream read length < to forced read length
|
||||
the trash must be read as padding
|
||||
"""
|
||||
class TestReadLength(rdpy.network.type.CompositeType):
|
||||
class TestReadLength(rdpy.core.type.CompositeType):
|
||||
def __init__(self, readLen):
|
||||
rdpy.network.type.CompositeType.__init__(self, readLen = readLen)
|
||||
self.padding = rdpy.network.type.UInt32Le(0)
|
||||
s = rdpy.network.type.Stream("\x00" * 10)
|
||||
s.readType(TestReadLength(rdpy.network.type.UInt8(10)))
|
||||
rdpy.core.type.CompositeType.__init__(self, readLen = readLen)
|
||||
self.padding = rdpy.core.type.UInt32Le(0)
|
||||
s = rdpy.core.type.Stream("\x00" * 10)
|
||||
s.readType(TestReadLength(rdpy.core.type.UInt8(10)))
|
||||
self.assertEqual(s.dataLen(), 0, "invalid stream read trash data as padding")
|
||||
|
||||
def test_stream_read_with_static_length_inferior(self):
|
||||
@@ -378,12 +378,12 @@ class TypeCase(unittest.TestCase):
|
||||
if total stream read length > to forced read length
|
||||
an InvalidSize exception is throw
|
||||
"""
|
||||
class TestReadLength(rdpy.network.type.CompositeType):
|
||||
class TestReadLength(rdpy.core.type.CompositeType):
|
||||
def __init__(self, readLen):
|
||||
rdpy.network.type.CompositeType.__init__(self, readLen = readLen)
|
||||
self.padding = rdpy.network.type.UInt32Le(0)
|
||||
s = rdpy.network.type.Stream("\x00" * 10)
|
||||
self.assertRaises(InvalidSize, s.readType, TestReadLength(rdpy.network.type.UInt8(2)))
|
||||
rdpy.core.type.CompositeType.__init__(self, readLen = readLen)
|
||||
self.padding = rdpy.core.type.UInt32Le(0)
|
||||
s = rdpy.core.type.Stream("\x00" * 10)
|
||||
self.assertRaises(InvalidSize, s.readType, TestReadLength(rdpy.core.type.UInt8(2)))
|
||||
|
||||
def test_stream_read_string(self):
|
||||
"""
|
||||
|
||||
@@ -27,8 +27,8 @@ sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
|
||||
import unittest
|
||||
import rdpy.protocol.rdp.ber as ber
|
||||
import rdpy.network.type as type
|
||||
import rdpy.base.error as error
|
||||
import rdpy.core.type as type
|
||||
import rdpy.core.error as error
|
||||
|
||||
class BERCase(unittest.TestCase):
|
||||
"""
|
||||
|
||||
@@ -27,8 +27,8 @@ sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
|
||||
import unittest
|
||||
import rdpy.protocol.rdp.per as per
|
||||
import rdpy.network.type as type
|
||||
import rdpy.base.error as error
|
||||
import rdpy.core.type as type
|
||||
import rdpy.core.error as error
|
||||
|
||||
class PERCase(unittest.TestCase):
|
||||
"""
|
||||
|
||||
@@ -27,8 +27,8 @@ sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
|
||||
import unittest
|
||||
import rdpy.protocol.rdp.tpkt as tpkt
|
||||
import rdpy.network.type as type
|
||||
import rdpy.base.error as error
|
||||
import rdpy.core.type as type
|
||||
import rdpy.core.error as error
|
||||
|
||||
class TPKTCase(unittest.TestCase):
|
||||
"""
|
||||
|
||||
@@ -27,8 +27,8 @@ sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
|
||||
import unittest
|
||||
import rdpy.protocol.rdp.x224 as x224
|
||||
import rdpy.network.type as type
|
||||
import rdpy.base.error as error
|
||||
import rdpy.core.type as type
|
||||
import rdpy.core.error as error
|
||||
|
||||
class X224Case(unittest.TestCase):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user