/// <summary> /// Constructor. Initialize member variables. /// </summary> /// <param name="transportConfig">Provides the transport parameters.</param> /// <param name="decodePacketCallback">Callback of decoding packet.</param> /// <param name="certificate">X509 certificate.</param> public RdpbcgrServerTransportStack( RdpbcgrServer rdpbcgrServer, RdpcbgrServerTransportConfig transportConfig, DecodePacketCallback decodePacketCallback, X509Certificate2 certificate) { this.rdpbcgrServer = rdpbcgrServer; this.config = transportConfig; if (this.config == null) { throw new System.InvalidCastException("TcpServerTransport needs SocketTransportConfig."); } this.decoder = decodePacketCallback; this.packetQueue = new QueueManager(); this.listenSock = new Socket(transportConfig.LocalIpAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); this.listenSock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); this.streamType = transportConfig.StreamType; IPEndPoint endPoint = new IPEndPoint(config.LocalIpAddress, config.LocalIpPort); this.listenSock.Bind(endPoint); this.listenSock.Listen(config.MaxConnections); this.acceptThread = new Thread(new ThreadStart(AcceptLoop)); this.receivingStreams = new Dictionary <Socket, RdpbcgrReceiveThread>(); this.cert = certificate; }
/// <summary> /// Update the config of transport at runtime. /// </summary> /// <param name="type">The type of transport stream.</param> internal void UpdateConfig(SecurityStreamType type) { foreach (Socket sock in this.receivingStreams.Keys) { if (receivingStreams[sock].ReceiveStream is SslStream || receivingStreams[sock].ReceiveStream is RdpbcgrServerCredSspStream) { //Skip the connections which already were updated to SSL or CredSSP. continue; } else { NetworkStream netStream = (NetworkStream)receivingStreams[sock].ReceiveStream; if (type == SecurityStreamType.Ssl) { SslStream sslStream = new SslStream(new ETWStream(netStream)); ((SslStream)sslStream).AuthenticateAsServer(this.cert); receivingStreams[sock].ReceiveStream = sslStream; } else if (type == SecurityStreamType.CredSsp) { string targetSPN = ConstValue.CREDSSP_SERVER_NAME_PREFIX + config.LocalIpAddress; RdpbcgrServerCredSspStream credSspStream = new RdpbcgrServerCredSspStream(new ETWStream(netStream), targetSPN); receivingStreams[sock].ReceiveStream = credSspStream; credSspStream.Authenticate(cert); } } } }
/// <summary> /// Constructor. Initialize member variables. /// </summary> /// <param name="sType">The type of security stream.</param> /// <param name="ip">The server ip.</param> /// <param name="port">The service port.</param> public RdpcbgrServerTransportConfig( SecurityStreamType sType, IPAddress ip, int port) { int ti = ConstValue.MAXCONNECTIONS; maxConnections = ti; streamType = sType; bufferSize = ConstValue.BUFFERSIZE; this.localIpAddress = ip; this.localIpPort = port; }
/// <summary> /// Constructor. Initialize member variables. /// </summary> /// <param name="sType">The type of security stream.</param> /// <param name="ip">The server ip.</param> /// <param name="port">The service port.</param> public RdpcbgrServerTransportConfig( SecurityStreamType sType, IPAddress ip, int port) { int ti = ConstValue.MAXCONNECTIONS; maxConnections = ti; streamType = sType; bufferSize = ConstValue.BUFFERSIZE; this.localIpAddress = ip; this.localIpPort = port; }
/// <summary> /// Update the config of transport at runtime. /// </summary> /// <param name="type">The type of transport stream.</param> internal void UpdateConfig(SecurityStreamType type) { foreach (Socket sock in this.receivingStreams.Keys) { if (receivingStreams[sock].ReceiveStream is SslStream || receivingStreams[sock].ReceiveStream is RdpbcgrServerCredSspStream) { //Skip the connections which already were updated to SSL or CredSSP. continue; } else { NetworkStream netStream = (NetworkStream)receivingStreams[sock].ReceiveStream; if (type == SecurityStreamType.Ssl) { SslStream sslStream = new SslStream(new ETWStream(netStream)); ((SslStream)sslStream).AuthenticateAsServer(this.cert); receivingStreams[sock].ReceiveStream = sslStream; } else if (type == SecurityStreamType.CredSsp) { string targetSPN = ConstValue.CREDSSP_SERVER_NAME_PREFIX + config.LocalIpAddress; RdpbcgrServerCredSspStream credSspStream = new RdpbcgrServerCredSspStream(new ETWStream(netStream), targetSPN); receivingStreams[sock].ReceiveStream = credSspStream; credSspStream.Authenticate(cert); } } } }
/// <summary> /// Constructor. Initialize member variables. /// </summary> /// <param name="transportConfig">Provides the transport parameters.</param> /// <param name="decodePacketCallback">Callback of decoding packet.</param> /// <param name="certificate">X509 certificate.</param> public RdpbcgrServerTransportStack( RdpbcgrServer rdpbcgrServer, RdpcbgrServerTransportConfig transportConfig, DecodePacketCallback decodePacketCallback, X509Certificate2 certificate) { this.rdpbcgrServer = rdpbcgrServer; this.config = transportConfig; if (this.config == null) { throw new System.InvalidCastException("TcpServerTransport needs SocketTransportConfig."); } this.decoder = decodePacketCallback; this.packetQueue = new QueueManager(); this.listenSock = new Socket(transportConfig.LocalIpAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); this.streamType = transportConfig.StreamType; IPEndPoint endPoint = new IPEndPoint(config.LocalIpAddress, config.LocalIpPort); this.listenSock.Bind(endPoint); this.listenSock.Listen(config.MaxConnections); this.acceptThread = new Thread(new ThreadStart(AcceptLoop)); this.receivingStreams = new Dictionary<Socket, RdpbcgrReceiveThread>(); this.cert = certificate; }