def readEncryptedPayload(self, s, saltedMacGeneration): """ @summary: decrypt basic RDP security payload @param s: {Stream} encrypted stream @param saltedMacGeneration: {bool} use salted mac generation @return: {Stream} decrypted """ #if update is needed if self._nbDecryptedPacket == 4096: log.debug("update decrypt key") self._currentDecrytKey = updateKey( self._initialDecrytKey, self._currentDecrytKey, self.getGCCServerSettings().SC_SECURITY.encryptionMethod.value) self._decryptRc4 = rc4.RC4Key(self._currentDecrytKey) self._nbDecryptedPacket = 0 signature = String(readLen = CallableValue(8)) encryptedPayload = String() s.readType((signature, encryptedPayload)) decrypted = rc4.crypt(self._decryptRc4, encryptedPayload.value) #ckeck signature if not saltedMacGeneration and macData(self._macKey, decrypted)[:8] != signature.value: raise InvalidExpectedDataException("bad signature") if saltedMacGeneration and macSaltedData(self._macKey, decrypted, self._nbDecryptedPacket)[:8] != signature.value: raise InvalidExpectedDataException("bad signature") #count self._nbDecryptedPacket += 1 return Stream(decrypted)
def readInteger(s): """ @summary: Read integer structure from stream @param s: stream @return: int or long python """ if not readUniversalTag(s, Tag.BER_TAG_INTEGER, False): raise InvalidExpectedDataException("Bad integer tag") size = readLength(s) if size == 1: integer = UInt8() s.readType(integer) return integer.value elif size == 2: integer = UInt16Be() s.readType(integer) return integer.value elif size == 3: integer1 = UInt8() integer2 = UInt16Be() s.readType(integer1) s.readType(integer2) return integer2.value + (integer1.value << 16) elif size == 4: integer = UInt32Be() s.readType(integer) return integer.value else: raise InvalidExpectedDataException("Wrong integer size")
def recvChannelJoinRequest(self, data): """ @summary: Receive for each client channel a request Send Channel Join Confirm or Connect upper layer when all channel are joined @param data: {Stream} """ opcode = UInt8() data.readType(opcode) if not self.readMCSPDUHeader(opcode.value, DomainMCSPDU.CHANNEL_JOIN_REQUEST): raise InvalidExpectedDataException( "Invalid MCS PDU : CHANNEL_JOIN_REQUEST expected") userId = per.readInteger16(data, Channel.MCS_USERCHANNEL_BASE) if self._userId != userId: raise InvalidExpectedDataException("Invalid MCS User Id") channelId = per.readInteger16(data) #actually algo support virtual channel but RDPY have no virtual channel confirm = 0 if channelId in self._channels.keys( ) or channelId == self._userId else 1 self.sendChannelJoinConfirm(channelId, confirm) self._nbChannelConfirmed += 1 if self._nbChannelConfirmed == self._serverSettings.getBlock( gcc.MessageType.SC_NET).channelCount.value + 2: self.allChannelConnected()
def recvChannelJoinConfirm(self, data): """ @summary: Receive a channel join confirm from server client automata function @param data: {Stream} """ opcode = UInt8() data.readType(opcode) if not self.readMCSPDUHeader(opcode.value, DomainMCSPDU.CHANNEL_JOIN_CONFIRM): raise InvalidExpectedDataException( "Invalid MCS PDU : CHANNEL_JOIN_CONFIRM expected") confirm = per.readEnumerates(data) userId = per.readInteger16(data, Channel.MCS_USERCHANNEL_BASE) if self._userId != userId: raise InvalidExpectedDataException("Invalid MCS User Id") channelId = per.readInteger16(data) #must confirm global channel and user channel if (confirm != 0) and (channelId == Channel.MCS_GLOBAL_CHANNEL or channelId == self._userId): raise InvalidExpectedDataException( "Server must confirm static channel") if confirm == 0: serverNet = self._serverSettings.getBlock(gcc.MessageType.SC_NET) for i in range(0, serverNet.channelCount.value): if channelId == serverNet.channelIdArray[i].value: self._channels[channelId] = self._virtualChannels[i][1] self.connectNextChannel()
def readConferenceCreateRequest(s): """ @summary: Read a response from client GCC create request @param s: Stream @param client settings (Settings) """ per.readChoice(s) per.readObjectIdentifier(s, t124_02_98_oid) per.readLength(s) per.readChoice(s) per.readSelection(s) per.readNumericString(s, 1) per.readPadding(s, 1) if per.readNumberOfSet(s) != 1: raise InvalidExpectedDataException( "Invalid number of set in readConferenceCreateRequest") if per.readChoice(s) != 0xc0: raise InvalidExpectedDataException( "Invalid choice in readConferenceCreateRequest") per.readOctetStream(s, h221_cs_key, 4) length = per.readLength(s) clientSettings = Settings(readLen=CallableValue(length)) s.readType(clientSettings) return clientSettings
def readBoolean(s): """ @summary: Return boolean @param s: stream @return: boolean """ if not readUniversalTag(s, Tag.BER_TAG_BOOLEAN, False): raise InvalidExpectedDataException("bad boolean tag") size = readLength(s) if size != 1: raise InvalidExpectedDataException("bad boolean size") b = UInt8() s.readType(b) return bool(b.value)
def readObjectIdentifier(s, oid): """ @summary: read object identifier @param oid: must be a tuple of 6 elements @param s: Stream @return: true if oid is same as in stream """ size = readLength(s) if size != 5: raise InvalidValue("size of stream oid is wrong %d != 5" % size) a_oid = [0, 0, 0, 0, 0, 0] t12 = UInt8() s.readType(t12) a_oid[0] = t12.value >> 4 a_oid[1] = t12.value & 0x0f s.readType(t12) a_oid[2] = t12.value s.readType(t12) a_oid[3] = t12.value s.readType(t12) a_oid[4] = t12.value s.readType(t12) a_oid[5] = t12.value if list(oid) != a_oid: raise InvalidExpectedDataException("invalid object identifier")
def __init__(self, updateData=None): CompositeType.__init__(self) self.updateHeader = UInt8( lambda: updateData.__class__._FASTPATH_UPDATE_TYPE_) self.compressionFlags = UInt8(conditional=lambda: ( (self.updateHeader.value >> 4 ) & FastPathOutputCompression.FASTPATH_OUTPUT_COMPRESSION_USED)) self.size = UInt16Le(lambda: sizeof(self.updateData)) def UpdateDataFactory(): """ @summary: Create correct object in accordance to self.updateHeader field """ for c in [FastPathBitmapUpdateDataPDU]: if (self.updateHeader.value & 0xf) == c._FASTPATH_UPDATE_TYPE_: return c() log.debug("unknown Fast Path PDU update data type : %s" % hex(self.updateHeader.value & 0xf)) return String() if updateData is None: updateData = FactoryType(UpdateDataFactory) elif not "_FASTPATH_UPDATE_TYPE_" in updateData.__class__.__dict__: raise InvalidExpectedDataException( "Try to send an invalid fast path data update PDU") self.updateData = updateData
def __init__(self, updateData=None, readLen=None): """ @param updateType: UpdateType macro @param updateData: Update data PDU in accordance with updateType (BitmapUpdateDataPDU) @param readLen: Max length to read """ CompositeType.__init__(self, readLen=readLen) self.updateType = UInt16Le(lambda: updateData.__class__._UPDATE_TYPE_) def UpdateDataFactory(): """ @summary: Create object in accordance self.updateType value """ for c in [BitmapUpdateDataPDU]: if self.updateType.value == c._UPDATE_TYPE_: return c() log.debug("unknown PDU update data type : %s" % hex(self.updateType.value)) return String() if updateData is None: updateData = FactoryType( UpdateDataFactory, conditional=lambda: (self.updateType.value != UpdateType.UPDATETYPE_SYNCHRONIZE)) elif not "_UPDATE_TYPE_" in updateData.__class__.__dict__: raise InvalidExpectedDataException( "Try to send an invalid data update PDU") self.updateData = updateData
def __init__(self, pduData=None, shareId=0): CompositeType.__init__(self) self.shareDataHeader = ShareDataHeader( lambda: sizeof(self), lambda: self.pduData.__class__._PDUTYPE2_, shareId) def PDUDataFactory(): """ @summary: Create object in accordance self.shareDataHeader.pduType2 value """ for c in [ UpdateDataPDU, SynchronizeDataPDU, ControlDataPDU, ErrorInfoDataPDU, FontListDataPDU, FontMapDataPDU, PersistentListPDU, ClientInputEventPDU, ShutdownDeniedPDU, ShutdownRequestPDU, SupressOutputDataPDU ]: if self.shareDataHeader.pduType2.value == c._PDUTYPE2_: return c() log.debug("unknown PDU data type : %s" % hex(self.shareDataHeader.pduType2.value)) return String() if pduData is None: pduData = FactoryType(PDUDataFactory) elif not "_PDUTYPE2_" in pduData.__class__.__dict__: raise InvalidExpectedDataException( "Try to send an invalid data PDU") self.pduData = pduData
def __init__(self, userId=0, pduMessage=None): CompositeType.__init__(self) self.shareControlHeader = ShareControlHeader( lambda: sizeof(self), lambda: pduMessage.__class__._PDUTYPE_, userId) def PDUMessageFactory(): """ @summary: build message in accordance of type self.shareControlHeader.pduType.value """ for c in [ DemandActivePDU, ConfirmActivePDU, DataPDU, DeactiveAllPDU ]: if self.shareControlHeader.pduType.value == c._PDUTYPE_: return c() log.debug("unknown PDU type : %s" % hex(self.shareControlHeader.pduType.value)) #read entire packet return String() if pduMessage is None: pduMessage = FactoryType(PDUMessageFactory) elif not "_PDUTYPE_" in pduMessage.__class__.__dict__: raise InvalidExpectedDataException("Try to send an invalid PDU") self.pduMessage = pduMessage
def recvConnectResponse(self, data): """ @summary: Receive MCS connect response from server Send Erect domain Request Send Attach User Request Wait Attach User Confirm @param data: {Stream} """ ber.readApplicationTag(data, UInt8(Message.MCS_TYPE_CONNECT_RESPONSE)) ber.readEnumerated(data) ber.readInteger(data) self.readDomainParams(data) if not ber.readUniversalTag(data, ber.Tag.BER_TAG_OCTET_STRING, False): raise InvalidExpectedDataException("invalid expected BER tag") gccRequestLength = ber.readLength(data) if data.dataLen() != gccRequestLength: raise InvalidSize("bad size of GCC request") self._serverSettings = gcc.readConferenceCreateResponse(data) #send domain request self.sendErectDomainRequest() #send attach user request self.sendAttachUserRequest() #now wait user confirm from server self.setNextState(self.recvAttachUserConfirm)
def sendClientChallengeResponse(self, platformChallenge): """ @summary: generate valid challenge response @param platformChallenge: {ServerPlatformChallenge} """ serverEncryptedChallenge = platformChallenge.encryptedPlatformChallenge.blobData.value #decrypt server challenge #it should be TEST word in unicode format serverChallenge = rc4.crypt(rc4.RC4Key(self._licenseKey), serverEncryptedChallenge) if serverChallenge != "T\x00E\x00S\x00T\x00\x00\x00": raise InvalidExpectedDataException("bad license server challenge") #generate hwid s = Stream() s.writeType((UInt32Le(2), String(self._hostname + self._username + "\x00" * 16))) hwid = s.getvalue()[:20] message = ClientPLatformChallengeResponse() message.encryptedPlatformChallengeResponse.blobData.value = serverEncryptedChallenge message.encryptedHWID.blobData.value = rc4.crypt( rc4.RC4Key(self._licenseKey), hwid) message.MACData.value = sec.macData(self._macSalt, serverChallenge + hwid) self._transport.sendFlagged(sec.SecurityFlag.SEC_LICENSE_PKT, LicPacket(message))
def __init__(self, message=None): CompositeType.__init__(self) #preambule self.bMsgtype = UInt8( lambda: self.licensingMessage.__class__._MESSAGE_TYPE_) self.flag = UInt8(Preambule.PREAMBLE_VERSION_3_0) self.wMsgSize = UInt16Le(lambda: sizeof(self)) def LicensingMessageFactory(): """ @summary: factory for message nego Use in read mode """ for c in [ LicensingErrorMessage, ServerLicenseRequest, ClientNewLicenseRequest, ServerPlatformChallenge, ClientPLatformChallengeResponse ]: if self.bMsgtype.value == c._MESSAGE_TYPE_: return c(readLen=self.wMsgSize - 4) log.debug("unknown license message : %s" % self.bMsgtype.value) return String() if message is None: message = FactoryType(LicensingMessageFactory) elif not "_MESSAGE_TYPE_" in message.__class__.__dict__: raise InvalidExpectedDataException( "Try to send an invalid license message") self.licensingMessage = message
def recv(self, s): """ @summary: receive license packet from PDU layer @return true when license automata is finish """ licPacket = LicPacket() s.readType(licPacket) #end of automata if licPacket.bMsgtype.value == MessageType.ERROR_ALERT and licPacket.licensingMessage.dwErrorCode.value == ErrorCode.STATUS_VALID_CLIENT and licPacket.licensingMessage.dwStateTransition.value == StateTransition.ST_NO_TRANSITION: return True elif licPacket.bMsgtype.value == MessageType.LICENSE_REQUEST: self.sendClientNewLicenseRequest(licPacket.licensingMessage) return False elif licPacket.bMsgtype.value == MessageType.PLATFORM_CHALLENGE: self.sendClientChallengeResponse(licPacket.licensingMessage) return False #yes get a new license elif licPacket.bMsgtype.value == MessageType.NEW_LICENSE: return True else: raise InvalidExpectedDataException("Not a valid license packet")
def __init__(self, capability=None): CompositeType.__init__(self) self.capabilitySetType = UInt16Le(lambda: capability.__class__._TYPE_) self.lengthCapability = UInt16Le(lambda: sizeof(self)) def CapabilityFactory(): """ Closure for capability factory """ for c in [ GeneralCapability, BitmapCapability, OrderCapability, BitmapCacheCapability, BitmapCacheRev2Capability, PointerCapability, InputCapability, BrushCapability, GlyphCapability, OffscreenBitmapCacheCapability, VirtualChannelCapability, SoundCapability, ControlCapability, WindowActivationCapability, FontCapability, ColorCacheCapability, ShareCapability, MultiFragmentUpdate ]: 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 return String(readLen=self.lengthCapability - 4) if capability is None: capability = FactoryType(CapabilityFactory) elif not "_TYPE_" in capability.__class__.__dict__: raise InvalidExpectedDataException( "Try to send an invalid capability block") self.capability = capability
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") if securityFlag.value & SecurityFlag.SEC_ENCRYPT: s = self.readEncryptedPayload(s, securityFlag.value & SecurityFlag.SEC_SECURE_CHECKSUM) s.readType(self._info) #next state send error license self.sendLicensingErrorMessage() #reinit state self.setNextState() self._presentation.connect()
def generateKeys(clientRandom, serverRandom, method): """ @param method: {gcc.Encryption} @param clientRandom: {str[32]} client random @param serverRandom: {str[32]} server random @see: http://msdn.microsoft.com/en-us/library/cc240785.aspx @return: MACKey, initialFirstKey128(ClientdecryptKey, serverEncryptKey), initialSecondKey128(ServerDecryptKey, ClientEncryptKey) """ preMasterHash = clientRandom[:24] + serverRandom[:24] masterHash = masterSecret(preMasterHash, clientRandom, serverRandom) sessionKey = sessionKeyBlob(masterHash, clientRandom, serverRandom) macKey128 = sessionKey[:16] initialFirstKey128 = finalHash(sessionKey[16:32], clientRandom, serverRandom) initialSecondKey128 = finalHash(sessionKey[32:48], clientRandom, serverRandom) #generate valid key if method == gcc.EncryptionMethod.ENCRYPTION_FLAG_40BIT: return gen40bits(macKey128), gen40bits(initialFirstKey128), gen40bits(initialSecondKey128) elif method == gcc.EncryptionMethod.ENCRYPTION_FLAG_56BIT: return gen56bits(macKey128), gen56bits(initialFirstKey128), gen56bits(initialSecondKey128) elif method == gcc.EncryptionMethod.ENCRYPTION_FLAG_128BIT: return macKey128, initialFirstKey128, initialSecondKey128 raise InvalidExpectedDataException("Bad encryption method")
def __init__(self, dataBlock=None): CompositeType.__init__(self) self.type = UInt16Le(lambda: self.dataBlock.__class__._TYPE_) self.length = UInt16Le(lambda: sizeof(self)) def DataBlockFactory(): """ @summary: build settings in accordance of type self.type.value """ for c in [ ClientCoreData, ClientSecurityData, ClientNetworkData, ServerCoreData, ServerNetworkData, ServerSecurityData ]: if self.type.value == c._TYPE_: return c(readLen=self.length - 4) log.debug("unknown GCC block type : %s" % hex(self.type.value)) #read entire packet return String(readLen=self.length - 4) if dataBlock is None: dataBlock = FactoryType(DataBlockFactory) elif not "_TYPE_" in dataBlock.__class__.__dict__: raise InvalidExpectedDataException( "Try to send an invalid GCC blocks") self.dataBlock = dataBlock
def recvConnectInitial(self, data): """ @summary: Receive MCS connect initial from client Send Connect Response Wait Erect Domain Request @param data: {Stream} """ ber.readApplicationTag(data, UInt8(Message.MCS_TYPE_CONNECT_INITIAL)) ber.readOctetString(data) ber.readOctetString(data) if not ber.readBoolean(data): raise InvalidExpectedDataException( "invalid expected BER boolean tag") self.readDomainParams(data) self.readDomainParams(data) self.readDomainParams(data) self._clientSettings = gcc.readConferenceCreateRequest( Stream(ber.readOctetString(data))) if not self._clientSettings.CS_NET is None: i = 1 for channelDef in self._clientSettings.CS_NET.channelDefArray._array: self._serverSettings.SC_NET.channelIdArray._array.append( UInt16Le(i + Channel.MCS_GLOBAL_CHANNEL)) #if channel can be handle by serve add it for serverChannelDef, layer in self._virtualChannels: if channelDef.name == serverChannelDef.name: self._channels[i + Channel.MCS_GLOBAL_CHANNEL] = layer i += 1 self.sendConnectResponse() self.setNextState(self.recvErectDomainRequest)
def recvData(self, data): """ @summary: Main receive method @param data: {Stream} """ opcode = UInt8() data.readType(opcode) if self.readMCSPDUHeader(opcode.value, DomainMCSPDU.DISCONNECT_PROVIDER_ULTIMATUM): log.info("MCS DISCONNECT_PROVIDER_ULTIMATUM") self._transport.close() return #client case elif not self.readMCSPDUHeader(opcode.value, self._receiveOpcode): raise InvalidExpectedDataException( "Invalid expected MCS opcode receive data") #server user id per.readInteger16(data, Channel.MCS_USERCHANNEL_BASE) channelId = per.readInteger16(data) per.readEnumerates(data) per.readLength(data) #channel id doesn't match a requested layer if not self._channels.has_key(channelId): log.error("receive data for an unconnected layer") return self._channels[channelId].recv(data)
def read(self, s): """ @summary: Check conditional callback Call __read__ function And check constness state after @param s: Stream @raise InvalidExpectedDataException: if constness is not respected """ self._is_readed = self._conditional() if not self._is_readed: return #not constant mode direct reading if not self._constant: self.__read__(s) return #constant mode old = deepcopy(self) self.__read__(s) #check constant value if old != self: #rollback read value s.pos -= sizeof(self) raise InvalidExpectedDataException( "%s const value expected %s != %s" % (self.__class__, old.value, self.value))
def recvClientRandom(self, s): """ @summary: receive client random and generate session keys @param s: {Stream} """ #packet preambule securityFlag = UInt16Le() securityFlagHi = UInt16Le() s.readType((securityFlag, securityFlagHi)) if not (securityFlag.value & SecurityFlag.SEC_EXCHANGE_PKT): raise InvalidExpectedDataException("waiting client random") message = ClientSecurityExchangePDU() s.readType(message) clientRandom = rsa.decrypt(message.encryptedClientRandom.value[::-1], self._rsaPrivateKey)[::-1] self._macKey, self._initialEncryptKey, self._initialDecrytKey = generateKeys( clientRandom, self.getGCCServerSettings().SC_SECURITY.serverRandom.value, self.getGCCServerSettings().SC_SECURITY.encryptionMethod.value) #initialize keys self._currentDecrytKey = self._initialDecrytKey self._currentEncryptKey = self._initialEncryptKey self._decryptRc4 = rc4.RC4Key(self._currentDecrytKey) self._encryptRc4 = rc4.RC4Key(self._currentEncryptKey) self.setNextState(self.recvInfoPkt)
def CertificateFactory(): """ Closure for capability factory """ for c in [ProprietaryServerCertificate, X509CertificateChain]: if self.dwVersion.value & 0x7fffffff == c._TYPE_: return c() raise InvalidExpectedDataException( "unknown certificate type : %s " % hex(self.dwVersion.value))
def recvAttachUserConfirm(self, data): """ @summary: Receive an attach user confirm Send Connect Channel @param data: {Stream} """ opcode = UInt8() data.readType(opcode) if not self.readMCSPDUHeader(opcode.value, DomainMCSPDU.ATTACH_USER_CONFIRM): raise InvalidExpectedDataException("Invalid MCS PDU : ATTACH_USER_CONFIRM expected") if per.readEnumerates(data) != 0: raise InvalidExpectedDataException("Server reject user") self._userId = per.readInteger16(data, Channel.MCS_USERCHANNEL_BASE) self.connectNextChannel()
def readOctetString(s): """ @summary: Read BER string structure @param s: stream @return: string python """ if not readUniversalTag(s, Tag.BER_TAG_OCTET_STRING, False): raise InvalidExpectedDataException("Unexpected BER tag") size = readLength(s) return s.read(size)
def recvConnectionConfirm(self, data): """ @summary: Receive connection confirm message Next state is recvData Call connect on presentation layer if all is good @param data: Stream that contain connection confirm @see: response -> http://msdn.microsoft.com/en-us/library/cc240506.aspx @see: failure ->http://msdn.microsoft.com/en-us/library/cc240507.aspx """ message = ServerConnectionConfirm() data.readType(message) if message.protocolNeg.failureCode._is_readed: pass #check presence of negotiation response if message.protocolNeg._is_readed: self._selectedProtocol = message.protocolNeg.selectedProtocol.value else: self._selectedProtocol = Protocols.PROTOCOL_RDP #NLA protocol doesn't support in actual version of RDPY if self._selectedProtocol in [Protocols.PROTOCOL_HYBRID_EX]: raise InvalidExpectedDataException( "RDPY doesn't support PROTOCOL_HYBRID_EX security Layer") #now i'm ready to receive data self.setNextState(self.recvData) if self._selectedProtocol == Protocols.PROTOCOL_RDP: log.warning('Client connected using RDP Security') # log.warning("*" * 43) # log.warning("*" + " " * 10 + "RDP Security selected" + " " * 10 + "*") # log.warning("*" * 43) #connection is done send to presentation self._presentation.connect() elif self._selectedProtocol == Protocols.PROTOCOL_SSL: log.warning('Client connected using SSL Security') # log.info("*" * 43) # log.info("*" + " " * 10 + "SSL Security selected" + " " * 10 + "*") # log.info("*" * 43) self._transport.startTLS(ClientTLSContext()) #connection is done send to presentation self._presentation.connect() elif self._selectedProtocol == Protocols.PROTOCOL_HYBRID: log.warning('Client connected using NLA Security') # log.info("*" * 43) # log.info("*" + " " * 10 + "NLA Security selected" + " " * 10 + "*") # log.info("*" * 43) self._transport.startNLA(ClientTLSContext(), lambda: self._presentation.connect())
def readApplicationTag(s, tag): """ @summary: Read application tag @param s: stream @param tag: tag class attributes @return: length of application packet """ byte = UInt8() s.readType(byte) if tag.value > 30: if byte.value != ( (Class.BER_CLASS_APPL | BerPc.BER_CONSTRUCT) | Tag.BER_TAG_MASK): raise InvalidExpectedDataException() s.readType(byte) if byte.value != tag.value: raise InvalidExpectedDataException("bad tag") else: if byte.value != ((Class.BER_CLASS_APPL | BerPc.BER_CONSTRUCT) | (Tag.BER_TAG_MASK & tag)): raise InvalidExpectedDataException() return readLength(s)
def readEnumerated(s): """ @summary: Read enumerated structure @param s: Stream @return: int or long """ if not readUniversalTag(s, Tag.BER_TAG_ENUMERATED, False): raise InvalidExpectedDataException("invalid ber tag") if readLength(s) != 1: raise InvalidSize("enumerate size is wrong") enumer = UInt8() s.readType(enumer) return enumer.value
def recvAttachUserRequest(self, data): """ @summary: Receive Attach user request Send Attach User Confirm Wait Channel Join Request @param data: {Stream} """ opcode = UInt8() data.readType(opcode) if not self.readMCSPDUHeader(opcode.value, DomainMCSPDU.ATTACH_USER_REQUEST): raise InvalidExpectedDataException("Invalid MCS PDU : ATTACH_USER_REQUEST expected") self.sendAttachUserConfirm() self.setNextState(self.recvChannelJoinRequest)