private void ChannelJoinRequestAndConfirm() { // Add all SVC ids in a List List <long> chIdList = new List <long>(); // Add User channel chIdList.Add(rdpbcgrClient.Context.UserChannelId); // Add IO channel chIdList.Add(rdpbcgrClient.Context.IOChannelId); // Add message channel if exist long?msgChId = rdpbcgrClient.Context.MessageChannelId; if (msgChId != null) { chIdList.Add(msgChId.Value); } // Add the other channels from server network data if (rdpbcgrClient.Context.VirtualChannelIdStore != null) { for (int i = 0; i < rdpbcgrClient.Context.VirtualChannelIdStore.Length; i++) { chIdList.Add((long)rdpbcgrClient.Context.VirtualChannelIdStore[i]); } } // Start join request and confirm sequence foreach (long channelId in chIdList) { SendClientMCSChannelJoinRequest(channelId); Server_MCS_Channel_Join_Confirm_Pdu confirm = ExpectPacket <Server_MCS_Channel_Join_Confirm_Pdu>(timeout); } }
/// <summary> /// Complete the channel join sequence /// </summary> public void ChannelJoinRequestAndConfirm() { // Add all SVC ids in a List List <long> chIdList = new List <long>(); // Add User channel chIdList.Add(rdpbcgrClientStack.Context.UserChannelId); // Add IO channel chIdList.Add(rdpbcgrClientStack.Context.IOChannelId); // Add message channel if exist long?msgChId = rdpbcgrClientStack.Context.MessageChannelId; if (msgChId != null) { chIdList.Add(msgChId.Value); } // Add the other channels from server network data if (rdpbcgrClientStack.Context.VirtualChannelIdStore != null) { for (int i = 0; i < rdpbcgrClientStack.Context.VirtualChannelIdStore.Length; i++) { chIdList.Add((long)rdpbcgrClientStack.Context.VirtualChannelIdStore[i]); } } // Start join request and confirm sequence foreach (long channelId in chIdList) { this.Site.Log.Add(LogEntryKind.Comment, "Start to create static virtual channel with channel ID {0}.", channelId); SendClientMCSChannelJoinRequest(NegativeType.None, channelId); Server_MCS_Channel_Join_Confirm_Pdu confirm = ExpectPacket <Server_MCS_Channel_Join_Confirm_Pdu>(pduWaitTimeSpan); this.Site.Assert.IsNotNull(confirm, "The RDP Server MUST response a Channel Join Confirm PDU after receiving a Channel Join Request PDU."); if (confirm.channelJoinConfirm.channelId.Value != channelId) { this.Site.Assert.Fail("In Channel Join phase, channel ID in Server_MCS_Channel_Join_Confirm_Pdu is not the same as it in Client_MCS_Channel_Join_Request."); } } }
/// <summary> /// Establish RDP Connection /// </summary> private void EstablishRDPConnection() { sessionContext = rdpbcgrServerStack.ExpectConnect(timeout); #region Connection Initial x224ConnectionRequest = ExpectPacket <Client_X_224_Connection_Request_Pdu>(sessionContext, timeout); Server_X_224_Connection_Confirm_Pdu confirmPdu = rdpbcgrServerStack.CreateX224ConnectionConfirmPdu(sessionContext, selectedProtocols_Values.PROTOCOL_RDP_FLAG, RDP_NEG_RSP_flags_Values.DYNVC_GFX_PROTOCOL_SUPPORTED | RDP_NEG_RSP_flags_Values.EXTENDED_CLIENT_DATA_SUPPORTED); SendPdu(confirmPdu); if (bool.Parse(detectInfo.IsWindowsImplementation)) { RdpbcgrServerSessionContext orgSession = sessionContext; sessionContext = rdpbcgrServerStack.ExpectConnect(timeout); if (sessionContext.Identity == orgSession.Identity) { sessionContext = rdpbcgrServerStack.ExpectConnect(timeout); } x224ConnectionRequest = ExpectPacket <Client_X_224_Connection_Request_Pdu>(sessionContext, timeout); confirmPdu = rdpbcgrServerStack.CreateX224ConnectionConfirmPdu(sessionContext, selectedProtocols_Values.PROTOCOL_RDP_FLAG, RDP_NEG_RSP_flags_Values.DYNVC_GFX_PROTOCOL_SUPPORTED | RDP_NEG_RSP_flags_Values.EXTENDED_CLIENT_DATA_SUPPORTED); SendPdu(confirmPdu); } #endregion Connection Initial #region Basic Setting Exchange mscConnectionInitialPDU = ExpectPacket <Client_MCS_Connect_Initial_Pdu_with_GCC_Conference_Create_Request>(sessionContext, timeout); SERVER_CERTIFICATE cert = null; int certLen = 0; int dwKeysize = 2048; byte[] privateExp, publicExp, modulus; cert = rdpbcgrServerStack.GenerateCertificate(dwKeysize, out privateExp, out publicExp, out modulus); certLen = 120 + dwKeysize / 8; Server_MCS_Connect_Response_Pdu_with_GCC_Conference_Create_Response connectRespPdu = rdpbcgrServerStack.CreateMCSConnectResponsePduWithGCCConferenceCreateResponsePdu( sessionContext, EncryptionMethods.ENCRYPTION_METHOD_128BIT, EncryptionLevel.ENCRYPTION_LEVEL_LOW, cert, certLen, MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECL | MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECR); SendPdu(connectRespPdu); sessionContext.ServerPrivateExponent = new byte[privateExp.Length]; Array.Copy(privateExp, sessionContext.ServerPrivateExponent, privateExp.Length); #endregion Basic Setting Exchange #region Channel Connection ExpectPacket <Client_MCS_Erect_Domain_Request>(sessionContext, timeout); ExpectPacket <Client_MCS_Attach_User_Request>(sessionContext, timeout); Server_MCS_Attach_User_Confirm_Pdu attachUserConfirmPdu = rdpbcgrServerStack.CreateMCSAttachUserConfirmPdu(sessionContext); SendPdu(attachUserConfirmPdu); //Join Channel int channelNum = 2; if (sessionContext.VirtualChannelIdStore != null) { channelNum += sessionContext.VirtualChannelIdStore.Length; } if (sessionContext.IsServerMessageChannelDataSend) { channelNum++; } for (int i = 0; i < channelNum; i++) { Client_MCS_Channel_Join_Request channelJoinPdu = ExpectPacket <Client_MCS_Channel_Join_Request>(sessionContext, timeout); Server_MCS_Channel_Join_Confirm_Pdu channelJoinResponse = rdpbcgrServerStack.CreateMCSChannelJoinConfirmPdu( sessionContext, channelJoinPdu.mcsChannelId); SendPdu(channelJoinResponse); } #endregion Channel Connection #region RDP Security Commencement securityExchangePDU = ExpectPacket <Client_Security_Exchange_Pdu>(sessionContext, timeout); #endregion RDP Security Commencement #region Secure Setting Exchange clientInfoPDU = ExpectPacket <Client_Info_Pdu>(sessionContext, timeout); #endregion Secure Setting Exchange #region Licensing Server_License_Error_Pdu_Valid_Client licensePdu = rdpbcgrServerStack.CreateLicenseErrorMessage(sessionContext); SendPdu(licensePdu); #endregion Licensing #region Capabilities Exchange RdpbcgrCapSet capSet = new RdpbcgrCapSet(); capSet.GenerateCapabilitySets(); Server_Demand_Active_Pdu demandActivePdu = rdpbcgrServerStack.CreateDemandActivePdu(sessionContext, capSet.CapabilitySets); SendPdu(demandActivePdu); confirmActivePDU = ExpectPacket <Client_Confirm_Active_Pdu>(sessionContext, timeout); clientCapSet = new RdpbcgrCapSet(); clientCapSet.CapabilitySets = confirmActivePDU.confirmActivePduData.capabilitySets; #endregion Capabilities Exchange #region Connection Finalization ExpectPacket <Client_Synchronize_Pdu>(sessionContext, timeout); Server_Synchronize_Pdu synchronizePdu = rdpbcgrServerStack.CreateSynchronizePdu(sessionContext); SendPdu(synchronizePdu); Server_Control_Pdu controlCooperatePdu = rdpbcgrServerStack.CreateControlCooperatePdu(sessionContext); SendPdu(controlCooperatePdu); ExpectPacket <Client_Control_Pdu_Cooperate>(sessionContext, timeout); ExpectPacket <Client_Control_Pdu_Request_Control>(sessionContext, timeout); Server_Control_Pdu controlGrantedPdu = rdpbcgrServerStack.CreateControlGrantedPdu(sessionContext); SendPdu(controlGrantedPdu); ITsCapsSet cap = this.clientCapSet.FindCapSet(capabilitySetType_Values.CAPSTYPE_BITMAPCACHE_REV2); if (cap != null) { TS_BITMAPCACHE_CAPABILITYSET_REV2 bitmapCacheV2 = (TS_BITMAPCACHE_CAPABILITYSET_REV2)cap; if ((bitmapCacheV2.CacheFlags & CacheFlags_Values.PERSISTENT_KEYS_EXPECTED_FLAG) != 0) { ExpectPacket <Client_Persistent_Key_List_Pdu>(sessionContext, timeout); } } ExpectPacket <Client_Font_List_Pdu>(sessionContext, timeout); Server_Font_Map_Pdu fontMapPdu = rdpbcgrServerStack.CreateFontMapPdu(sessionContext); SendPdu(fontMapPdu); #endregion Connection Finalization // Init for RDPEDYC try { rdpedycServer = new RdpedycServer(rdpbcgrServerStack, sessionContext); rdpedycServer.ExchangeCapabilities(timeout); } catch (Exception) { rdpedycServer = null; } }