private void SendClientX224ConnectionRequest(
            requestedProtocols_Values requestedProtocols,
            bool isRdpNegReqPresent          = true,
            bool isRoutingTokenPresent       = false,
            bool isCookiePresent             = false,
            bool isRdpCorrelationInfoPresent = false)
        {
            Client_X_224_Connection_Request_Pdu x224ConnectReqPdu = rdpbcgrClient.CreateX224ConnectionRequestPdu(requestedProtocols);

            if (isRoutingTokenPresent)
            {
                // Present the routingToken
                x224ConnectReqPdu.routingToken             = ASCIIEncoding.ASCII.GetBytes(RdpbcgrTestData.DefaultX224ConnectReqRoutingToken);
                x224ConnectReqPdu.tpktHeader.length       += (ushort)x224ConnectReqPdu.routingToken.Length;
                x224ConnectReqPdu.x224Crq.lengthIndicator += (byte)x224ConnectReqPdu.routingToken.Length;
            }
            if (isCookiePresent)
            {
                // Present the cookie
                x224ConnectReqPdu.cookie                   = RdpbcgrTestData.DefaultX224ConnectReqCookie;
                x224ConnectReqPdu.tpktHeader.length       += (ushort)x224ConnectReqPdu.cookie.Length;
                x224ConnectReqPdu.x224Crq.lengthIndicator += (byte)x224ConnectReqPdu.cookie.Length;
            }
            if (!isRdpNegReqPresent)
            {
                // RdpNegReq is already present, remove it if isRdpNegReqPresent is false
                x224ConnectReqPdu.rdpNegData = null;
                int rdpNegDataSize = sizeof(byte) + sizeof(byte) + sizeof(ushort) + sizeof(uint);
                x224ConnectReqPdu.tpktHeader.length       -= (ushort)rdpNegDataSize;
                x224ConnectReqPdu.x224Crq.lengthIndicator -= (byte)rdpNegDataSize;
            }
            if (isRdpCorrelationInfoPresent)
            {
                // Present the RdpCorrelationInfo
                x224ConnectReqPdu.rdpCorrelationInfo               = new RDP_NEG_CORRELATION_INFO();
                x224ConnectReqPdu.rdpCorrelationInfo.type          = RDP_NEG_CORRELATION_INFO_Type.TYPE_RDP_CORRELATION_INFO;
                x224ConnectReqPdu.rdpCorrelationInfo.flags         = 0;
                x224ConnectReqPdu.rdpCorrelationInfo.length        = 36;
                x224ConnectReqPdu.rdpCorrelationInfo.correlationId = RdpbcgrTestData.GetDefaultX224ConnectReqCorrelationId();
                x224ConnectReqPdu.rdpCorrelationInfo.reserved      = new byte[16];
                x224ConnectReqPdu.tpktHeader.length       += (ushort)x224ConnectReqPdu.rdpCorrelationInfo.length;
                x224ConnectReqPdu.x224Crq.lengthIndicator += (byte)x224ConnectReqPdu.rdpCorrelationInfo.length;
            }
            rdpbcgrClient.SendPdu(x224ConnectReqPdu);
        }
Esempio n. 2
0
        /// <summary>
        /// Establish the RDPBCGR connection with RDP server
        /// If the SVCNames is not null, then a RDPEDYC static channel is created.
        /// </summary>
        /// <param name="encryptProtocol">Encryption protocol, RDP, TLS, Credssp </param>
        /// <param name="requestedProtocols"></param>
        /// <param name="SVCNames">Static virtual virtual name, DRDYNVC for EDYC channel name</param>
        /// <param name="highestCompressionTypeSupported">whether compressed supported </param>
        /// <param name="isReconnect">whether reconnect supported </param>
        /// <param name="autoLogon">whether autologon supported </param>
        /// <param name="supportEGFX">whether EGFX supported </param>
        /// <param name="supportAutoDetect">whether auto detect supported </param>
        /// <param name="supportHeartbeatPDU">whether HeartbeatPDU supported </param>
        /// <param name="supportMultitransportReliable">whether MultitransportReliable supported </param>
        /// <param name="supportMultitransportLossy">whether MultitransportLossy supported </param>
        /// <param name="supportAutoReconnect">whether AutoReconnect supported </param>
        /// <param name="supportFastPathInput">whether FastPathInput supported </param>
        /// <param name="supportFastPathOutput">whether FastPathOutput supported </param>
        /// <param name="supportSurfaceCommands">whether SurfaceCommands supported </param>
        /// <param name="supportSVCCompression">whether SVCCompression supported </param>
        /// <param name="supportRemoteFXCodec">whether RemoteFXCodec supported </param>
        public void ConnectToServer(EncryptedProtocol encryptProtocol,
                                    requestedProtocols_Values requestedProtocols,
                                    string[] SVCNames,
                                    CompressionType highestCompressionTypeSupported = CompressionType.PACKET_COMPR_TYPE_RDP61,
                                    bool isReconnect                   = false,
                                    bool autoLogon                     = false,
                                    bool supportEGFX                   = false,
                                    bool supportAutoDetect             = false,
                                    bool supportHeartbeatPDU           = false,
                                    bool supportMultitransportReliable = false,
                                    bool supportMultitransportLossy    = false,
                                    bool supportAutoReconnect          = false,
                                    bool supportFastPathInput          = false,
                                    bool supportFastPathOutput         = false,
                                    bool supportSurfaceCommands        = false,
                                    bool supportSVCCompression         = false,
                                    bool supportRemoteFXCodec          = false
                                    )
        {
            this.bcgrAdapter.ConnectToServer(encryptProtocol);
            this.bcgrAdapter.EstablishRDPConnection(requestedProtocols,
                                                    SVCNames,
                                                    highestCompressionTypeSupported,
                                                    isReconnect,
                                                    autoLogon,
                                                    supportEGFX,
                                                    supportAutoDetect,
                                                    supportHeartbeatPDU,
                                                    supportMultitransportReliable,
                                                    supportMultitransportLossy,
                                                    supportAutoReconnect,
                                                    supportFastPathInput,
                                                    supportFastPathOutput,
                                                    supportSurfaceCommands,
                                                    supportSVCCompression,
                                                    supportRemoteFXCodec
                                                    );

            rdpedycClientStack = new RdpedycClient(bcgrAdapter.rdpbcgrClientStack.Context, false);

            rdpedycClientStack.UnhandledExceptionReceived += (ex) =>
            {
                Site.Log.Add(LogEntryKind.Debug, $"Unhandled exception from RdpedycClient: {ex}");
            };
        }
        private bool LoadConfig()
        {
            if (!IPAddress.TryParse(clientName, out clientAddress))
            {
                clientAddress = Dns.GetHostEntry(clientName).AddressList.First();
            }

            requestedProtocol = requestedProtocols_Values.PROTOCOL_RDP_FLAG;
            encryptedProtocol = EncryptedProtocol.Rdp;

            string strWaitTime = DetectorUtil.GetPropertyValue("WaitTime");

            if (strWaitTime != null)
            {
                int waitTime = Int32.Parse(strWaitTime);
                timeout = new TimeSpan(0, 0, waitTime);
            }
            else
            {
                timeout = new TimeSpan(0, 0, 10);
            }

            return(true);
        }
        private bool EstablishRDPConnection(
            Configs config,
            requestedProtocols_Values requestedProtocols,
            string[] SVCNames,
            CompressionType highestCompressionTypeSupported,
            bool isReconnect                   = false,
            bool autoLogon                     = false,
            bool supportEGFX                   = false,
            bool supportAutoDetect             = false,
            bool supportHeartbeatPDU           = false,
            bool supportMultitransportReliable = false,
            bool supportMultitransportLossy    = false,
            bool supportAutoReconnect          = false,
            bool supportFastPathInput          = false,
            bool supportFastPathOutput         = false,
            bool supportSurfaceCommands        = false,
            bool supportSVCCompression         = false,
            bool supportRemoteFXCodec          = false)
        {
            // Connection Initiation
            SendClientX224ConnectionRequest(requestedProtocols);
            Server_X_224_Connection_Confirm_Pdu connectionConfirmPdu = ExpectPacket <Server_X_224_Connection_Confirm_Pdu>(new TimeSpan(0, 0, 60));

            if (connectionConfirmPdu == null)
            {
                TimeSpan waitTime = new TimeSpan(0, 0, 1);
                Server_X_224_Negotiate_Failure_Pdu failurePdu = ExpectPacket <Server_X_224_Negotiate_Failure_Pdu>(waitTime);
                if (failurePdu != null)
                {
                    DetectorUtil.WriteLog("Received a Server X224 Connection confirm with RDP_NEG_FAILURE structure.");
                }
                DetectorUtil.WriteLog("Expecting a Server X224 Connection Confirm PDU.");
                return(false);
            }

            // Basic Settings Exchange
            SendClientMCSConnectInitialPDU(
                SVCNames,
                supportEGFX,
                supportAutoDetect,
                supportHeartbeatPDU,
                supportMultitransportReliable,
                supportMultitransportLossy,
                false);
            connectResponsePdu = ExpectPacket <Server_MCS_Connect_Response_Pdu_with_GCC_Conference_Create_Response>(timeout);
            if (connectResponsePdu == null)
            {
                return(false);
            }

            bool serverSupportUDPFECR = false;
            bool serverSupportUDPFECL = false;

            if (connectResponsePdu.mcsCrsp.gccPdu.serverMultitransportChannelData != null)
            {
                if (connectResponsePdu.mcsCrsp.gccPdu.serverMultitransportChannelData.flags.HasFlag(MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECR))
                {
                    serverSupportUDPFECR = true;
                }
                if (connectResponsePdu.mcsCrsp.gccPdu.serverMultitransportChannelData.flags.HasFlag(MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECL))
                {
                    serverSupportUDPFECL = true;
                }
            }
            detectInfo.IsSupportRDPEMT = serverSupportUDPFECR || serverSupportUDPFECL;

            // Channel Connection
            SendClientMCSErectDomainRequest();
            SendClientMCSAttachUserRequest();
            Server_MCS_Attach_User_Confirm_Pdu userConfirmPdu = ExpectPacket <Server_MCS_Attach_User_Confirm_Pdu>(timeout);

            if (userConfirmPdu == null)
            {
                return(false);
            }
            ChannelJoinRequestAndConfirm();

            // RDP Security Commencement
            if (rdpbcgrClient.Context.ServerSelectedProtocol == (uint)selectedProtocols_Values.PROTOCOL_RDP_FLAG)
            {
                SendClientSecurityExchangePDU();
            }

            // Secure Settings Exchange
            SendClientInfoPDU(config, highestCompressionTypeSupported, isReconnect, autoLogon);
            rdpeleClient = new RdpeleClient(rdpbcgrClient);

            try
            {
                detectInfo.IsSupportRDPELE = ProcessLicenseSequence(config, timeout);
            }
            catch
            {
                detectInfo.IsSupportRDPELE = false;
            }
            rdpeleClient.Dispose();

            // Capabilities Exchange
            Server_Demand_Active_Pdu demandActivePdu = ExpectPacket <Server_Demand_Active_Pdu>(timeout);

            if (demandActivePdu == null)
            {
                return(false);
            }
            SendClientConfirmActivePDU(
                supportAutoReconnect,
                supportFastPathInput,
                supportFastPathOutput,
                supportSVCCompression);

            // Connection Finalization
            SendClientSynchronizePDU();
            Server_Synchronize_Pdu syncPdu = ExpectPacket <Server_Synchronize_Pdu>(timeout);

            if (syncPdu == null)
            {
                return(false);
            }
            Server_Control_Pdu_Cooperate CoopControlPdu = ExpectPacket <Server_Control_Pdu_Cooperate>(timeout);

            if (CoopControlPdu == null)
            {
                return(false);
            }
            SendClientControlCooperatePDU();
            SendClientControlRequestPDU();
            Server_Control_Pdu_Granted_Control grantedControlPdu = ExpectPacket <Server_Control_Pdu_Granted_Control>(timeout);

            if (grantedControlPdu == null)
            {
                return(false);
            }
            SendClientFontListPDU();
            Server_Font_Map_Pdu fontMapPdu = ExpectPacket <Server_Font_Map_Pdu>(timeout);

            if (fontMapPdu == null)
            {
                return(false);
            }
            return(true);
        }
        protected void LoadConfig()
        {
            #region Security Approach and Protocol
            string strRDPSecurityProtocol;
            bool   isNegotiationBased = true;
            if (!PtfPropUtility.GetBoolPtfProperty(Site, "RDP.Security.Negotiation", out isNegotiationBased))
            {
                assumeFailForInvalidPtfProp("RDP.Security.Negotiation");
            }

            requestProtocol = requestedProtocols_Values.PROTOCOL_RDP_FLAG;
            if (!PtfPropUtility.GetStringPtfProperty(Site, "RDP.Security.Protocol", out strRDPSecurityProtocol))
            {
                assumeFailForInvalidPtfProp("RDP.Security.Protocol");
            }
            else
            {//TLS, CredSSP, or RDP
                if (strRDPSecurityProtocol.Equals("TLS", StringComparison.CurrentCultureIgnoreCase))
                {
                    requestProtocol = requestedProtocols_Values.PROTOCOL_SSL_FLAG;
                    if (isNegotiationBased)
                    {
                        transportProtocol = EncryptedProtocol.NegotiationTls;
                    }
                    else
                    {
                        transportProtocol = EncryptedProtocol.DirectTls;
                    }
                }
                else if (strRDPSecurityProtocol.Equals("CredSSP", StringComparison.CurrentCultureIgnoreCase))
                {
                    requestProtocol = requestedProtocols_Values.PROTOCOL_HYBRID_FLAG;
                    if (isNegotiationBased)
                    {
                        transportProtocol = EncryptedProtocol.NegotiationCredSsp;
                    }
                    else
                    {
                        transportProtocol = EncryptedProtocol.DirectCredSsp;
                    }
                }
                else if (strRDPSecurityProtocol.Equals("RDP", StringComparison.CurrentCultureIgnoreCase))
                {
                    requestProtocol = requestedProtocols_Values.PROTOCOL_RDP_FLAG;
                    if (!isNegotiationBased)
                    {
                        this.Site.Log.Add(LogEntryKind.Warning, "The property \"RDP.Security.Protocol\" is not valid and will be ingored. (When  use RDP as security protocol, the negotiation-based approch MUST be used.");
                    }
                    transportProtocol = EncryptedProtocol.Rdp;
                }
                else
                {
                    assumeFailForInvalidPtfProp("RDP.Security.Protocol");
                }
            }

            #region WaitTime
            string strWaitTime = Site.Properties["WaitTime"];
            if (strWaitTime != null)
            {
                int waitSeconds = Int32.Parse(strWaitTime);
                timeout = new TimeSpan(0, 0, waitSeconds);
            }
            #endregion

            #endregion
        }
        /// <summary>
        /// Establish a RDP connection with RDP Server
        /// </summary>
        /// <param name="requestedProtocols">Flags indicate supported security protocols</param>
        /// <param name="SVCNames">Array of static virtual channels' name</param>
        /// <param name="highestCompressionTypeSupported">Indicate the highest compression type supported</param>
        /// <param name="isReconnect">Whether this is in a reconnection sequence</param>        ///
        /// <param name="autoLogon">Whether auto logon using username and password in client info PDU</param>
        /// <param name="supportEGFX">Set the support of RDPEGFX</param>
        /// <param name="supportAutoDetect">Set the support of auto-detect</param>
        /// <param name="supportHeartbeatPDU">Set the support of Heartbeat PDU</param>
        /// <param name="supportMultitransportReliable">Set the support of reliable multitransport</param>
        /// <param name="supportMultitransportLossy">Set the support of lossy multitransport</param>
        /// <param name="supportAutoReconnect">Set the support of auto-reconnect</param>
        /// <param name="supportFastPathInput">Set the support of fast-path input</param>
        /// <param name="supportFastPathOutput">Set the support of fast-path output</param>
        /// <param name="supportSurfaceCommands">Set the support of surface commands</param>
        /// <param name="supportSVCCompression">Set the support of static virtual channel data compression</param>
        /// <param name="supportRemoteFXCodec">Set the support of RemoteFX codecs</param>
        public void EstablishRDPConnection(requestedProtocols_Values requestedProtocols,
                                           string[] SVCNames,
                                           CompressionType highestCompressionTypeSupported,
                                           bool isReconnect                   = false,
                                           bool autoLogon                     = false,
                                           bool supportEGFX                   = false,
                                           bool supportAutoDetect             = false,
                                           bool supportHeartbeatPDU           = false,
                                           bool supportMultitransportReliable = false,
                                           bool supportMultitransportLossy    = false,
                                           bool supportAutoReconnect          = false,
                                           bool supportFastPathInput          = false,
                                           bool supportFastPathOutput         = false,
                                           bool supportSurfaceCommands        = false,
                                           bool supportSVCCompression         = false,
                                           bool supportRemoteFXCodec          = false)
        {
            #region logging
            string requestProtocolString = "PROTOCOL_RDP_FLAG";
            if (requestedProtocols.HasFlag(requestedProtocols_Values.PROTOCOL_SSL_FLAG))
            {
                requestProtocolString = requestProtocolString + "|PROTOCOL_SSL_FLAG";
            }
            if (requestedProtocols.HasFlag(requestedProtocols_Values.PROTOCOL_HYBRID_FLAG))
            {
                requestProtocolString = requestProtocolString + "|PROTOCOL_HYBRID_FLAG";
            }
            if (requestedProtocols.HasFlag(requestedProtocols_Values.PROTOCOL_HYBRID_EX))
            {
                requestProtocolString = requestProtocolString + "|PROTOCOL_HYBRID_EX";
            }
            string svcNameString = "";
            if (SVCNames != null && SVCNames.Length > 0)
            {
                foreach (string svcName in SVCNames)
                {
                    svcNameString = svcNameString + svcName + ",";
                }
            }
            this.Site.Log.Add(LogEntryKind.Comment, @"EstablishRDPConnection:
                request Protocols = {0},
                Name of static virtual channels = {1},
                Highest compression type supported = {2},
                Is Reconnect = {3}
                RDPEGFX supported = {4},
                AutoDetect supported = {5},
                HeartbeatPDU supported = {6},
                Reliable Multitransport supported = {7},
                Lossy Multitransport supported = {8},
                AutoReconnect supported = {9},
                FastPathInput supported= {10},
                FastPathOutput supported = {11},
                SurfaceCommands supported = {12},
                SVCCompression supported = {13},
                RemoteFXCodec supported = {14}.",
                              requestProtocolString, svcNameString, highestCompressionTypeSupported.ToString(), isReconnect, supportEGFX, supportAutoDetect, supportHeartbeatPDU,
                              supportMultitransportReliable, supportMultitransportLossy, supportAutoReconnect, supportFastPathInput, supportFastPathOutput, supportSurfaceCommands,
                              supportSVCCompression, supportRemoteFXCodec);
            #endregion logging

            #region Connection Initiation

            SendClientX224ConnectionRequest(NegativeType.None, requestedProtocols);

            Server_X_224_Connection_Confirm_Pdu connectionConfirmPdu = ExpectPacket <Server_X_224_Connection_Confirm_Pdu>(pduWaitTimeSpan);
            if (connectionConfirmPdu == null)
            {
                TimeSpan waitTime = new TimeSpan(0, 0, 1);
                Server_X_224_Negotiate_Failure_Pdu failurePdu = ExpectPacket <Server_X_224_Negotiate_Failure_Pdu>(waitTime);
                if (failurePdu != null)
                {
                    Site.Assert.Fail("Received a Server X224 Connection confirm with RDP_NEG_FAILURE structure, failureCode is {0}.", failurePdu.rdpNegFailure.failureCode);
                }
                Site.Assert.Fail("Expecting a Server X224 Connection Confirm PDU.");
            }

            if (supportEGFX)
            {
                // Verify support of EGFX on Server
                Site.Assert.IsTrue(connectionConfirmPdu.rdpNegData != null &&
                                   connectionConfirmPdu.rdpNegData.flags.HasFlag(RDP_NEG_RSP_flags_Values.DYNVC_GFX_PROTOCOL_SUPPORTED), "The RDP Server should support RDPEGFX.");
            }
            #endregion Connection Initiation

            #region Basic Setting Exchange

            SendClientMCSConnectInitialPDU(NegativeType.None, SVCNames, supportEGFX, supportAutoDetect, supportHeartbeatPDU, supportMultitransportReliable, supportMultitransportLossy, false);

            Server_MCS_Connect_Response_Pdu_with_GCC_Conference_Create_Response connectResponsePdu = ExpectPacket <Server_MCS_Connect_Response_Pdu_with_GCC_Conference_Create_Response>(pduWaitTimeSpan);
            Site.Assert.IsNotNull(connectResponsePdu, "Expecting a Server MCS Connect Response PDU with GCC Conference Create Response.");
            if (connectResponsePdu.mcsCrsp.gccPdu.serverMultitransportChannelData != null)
            {
                if (connectResponsePdu.mcsCrsp.gccPdu.serverMultitransportChannelData.flags.HasFlag(MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECR))
                {
                    this.serverSupportUDPFECR = true;
                }
                if (connectResponsePdu.mcsCrsp.gccPdu.serverMultitransportChannelData.flags.HasFlag(MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECL))
                {
                    this.serverSupportUDPFECL = true;
                }
                if (connectResponsePdu.mcsCrsp.gccPdu.serverMultitransportChannelData.flags.HasFlag(MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDP_PREFERRED))
                {
                    this.serverSupportUDPPrefferred = true;
                }
            }

            #endregion Basic Setting Exchange

            #region Channel Connection

            SendClientMCSErectDomainRequest(NegativeType.None);

            SendClientMCSAttachUserRequest(NegativeType.None);

            Server_MCS_Attach_User_Confirm_Pdu userConfirmPdu = ExpectPacket <Server_MCS_Attach_User_Confirm_Pdu>(pduWaitTimeSpan);
            Site.Assert.IsNotNull(userConfirmPdu, "Expecting a Server MCS Attach User Confirm PDU.");

            ChannelJoinRequestAndConfirm();

            #endregion

            #region RDP Security Commencement

            if (rdpbcgrClientStack.Context.ServerSelectedProtocol == (uint)selectedProtocols_Values.PROTOCOL_RDP_FLAG)
            {
                SendClientSecurityExchangePDU(NegativeType.None);
            }

            #endregion

            #region Secure Setting Exchange

            SendClientInfoPDU(NegativeType.None, highestCompressionTypeSupported, isReconnect, autoLogon);

            #endregion

            #region Licensing
            Server_License_Error_Pdu_Valid_Client licenseErrorPdu = ExpectPacket <Server_License_Error_Pdu_Valid_Client>(pduWaitTimeSpan);
            Site.Assert.IsNotNull(licenseErrorPdu, "Expecting a Server License Error PDU.");

            #endregion

            #region Capabilities Exchange

            Server_Demand_Active_Pdu demandActivePdu = ExpectPacket <Server_Demand_Active_Pdu>(pduWaitTimeSpan);
            Site.Assert.IsNotNull(demandActivePdu, "Expecting a Server Demand Active PDU.");

            SendClientConfirmActivePDU(NegativeType.None, supportAutoReconnect, supportFastPathInput, supportFastPathOutput, supportSurfaceCommands, supportSVCCompression, supportRemoteFXCodec);

            #endregion

            #region Connection Finalization

            SendClientSynchronizePDU();

            Server_Synchronize_Pdu syncPdu = ExpectPacket <Server_Synchronize_Pdu>(pduWaitTimeSpan);
            Site.Assert.IsNotNull(syncPdu, "Expecting a Server Synchronize PDU.");

            Server_Control_Pdu_Cooperate CoopControlPdu = ExpectPacket <Server_Control_Pdu_Cooperate>(pduWaitTimeSpan);
            Site.Assert.IsNotNull(CoopControlPdu, "Expecting a Server Control PDU - Cooperate.");

            SendClientControlCooperatePDU();

            SendClientControlRequestPDU();

            Server_Control_Pdu_Granted_Control grantedControlPdu = ExpectPacket <Server_Control_Pdu_Granted_Control>(pduWaitTimeSpan);
            Site.Assert.IsNotNull(grantedControlPdu, "Expecting a Server Control PDU - Granted Control.");


            if (IsBitmapCacheHostSupport)
            {
                SendClientPersistentKeyListPDU();
            }

            SendClientFontListPDU();

            Server_Font_Map_Pdu fontMapPdu = ExpectPacket <Server_Font_Map_Pdu>(pduWaitTimeSpan);
            Site.Assert.IsNotNull(fontMapPdu, "Expecting a Server Font Map PDU.");

            #endregion
        }
        protected void LoadConfig()
        {
            #region Security Approach and Protocol
            string strRDPSecurityProtocol;
            bool   isNegotiationBased = true;
            if (!PtfPropUtility.GetBoolPtfProperty(Site, RdpPtfPropNames.RdpSecurityNegotiation, out isNegotiationBased))
            {
                assumeFailForInvalidPtfProp(RdpPtfPropNames.RdpSecurityNegotiation);
            }

            requestProtocol = requestedProtocols_Values.PROTOCOL_RDP_FLAG;
            if (!PtfPropUtility.GetStringPtfProperty(Site, RdpPtfPropNames.RdpSecurityProtocol, out strRDPSecurityProtocol))
            {
                assumeFailForInvalidPtfProp(RdpPtfPropNames.RdpSecurityProtocol);
            }
            else
            {//TLS, CredSSP, or RDP
                if (strRDPSecurityProtocol.Equals("TLS", StringComparison.CurrentCultureIgnoreCase))
                {
                    requestProtocol = requestedProtocols_Values.PROTOCOL_SSL_FLAG;
                    this.Site.Assume.IsTrue(
                        isNegotiationBased,
                        "When TLS is used as the security protocol, {0} is set to 'TLS', {1} must be true.",
                        RdpPtfPropNames.RdpSecurityProtocol,
                        RdpPtfPropNames.RdpSecurityNegotiation);
                    transportProtocol = EncryptedProtocol.NegotiationTls;
                }
                else if (strRDPSecurityProtocol.Equals("CredSSP", StringComparison.CurrentCultureIgnoreCase))
                {
                    requestProtocol = requestedProtocols_Values.PROTOCOL_HYBRID_FLAG;
                    if (isNegotiationBased)
                    {
                        transportProtocol = EncryptedProtocol.NegotiationCredSsp;
                    }
                    else
                    {
                        transportProtocol = EncryptedProtocol.DirectCredSsp;
                    }
                }
                else if (strRDPSecurityProtocol.Equals("RDP", StringComparison.CurrentCultureIgnoreCase))
                {
                    requestProtocol   = requestedProtocols_Values.PROTOCOL_RDP_FLAG;
                    transportProtocol = EncryptedProtocol.Rdp;
                }
                else
                {
                    assumeFailForInvalidPtfProp(RdpPtfPropNames.RdpSecurityProtocol);
                }
            }

            #region WaitTime
            string strWaitTime = Site.Properties["WaitTime"];
            if (strWaitTime != null)
            {
                int waitSeconds = Int32.Parse(strWaitTime);
                timeout = new TimeSpan(0, 0, waitSeconds);
            }
            #endregion

            #endregion
        }
        private bool LoadConfig()
        {
            if (!IPAddress.TryParse(clientName, out clientAddress))
            {
                clientAddress = Dns.GetHostEntry(clientName).AddressList.First();
            }

            bool   isNegotiationBased = true;
            string negotiation        = DetectorUtil.GetPropertyValue("RDP.Security.Negotiation");

            if (negotiation.Equals("true", StringComparison.CurrentCultureIgnoreCase))
            {
                isNegotiationBased = true;
            }
            else if (negotiation.Equals("false", StringComparison.CurrentCultureIgnoreCase))
            {
                isNegotiationBased = false;
            }
            else
            {
                throw new Exception(
                          String.Format("The property value \"{0}\" is invalid or not present in RDP.Security.Negotiation in ptfconfig", negotiation));
            }

            string protocol = DetectorUtil.GetPropertyValue("RDP.Security.Protocol");

            if (protocol.Equals("TLS", StringComparison.CurrentCultureIgnoreCase))
            {
                requestedProtocol = requestedProtocols_Values.PROTOCOL_SSL_FLAG;
                if (!isNegotiationBased)
                {
                    throw new Exception(
                              String.Format("When TLS is used as the security protocol, RDP.Security.Negotiation must be true;" +
                                            "actually RDP.Security.Negotiation is set to \"{0}\".", negotiation));
                }
                encryptedProtocol = EncryptedProtocol.NegotiationTls;
            }
            else if (protocol.Equals("CredSSP", StringComparison.CurrentCultureIgnoreCase))
            {
                requestedProtocol = requestedProtocols_Values.PROTOCOL_HYBRID_FLAG;
                if (isNegotiationBased)
                {
                    encryptedProtocol = EncryptedProtocol.NegotiationCredSsp;
                }
                else
                {
                    encryptedProtocol = EncryptedProtocol.NegotiationTls;
                }
            }
            else if (protocol.Equals("RDP", StringComparison.CurrentCultureIgnoreCase))
            {
                requestedProtocol = requestedProtocols_Values.PROTOCOL_RDP_FLAG;
                encryptedProtocol = EncryptedProtocol.Rdp;
            }
            else
            {
                throw new Exception(
                          String.Format("The property value \"{0}\" is invalid or not present in RDP.Security.Protocol in ptfconfig", protocol));
            }

            string strWaitTime = DetectorUtil.GetPropertyValue("WaitTime");

            if (strWaitTime != null)
            {
                int waitTime = Int32.Parse(strWaitTime);
                timeout = new TimeSpan(0, 0, waitTime);
            }
            else
            {
                timeout = new TimeSpan(0, 0, 10);
            }

            return(true);
        }
        /// <summary>
        /// Load configuration from PTF config file
        /// </summary>
        private void LoadConfiguation()
        {
            string tempStr;

            if (!PtfPropUtility.GetStringPtfProperty(Site, "RDP.ServerName", out serverName))
            {
                AssumeFailForInvalidPtfProp("RDP.ServerName");
            }

            if (PtfPropUtility.GetStringPtfProperty(Site, "RDP.ServerDomain", out tempStr))
            {
                if (tempStr != null && tempStr.Length > 0)
                {
                    this.domain = tempStr;
                }
                else
                {
                    this.domain = this.serverName;
                }
            }

            if (!PtfPropUtility.GetIntPtfProperty(Site, "RDP.ServerPort", out serverPort))
            {
                AssumeFailForInvalidPtfProp("RDP.ServerPort");
            }

            if (!PtfPropUtility.GetStringPtfProperty(Site, "RDP.ServerUserName", out userName))
            {
                AssumeFailForInvalidPtfProp("RDP.ServerUserName");
            }

            if (!PtfPropUtility.GetStringPtfProperty(Site, "RDP.ServerUserPassword", out password))
            {
                AssumeFailForInvalidPtfProp("RDP.ServerUserPassword");
            }

            if (!PtfPropUtility.GetStringPtfProperty(Site, "RDP.ClientName", out localAddress))
            {
                AssumeFailForInvalidPtfProp("RDP.ClientName");
            }

            int waitTime;

            if (!PtfPropUtility.GetIntPtfProperty(Site, "Timeout", out waitTime))
            {
                AssumeFailForInvalidPtfProp("Timeout");
            }
            timeout = new TimeSpan(0, 0, waitTime);

            if (!PtfPropUtility.GetIntPtfProperty(Site, "MultiTransportTimeout", out waitTime))
            {
                AssumeFailForInvalidPtfProp("MultiTransportTimeout");
            }
            multiTransportTimeout = new TimeSpan(0, 0, waitTime);

            PtfPropUtility.GetBoolPtfProperty(Site, "IsWindowsImplementation", out isWindowsImplementation);
            PtfPropUtility.GetBoolPtfProperty(Site, "VerifyRdpbcgrMessages", out verifyPduEnabled);
            PtfPropUtility.GetBoolPtfProperty(Site, "VerifyShouldBehaviors", out verifyShouldBehaviors);
            PtfPropUtility.GetBoolPtfProperty(Site, "RDPEDYCSupported", out isEDYCSupported);
            PtfPropUtility.GetBoolPtfProperty(Site, "RDPELESupported", out isELESupported);
            PtfPropUtility.GetBoolPtfProperty(Site, "IssueTemporaryLicenseForTheFirstTime", out issueTemporaryLicenseForTheFirstTime);

            if (PtfPropUtility.GetStringPtfProperty(Site, "RDP.Version", out tempStr))
            {
                rdpVersion = new Version(tempStr);
            }
            else
            {
                AssumeFailForInvalidPtfProp("RDP.Version");
            }

            #region Security Approach and Protocol
            string strRDPSecurityProtocol;
            string strRDPSecurityTlsVersion;
            bool   isNegotiationBased = true;
            if (!PtfPropUtility.GetBoolPtfProperty(Site, "RDP.Security.Negotiation", out isNegotiationBased))
            {
                AssumeFailForInvalidPtfProp("RDP.Security.Negotiation");
            }

            requestProtocol = requestedProtocols_Values.PROTOCOL_RDP_FLAG;
            if (!PtfPropUtility.GetStringPtfProperty(Site, "RDP.Security.Protocol", out strRDPSecurityProtocol))
            {
                AssumeFailForInvalidPtfProp("RDP.Security.Protocol");
            }

            //TLS, CredSSP, or RDP
            if (strRDPSecurityProtocol.Equals("TLS", StringComparison.CurrentCultureIgnoreCase))
            {
                if (PtfPropUtility.GetStringPtfProperty(Site, "RDP.Security.TLS.Version", out strRDPSecurityTlsVersion))
                {
                    // TLS1.0, TLS1.1, TLS1.2 or None
                    if (strRDPSecurityTlsVersion.Equals("TLS1.0", StringComparison.CurrentCultureIgnoreCase))
                    {
                        tlsVersion = SslProtocols.Tls;
                    }
                    else if (strRDPSecurityTlsVersion.Equals("TLS1.1", StringComparison.CurrentCultureIgnoreCase))
                    {
                        tlsVersion = SslProtocols.Tls11;
                    }
                    else if (strRDPSecurityTlsVersion.Equals("TLS1.2", StringComparison.CurrentCultureIgnoreCase))
                    {
                        tlsVersion = SslProtocols.Tls12;
                    }
                    else if (strRDPSecurityTlsVersion.Equals("None", StringComparison.CurrentCultureIgnoreCase))
                    {
                        tlsVersion = SslProtocols.None;
                    }
                    else
                    {
                        this.Site.Log.Add(LogEntryKind.Comment, "TLS is used as security protocol and the TLS Version is {0}.", strRDPSecurityTlsVersion);
                        this.Site.Assume.Fail("When TLS is used as the security protocol, {0} must be one of TLS1.0, TLS1.1, or TLS1.2; actually it is set to {1}",
                                              "RDP.Security.TLS.Version",
                                              tlsVersion);
                    }
                }
                else
                {
                    AssumeFailForInvalidPtfProp("RDP.Security.TLS.Version");
                }

                requestProtocol = requestedProtocols_Values.PROTOCOL_SSL_FLAG;
                this.Site.Assume.IsTrue(
                    isNegotiationBased,
                    "When TLS is used as the security protocol, {0} is set to 'TLS', {1} must be true.",
                    "RDP.Security.Protocol",
                    "RDP.Security.Negotiation");
                transportProtocol = EncryptedProtocol.NegotiationTls;
            }
            else if (strRDPSecurityProtocol.Equals("CredSSP", StringComparison.CurrentCultureIgnoreCase))
            {
                requestProtocol = requestedProtocols_Values.PROTOCOL_SSL_FLAG | requestedProtocols_Values.PROTOCOL_HYBRID_FLAG | requestedProtocols_Values.PROTOCOL_HYBRID_EX;
                if (isNegotiationBased)
                {
                    transportProtocol = EncryptedProtocol.NegotiationCredSsp;
                }
                else
                {
                    transportProtocol = EncryptedProtocol.DirectCredSsp;
                }
            }
            else if (strRDPSecurityProtocol.Equals("RDP", StringComparison.CurrentCultureIgnoreCase))
            {
                requestProtocol   = requestedProtocols_Values.PROTOCOL_RDP_FLAG;
                transportProtocol = EncryptedProtocol.Rdp;
            }
            else
            {
                AssumeFailForInvalidPtfProp("RDP.Security.Protocol");
            }

            #endregion
        }
Esempio n. 10
0
        protected void LoadConfig()
        {
            #region Security Approach and Protocol
            string strRDPSecurityProtocol;
            bool   isNegotiationBased = true;
            if (!PtfPropUtility.GetBoolPtfProperty(Site, RdpPtfPropNames.RdpSecurityNegotiation, out isNegotiationBased))
            {
                assumeFailForInvalidPtfProp(RdpPtfPropNames.RdpSecurityNegotiation);
            }

            requestProtocol = requestedProtocols_Values.PROTOCOL_RDP_FLAG;
            if (!PtfPropUtility.GetStringPtfProperty(Site, RdpPtfPropNames.RdpSecurityProtocol, out strRDPSecurityProtocol))
            {
                assumeFailForInvalidPtfProp(RdpPtfPropNames.RdpSecurityProtocol);
            }
            else
            {//TLS, CredSSP, or RDP
                if (strRDPSecurityProtocol.Equals("TLS", StringComparison.CurrentCultureIgnoreCase))
                {
                    requestProtocol = requestedProtocols_Values.PROTOCOL_SSL_FLAG;
                    this.Site.Assume.IsTrue(
                        isNegotiationBased,
                        "When TLS is used as the security protocol, {0} is set to 'TLS', {1} must be true.",
                        RdpPtfPropNames.RdpSecurityProtocol,
                        RdpPtfPropNames.RdpSecurityNegotiation);
                    transportProtocol = EncryptedProtocol.NegotiationTls;
                    string strTlsVersion;
                    if (PtfPropUtility.GetStringPtfProperty(Site, RdpPtfPropNames.RdpSecurityTlsVersion, out strTlsVersion))
                    {
                        if (!strTlsVersion.Equals("TLS1.0", StringComparison.CurrentCultureIgnoreCase) &&
                            !strTlsVersion.Equals("TLS1.1", StringComparison.CurrentCultureIgnoreCase) &&
                            !strTlsVersion.Equals("TLS1.2", StringComparison.CurrentCultureIgnoreCase))
                        {
                            this.Site.Assume.Fail("When TLS is used as the security protocol, {0} must be one of TLS1.0, TLS1.1, or TLS1.2; actually it is set to {1}",
                                                  RdpPtfPropNames.RdpSecurityTlsVersion,
                                                  strTlsVersion);
                        }
                        else
                        {
                            this.Site.Log.Add(LogEntryKind.Comment, "TLS is used as security protocol and the TLS Version is {0}.", strTlsVersion);
                        }
                    }
                    else
                    {
                        assumeFailForInvalidPtfProp(RdpPtfPropNames.RdpSecurityTlsVersion);
                    }
                }
                else if (strRDPSecurityProtocol.Equals("CredSSP", StringComparison.CurrentCultureIgnoreCase))
                {
                    requestProtocol = requestedProtocols_Values.PROTOCOL_HYBRID_FLAG;
                    if (isNegotiationBased)
                    {
                        transportProtocol = EncryptedProtocol.NegotiationCredSsp;
                    }
                    else
                    {
                        transportProtocol = EncryptedProtocol.DirectCredSsp;
                    }
                }
                else if (strRDPSecurityProtocol.Equals("RDP", StringComparison.CurrentCultureIgnoreCase))
                {
                    requestProtocol   = requestedProtocols_Values.PROTOCOL_RDP_FLAG;
                    transportProtocol = EncryptedProtocol.Rdp;
                }
                else
                {
                    assumeFailForInvalidPtfProp(RdpPtfPropNames.RdpSecurityProtocol);
                }
            }

            #region Is Windows Implementation
            string strIsWindows = Site.Properties["IsWindowsImplementation"];
            if (strIsWindows != null)
            {
                isWindowsImplementation = Boolean.Parse(strIsWindows);
            }
            #endregion

            #region WaitTime
            string strWaitTime = Site.Properties["WaitTime"];
            if (strWaitTime != null)
            {
                int waitSeconds = Int32.Parse(strWaitTime);
                timeout = new TimeSpan(0, 0, waitSeconds);
            }
            #endregion

            #endregion


            string rdpVersionProp = this.Site.Properties["RDP.Version"];
            if (!string.IsNullOrEmpty(rdpVersionProp))
            {
                rdpVersion = new Version(rdpVersionProp);
            }
            else
            {
                this.Site.Assume.Fail("The property \"{0}\" is invalid or not present in PTFConfig file!", "RDP.Version");
            }
        }