public XSPWorker(Socket client, EndPoint localEP, ApplicationServer server, bool secureConnection, SecurityProtocolType securityProtocol, X509Certificate cert, PrivateKeySelectionCallback keyCB, bool allowClientCert, bool requireClientCert) { if (secureConnection) { ssl = new SslInformation { AllowClientCertificate = allowClientCert, RequireClientCertificate = requireClientCert, RawServerCertificate = cert.GetRawCertData() }; netStream = new LingeringNetworkStream(client, true); var s = new SslServerStream(netStream, cert, requireClientCert, false); s.PrivateKeyCertSelectionDelegate += keyCB; s.ClientCertValidationDelegate += ClientCertificateValidation; stream = s; } else { netStream = new LingeringNetworkStream(client, false); stream = netStream; } sock = client; this.server = server; remoteEP = (IPEndPoint)client.RemoteEndPoint; this.localEP = (IPEndPoint)localEP; }
static string PostStream(Mono.Security.Protocol.Tls.SecurityProtocolType protocol, string url, byte[] buffer) { Uri uri = new Uri(url); string post = "POST " + uri.AbsolutePath + " HTTP/1.0\r\n"; post += "Content-Type: application/x-www-form-urlencoded\r\n"; post += "Content-Length: " + (buffer.Length + 5).ToString() + "\r\n"; post += "Host: " + uri.Host + "\r\n\r\n"; post += "TEST="; byte[] bytes = Encoding.Default.GetBytes(post); IPHostEntry host = Dns.Resolve(uri.Host); IPAddress ip = host.AddressList [0]; Socket socket = new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp); socket.Connect(new IPEndPoint(ip, uri.Port)); NetworkStream ns = new NetworkStream(socket, false); SslClientStream ssl = new SslClientStream(ns, uri.Host, false, protocol); ssl.ServerCertValidationDelegate += new CertificateValidationCallback(CertificateValidation); ssl.Write(bytes, 0, bytes.Length); ssl.Write(buffer, 0, buffer.Length); ssl.Flush(); StreamReader reader = new StreamReader(ssl, Encoding.UTF8); string result = reader.ReadToEnd(); int start = result.IndexOf("\r\n\r\n") + 4; start = result.IndexOf("\r\n\r\n") + 4; return(result.Substring(start)); }
public XSPWorker (Socket client, EndPoint localEP, ApplicationServer server, bool secureConnection, SecurityProtocolType securityProtocol, X509Certificate cert, PrivateKeySelectionCallback keyCB, bool allowClientCert, bool requireClientCert) { if (secureConnection) { ssl = new SslInformation { AllowClientCertificate = allowClientCert, RequireClientCertificate = requireClientCert, RawServerCertificate = cert.GetRawCertData () }; netStream = new LingeringNetworkStream (client, true); var s = new SslServerStream (netStream, cert, requireClientCert, false); s.PrivateKeyCertSelectionDelegate += keyCB; s.ClientCertValidationDelegate += ClientCertificateValidation; stream = s; } else { netStream = new LingeringNetworkStream (client, false); stream = netStream; } sock = client; this.server = server; remoteEP = (IPEndPoint) client.RemoteEndPoint; this.localEP = (IPEndPoint) localEP; }
public XSPWebSource(IPAddress address, int port, SecurityProtocolType securityProtocol, X509Certificate cert, PrivateKeySelectionCallback keyCB, bool allowClientCert, bool requireClientCert, bool single_app) { secureConnection = (cert != null && keyCB != null); this.bindAddress = new IPEndPoint (address, port); this.SecurityProtocol = securityProtocol; this.cert = cert; this.keyCB = keyCB; this.allowClientCert = allowClientCert; this.requireClientCert = requireClientCert; }
public XSPWebSource(IPAddress address, int port, SecurityProtocolType securityProtocol, X509Certificate cert, PrivateKeySelectionCallback keyCB, bool allowClientCert, bool requireClientCert, bool single_app) { secureConnection = (cert != null && keyCB != null); bindAddress = new IPEndPoint(address, port); this.securityProtocol = securityProtocol; this.cert = cert; this.keyCB = keyCB; this.allowClientCert = allowClientCert; this.requireClientCert = requireClientCert; }
public void SetProtocol(string protocol) { if (protocol != null) { try { this.protocol = (SecurityProtocolType)Enum.Parse(typeof(SecurityProtocolType), protocol); } catch (Exception e) { string message = String.Format("The value '{0}' given for security protocol is invalid.", protocol); throw new CryptographicException(message, e); } } else { this.protocol = SecurityProtocolType.Default; } }
public static void Main (string[] args) { if (args.Length == 0) { Usage ("Missing arguments"); return; } ArrayList urls = new ArrayList (); foreach (string arg in args) { switch (arg) { // protocol case "--any": protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Default; break; case "--ssl": case "--ssl3": protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Ssl3; break; case "--tls": case "--tls1": protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Tls; break; // options case "--time": time = true; break; case "--show": show = true; break; case "--help": Usage (null); return; // credentials, certificates, urls or bad options default: if (arg.StartsWith ("--read:")) { string rval = arg.Substring (7); if (rval == "loop") readloop = true; else read = Int32.Parse (rval); continue; } else if (arg.StartsWith ("--write:")) { string wval = arg.Substring (8); if (wval == "loop") writeloop = true; else write = Int32.Parse (wval); continue; } else if (arg.StartsWith ("--")) { Usage ("Invalid option " + arg); return; } urls.Add (arg); break; } } if (readloop && writeloop) { Usage ("Can't loop on both read and write"); return; } int loop = 1; if (readloop || writeloop) { // this is it meant to be stopped manually loop = Int32.MaxValue; } if (urls.Count == 0) { Usage ("no URL were specified"); return; } for (int i = 0; i < loop; i++) { if (readloop || writeloop) Console.WriteLine ("*** LOOP {0} ***", i); foreach (string url in urls) { Console.WriteLine ("{0}{1}", Environment.NewLine, url); string content = null; DateTime start = DateTime.Now; Uri uri = new Uri (url); if (uri.Scheme != Uri.UriSchemeHttps) throw new NotSupportedException ("Stream only works with HTTPS protocol"); ControlledNetworkStream ns = null; try { IPHostEntry host = Dns.Resolve (uri.Host); IPAddress ip = host.AddressList [0]; Socket socket = new Socket (ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp); socket.Connect (new IPEndPoint (ip, uri.Port)); ns = new ControlledNetworkStream (socket, false); ns.MaximumRead = (readloop) ? i : read; ns.MaximumWrite = (writeloop) ? i : write; SslClientStream ssl = new SslClientStream (ns, uri.Host, false, protocol); ssl.ServerCertValidationDelegate += new CertificateValidationCallback (CertificateValidation); StreamWriter sw = new StreamWriter (ssl); sw.WriteLine ("GET {0}{1}", uri.AbsolutePath, Environment.NewLine); sw.Flush (); StreamReader sr = new StreamReader (ssl, Encoding.UTF8); content = sr.ReadToEnd (); } catch (Exception e) { // HResult is protected - but very useful in debugging PropertyInfo pi = e.GetType ().GetProperty ("HResult", BindingFlags.NonPublic | BindingFlags.GetProperty | BindingFlags.Instance); Console.WriteLine ("FAILED: #{0}", (int)pi.GetValue (e, null)); Console.WriteLine (e.ToString ()); if (ns != null) { Console.WriteLine ("Bytes Read: {0}", ns.CurrentRead); Console.WriteLine ("Max Read: {0}", ns.MaximumRead); Console.WriteLine ("Bytes Write: {0}", ns.CurrentWrite); Console.WriteLine ("Max Write: {0}", ns.MaximumWrite); } } TimeSpan ts = (DateTime.Now - start); if ((show) && (content != null)) { Console.WriteLine ("{0}{1}{0}", Environment.NewLine, content); } if (time) { Console.WriteLine ("Time: " + ts.ToString ()); } } } }
public static void Main(string[] args) { if (args.Length == 0) { Usage ("Missing arguments"); return; } ArrayList urls = new ArrayList (); foreach (string arg in args) { switch (arg) { // protocol case "--any": protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Default; break; case "--ssl": case "--ssl3": protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Ssl3; break; case "--ssl2": protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Ssl2; // note: will only works with Fx 1.2 // but the tool doesn't link with it Usage ("Not supported"); return; case "--tls": case "--tls1": protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Tls; break; // class case "--stream": web = false; break; case "--web": web = true; break; // options case "--time": time = true; break; case "--show": show = true; break; case "--help": Usage (null); return; // credentials, certificates, urls or bad options default: if (arg.StartsWith ("--digest:")) { digestCred = GetCredentials (arg.Substring (9)); continue; } else if (arg.StartsWith ("--basic:")) { basicCred = GetCredentials (arg.Substring (8)); continue; } else if (arg.StartsWith ("--x:")) { string filename = arg.Substring (4); X509Certificate x509 = X509Certificate.CreateFromCertFile (filename); certificates.Add (x509); continue; } else if (arg.StartsWith ("--")) { Usage ("Invalid option " + arg); return; } urls.Add (arg); break; } } if (urls.Count == 0) { Usage ("no URL were specified"); return; } foreach (string url in urls) { Console.WriteLine ("{0}{1}", Environment.NewLine, url); string content = null; DateTime start = DateTime.Now; try { if (web) { content = GetWebPage (url); } else { content = GetStreamPage (url); } } catch (Exception e) { // HResult is now public (was protected before 4.5) Console.WriteLine ("FAILED: #{0}", e.HResult); Console.WriteLine (e.ToString ()); } TimeSpan ts = (DateTime.Now - start); if ((show) && (content != null)) { Console.WriteLine ("{0}{1}{0}", Environment.NewLine, content); } if (time) { Console.WriteLine ("Time: " + ts.ToString ()); } } }
public static void Main(string[] args) { if (args.Length == 0) { Usage("Missing arguments"); return; } ArrayList urls = new ArrayList(); foreach (string arg in args) { switch (arg) { // protocol case "--any": protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Default; break; case "--ssl": case "--ssl3": protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Ssl3; break; case "--tls": case "--tls1": protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Tls; break; // options case "--time": time = true; break; case "--show": show = true; break; case "--help": Usage(null); return; // credentials, certificates, urls or bad options default: if (arg.StartsWith("--read:")) { string rval = arg.Substring(7); if (rval == "loop") { readloop = true; } else { read = Int32.Parse(rval); } continue; } else if (arg.StartsWith("--write:")) { string wval = arg.Substring(8); if (wval == "loop") { writeloop = true; } else { write = Int32.Parse(wval); } continue; } else if (arg.StartsWith("--")) { Usage("Invalid option " + arg); return; } urls.Add(arg); break; } } if (readloop && writeloop) { Usage("Can't loop on both read and write"); return; } int loop = 1; if (readloop || writeloop) { // this is it meant to be stopped manually loop = Int32.MaxValue; } if (urls.Count == 0) { Usage("no URL were specified"); return; } for (int i = 0; i < loop; i++) { if (readloop || writeloop) { Console.WriteLine("*** LOOP {0} ***", i); } foreach (string url in urls) { Console.WriteLine("{0}{1}", Environment.NewLine, url); string content = null; DateTime start = DateTime.Now; Uri uri = new Uri(url); if (uri.Scheme != Uri.UriSchemeHttps) { throw new NotSupportedException("Stream only works with HTTPS protocol"); } ControlledNetworkStream ns = null; try { IPHostEntry host = Dns.Resolve(uri.Host); IPAddress ip = host.AddressList [0]; Socket socket = new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp); socket.Connect(new IPEndPoint(ip, uri.Port)); ns = new ControlledNetworkStream(socket, false); ns.MaximumRead = (readloop) ? i : read; ns.MaximumWrite = (writeloop) ? i : write; SslClientStream ssl = new SslClientStream(ns, uri.Host, false, protocol); ssl.ServerCertValidationDelegate += new CertificateValidationCallback(CertificateValidation); StreamWriter sw = new StreamWriter(ssl); sw.WriteLine("GET {0}{1}", uri.AbsolutePath, Environment.NewLine); sw.Flush(); StreamReader sr = new StreamReader(ssl, Encoding.UTF8); content = sr.ReadToEnd(); } catch (Exception e) { // HResult is protected - but very useful in debugging PropertyInfo pi = e.GetType().GetProperty("HResult", BindingFlags.NonPublic | BindingFlags.GetProperty | BindingFlags.Instance); Console.WriteLine("FAILED: #{0}", (int)pi.GetValue(e, null)); Console.WriteLine(e.ToString()); if (ns != null) { Console.WriteLine("Bytes Read: {0}", ns.CurrentRead); Console.WriteLine("Max Read: {0}", ns.MaximumRead); Console.WriteLine("Bytes Write: {0}", ns.CurrentWrite); Console.WriteLine("Max Write: {0}", ns.MaximumWrite); } } TimeSpan ts = (DateTime.Now - start); if ((show) && (content != null)) { Console.WriteLine("{0}{1}{0}", Environment.NewLine, content); } if (time) { Console.WriteLine("Time: " + ts.ToString()); } } } }
public SecurityConfiguration() { protocol = SecurityProtocolType.Default; }
public void SetProtocol(string protocol) { if (protocol != null) { try { this.protocol = (SecurityProtocolType) Enum.Parse (typeof (SecurityProtocolType), protocol); } catch (Exception e) { string message = String.Format ("The value '{0}' given for security protocol is invalid.", protocol); throw new CryptographicException (message, e); } } else { this.protocol = SecurityProtocolType.Default; } }
public static void Main(string[] args) { if (args.Length == 0) { Usage("Missing arguments"); return; } ArrayList urls = new ArrayList(); foreach (string arg in args) { switch (arg) { // protocol case "--any": protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Default; break; case "--ssl": case "--ssl3": protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Ssl3; break; case "--ssl2": protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Ssl2; // note: will only works with Fx 1.2 // but the tool doesn't link with it Usage("Not supported"); return; case "--tls": case "--tls1": protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Tls; break; // class case "--stream": web = false; break; case "--web": web = true; break; // options case "--time": time = true; break; case "--show": show = true; break; case "--help": Usage(null); return; // credentials, certificates, urls or bad options default: if (arg.StartsWith("--digest:")) { digestCred = GetCredentials(arg.Substring(9)); continue; } else if (arg.StartsWith("--basic:")) { basicCred = GetCredentials(arg.Substring(8)); continue; } else if (arg.StartsWith("--x:")) { string filename = arg.Substring(4); X509Certificate x509 = X509Certificate.CreateFromCertFile(filename); certificates.Add(x509); continue; } else if (arg.StartsWith("--")) { Usage("Invalid option " + arg); return; } urls.Add(arg); break; } } if (urls.Count == 0) { Usage("no URL were specified"); return; } foreach (string url in urls) { Console.WriteLine("{0}{1}", Environment.NewLine, url); string content = null; DateTime start = DateTime.Now; try { if (web) { content = GetWebPage(url); } else { content = GetStreamPage(url); } } catch (Exception e) { // HResult is now public (was protected before 4.5) Console.WriteLine("FAILED: #{0}", e.HResult); Console.WriteLine(e.ToString()); } TimeSpan ts = (DateTime.Now - start); if ((show) && (content != null)) { Console.WriteLine("{0}{1}{0}", Environment.NewLine, content); } if (time) { Console.WriteLine("Time: " + ts.ToString()); } } }
static int Main(string[] args) { if (args.Length < 1) { Help(); return(2); } string url = args [0]; int size = 1024; bool ssl = true; Mono.Security.Protocol.Tls.SecurityProtocolType protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Tls; if (args.Length > 1) { for (int i = 1; i < args.Length; i++) { switch (args [i].ToLower()) { case "--ssl3": ssl = true; protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Ssl3; break; case "--tls": case "--tls1": ssl = true; protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Tls; break; case "--web": ssl = false; break; default: size = Int32.Parse(args [i]); break; } } } // prepare test buffer byte[] data = new byte[size]; for (int i = 0; i < size; i++) { data[i] = 65; } string result = (ssl ? PostStream(protocol, url, data) : PostWeb(url, data)); if (data.Length != result.Length) { Console.WriteLine("Invalid length {0}. Expected {1}", result.Length, data.Length); return(1); } for (int i = 0; i < result.Length; i++) { if (result[i] != 'A') { Console.WriteLine("Error at position #{0} - received '{1}'", i, result[i]); return(1); } } Console.WriteLine("Result OK (length: {0})", result.Length); return(0); }