public void backslash_removes_previous_char(string textWithBackslashes, string textWithoutBackslashes) { var textBytesWithoutBacklashes = Encoding.ASCII.GetBytes(textWithoutBackslashes); var textBytesWithBackslashes = Encoding.ASCII.GetBytes(textWithBackslashes); Assert.Equal(textBytesWithoutBacklashes, StringReaderStream.ProcessBackslashes(textBytesWithBackslashes)); }
public virtual void Starttls() { var store = new X509Store(StoreName.Root, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); X509Certificate2 ca_cert = new X509Certificate2(); ca_cert.Import(System.IO.File.ReadAllBytes("/tmp/CA.p12")); store.Add(ca_cert); store.Close(); System.Security.Cryptography.X509Certificates.X509Certificate2 CPrivate = new System.Security.Cryptography.X509Certificates.X509Certificate2(); CPrivate.Import(System.IO.File.ReadAllBytes("/tmp/ffwronbpi.feuerwehrcloud.de.p12")); System.Security.Cryptography.X509Certificates.X509Certificate CPublic = new System.Security.Cryptography.X509Certificates.X509Certificate2(); CPublic.Import(System.IO.File.ReadAllBytes("/tmp/ffwronbpi.feuerwehrcloud.de.cer")); try { SSLStream = new System.Net.Security.SslStream(this.NetworkStream, false, null, null); SSLStream.AuthenticateAsServer(CPrivate, false, System.Security.Authentication.SslProtocols.Default, true); //SSLStream. } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } SSLWriter = new StreamWriter(SSLStream); SSLReader = new StringReaderStream(SSLStream, 4096); UseSSL = true; }
public async Task ProcessCommandsAsync() { var cancellationToken = _cts.Token; try { while (!_cts.IsCancellationRequested) { byte[] line; try { line = await _readLineSource.ReadLineAsync(cancellationToken); if (line == null) { RequestDisconnection(this, RequestDisconnectionEventArgs.Expected); return; } } catch (IOException) { RequestDisconnection(this, RequestDisconnectionEventArgs.Unexpected); return; } catch (TaskCanceledException) { return; } catch (ObjectDisposedException) { return; } DetectedActivity(this, EventArgs.Empty); line = StringReaderStream.ProcessBackslashes(line); ProcessLineCommand(this, new BufferEventArgs(line)); } } catch (Exception ex) { MailServerLogger.Instance.Error(ex); RequestDisconnection(this, RequestDisconnectionEventArgs.Unexpected); } finally { _cts = new CancellationTokenSource(); } }
protected BaseConnection(PortListener portBinding, TcpClient tcpClient) { if (portBinding == null) { throw new ArgumentNullException("portBinding"); } if (tcpClient == null) { throw new ArgumentNullException("tcpClient"); } PortBinding = portBinding; TcpClient = tcpClient; ConnectionInitiated = DateTime.UtcNow; /*var store = new X509Store(StoreName.Root, StoreLocation.CurrentUser); * store.Open(OpenFlags.ReadWrite); * X509Certificate2 ca_cert = new X509Certificate2(); * ca_cert.Import (System.IO.File.ReadAllBytes ("/tmp/CA.p12")); * store.Add(ca_cert); * store.Close(); * * System.Security.Cryptography.X509Certificates.X509Certificate2 CPrivate = new System.Security.Cryptography.X509Certificates.X509Certificate2(); * CPrivate.Import (System.IO.File.ReadAllBytes ("/tmp/ffwronbpi.feuerwehrcloud.de.p12")); * System.Security.Cryptography.X509Certificates.X509Certificate CPublic = new System.Security.Cryptography.X509Certificates.X509Certificate2 (); * CPublic.Import (System.IO.File.ReadAllBytes( "/tmp/ffwronbpi.feuerwehrcloud.de.cer")); * * try { * SSLStream = new System.Net.Security.SslStream(tcpClient.GetStream(), true, null, null); * SSLStream.AuthenticateAsServer(CPrivate,false, System.Security.Authentication.SslProtocols.Default,true); * //SSLStream. * } catch (Exception ex) { * System.Diagnostics.Debug.WriteLine (ex.Message); * } * * Writer = new StreamWriter (SSLStream); * Reader = new StringReaderStream (SSLStream, 4096); */ NetworkStream = tcpClient.GetStream(); Reader = new StringReaderStream(NetworkStream); Writer = new StreamWriter(NetworkStream) { AutoFlush = true }; RemoteEndPoint = (IPEndPoint)tcpClient.Client.RemoteEndPoint; }
protected BaseConnection(PortListener portBinding, TcpClient tcpClient) { if (portBinding == null) { throw new ArgumentNullException("portBinding"); } if (tcpClient == null) { throw new ArgumentNullException("tcpClient"); } PortBinding = portBinding; TcpClient = tcpClient; ConnectionInitiated = DateTime.UtcNow; NetworkStream = tcpClient.GetStream(); Reader = new StringReaderStream(NetworkStream); Writer = new StreamWriter(NetworkStream) { AutoFlush = true }; RemoteEndPoint = (IPEndPoint)tcpClient.Client.RemoteEndPoint; }