work on bitwise operator
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
'''
|
||||
@author: sylvain
|
||||
'''
|
||||
from rdpy.protocol.network.type import UInt16Le
|
||||
from rdpy.protocol.network.type import UInt8, UInt16Be
|
||||
from rdpy.utils.const import ConstAttributes
|
||||
from rdpy.protocol.network.error import InvalidExpectedDataException
|
||||
|
||||
@ConstAttributes
|
||||
class BerPc(object):
|
||||
BER_PC_MASK = UInt16Le(0x20)
|
||||
BER_PRIMITIVE = UInt16Le(0x00)
|
||||
BER_CONSTRUCT = UInt16Le(0x20)
|
||||
BER_PC_MASK = UInt8(0x20)
|
||||
BER_PRIMITIVE = UInt8(0x00)
|
||||
BER_CONSTRUCT = UInt8(0x20)
|
||||
|
||||
def berPC(pc):
|
||||
'''
|
||||
@@ -19,4 +20,33 @@ def berPC(pc):
|
||||
return BerPc.BER_CONSTRUCT
|
||||
else:
|
||||
return BerPc.BER_PRIMITIVE
|
||||
|
||||
|
||||
def readLength(s):
|
||||
'''
|
||||
read length of ber structure
|
||||
length be on 1 2 or 3 bytes
|
||||
'''
|
||||
size = None
|
||||
byte = UInt8()
|
||||
s.readType(byte)
|
||||
if (byte & UInt8(0x80)) == UInt8(0x80):
|
||||
byte &= ~UInt8(0x80)
|
||||
if byte == UInt8(1):
|
||||
size = UInt8()
|
||||
elif byte == UInt8(2):
|
||||
size = UInt16Be()
|
||||
else:
|
||||
raise InvalidExpectedDataException("ber length may be 1 or 2")
|
||||
s.readType(size)
|
||||
else:
|
||||
size = byte
|
||||
return size
|
||||
|
||||
def writeLength(size):
|
||||
'''
|
||||
write length as expected in Ber specification
|
||||
'''
|
||||
if size > UInt16Be(0x7f):
|
||||
return (UInt8(0x82), size)
|
||||
else:
|
||||
return UInt8(size.value)
|
||||
3
rdpy/protocol/rdp/per.py
Normal file
3
rdpy/protocol/rdp/per.py
Normal file
@@ -0,0 +1,3 @@
|
||||
'''
|
||||
@author: sylvain
|
||||
'''
|
||||
@@ -136,12 +136,10 @@ class TPDU(LayerAutomata):
|
||||
if negResp.len != UInt16Le(0x0008):
|
||||
raise InvalidExpectedDataException("invalid size of negotiation response")
|
||||
|
||||
protocol = negResp.protocol
|
||||
if protocol != self._protocol:
|
||||
raise NegotiationFailure("protocol negotiation failure")
|
||||
self._protocol = negResp.protocol
|
||||
|
||||
#_transport is TPKT and transport is TCP layer of twisted
|
||||
if self._protocol == Protocols.PROTOCOL_SSL:
|
||||
#_transport is TPKT and transport is TCP layer of twisted
|
||||
self._transport.transport.startTLS(ClientTLSContext())
|
||||
else:
|
||||
raise NegotiationFailure("protocol negociation failure")
|
||||
|
||||
Reference in New Issue
Block a user