diff options
author | Martin Baulig <mabaul@microsoft.com> | 2019-01-21 23:17:34 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2019-01-23 16:32:16 +0300 |
commit | 22d01c707cb423464f13305991a8a11b74d82153 (patch) | |
tree | a69fa3afec788b4f145594aad28f8bfa16f13daa /mcs/class/Mono.Security | |
parent | 2aeb4afa26c4c5f578a3e46643b22f6bfe106a00 (diff) |
[Mono.Security]: Remove some obsolete test tools.
These tools were using the obsolete `Mono.Security.Protocol.Tls` code
(Legacy TLS), which is scheduled for removal.
Diffstat (limited to 'mcs/class/Mono.Security')
35 files changed, 0 insertions, 3057 deletions
diff --git a/mcs/class/Mono.Security/Test/tools/README b/mcs/class/Mono.Security/Test/tools/README index b4faab622f7..6b76dcd2b04 100644 --- a/mcs/class/Mono.Security/Test/tools/README +++ b/mcs/class/Mono.Security/Test/tools/README @@ -1,20 +1,5 @@ Here are some test tools for Mono.Security assembly. -- tlstest - SSL3/TLS1 tool to securely download web pages. The tool will show - details if the certificate isn't trusted (or any other certificate - realted error). - -- cutcli - SSL3/TLS1 tool that can cut the transmission (read or write) after - "n" bytes are sent/received. This can simulate a server that hangs - in the middle of a record. It can also be used to simulate DoS as - the connection isn't closed. - -- postecho - SSL3/TLS1 tool to post a buffer to a web server and check that it - was echoed back correctly. Requires a script on the server side. - - npdbtest Npgsql-based tool to test the SSL implementation. Requires PostgreSQL installed. diff --git a/mcs/class/Mono.Security/Test/tools/cutcli/ControlledNetworkStream.cs b/mcs/class/Mono.Security/Test/tools/cutcli/ControlledNetworkStream.cs deleted file mode 100644 index 3065b232400..00000000000 --- a/mcs/class/Mono.Security/Test/tools/cutcli/ControlledNetworkStream.cs +++ /dev/null @@ -1,120 +0,0 @@ -using System; -using System.IO; -using System.Net.Sockets; - -namespace Mono.Test { - - public class ControlledNetworkStream : NetworkStream { - - private int _maxRead; - private int _maxWrite; - private int _curRead; - private int _curWrite; - - public ControlledNetworkStream (Socket socket) - : base (socket) - { - _maxRead = -1; - _maxWrite = -1; - _curRead = 0; - _curWrite = 0; - } - - public ControlledNetworkStream (Socket socket, bool ownsSocket) - : base (socket, ownsSocket) - { - _maxRead = -1; - _maxWrite = -1; - _curRead = 0; - _curWrite = 0; - } - - // properties - - public int CurrentRead { - get { return _curRead; } - } - - public int CurrentWrite { - get { return _curWrite; } - } - - public int MaximumRead { - get { return _maxRead; } - set { _maxRead = value; } - } - - public int MaximumWrite { - get { return _maxWrite; } - set { _maxWrite = value; } - } - - // methods - - public override IAsyncResult BeginRead (byte[] buffer, int offset, int size, AsyncCallback callback, object state) - { - return base.BeginRead (buffer, offset, PreCheckRead (size), callback, state); - } - - public override int EndRead (IAsyncResult asyncResult) - { - return PostCheckRead (base.EndRead (asyncResult)); - } - - public override int Read (byte[] buffer, int offset, int size) - { - return PostCheckRead (base.Read (buffer, offset, PreCheckRead (size))); - } - - public override IAsyncResult BeginWrite (byte[] buffer, int offset, int size, AsyncCallback callback, object state) - { - return base.BeginWrite (buffer, offset, PreCheckWrite (size), callback, state); - } - - public override void EndWrite (IAsyncResult asyncResult) - { - PostCheckWrite (); - base.EndWrite (asyncResult); - } - - public override void Write (byte[] buffer, int offset, int size) - { - base.Write (buffer, offset, PreCheckWrite (size)); - PostCheckWrite (); - } - - // internal stutff - - private int PreCheckRead (int size) - { - if (_maxRead < 0) - return size; - - if (_curRead + size > _maxRead) - size = _maxRead - _curRead; - - return size; - } - - private int PostCheckRead (int size) - { - _curRead += size; - return size; - } - - private int PreCheckWrite (int size) - { - if (_maxWrite < 0) - return size; - - if (_curWrite + size > _maxWrite) - size = _maxWrite - _curWrite; - - return size; - } - - private void PostCheckWrite () - { - } - } -} diff --git a/mcs/class/Mono.Security/Test/tools/cutcli/Makefile b/mcs/class/Mono.Security/Test/tools/cutcli/Makefile deleted file mode 100644 index 45774dbb59b..00000000000 --- a/mcs/class/Mono.Security/Test/tools/cutcli/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -thisdir = class/Mono.Security/Test/tools/cutcli -SUBDIRS = -include ../../../../../build/rules.make - -LOCAL_MCS_FLAGS = /r:System.dll /r:Mono.Security.dll - -all-local install-local uninstall-local: - -test-local: - -# ??? What do we run here? - -run-test-local: - -clean-local: - rm -f *.exe *.pdb - -sources = cutcli.cs ControlledNetworkStream.cs - -DISTFILES = $(sources) - -dist-local: dist-default - -all: cutcli.exe - -cutcli.exe: $(sources) - $(CSCOMPILE) /target:exe /out:$@ $(sources) diff --git a/mcs/class/Mono.Security/Test/tools/cutcli/cutcli.cs b/mcs/class/Mono.Security/Test/tools/cutcli/cutcli.cs deleted file mode 100644 index 6918fdddfba..00000000000 --- a/mcs/class/Mono.Security/Test/tools/cutcli/cutcli.cs +++ /dev/null @@ -1,239 +0,0 @@ -// -// CutCli.cs: A TLS/SSL Test Program that can cut the communication after -// 'x' read bytes and/or 'y' bytes written. -// -// Author: -// Sebastien Pouliot <sebastien@ximian.com> -// -// (C) 2005 Novell (http://www.novell.com) -// - -using System; -using System.Collections; -using System.Globalization; -using System.IO; -using System.Net; -using System.Net.Sockets; -using System.Reflection; -using System.Security.Cryptography.X509Certificates; -using System.Text; - -using Mono.Security.Protocol.Tls; -using Mono.Test; - -public class TlsTest { - - public static void Usage (string message) - { - Console.WriteLine ("{0}tlstest - Copyright (c) 2004 Novell", Environment.NewLine); - if (message != null) { - Console.WriteLine ("{0}{1}{0}", Environment.NewLine, message); - } - Console.WriteLine ("Usage:"); - Console.WriteLine ("tlstest [protocol] [class] [credentials] [--x:x509 [--x:x509]] [--time] [--show] url [...]"); - Console.WriteLine ("{0}protocol (only applicable when using stream)", Environment.NewLine); - Console.WriteLine ("\t--any \tNegotiate protocol [default]"); - Console.WriteLine ("\t--ssl \tUse SSLv3"); - Console.WriteLine ("\t--ssl3 \tUse SSLv3"); - Console.WriteLine ("\t--tls \tUse TLSv1"); - Console.WriteLine ("\t--tls1 \tUse TLSv1"); - Console.WriteLine ("{0}credentials", Environment.NewLine); - Console.WriteLine ("\t--basic:username:password:domain\tBasic Authentication"); - Console.WriteLine ("\t--digest:username:password:domain\tDigest Authentication"); - Console.WriteLine ("{0}options", Environment.NewLine); - Console.WriteLine ("\t--x:x509\tX.509 client certificate (multiple entries allowed"); - Console.WriteLine ("\t--time \tShow the time required for each page load"); - Console.WriteLine ("\t--show \tShow the web page content on screen"); - Console.WriteLine ("{0}\turl [...]\tOne, or more, URL to download{0}", Environment.NewLine); - } - - private static bool show; - private static bool time; - private static Mono.Security.Protocol.Tls.SecurityProtocolType protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Default; - private static int read = -1; - private static int write = -1; - private static bool readloop = false; - private static bool writeloop = false; - - 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 ()); - } - } - } - } - - private static void ShowCertificateError (int error) - { - string message = null; - switch (error) { - case -2146762490: - message = "CERT_E_PURPOSE 0x800B0106"; - break; - case -2146762481: - message = "CERT_E_CN_NO_MATCH 0x800B010F"; - break; - case -2146869223: - message = "TRUST_E_BASIC_CONSTRAINTS 0x80096019"; - break; - case -2146869232: - message = "TRUST_E_BAD_DIGEST 0x80096010"; - break; - case -2146762494: - message = "CERT_E_VALIDITYPERIODNESTING 0x800B0102"; - break; - case -2146762495: - message = "CERT_E_EXPIRED 0x800B0101"; - break; - case -2146762486: - message = "CERT_E_CHAINING 0x800B010A"; - break; - case -2146762487: - message = "CERT_E_UNTRUSTEDROOT 0x800B0109"; - break; - default: - message = "unknown (try WinError.h)"; - break; - } - Console.WriteLine ("Error #{0}: {1}", error, message); - } - - private static bool CertificateValidation (X509Certificate certificate, int[] certificateErrors) - { - if (certificateErrors.Length > 0) { - Console.WriteLine (certificate.ToString (true)); - // X509Certificate.ToString(true) doesn't show dates :-( - Console.WriteLine ("\tValid From: {0}", certificate.GetEffectiveDateString ()); - Console.WriteLine ("\tValid Until: {0}{1}", certificate.GetExpirationDateString (), Environment.NewLine); - // multiple errors are possible using SslClientStream - foreach (int error in certificateErrors) { - ShowCertificateError (error); - } - } - // whatever the reason we do not stop the SSL connection - return true; - } -} - diff --git a/mcs/class/Mono.Security/Test/tools/mutual/.gitattributes b/mcs/class/Mono.Security/Test/tools/mutual/.gitattributes deleted file mode 100644 index 947e32bf108..00000000000 --- a/mcs/class/Mono.Security/Test/tools/mutual/.gitattributes +++ /dev/null @@ -1,3 +0,0 @@ -/ca.pem -crlf -/client.pem -crlf -/mutual.cs -crlf diff --git a/mcs/class/Mono.Security/Test/tools/mutual/Makefile b/mcs/class/Mono.Security/Test/tools/mutual/Makefile deleted file mode 100644 index dcea4bd4fb2..00000000000 --- a/mcs/class/Mono.Security/Test/tools/mutual/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -thisdir = class/Mono.Security/Test/tools/mutual -SUBDIRS = -include ../../../../../build/rules.make - -LOCAL_MCS_FLAGS = /r:System.dll /r:Mono.Security.dll - -all-local install-local uninstall-local: - -test-local: - -# ??? What do we run here? - -run-test-local: - -clean-local: - rm -f *.exe *.pdb *.mdb - -sources = mutual.cs - -DISTFILES = $(sources) ca.pem client.p12 client.pem server_cert.pem \ - server_key.pem server.sh README - -dist-local: dist-default - -all: mutual.exe - -mutual.exe: mutual.cs - $(CSCOMPILE) /target:exe /out:$@ $^ diff --git a/mcs/class/Mono.Security/Test/tools/mutual/README b/mcs/class/Mono.Security/Test/tools/mutual/README deleted file mode 100644 index 8c40ae85e34..00000000000 --- a/mcs/class/Mono.Security/Test/tools/mutual/README +++ /dev/null @@ -1,39 +0,0 @@ -mutual.exe is a test tool for mutual authentication. The tool works for both -SSL3 and TLS1 protocols. A script is provided to use OpenSSL as a server. - -1. Testing TLS1 mutual authentication - -% mono mutual.exe localhost TLS client.p12 demo - - -2. Testing SSL3 mutual authentication - -% mono mutual.exe localhost SSL client.p12 demo - - -3. Testing TLS1 without mutual authentication [*] - -% mono mutual.exe localhost TLS - - -4. Testing SSL3 without mutual authentication [*] - -% mono mutual.exe localhost SSL - - -5. Testing TLS1 _optional_ mutual authentication [**] - -% mono mutual.exe localhost TLS - - -6. Testing SSL3 _optional_ mutual authentication [**] - -% mono mutual.exe localhost SSL - - - -[*] OpenSSL (if used) requires a mutual authentication. So test #3 and #4 are -expected to fail. - -[**] Test 5 and 6 must be executed with the serveropt.sh script running. Both -tests ARE NOT expected to fail. diff --git a/mcs/class/Mono.Security/Test/tools/mutual/ca.pem b/mcs/class/Mono.Security/Test/tools/mutual/ca.pem deleted file mode 100644 index c837dce7f9c..00000000000 --- a/mcs/class/Mono.Security/Test/tools/mutual/ca.pem +++ /dev/null @@ -1,15 +0,0 @@ ------BEGIN CERTIFICATE-----
-MIICXjCCAgigAwIBAgIBADANBgkqhkiG9w0BAQQFADBbMRAwDgYDVQQKEwdNaWRk
-c29sMRAwDgYDVQQHEwdIYW1idXJnMRAwDgYDVQQIEwdHZXJtYW55MQswCQYDVQQG
-EwJERTEWMBQGA1UEAxMNTWlkZHNvbERlbW9DQTAeFw0wNDA4MjUxNTAyNDdaFw0x
-NDA4MjgxNTAyNDdaMFsxEDAOBgNVBAoTB01pZGRzb2wxEDAOBgNVBAcTB0hhbWJ1
-cmcxEDAOBgNVBAgTB0dlcm1hbnkxCzAJBgNVBAYTAkRFMRYwFAYDVQQDEw1NaWRk
-c29sRGVtb0NBMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJMY+RSPiP9KpxznPE0S
-PGHhStc25y1CDHGdR33T1PCg3cD+XX5nLDTn83Jb3KU1j/Nh5sDi7RLflrSo8oXz
-OAkCAwEAAaOBtjCBszAMBgNVHRMEBTADAQH/MB0GA1UdDgQWBBTSHOgWrKCgE3Bg
-SksGSZdJjL6pLTCBgwYDVR0jBHwweoAU0hzoFqygoBNwYEpLBkmXSYy+qS2hX6Rd
-MFsxEDAOBgNVBAoTB01pZGRzb2wxEDAOBgNVBAcTB0hhbWJ1cmcxEDAOBgNVBAgT
-B0dlcm1hbnkxCzAJBgNVBAYTAkRFMRYwFAYDVQQDEw1NaWRkc29sRGVtb0NBggEA
-MA0GCSqGSIb3DQEBBAUAA0EAHYPXGT8tDS0LyFIAor8PZ3zP+MxIHm9p87IarsFI
-elsb1+JaFNVYb3Mzh+dXY93NrTsxIjgbi8ld8X0w4KElHA==
------END CERTIFICATE-----
diff --git a/mcs/class/Mono.Security/Test/tools/mutual/client.p12 b/mcs/class/Mono.Security/Test/tools/mutual/client.p12 Binary files differdeleted file mode 100644 index f7f220e4c3a..00000000000 --- a/mcs/class/Mono.Security/Test/tools/mutual/client.p12 +++ /dev/null diff --git a/mcs/class/Mono.Security/Test/tools/mutual/client.pem b/mcs/class/Mono.Security/Test/tools/mutual/client.pem deleted file mode 100644 index 53c60af5f1c..00000000000 --- a/mcs/class/Mono.Security/Test/tools/mutual/client.pem +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN CERTIFICATE-----
-MIICejCCAiSgAwIBAgIBATANBgkqhkiG9w0BAQQFADBbMRAwDgYDVQQKEwdNaWRk
-c29sMRAwDgYDVQQHEwdIYW1idXJnMRAwDgYDVQQIEwdHZXJtYW55MQswCQYDVQQG
-EwJERTEWMBQGA1UEAxMNTWlkZHNvbERlbW9DQTAeFw0wNDA4MjUxNTAzMTlaFw0x
-NDA4MjMxNTAzMTlaMEsxCzAJBgNVBAYTAkRFMRAwDgYDVQQIEwdHZXJtYW55MRAw
-DgYDVQQKEwdNaWRkc29sMRgwFgYDVQQDEw9NaWRkc29sRGVtb0NlcnQwXDANBgkq
-hkiG9w0BAQEFAANLADBIAkEApnQapV0DtGUrE1Z0Jn3DCdXL43f8qbvUunlKhq2P
-8errH5r4dl4ZVjod43KZV5yp0TKNQOvVRWEucNVMwCcs1wIDAQABo4HiMIHfMAwG
-A1UdEwQFMAMBAf8wHQYDVR0OBBYEFACmgZvTLGm1MEwTJM2U1aaNLVpYMIGDBgNV
-HSMEfDB6gBTSHOgWrKCgE3BgSksGSZdJjL6pLaFfpF0wWzEQMA4GA1UEChMHTWlk
-ZHNvbDEQMA4GA1UEBxMHSGFtYnVyZzEQMA4GA1UECBMHR2VybWFueTELMAkGA1UE
-BhMCREUxFjAUBgNVBAMTDU1pZGRzb2xEZW1vQ0GCAQAwCwYDVR0PBAQDAgPoMB0G
-A1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjANBgkqhkiG9w0BAQQFAANBAIFM
-ji0oB+sdOqRgrjtmt9ojpul6ZvDYrN6CKunLLIO20qlqN8X91TlUMnkKuxjvZFoy
-KH/hGPS3mvKWaeN+9q0=
------END CERTIFICATE-----
diff --git a/mcs/class/Mono.Security/Test/tools/mutual/mutual.cs b/mcs/class/Mono.Security/Test/tools/mutual/mutual.cs deleted file mode 100644 index 1f4b6a95cdd..00000000000 --- a/mcs/class/Mono.Security/Test/tools/mutual/mutual.cs +++ /dev/null @@ -1,93 +0,0 @@ -using System;
-using System.IO;
-using System.Net.Sockets;
-using System.Security.Cryptography;
-using System.Security.Cryptography.X509Certificates;
-
-using Mono.Security.Protocol.Tls;
-
-class TestSslClientStream {
-
- static Mono.Security.X509.PKCS12 p12;
-
- [STAThread]
- static void Main(string[] args)
- {
- string host = "localhost";
- if (args.Length > 0)
- host = args[0];
-
- SecurityProtocolType protocol = SecurityProtocolType.Tls;
- if (args.Length > 1) {
- switch (args [1].ToUpper ()) {
- case "SSL":
- protocol = SecurityProtocolType.Ssl3;
- break;
- }
- }
-
- X509CertificateCollection certificates = null;
- if (args.Length > 2) {
- string password = null;
- if (args.Length > 3)
- password = args [3];
-
- p12 = Mono.Security.X509.PKCS12.LoadFromFile(args [2], password);
-
- certificates = new X509CertificateCollection ();
- foreach (Mono.Security.X509.X509Certificate cert in p12.Certificates) {
- certificates.Add(new X509Certificate(cert.RawData));
- }
- }
-
- TcpClient client = new TcpClient ();
- client.Connect (host, 4433);
-
- SslClientStream ssl = new SslClientStream (client.GetStream(), host, false, protocol, certificates);
- ssl.ServerCertValidationDelegate += new CertificateValidationCallback (CertificateValidation);
- ssl.ClientCertSelectionDelegate += new CertificateSelectionCallback (ClientCertificateSelection);
- ssl.PrivateKeyCertSelectionDelegate += new PrivateKeySelectionCallback (PrivateKeySelection);
-
- StreamWriter sw = new StreamWriter (ssl, System.Text.Encoding.ASCII);
- sw.WriteLine ("GET /clientcert.aspx{0}", Environment.NewLine);
- sw.Flush ();
-
- StreamReader sr = new StreamReader (ssl);
- Console.WriteLine (sr.ReadToEnd ());
- }
-
- static bool CertificateValidation (X509Certificate certificate, int[] certificateErrors)
- {
- Console.WriteLine ("CertificateValidation");
- Console.WriteLine (certificate.ToString (true));
- Console.WriteLine ("\tError(s)");
- foreach (int error in certificateErrors)
- Console.WriteLine ("\t\t#{0}", error);
- Console.WriteLine ();
- return true;
- }
-
- static X509Certificate ClientCertificateSelection (X509CertificateCollection clientCertificates,
- X509Certificate serverCertificate, string targetHost, X509CertificateCollection serverRequestedCertificates)
- {
- Console.WriteLine ("ClientCertificateSelection");
- Console.WriteLine ("\tClient Certificates ({0})", clientCertificates.Count);
- int i = 1;
- foreach (X509Certificate client in clientCertificates)
- Console.WriteLine ("#{0} - {1}", i++, client.ToString (true));
- Console.WriteLine ("\tHost: {0}", targetHost);
- Console.Write ("SERVER {0}", serverCertificate.ToString (true));
- Console.WriteLine ();
- return clientCertificates [0];
- }
-
- static AsymmetricAlgorithm PrivateKeySelection (X509Certificate certificate, string targetHost)
- {
- Console.WriteLine ("PrivateKeySelection");
- Console.WriteLine ("\tHost: {0}", targetHost);
- Console.WriteLine (certificate.ToString (true));
- Console.WriteLine ("\tPrivateKeySelection ({0})", p12.Keys.Count);
- Console.WriteLine ();
- return (AsymmetricAlgorithm) p12.Keys [0];
- }
-}
diff --git a/mcs/class/Mono.Security/Test/tools/mutual/server.sh b/mcs/class/Mono.Security/Test/tools/mutual/server.sh deleted file mode 100755 index e21f27e29d9..00000000000 --- a/mcs/class/Mono.Security/Test/tools/mutual/server.sh +++ /dev/null @@ -1 +0,0 @@ -openssl s_server -www -cert server_cert.pem -key server_key.pem -Verify client.pem -CAfile ca.pem diff --git a/mcs/class/Mono.Security/Test/tools/mutual/server_cert.pem b/mcs/class/Mono.Security/Test/tools/mutual/server_cert.pem deleted file mode 100644 index 4ad3d6ce62d..00000000000 --- a/mcs/class/Mono.Security/Test/tools/mutual/server_cert.pem +++ /dev/null @@ -1,66 +0,0 @@ -Certificate: - Data: - Version: 3 (0x2) - Serial Number: 1 (0x1) - Signature Algorithm: md5WithRSAEncryption - Issuer: C=CA, ST=Quebec, L=Quebec City, O=Novell Ximian, OU=Mono Project, CN=Test CA - Validity - Not Before: Apr 12 15:17:58 2005 GMT - Not After : Apr 12 15:17:58 2006 GMT - Subject: C=CA, ST=Quebec, L=Quebec City, O=Novell Ximian, OU=Mono Project, CN=SSL Test - Subject Public Key Info: - Public Key Algorithm: rsaEncryption - RSA Public Key: (1024 bit) - Modulus (1024 bit): - 00:d7:56:5b:61:f3:7b:5a:db:5c:ec:a5:c0:f6:85: - 7f:74:67:33:b7:fc:55:72:f5:94:05:52:8c:da:73: - 70:0a:7f:6f:f6:7a:70:d5:85:d9:64:9b:1f:82:a2: - b7:57:d5:e5:77:6e:da:bf:a3:c5:5d:32:c5:05:1c: - 2d:8b:98:08:a5:a5:e4:15:52:68:f5:01:b1:b8:d0: - bb:1b:d0:80:83:bc:17:32:06:fc:05:18:e7:1e:97: - ac:ab:de:2d:51:d5:14:78:f7:05:ac:e8:4e:25:f4: - ff:86:d8:58:d4:9d:e1:e4:02:a1:30:23:c0:b0:19: - 9a:15:33:ae:ba:62:08:c5:29 - Exponent: 65537 (0x10001) - X509v3 extensions: - X509v3 Basic Constraints: - CA:FALSE - Netscape Comment: - OpenSSL Generated Certificate - X509v3 Subject Key Identifier: - 65:BB:48:01:4B:DB:D8:9A:FE:AB:96:C1:73:26:FB:03:27:B3:06:5F - X509v3 Authority Key Identifier: - keyid:90:32:BC:6C:64:D2:5E:46:98:5F:20:31:DA:2F:E9:15:5D:C9:90:31 - DirName:/C=CA/ST=Quebec/L=Quebec City/O=Novell Ximian/OU=Mono Project/CN=Test CA - serial:00 - - Signature Algorithm: md5WithRSAEncryption - 5a:e3:d5:c7:69:dd:f7:84:e2:19:ee:a0:0d:d6:bb:a9:28:52: - 15:bc:dc:c3:ad:57:65:07:4c:36:ff:be:7f:15:59:c7:f4:be: - 6c:f2:88:8a:7a:59:14:0b:fa:07:e0:35:2f:0c:89:33:2c:5f: - bd:67:03:f5:e6:81:ad:db:f1:12:18:f5:39:63:f7:62:f4:2d: - e2:9f:f6:e8:32:98:af:bc:ae:65:04:6f:d1:de:d8:3b:aa:b7: - 66:1e:fa:77:16:dd:b5:eb:7d:b6:ed:a0:8f:68:cd:a0:11:e6: - dc:bb:a6:ba:31:40:88:b1:04:fe:e8:ca:1d:57:5c:1e:89:8a: - 07:bd ------BEGIN CERTIFICATE----- -MIIDXzCCAsigAwIBAgIBATANBgkqhkiG9w0BAQQFADB1MQswCQYDVQQGEwJDQTEP -MA0GA1UECBMGUXVlYmVjMRQwEgYDVQQHEwtRdWViZWMgQ2l0eTEWMBQGA1UEChMN -Tm92ZWxsIFhpbWlhbjEVMBMGA1UECxMMTW9ubyBQcm9qZWN0MRAwDgYDVQQDEwdU -ZXN0IENBMB4XDTA1MDQxMjE1MTc1OFoXDTA2MDQxMjE1MTc1OFowdjELMAkGA1UE -BhMCQ0ExDzANBgNVBAgTBlF1ZWJlYzEUMBIGA1UEBxMLUXVlYmVjIENpdHkxFjAU -BgNVBAoTDU5vdmVsbCBYaW1pYW4xFTATBgNVBAsTDE1vbm8gUHJvamVjdDERMA8G -A1UEAxMIU1NMIFRlc3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANdWW2Hz -e1rbXOylwPaFf3RnM7f8VXL1lAVSjNpzcAp/b/Z6cNWF2WSbH4Kit1fV5Xdu2r+j -xV0yxQUcLYuYCKWl5BVSaPUBsbjQuxvQgIO8FzIG/AUY5x6XrKveLVHVFHj3Bazo -TiX0/4bYWNSd4eQCoTAjwLAZmhUzrrpiCMUpAgMBAAGjgf0wgfowCQYDVR0TBAIw -ADAsBglghkgBhvhCAQ0EHxYdT3BlblNTTCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUw -HQYDVR0OBBYEFGW7SAFL29ia/quWwXMm+wMnswZfMIGfBgNVHSMEgZcwgZSAFJAy -vGxk0l5GmF8gMdov6RVdyZAxoXmkdzB1MQswCQYDVQQGEwJDQTEPMA0GA1UECBMG -UXVlYmVjMRQwEgYDVQQHEwtRdWViZWMgQ2l0eTEWMBQGA1UEChMNTm92ZWxsIFhp -bWlhbjEVMBMGA1UECxMMTW9ubyBQcm9qZWN0MRAwDgYDVQQDEwdUZXN0IENBggEA -MA0GCSqGSIb3DQEBBAUAA4GBAFrj1cdp3feE4hnuoA3Wu6koUhW83MOtV2UHTDb/ -vn8VWcf0vmzyiIp6WRQL+gfgNS8MiTMsX71nA/Xmga3b8RIY9Tlj92L0LeKf9ugy -mK+8rmUEb9He2Duqt2Ye+ncW3bXrfbbtoI9ozaAR5ty7proxQIixBP7oyh1XXB6J -ige9 ------END CERTIFICATE----- diff --git a/mcs/class/Mono.Security/Test/tools/mutual/server_key.pem b/mcs/class/Mono.Security/Test/tools/mutual/server_key.pem deleted file mode 100644 index 497199b6e96..00000000000 --- a/mcs/class/Mono.Security/Test/tools/mutual/server_key.pem +++ /dev/null @@ -1,15 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIICXAIBAAKBgQDXVlth83ta21zspcD2hX90ZzO3/FVy9ZQFUozac3AKf2/2enDV -hdlkmx+CordX1eV3btq/o8VdMsUFHC2LmAilpeQVUmj1AbG40Lsb0ICDvBcyBvwF -GOcel6yr3i1R1RR49wWs6E4l9P+G2FjUneHkAqEwI8CwGZoVM666YgjFKQIDAQAB -AoGAfYxJ50gQSZ7QBOF3KcQX1YQ+MS0bnNT1okzI9qyLTHOUkb49fyB06SVQL9gy -0TFSglnNjCIt9fKd0CbnnxXbI7cPf35SYB8GXJKoF8wOTx/QfPHKn5GCYDX7GPcm -Q3praI+J8XiS7DN6WVbcB+pdqsU+uEYWLhe5CiDUBaxBlqECQQD1lZjeuNzNRuF9 -ylltDfDEXmEsb/uAP6LV5rKF6bXLrXCEOp+FExqXOHHzawoI/NEioDI2r/modFKc -xEU19gZlAkEA4HhbNWhBks0XBN6nRECjn2F40PSt9JAMoaHbC+sMEQVbQ+Qdwi2E -261LlV22maCwEsq6AuPnMMSgjio1tapldQJAOhrlCn1OsLr+ixafRfAwcSWrdCoi -pVtpGZb10j1TqBcnMgH00DWO6wyN2XwP6cR3buvcNZg5R6QOD81YWsYVCQJAZtTc -O9g6Cg1oWTPC/tJ54r7dgSRGOL5w+u7SEWCpU3bXu39aXqVJsvVtpcybpT9mygUT -N9W+CKpbPyV5G3MnLQJBAIdhgi3/X2Oc55U1Wlo3tQeKvolouSm5XVvKikFrQiDy -x1iY5mGo93eqDIIzkxRFfYOt9HIeuhIjddNGgXHExe4= ------END RSA PRIVATE KEY----- diff --git a/mcs/class/Mono.Security/Test/tools/mutual/serveropt.sh b/mcs/class/Mono.Security/Test/tools/mutual/serveropt.sh deleted file mode 100755 index 11210e9e999..00000000000 --- a/mcs/class/Mono.Security/Test/tools/mutual/serveropt.sh +++ /dev/null @@ -1 +0,0 @@ -openssl s_server -www -cert server_cert.pem -key server_key.pem -verify client.pem -CAfile ca.pem diff --git a/mcs/class/Mono.Security/Test/tools/postecho/.gitattributes b/mcs/class/Mono.Security/Test/tools/postecho/.gitattributes deleted file mode 100644 index 103d330be3a..00000000000 --- a/mcs/class/Mono.Security/Test/tools/postecho/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -/sendback.asp -crlf diff --git a/mcs/class/Mono.Security/Test/tools/postecho/Makefile b/mcs/class/Mono.Security/Test/tools/postecho/Makefile deleted file mode 100644 index 45465134935..00000000000 --- a/mcs/class/Mono.Security/Test/tools/postecho/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -thisdir = class/Mono.Security/Test/tools/postecho -SUBDIRS = -include ../../../../../build/rules.make - -LOCAL_MCS_FLAGS = /r:System.dll /r:Mono.Security.dll - -all-local install-local uninstall-local: - -test-local: - -# ??? What do we run here? - -run-test-local: - -clean-local: - rm -f *.exe *.mdb *.pdb - -sources = postecho.cs postmulti.cs - -DISTFILES = $(sources) - -dist-local: dist-default - -all: postecho.exe postmulti.exe - -postecho.exe: postecho.cs - $(CSCOMPILE) /target:exe /out:$@ $^ - -postmulti.exe: postmulti.cs - $(CSCOMPILE) /target:exe /out:$@ $^ diff --git a/mcs/class/Mono.Security/Test/tools/postecho/README b/mcs/class/Mono.Security/Test/tools/postecho/README deleted file mode 100644 index 3f926b4a447..00000000000 --- a/mcs/class/Mono.Security/Test/tools/postecho/README +++ /dev/null @@ -1,38 +0,0 @@ -POSTECHO - -To run the postecho tool your web server must have a script present to return -the TEST variable value to the tool. - -The tool can use the HttpWebRequest|Response or the SslClientStream directly. -This is almost identical when executed on Mono but very different (execution -wise not result wise) if you test with the MS runtime. - - -POSTMULTI - -To run the postmulti tool your web server(s) must have a script present to -return the TEST variable value to the tool. - -The tool use async HttpWebRequest|Response to send and receive a fixed (in -source code, default is 1 megabytes) length buffer from all URLs specified -on the command line. - -The WaitHandle class has a limit of 64 handles. Supplying more than 64 URLs -on the command-line will result in a NotSupportedException exception. - - -NOTES - -Available server-side scripts - -1. sendback.asp - - ASP script to return back the TEST value. - -2. sendback.aspx - - ASP.NET script to return back the TEST value. - - -Sebastien Pouliot -sebastien@ximian.com diff --git a/mcs/class/Mono.Security/Test/tools/postecho/postecho.cs b/mcs/class/Mono.Security/Test/tools/postecho/postecho.cs deleted file mode 100644 index f340af865c9..00000000000 --- a/mcs/class/Mono.Security/Test/tools/postecho/postecho.cs +++ /dev/null @@ -1,203 +0,0 @@ -// -// postecho.cs: TLS/SSL Post Echo Test Program -// -// Authors: -// Gonzalo Paniagua Javier <gonzalo@ximian.com> -// Sebastien Pouliot <sebastien@ximian.com> -// -// (C) 2005 Novell (http://www.novell.com) -// - -using System; -using System.IO; -using System.Net; -using System.Net.Sockets; -using System.Text; -using System.Security.Cryptography.X509Certificates; -using Mono.Security.Protocol.Tls; - -class PostEcho { - - static void Help () - { - Console.WriteLine ("postecho url [size] [--web | --ssl3 | --tls1]"); - Console.WriteLine (" default size is 1024 (bytes)"); - Console.WriteLine (" default mode is --tls1"); - Console.WriteLine ("* a server side script must be installed to run postecho"); - } - - static string PostWeb (string url, byte[] buffer) - { - ServicePointManager.CertificatePolicy = new TestCertificatePolicy (); - - string postdata = "TEST="; - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); - req.Method = "POST"; - req.ContentType = "application/x-www-form-urlencoded"; - req.ContentLength = 5 + buffer.Length; - Stream output = req.GetRequestStream (); - byte [] bytes = Encoding.Default.GetBytes (postdata); - output.Write (bytes, 0, bytes.Length); - output.Write (buffer, 0, buffer.Length); - output.Close (); - HttpWebResponse response = (HttpWebResponse) req.GetResponse (); - StreamReader reader = new StreamReader (response.GetResponseStream ()); - return reader.ReadToEnd (); - } - - 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); - } - - 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; - } - - private static void ShowCertificateError (int error) - { - string message = null; - switch (error) - { - case -2146762490: - message = "CERT_E_PURPOSE 0x800B0106"; - break; - case -2146762481: - message = "CERT_E_CN_NO_MATCH 0x800B010F"; - break; - case -2146869223: - message = "TRUST_E_BASIC_CONSTRAINTS 0x80096019"; - break; - case -2146869232: - message = "TRUST_E_BAD_DIGEST 0x80096010"; - break; - case -2146762494: - message = "CERT_E_VALIDITYPERIODNESTING 0x800B0102"; - break; - case -2146762495: - message = "CERT_E_EXPIRED 0x800B0101"; - break; - case -2146762486: - message = "CERT_E_CHAINING 0x800B010A"; - break; - case -2146762487: - message = "CERT_E_UNTRUSTEDROOT 0x800B0109"; - break; - default: - message = "unknown (try WinError.h)"; - break; - } - Console.WriteLine ("Error #{0}: {1}", error, message); - } - - private static bool CertificateValidation (X509Certificate certificate, int[] certificateErrors) - { - if (certificateErrors.Length > 0) - { - Console.WriteLine (certificate.ToString (true)); - // X509Certificate.ToString(true) doesn't show dates :-( - Console.WriteLine ("\tValid From: {0}", certificate.GetEffectiveDateString ()); - Console.WriteLine ("\tValid Until: {0}{1}", certificate.GetExpirationDateString (), Environment.NewLine); - // multiple errors are possible using SslClientStream - foreach (int error in certificateErrors) - { - ShowCertificateError (error); - } - } - // whatever the reason we do not stop the SSL connection - return true; - } - - public class TestCertificatePolicy : ICertificatePolicy { - - public bool CheckValidationResult (ServicePoint sp, X509Certificate certificate, WebRequest request, int error) - { - if (error != 0) { - Console.WriteLine (certificate.ToString (true)); - // X509Certificate.ToString(true) doesn't show dates :-( - Console.WriteLine ("\tValid From: {0}", certificate.GetEffectiveDateString ()); - Console.WriteLine ("\tValid Until: {0}{1}", certificate.GetExpirationDateString (), Environment.NewLine); - - ShowCertificateError (error); - } - // whatever the reason we do not stop the SSL connection - return true; - } - } -} - diff --git a/mcs/class/Mono.Security/Test/tools/postecho/postmulti.cs b/mcs/class/Mono.Security/Test/tools/postecho/postmulti.cs deleted file mode 100644 index a9f184ddd9f..00000000000 --- a/mcs/class/Mono.Security/Test/tools/postecho/postmulti.cs +++ /dev/null @@ -1,135 +0,0 @@ -// -// postmulti.cs: Multi-sessions TLS/SSL Test Program -// based on tlstest.cs, tlsmulti.cs and postecho.cs -// -// Author: -// Sebastien Pouliot <sebastien@ximian.com> -// -// Copyright (C) 2004-2005 Novell (http://www.novell.com) -// - -using System; -using System.Collections; -using System.Globalization; -using System.IO; -using System.Net; -using System.Net.Sockets; -using System.Reflection; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using System.Threading; - -using Mono.Security.Protocol.Tls; - -public class State { - - static ArrayList handleList = new ArrayList (); - - private int id; - private HttpWebRequest request; - private ManualResetEvent handle; - - public State (int id, HttpWebRequest req) - { - this.id = id; - request = req; - handle = new ManualResetEvent (false); - handleList.Add (handle); - } - - public int Id { - get { return id; } - } - - public HttpWebRequest Request { - get { return request; } - } - - public void Complete () - { - handle.Set (); - } - - static public void WaitAll () - { - if (handleList.Count > 0) { - WaitHandle[] handles = (WaitHandle[]) handleList.ToArray (typeof (WaitHandle)); - WaitHandle.WaitAll (handles); - handleList.Clear (); - } - } -} - -public class MultiTest { - - public const int buffersize = 1024 * 1024; - - static byte[] data = new byte [buffersize]; - - public static void Main (string[] args) - { - ServicePointManager.CertificatePolicy = new TestCertificatePolicy (); - - string postdata = "TEST="; - byte[] bytes = Encoding.Default.GetBytes (postdata); - - // prepare test buffer - for (int i = 0; i < buffersize; i++) - data[i] = 65; - - int id = 1; - foreach (string url in args) { - Console.WriteLine ("POST #{0} at {1}", id, url); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); - req.Method = "POST"; - req.ContentType = "application/x-www-form-urlencoded"; - req.ContentLength = 5 + data.Length; - - Stream output = req.GetRequestStream (); - output.Write (bytes, 0, bytes.Length); - output.Write (data, 0, data.Length); - output.Close (); - - State s = new State (id++, req); - req.BeginGetResponse (new AsyncCallback (ResponseCallback), s); - } - - State.WaitAll (); - } - - private static void ResponseCallback (IAsyncResult result) - { - State state = ((State) result.AsyncState); - HttpWebResponse response = (HttpWebResponse) state.Request.EndGetResponse (result); - - Stream stream = response.GetResponseStream (); - StreamReader sr = new StreamReader (stream, Encoding.UTF8); - string received = sr.ReadToEnd (); - - if (data.Length != received.Length) { - Console.WriteLine ("ECHO #{0} - Invalid length {1}. Expected {2}", state.Id, received.Length, data.Length); - } else { - bool ok = true; - for (int i = 0; i < received.Length; i++) { - if (received[i] != 'A') { - ok = false; - Console.WriteLine ("ECHO #{0} - Error at position #{1} - received '{2}'", state.Id, i, received[i]); - break; - } - } - if (ok) - Console.WriteLine ("ECHO #{0} - Result OK (length: {1})", state.Id, received.Length); - } - - state.Complete (); - } - - public class TestCertificatePolicy : ICertificatePolicy { - - public bool CheckValidationResult (ServicePoint sp, X509Certificate certificate, WebRequest request, int error) - { - // whatever the reason we do not stop the SSL connection - return true; - } - } -} diff --git a/mcs/class/Mono.Security/Test/tools/postecho/sendback.ashx b/mcs/class/Mono.Security/Test/tools/postecho/sendback.ashx deleted file mode 100644 index b9f4a8ec299..00000000000 --- a/mcs/class/Mono.Security/Test/tools/postecho/sendback.ashx +++ /dev/null @@ -1,45 +0,0 @@ -<%@ WebHandler Language="c#" class="XSPTest.SendBack" %> - -using System; -using System.IO; -using System.Web; - -namespace XSPTest -{ - public class SendBack : IHttpHandler - { - public void ProcessRequest (HttpContext context) - { - // Replies with the content of the TEST form variable. - ProcessRequestTestVar (context); - // Replies with all the contents in the input stream - //ProcessRequestAll (context); - } - - void ProcessRequestTestVar (HttpContext context) - { - string test = context.Request ["TEST"]; - context.Response.Write (test); - Console.WriteLine ("Done writing a string of {0} characters.", (test != null) ? test.Length : 0); - } - - void ProcessRequestAll (HttpContext context) - { - byte [] bytes = new byte [10240]; - Stream input = context.Request.InputStream; - Stream output = context.Response.OutputStream; - int nread; - int total = 0; - while ((nread = input.Read (bytes, 0, 10240)) > 0) { - output.Write (bytes, 0, nread); - total += nread; - } - Console.WriteLine ("Done writing {0} bytes.", total); - } - - public bool IsReusable { - get { return true; } - } - } -} - diff --git a/mcs/class/Mono.Security/Test/tools/postecho/sendback.asp b/mcs/class/Mono.Security/Test/tools/postecho/sendback.asp deleted file mode 100644 index 160980a7c2f..00000000000 --- a/mcs/class/Mono.Security/Test/tools/postecho/sendback.asp +++ /dev/null @@ -1,3 +0,0 @@ -<%@LANGUAGE="VBSCRIPT"%>
-<%= Request.Form("TEST") %>
-
diff --git a/mcs/class/Mono.Security/Test/tools/postecho/sendback.aspx b/mcs/class/Mono.Security/Test/tools/postecho/sendback.aspx deleted file mode 100644 index 68565ed2f33..00000000000 --- a/mcs/class/Mono.Security/Test/tools/postecho/sendback.aspx +++ /dev/null @@ -1 +0,0 @@ -<%= Request.Form ("TEST") %>
\ No newline at end of file diff --git a/mcs/class/Mono.Security/Test/tools/server/Makefile b/mcs/class/Mono.Security/Test/tools/server/Makefile deleted file mode 100644 index f6362b8950e..00000000000 --- a/mcs/class/Mono.Security/Test/tools/server/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -thisdir = class/Mono.Security/Test/tools/server -SUBDIRS = -include ../../../../../build/rules.make - -LOCAL_MCS_FLAGS = -r:System.dll -r:Mono.Security.dll - -all-local install-local uninstall-local: - -test-local: - -# ??? What do we run here? - -run-test-local: - -clean-local: - rm -f *.exe *.pdb *.mdb ssl.cer ssl.pvk index.html* - -sources = msslserver.cs - -DISTFILES = $(sources) mutual.pem README Makefile - -dist-local: dist-default - -all: msslserver.exe ssl.pvk - -msslserver.exe: msslserver.cs - $(CSCOMPILE) /target:exe /out:$@ $^ - -ssl.pvk: - makecert -r -eku 1.3.6.1.5.5.7.3.1 -n "CN=$(HOSTNAME)" -sv ssl.pvk ssl.cer diff --git a/mcs/class/Mono.Security/Test/tools/server/README b/mcs/class/Mono.Security/Test/tools/server/README deleted file mode 100644 index a15294d94a5..00000000000 --- a/mcs/class/Mono.Security/Test/tools/server/README +++ /dev/null @@ -1,55 +0,0 @@ -SSL SERVER WITH MUTUAL AUTHENTICATION SUPPORT - -This server code (msslserver.cs) is an updated version from -http://pages.infinit.net/ctech/200411.html - -It has been updated to support mutual authentication and accept any (or no) -client certificates. The server listen to port 4443 (i.e. not the standard SSL -port) to coexists with other web servers possibily present on the computer. - - -TEST CASES - -1. Mutual authentication with automatic SSL/TLS detection (TLS by default) - -wget --no-check-certificate --certificate=mutual.pem --private-key=mutual.pem https://localhost:4433 - - -2. Mutual authentication with SSL3 - -wget --no-check-certificate --secure-protocol=sslv3 --certificate=mutual.pem --private-key=mutual.pem https://localhost:4433 - - -3. Mutual authentication with TLS1 - -wget --no-check-certificate --secure-protocol=tlsv1 --certificate=mutual.pem --private-key=mutual.pem https://localhost:4433 - - -4. Optional mutual authentication with automatic SSL/TLS detection (TLS by default) - -wget --no-check-certificate https://localhost:4433 - - -5. Optional mutual authentication with SSL3 - -wget --no-check-certificate --secure-protocol=sslv3 https://localhost:4433 - - -6. Optional mutual authentication with TLS1 - -wget --no-check-certificate --secure-protocol=tlsv1 https://localhost:4433 - - -NOTES - -* Mono.Security.dll version - - This sample/test requires Mono.Security.dll from Mono 1.1.9 or later. - -* SSL versions - - --secure-protocol=sslv2 is for SSL2 which isn't supported. - -* Convertion from PKCS#12 to PEM (wget/OpenSSL) - - openssl pkcs12 -in ../mutual/client.p12 -out mutual.pem -nodes diff --git a/mcs/class/Mono.Security/Test/tools/server/msslserver.cs b/mcs/class/Mono.Security/Test/tools/server/msslserver.cs deleted file mode 100644 index 4f1723d70cb..00000000000 --- a/mcs/class/Mono.Security/Test/tools/server/msslserver.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System; -using System.IO; -using System.Net; -using System.Net.Sockets; -using System.Text; - -using Mono.Security.Authenticode; -using Mono.Security.Protocol.Tls; -using System.Security.Cryptography; -using System.Security.Cryptography.X509Certificates; - -namespace SslHttpServer -{ - class SslHttpServer - { - private static X509Certificate _certificate = null; - private static string certfile; - private static string keyfile; - - static void Main (string [] args) - { - certfile = (args.Length > 1) ? args [0] : "ssl.cer"; - keyfile = (args.Length > 1) ? args [1] : "ssl.pvk"; - - Socket listenSocket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - IPEndPoint localEndPoint = new IPEndPoint (IPAddress.Any, 4433); - Socket requestSocket; - - listenSocket.Bind (localEndPoint); - listenSocket.Listen (10); - - while (true) { - try { - requestSocket = listenSocket.Accept (); - using (NetworkStream ns = new NetworkStream (requestSocket, FileAccess.ReadWrite, true)) { - using (SslServerStream s = new SslServerStream (ns, Certificate, false, false)) { - s.PrivateKeyCertSelectionDelegate += new PrivateKeySelectionCallback (GetPrivateKey); - s.ClientCertValidationDelegate += new CertificateValidationCallback (VerifyClientCertificate); - StreamReader reader = new StreamReader (s); - StreamWriter writer = new StreamWriter (s, Encoding.ASCII); - - string line; - // Read request header - do { - line = reader.ReadLine (); - if (line != null) - Console.WriteLine (line); - } - while (line != null && line.Length > 0); - - string answer = String.Format ("HTTP/1.0 200{0}Connection: close{0}" + - "Content-Type: text/html{0}Content-Encoding: {1}{0}{0}" + - "<html><body><h1>Hello {2}!</h1></body></html>{0}", - "\r\n", Encoding.ASCII.WebName, - s.ClientCertificate == null ? "World" : s.ClientCertificate.GetName ()); - - // Send response - writer.Write (answer); - - writer.Flush (); - s.Flush (); - ns.Flush (); - } - } - } - catch (Exception ex) { - Console.WriteLine ("---------------------------------------------------------"); - Console.WriteLine (ex.ToString ()); - } - } - } - - private static X509Certificate Certificate { - get { - if (_certificate == null) - _certificate = X509Certificate.CreateFromCertFile (certfile); - return _certificate; - } - } - - // note: makecert creates the private key in the PVK format - private static AsymmetricAlgorithm GetPrivateKey (X509Certificate certificate, string targetHost) - { - PrivateKey key = PrivateKey.CreateFromFile (keyfile); - return key.RSA; - } - - private static bool VerifyClientCertificate (X509Certificate certificate, int[] certificateErrors) - { - if (certificate != null) { - Console.WriteLine (certificate.ToString (true)); - } else { - Console.WriteLine ("No client certificate provided."); - } - - foreach (int error in certificateErrors) - Console.WriteLine ("\terror #{0}", error); - return true; - } - } -} diff --git a/mcs/class/Mono.Security/Test/tools/server/mutual.pem b/mcs/class/Mono.Security/Test/tools/server/mutual.pem deleted file mode 100644 index a28ce722e46..00000000000 --- a/mcs/class/Mono.Security/Test/tools/server/mutual.pem +++ /dev/null @@ -1,53 +0,0 @@ -Bag Attributes - localKeyID: 1F DC A6 8D CB 2B F4 7E 64 DC FC 54 61 58 AB 41 3E 35 45 24 - friendlyName: MiddsolDemoCert -subject=/C=DE/ST=Germany/O=Middsol/CN=MiddsolDemoCert -issuer=/O=Middsol/L=Hamburg/ST=Germany/C=DE/CN=MiddsolDemoCA ------BEGIN CERTIFICATE----- -MIICejCCAiSgAwIBAgIBATANBgkqhkiG9w0BAQQFADBbMRAwDgYDVQQKEwdNaWRk -c29sMRAwDgYDVQQHEwdIYW1idXJnMRAwDgYDVQQIEwdHZXJtYW55MQswCQYDVQQG -EwJERTEWMBQGA1UEAxMNTWlkZHNvbERlbW9DQTAeFw0wNDA4MjUxNTAzMTlaFw0x -NDA4MjMxNTAzMTlaMEsxCzAJBgNVBAYTAkRFMRAwDgYDVQQIEwdHZXJtYW55MRAw -DgYDVQQKEwdNaWRkc29sMRgwFgYDVQQDEw9NaWRkc29sRGVtb0NlcnQwXDANBgkq -hkiG9w0BAQEFAANLADBIAkEApnQapV0DtGUrE1Z0Jn3DCdXL43f8qbvUunlKhq2P -8errH5r4dl4ZVjod43KZV5yp0TKNQOvVRWEucNVMwCcs1wIDAQABo4HiMIHfMAwG -A1UdEwQFMAMBAf8wHQYDVR0OBBYEFACmgZvTLGm1MEwTJM2U1aaNLVpYMIGDBgNV -HSMEfDB6gBTSHOgWrKCgE3BgSksGSZdJjL6pLaFfpF0wWzEQMA4GA1UEChMHTWlk -ZHNvbDEQMA4GA1UEBxMHSGFtYnVyZzEQMA4GA1UECBMHR2VybWFueTELMAkGA1UE -BhMCREUxFjAUBgNVBAMTDU1pZGRzb2xEZW1vQ0GCAQAwCwYDVR0PBAQDAgPoMB0G -A1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjANBgkqhkiG9w0BAQQFAANBAIFM -ji0oB+sdOqRgrjtmt9ojpul6ZvDYrN6CKunLLIO20qlqN8X91TlUMnkKuxjvZFoy -KH/hGPS3mvKWaeN+9q0= ------END CERTIFICATE----- -Bag Attributes - friendlyName: MiddsolDemoCA -subject=/O=Middsol/L=Hamburg/ST=Germany/C=DE/CN=MiddsolDemoCA -issuer=/O=Middsol/L=Hamburg/ST=Germany/C=DE/CN=MiddsolDemoCA ------BEGIN CERTIFICATE----- -MIICXjCCAgigAwIBAgIBADANBgkqhkiG9w0BAQQFADBbMRAwDgYDVQQKEwdNaWRk -c29sMRAwDgYDVQQHEwdIYW1idXJnMRAwDgYDVQQIEwdHZXJtYW55MQswCQYDVQQG -EwJERTEWMBQGA1UEAxMNTWlkZHNvbERlbW9DQTAeFw0wNDA4MjUxNTAyNDdaFw0x -NDA4MjgxNTAyNDdaMFsxEDAOBgNVBAoTB01pZGRzb2wxEDAOBgNVBAcTB0hhbWJ1 -cmcxEDAOBgNVBAgTB0dlcm1hbnkxCzAJBgNVBAYTAkRFMRYwFAYDVQQDEw1NaWRk -c29sRGVtb0NBMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJMY+RSPiP9KpxznPE0S -PGHhStc25y1CDHGdR33T1PCg3cD+XX5nLDTn83Jb3KU1j/Nh5sDi7RLflrSo8oXz -OAkCAwEAAaOBtjCBszAMBgNVHRMEBTADAQH/MB0GA1UdDgQWBBTSHOgWrKCgE3Bg -SksGSZdJjL6pLTCBgwYDVR0jBHwweoAU0hzoFqygoBNwYEpLBkmXSYy+qS2hX6Rd -MFsxEDAOBgNVBAoTB01pZGRzb2wxEDAOBgNVBAcTB0hhbWJ1cmcxEDAOBgNVBAgT -B0dlcm1hbnkxCzAJBgNVBAYTAkRFMRYwFAYDVQQDEw1NaWRkc29sRGVtb0NBggEA -MA0GCSqGSIb3DQEBBAUAA0EAHYPXGT8tDS0LyFIAor8PZ3zP+MxIHm9p87IarsFI -elsb1+JaFNVYb3Mzh+dXY93NrTsxIjgbi8ld8X0w4KElHA== ------END CERTIFICATE----- -Bag Attributes - localKeyID: 1F DC A6 8D CB 2B F4 7E 64 DC FC 54 61 58 AB 41 3E 35 45 24 - friendlyName: MiddsolDemoCert -Key Attributes: <No Attributes> ------BEGIN RSA PRIVATE KEY----- -MIIBOQIBAAJBAKZ0GqVdA7RlKxNWdCZ9wwnVy+N3/Km71Lp5Soatj/Hq6x+a+HZe -GVY6HeNymVecqdEyjUDr1UVhLnDVTMAnLNcCAwEAAQJAbg0heOeQhXrGChkE3lYT -17LVBOXV1VrsgQWkcnraSvUXqbFe9i6K9ixA0tkYP7EDdxePy+lvL7WX2FPO87T9 -cQIhANZ14EcToA1M76WQvnVd2PykfO8yLunn3B7v2e5Uba/DAiEAxrHIKNzm8sHL -jqAu//d8+QXW7yHcfG1cXi1cLBMOMV0CICAF9flnCs0xoc89L9NishX3kdg9zBeN -Uack9YvK+531AiAOxJHy75A+xMajYCZ+Id/pBlUWSvb/TIWL/mUWZYgthQIgJSiW -fr2dfTbD+cE5QdW+IPn8QTWhqiyJKR5HPXMk+iE= ------END RSA PRIVATE KEY----- diff --git a/mcs/class/Mono.Security/Test/tools/sockethell/Makefile b/mcs/class/Mono.Security/Test/tools/sockethell/Makefile deleted file mode 100644 index 6557bccc3e5..00000000000 --- a/mcs/class/Mono.Security/Test/tools/sockethell/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -thisdir = class/Mono.Security/Test/tools/sockethell -SUBDIRS = -include ../../../../../build/rules.make - -LOCAL_MCS_FLAGS = -r:System.dll -r:Mono.Security.dll -r:../../../../lib/net_4_x/nunitlite.dll - -all-local install-local uninstall-local: - -test-local: - -run-test-local: SocketHell.dll - mono ../../../../lib/net_4_x/nunit-console.exe SocketHell.dll - -clean-local: - rm -f *.dll *.mdb *.pdb TestResult.xml - -sources = SocketHell.cs - -DISTFILES = $(sources) - -dist-local: dist-default - -all: SocketHell.dll - -SocketHell.dll: SocketHell.cs - $(CSCOMPILE) -target:library -out:$@ $^ diff --git a/mcs/class/Mono.Security/Test/tools/sockethell/SocketHell.cs b/mcs/class/Mono.Security/Test/tools/sockethell/SocketHell.cs deleted file mode 100644 index 4feef8a9020..00000000000 --- a/mcs/class/Mono.Security/Test/tools/sockethell/SocketHell.cs +++ /dev/null @@ -1,890 +0,0 @@ -using System; -using System.Collections; -using System.IO; -using System.Net; -using System.Net.Sockets; -using System.Security.Cryptography; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using System.Threading; - -using Mono.Security.Authenticode; -using Mono.Security.Protocol.Tls; -using NUnit.Framework; - -namespace Coversant.SoapBox.Base.Test -{ - [TestFixture] - public class SocketHell - { - //this is used for shutting down sockets, so mono doesn't race out of control - //see http://bugzilla.ximian.com/show_bug.cgi?id=75826 - //it doesn't always work with higher loads, but usually - //fixes this issue with a small number of sockets like we use here - public static object GlobalSocketLock = new object(); - public static int GlobalSocketLockWait = 500; - - //Wrap BeginRead or BeginWrite calls to either Ssl Stream with a BeginInvoke? - public static bool FakeAsyncReadWithDelegate = true; - public static bool FakeAsyncWriteWithDelegate = false; - - private string CertFile = "socketpong.cer"; - private string PvkFile = "socketpong.pvk"; - private string PvkPassword = ""; - private int SendIterations = 100; - private int BytesPerIteration = 8192; - private int ReadBufferSize = 8192; - private int TotalClients = 20; - private int TestTimeoutMs = 60000; - private bool ClientInitiatedClose = false; - private ManualResetEvent _testComplete; - private int _clientsComplete; - private Exception _firstAsyncException; - - [Test] - public void NetworkStreamPong_10() - { - TotalClients = 10; - SendIterations = 100; - TestTimeoutMs = 30000; - FakeAsyncReadWithDelegate = false; - FakeAsyncWriteWithDelegate = false; - ClientInitiatedClose = false; - SocketPong(false, BytesPerIteration, ReadBufferSize); - } - - [Test] - public void ClientCloseNetworkStreamPong_10() - { - TotalClients = 10; - SendIterations = 100; - TestTimeoutMs = 30000; - FakeAsyncReadWithDelegate = false; - FakeAsyncWriteWithDelegate = false; - ClientInitiatedClose = true; - SocketPong(false, BytesPerIteration, ReadBufferSize); - } - - [Test] - public void NetworkStreamPong_100() - { - TotalClients = 100; - SendIterations = 100; - TestTimeoutMs = 300000; - FakeAsyncReadWithDelegate = false; - FakeAsyncWriteWithDelegate = false; - ClientInitiatedClose = false; - SocketPong(false, BytesPerIteration, ReadBufferSize); - } - - [Test] - public void NetworkStreamPong_100_1000() - { - TotalClients = 100; - SendIterations = 1000; - TestTimeoutMs = 0; - FakeAsyncReadWithDelegate = false; - FakeAsyncWriteWithDelegate = false; - ClientInitiatedClose = false; - SocketPong(false, BytesPerIteration, ReadBufferSize); - } - - [Test] - public void TlsStreamPong_10() - { - TotalClients = 10; - SendIterations = 100; - TestTimeoutMs = 60000; - FakeAsyncReadWithDelegate = false; - FakeAsyncWriteWithDelegate = false; - ClientInitiatedClose = false; - SocketPong(true, BytesPerIteration, ReadBufferSize); - } - - [Test] - public void ClientCloseTlsStreamPong_10() - { - TotalClients = 10; - SendIterations = 100; - TestTimeoutMs = 60000; - FakeAsyncReadWithDelegate = false; - FakeAsyncWriteWithDelegate = false; - ClientInitiatedClose = true; - SocketPong(true, BytesPerIteration, ReadBufferSize); - } - - [Test] - public void TlsStreamPong_100() - { - TotalClients = 100; - SendIterations = 100; - TestTimeoutMs = 0; - FakeAsyncReadWithDelegate = false; - FakeAsyncWriteWithDelegate = false; - ClientInitiatedClose = false; - SocketPong(true, BytesPerIteration, ReadBufferSize); - } - - [Test] - public void TlsStreamPong_100_1000() - { - TotalClients = 100; - SendIterations = 1000; - TestTimeoutMs = 0; - FakeAsyncReadWithDelegate = false; - FakeAsyncWriteWithDelegate = false; - ClientInitiatedClose = false; - SocketPong(true, BytesPerIteration, ReadBufferSize); - } - - [Test] - public void FakeAsyncReadTlsStreamPong_10() - { - - TotalClients = 10; - SendIterations = 100; - TestTimeoutMs = 60000; - FakeAsyncReadWithDelegate = true; - FakeAsyncWriteWithDelegate = false; - ClientInitiatedClose = false; - SocketPong(true, BytesPerIteration, ReadBufferSize); - } - - [Test] - public void ClientCloseFakeAsyncReadTlsStreamPong_10() - { - - TotalClients = 10; - SendIterations = 100; - TestTimeoutMs = 60000; - FakeAsyncReadWithDelegate = true; - FakeAsyncWriteWithDelegate = false; - ClientInitiatedClose = true; - SocketPong(true, BytesPerIteration, ReadBufferSize); - } - - [Test] - public void FakeAsyncReadTlsStreamPong_10_1000() - { - - TotalClients = 10; - SendIterations = 1000; - TestTimeoutMs = 0; - FakeAsyncReadWithDelegate = true; - FakeAsyncWriteWithDelegate = false; - ClientInitiatedClose = false; - SocketPong(true, BytesPerIteration, ReadBufferSize); - } - - [Test] - public void FakeAsyncReadWriteTlsStreamPong_10() - { - TotalClients = 10; - SendIterations = 100; - TestTimeoutMs = 60000; - FakeAsyncReadWithDelegate = true; - FakeAsyncWriteWithDelegate = true; - ClientInitiatedClose = false; - SocketPong(true, BytesPerIteration, ReadBufferSize); - } - - [Test] - public void FakeAsyncWriteTlsStreamPong_10() - { - TotalClients = 10; - SendIterations = 100; - TestTimeoutMs = 60000; - FakeAsyncReadWithDelegate = false; - FakeAsyncWriteWithDelegate = true; - ClientInitiatedClose = false; - SocketPong(true, BytesPerIteration, ReadBufferSize); - } - - [Test] - public void SmallerBufferNetworkStreamPong_10() - { - TotalClients = 10; - SendIterations = 100; - TestTimeoutMs = 30000; - FakeAsyncReadWithDelegate = false; - FakeAsyncWriteWithDelegate = false; - ClientInitiatedClose = false; - SocketPong(false, BytesPerIteration, Convert.ToInt32(BytesPerIteration / 2)); - } - - [Test] - public void SmallerBufferTlsStreamPong_10() - { - TotalClients = 10; - SendIterations = 100; - TestTimeoutMs = 60000; - FakeAsyncReadWithDelegate = false; - FakeAsyncWriteWithDelegate = false; - ClientInitiatedClose = false; - SocketPong(true, BytesPerIteration, Convert.ToInt32(BytesPerIteration / 2)); - } - - [Test] - public void SmallerBufferFakeAsyncReadTlsStreamPong_10() - { - TotalClients = 10; - SendIterations = 100; - TestTimeoutMs = 60000; - FakeAsyncReadWithDelegate = true; - FakeAsyncWriteWithDelegate = false; - ClientInitiatedClose = false; - SocketPong(true, BytesPerIteration, Convert.ToInt32(BytesPerIteration / 2)); - } - - private void SocketPong(bool useTls, int bytesPerIteration, int readBufferSize) - { - _clientsComplete = 0; - _firstAsyncException = null; - _testComplete = new ManualResetEvent(false); - - ArrayList clients = new ArrayList(); - SocketPongServer server = new SocketPongServer(useTls, readBufferSize, CertFile, PvkFile, PvkPassword); - server.ExceptionOccurred += new AsyncTestClassBase.ExceptionOccurredEventHandler(this.ExceptionCallback); - - server.Start(); - - try - { - for (int i = 0; i < TotalClients; i++) - { - if (_testComplete.WaitOne(0, false)) - break; - - SocketPingClient client = new SocketPingClient(useTls, server.LocalEndPoint, SendIterations, bytesPerIteration, readBufferSize); - client.ExceptionOccurred += new AsyncTestClassBase.ExceptionOccurredEventHandler(this.ExceptionCallback); - client.TestComplete += new SocketPingClient.TestCompleteEventHandler(this.TestCompleteCallback); - client.Start(); - } - - if (TestTimeoutMs <= 0) - _testComplete.WaitOne(); - else - { - if (!_testComplete.WaitOne(TestTimeoutMs, false)) - Assert.Fail("Tests timed out"); - } - - if (null != _firstAsyncException) - Assert.Fail(_firstAsyncException.ToString()); - } - finally - { - if (ClientInitiatedClose) - CloseClients(clients); - - server.ExceptionOccurred -= new AsyncTestClassBase.ExceptionOccurredEventHandler(this.ExceptionCallback); - server.Stop(); - - if (!ClientInitiatedClose) - CloseClients(clients); - - } - } - - private void CloseClients(ArrayList clients) - { - foreach (SocketPingClient client in clients) - { - client.ExceptionOccurred -= new AsyncTestClassBase.ExceptionOccurredEventHandler(this.ExceptionCallback); - client.TestComplete -= new SocketPingClient.TestCompleteEventHandler(this.TestCompleteCallback); - client.Stop(); - } - } - - private void ExceptionCallback(Exception ex) - { - if (_testComplete.WaitOne(0, false)) - return; - - lock (this) - { - if (null == _firstAsyncException) - { - _firstAsyncException = ex; - _testComplete.Set(); - } - } - } - - private void TestCompleteCallback(object sender) - { - if (_testComplete.WaitOne(0, false)) - return; - - lock (this) - { - _clientsComplete++; - - if (_clientsComplete == TotalClients) - _testComplete.Set(); - } - } - } - - public class SocketPingClient : TlsEnabledSocketBase - { - int _bytesPerIteration; - int _iterations; - int _currentIteration; - IPEndPoint _server; - int _totalBytesRead; - int _expectedBytes; - Random _byteGenerator; - - public delegate void TestCompleteEventHandler(object sender); - public event TestCompleteEventHandler TestComplete; - - public SocketPingClient(bool useTls, IPEndPoint server, int iterations, int bytesPerIteration, int readBufferSize): - base(useTls, readBufferSize) - { - _server = server; - _iterations = iterations; - _bytesPerIteration = bytesPerIteration; - _byteGenerator = new Random(); - _expectedBytes = (_iterations * _bytesPerIteration); - _currentIteration = 0; - } - - protected override void OnStart() - { - Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - socket.Connect(_server); - - this.InitializeNetworkStream(socket); - - if (this.UseTls) - { - SslClientStream secureStream = new SslClientStream(base.NetworkStream, "localhost", true, Mono.Security.Protocol.Tls.SecurityProtocolType.Tls); - secureStream.ServerCertValidationDelegate = new CertificateValidationCallback(CertValidationCallback); - base.SecureStream = secureStream; - } - - SendMoreData(); - - byte[] readBuffer = new byte[ReadBufferSize]; - this.BeginRead(readBuffer, 0, readBuffer.Length, new AsyncCallback(BeginReadCallback), readBuffer); - } - - private void SendMoreData() - { - _currentIteration++; - - if (_currentIteration > _iterations) - return; - - byte[] buff = new byte[_bytesPerIteration]; - _byteGenerator.NextBytes(buff); - -// WTrace.TraceInfo("Socket Hell", this.GetType(), "Writing iteration {0} of {1}.", _currentIteration, _iterations); - - this.BeginWrite(buff, 0, buff.Length, new AsyncCallback(BeginWriteCallback), null); - } - - private void BeginWriteCallback(IAsyncResult asyncResult) - { - if (_stop) - return; - - try - { - this.EndWrite(asyncResult); - SendMoreData(); - } - catch (Exception ex) - { - OnExceptionOccurred(ex); - } - } - - private void BeginReadCallback(IAsyncResult asyncResult) - { - if (_stop) - return; - - try - { - int bytesRead = this.EndRead(asyncResult); - - bool done = false; - _totalBytesRead += bytesRead; - - done = (_totalBytesRead == _expectedBytes); - -// WTrace.TraceVerbose("Socket Hell", this.GetType(), "Read {0} of {1} bytes. Done? {2}", _totalBytesRead, _expectedBytes, done); - - if (done) - { - OnTestComplete(this); - } - else - { - byte[] readBuffer = (byte[])asyncResult.AsyncState; - this.BeginRead(readBuffer, 0, readBuffer.Length, new AsyncCallback(BeginReadCallback), readBuffer); - } - } - catch (Exception ex) - { - OnExceptionOccurred(ex); - } - } - - protected void OnTestComplete(object sender) - { - try - { - if (null != TestComplete) - TestComplete(sender); - } - catch (Exception ex) - { - OnExceptionOccurred(ex); - } - } - - private bool CertValidationCallback(X509Certificate certificate, int[] certificateErrors) - { - return true; - } - - } - - public class SocketPongClient: TlsEnabledSocketBase - { - private byte[] _readBuffer; - - private AsymmetricAlgorithm _privateKey; - - public SocketPongClient(Socket socket, bool useTls, int readBufferSize, string certFile, string pvkFile, string pvkPassword): - base(useTls, readBufferSize, socket) - { - if (useTls) - { - _privateKey = PrivateKey.CreateFromFile(pvkFile, pvkPassword).RSA; - - SslServerStream secureStream = new SslServerStream( - base.NetworkStream, - X509Certificate.CreateFromCertFile(certFile), - false, - true, - Mono.Security.Protocol.Tls.SecurityProtocolType.Tls); - - secureStream.PrivateKeyCertSelectionDelegate = new PrivateKeySelectionCallback(PrivateKeyCertSelectionCallback); - - base.SecureStream = secureStream; - } - } - - private AsymmetricAlgorithm PrivateKeyCertSelectionCallback(X509Certificate certificate, string targetHost) - { - return _privateKey; - } - - protected override void OnStart() - { - _readBuffer = new byte[ReadBufferSize]; - - this.BeginRead(_readBuffer, 0, _readBuffer.Length, new AsyncCallback(BeginReadCallback), null); - } - - private void BeginReadCallback(IAsyncResult asyncResult) - { - if (_stop) - return; - - try - { - int bytesRead = this.EndRead(asyncResult); - - byte[] sendBuffer = new byte[_readBuffer.Length]; - _readBuffer.CopyTo(sendBuffer, 0); - - if (_stop) - return; - -// WTrace.TraceVerbose("Socket Hell", this.GetType(), "Echoing"); - - this.BeginWrite(sendBuffer, 0, bytesRead, new AsyncCallback(NullBeginWriteCallback), null); - - if (_stop) - return; - -// WTrace.TraceVerbose("Socket Hell", this.GetType(), "Reading"); - - this.BeginRead(_readBuffer, 0, _readBuffer.Length, new AsyncCallback(BeginReadCallback), null); - } - catch (Exception ex) - { - OnExceptionOccurred(ex); - } - } - - } - - public abstract class TlsEnabledSocketBase : AsyncTestClassBase - { - private bool _useTls; - private NetworkStream _networkStream; - private Stream _secureStream; - private int _readBufferSize; - - protected TlsEnabledSocketBase(bool useTls, int readBufferSize) - { - _useTls = useTls; - _readBufferSize = readBufferSize; - } - - protected TlsEnabledSocketBase(bool useTls, int readBufferSize, Socket connectedSocket) - : this(useTls, readBufferSize) - { - _useTls = useTls; - InitializeNetworkStream(connectedSocket); - } - - protected virtual void InitializeNetworkStream(Socket connectedSocket) - { - _networkStream = new NetworkStream(connectedSocket, FileAccess.ReadWrite, true); - } - - protected int ReadBufferSize - { - get { return _readBufferSize; } - } - - protected bool UseTls - { - get { return _useTls; } - set { _useTls = value; } - } - - protected Stream SecureStream - { - get { return _secureStream; } - set { _secureStream = value; } - } - - protected NetworkStream NetworkStream - { - get { return _networkStream; } - set { _networkStream = value; } - } - - protected Stream CurrentStream - { - get - { - if (null != _secureStream) - return _secureStream; - else - return _networkStream; - } - } - - private delegate int MonoBeginReadDelegate(byte[] buffer, int offest, int count); - private MonoBeginReadDelegate _currentReadOperation; - - private delegate void MonoBeginWriteDelegate(byte[] buffer, int offest, int count); - private MonoBeginWriteDelegate _currentWriteOperation; - - protected IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) - { - if (UseTls && SocketHell.FakeAsyncReadWithDelegate) - { - - _currentReadOperation = new MonoBeginReadDelegate(this.CurrentStream.Read); - - return _currentReadOperation.BeginInvoke(buffer, offset, count, callback, state); - } - else - { - return this.CurrentStream.BeginRead(buffer, offset, count, callback, state); - } - } - - protected int EndRead(IAsyncResult asyncResult) - { - if (UseTls && SocketHell.FakeAsyncReadWithDelegate) - { - int result; - try - { - result = _currentReadOperation.EndInvoke(asyncResult); - } - finally - { - _currentReadOperation = null; - } - - return result; - } - else - { - return this.CurrentStream.EndRead(asyncResult); - } - } - - protected IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) - { - if (UseTls && SocketHell.FakeAsyncWriteWithDelegate) - { - _currentWriteOperation = new MonoBeginWriteDelegate(this.CurrentStream.Write); - return _currentWriteOperation.BeginInvoke(buffer, offset, count, callback, state); - } - else - { - return this.CurrentStream.BeginWrite(buffer, offset, count, callback, state); - } - } - - protected void EndWrite(IAsyncResult asyncResult) - { - if (UseTls && SocketHell.FakeAsyncWriteWithDelegate) - { - try - { - _currentWriteOperation.EndInvoke(asyncResult); - } - finally - { - _currentWriteOperation = null; - } - } - else - { - this.CurrentStream.EndWrite(asyncResult); - } - } - - protected override void OnStop() - { - lock (SocketHell.GlobalSocketLock) - { - //this sleep helps to stop the CPU race, but it isn't perfect - System.Threading.Thread.Sleep(SocketHell.GlobalSocketLockWait); - - try - { - if (null != this.CurrentStream) - this.CurrentStream.Close(); - - _secureStream = null; - _networkStream = null; - } - catch (Exception ex) - { - OnExceptionOccurred(ex); - } - } - } - - protected void NullBeginWriteCallback(IAsyncResult asyncResult) - { - if (_stop) - return; - - try - { - this.EndWrite(asyncResult); - } - catch (Exception ex) - { - OnExceptionOccurred(ex); - } - } - - protected void NullBeginReadCallback(IAsyncResult asyncResult) - { - if (_stop) - return; - - try - { - this.EndRead(asyncResult); - } - catch (Exception ex) - { - OnExceptionOccurred(ex); - } - } - } - - public class SocketPongServer : AsyncTestClassBase - { - private bool _useTls; - - private string _certFile; - private string _pvkFile; - private string _pvkPassword; - - private Socket _listener; - - private int _readBufferSize; - - private ArrayList _connectedClients; - - public SocketPongServer(bool useTls, int readBufferSize, string certFile, string pvkFile, string pvkPassword): base() - { - _useTls = useTls; - _readBufferSize = readBufferSize; - _certFile = certFile; - _pvkFile = pvkFile; - _pvkPassword = pvkPassword; - - _connectedClients = new ArrayList(); - } - - protected override void OnStart() - { - _listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - _listener.Bind(new IPEndPoint(IPAddress.Loopback, 0)); - _listener.Listen(int.MaxValue); - _listener.BeginAccept(new AsyncCallback(BeginAcceptCallback), null); - } - - private void BeginAcceptCallback(IAsyncResult asyncResult) - { - if (_stop) - return; - - try - { - Socket accepted = _listener.EndAccept(asyncResult); - - if (_stop) - return; - - SocketPongClient newClient = new SocketPongClient(accepted, _useTls, _readBufferSize, _certFile, _pvkFile, _pvkPassword); - _connectedClients.Add(newClient); - newClient.ExceptionOccurred += new ExceptionOccurredEventHandler(OnExceptionOccurred); - newClient.Start(); - - if (_stop) - return; - - _listener.BeginAccept(new AsyncCallback(BeginAcceptCallback), null); - } - catch (Exception ex) - { - OnExceptionOccurred(ex); - } - } - - protected override void OnStop() - { - lock (SocketHell.GlobalSocketLock) - { - //this sleep helps to stop the CPU race, but it isn't perfect - System.Threading.Thread.Sleep(SocketHell.GlobalSocketLockWait); - - if (null != _listener) - _listener.Close(); - - _listener = null; - } - - foreach (SocketPongClient client in _connectedClients) - { - //absorb shutdown exceptions for each client as to not effect the test suite as a whole - try - { - client.Stop(); - client.ExceptionOccurred -= new ExceptionOccurredEventHandler(OnExceptionOccurred); - } - catch (Exception ex) - { - OnExceptionOccurred(ex); - } - } - } - - public IPEndPoint LocalEndPoint - { - get - { - return (IPEndPoint)_listener.LocalEndPoint; - } - } - - } - - public class AsyncTestClassBase - { - protected volatile bool _stop; - - public delegate void ExceptionOccurredEventHandler(Exception ex); - public event ExceptionOccurredEventHandler ExceptionOccurred; - - protected virtual void OnExceptionOccurred(Exception ex) - { - if (_stop) - return; - - if (ex is NullReferenceException || ex is ObjectDisposedException) - { -// WTrace.TraceInfo("Socket Hell", this.GetType(), "Ignoring NullReferenceException or ObjectDisposedException"); - return; - } - - if (ex is IOException) - { - if (null != ex.InnerException) - { - if (ex.InnerException is SocketException) - { - SocketException socketEx = ex.InnerException as SocketException; - if (10054 == socketEx.ErrorCode) - { -// WTrace.TraceInfo("Socket Hell", this.GetType(), "Ignoring \"Forcibly Closed\" socket exception."); - return; - } - } - } - } - - try - { -// WTrace.TraceError("Socket Hell", this.GetType(), "Async Exception!\n{0}", ex.ToString()); - - if (null != ExceptionOccurred) - ExceptionOccurred(ex); - } - catch { } - - //let the test shut us down instead. - //try - //{ - // Stop(); - //} - //catch { } - } - - public void Start() - { - _stop = false; - - lock (this) - { - OnStart(); - } - } - - protected virtual void OnStart() { } - - public void Stop() - { - _stop = true; - - lock (this) - { - OnStop(); - } - } - - protected virtual void OnStop() { } - - } -} diff --git a/mcs/class/Mono.Security/Test/tools/tlstest/Makefile b/mcs/class/Mono.Security/Test/tools/tlstest/Makefile deleted file mode 100644 index 018fa34f6ca..00000000000 --- a/mcs/class/Mono.Security/Test/tools/tlstest/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -thisdir = class/Mono.Security/Test/tools/tlstest -SUBDIRS = -include ../../../../../build/rules.make - -LOCAL_MCS_FLAGS = /r:System.dll /r:Mono.Security.dll - -all-local install-local uninstall-local: - -test-local: - -# ??? What do we run here? - -run-test-local: - -clean-local: - rm -f *.exe *.pdb - -sources = tlstest.cs tlsmulti.cs tlsasync.cs tlssave.cs - -DISTFILES = $(sources) - -dist-local: dist-default - -all: tlstest.exe tlsmulti.exe tlsasync.exe tlssave.exe - -tlstest.exe: tlstest.cs - $(CSCOMPILE) /target:exe /out:$@ $^ - -tlsmulti.exe: tlsmulti.cs - $(CSCOMPILE) /target:exe /out:$@ $^ - -tlsasync.exe: tlsasync.cs - $(CSCOMPILE) /target:exe /out:$@ $^ - -tlssave.exe: tlssave.cs - $(CSCOMPILE) /target:exe /out:$@ $^ diff --git a/mcs/class/Mono.Security/Test/tools/tlstest/README b/mcs/class/Mono.Security/Test/tools/tlstest/README deleted file mode 100644 index c5e9d410629..00000000000 --- a/mcs/class/Mono.Security/Test/tools/tlstest/README +++ /dev/null @@ -1,30 +0,0 @@ -The tlstest directory contains several test tools. They were made to test -the SSL/TLS implementation but most of them are also good test for regular -HTTP (when used with HttpWebRequest). - - -tlstest - * works with HttpWebRequest (--web) or SslClientStream (--ssl | --tls) - * work synchronously; - -tlsmulti - * only works with HttpWebRequest (http or https) - * work asynchronously with Begin|EndGetResponse; - * can download up to 64 URLs simulteanously; - -tlsasync - * only works with HttpWebRequest (http or https) - * work asynchronously with Begin|EndGetResponse and [Begin|End] - GetResponseStream; - * can download up to 64 URLs simulteanously; - -tlssave - * only works with HttpWebRequest (http or https) - * work asynchronously with Begin|EndGetResponse and [Begin|End] - GetResponseStream; - * saves every downloaded URL into a file (1, 2, ...); - * used to download and compare (md5sum) very large files; - - -Note: With Mono the HttpWebRequest will call the SslClientStream for HTTPS. -However under the MS runtime SslClientStream won't be called. diff --git a/mcs/class/Mono.Security/Test/tools/tlstest/tlsasync.cs b/mcs/class/Mono.Security/Test/tools/tlstest/tlsasync.cs deleted file mode 100644 index b6afab097e8..00000000000 --- a/mcs/class/Mono.Security/Test/tools/tlstest/tlsasync.cs +++ /dev/null @@ -1,150 +0,0 @@ -// -// tlsasync.cs: Multi-sessions TLS/SSL Test Program with async streams -// based on tlstest.cs and tlsmulti.cs -// -// Author: -// Sebastien Pouliot <sebastien@ximian.com> -// -// Copyright (C) 2004-2005 Novell (http://www.novell.com) -// - -using System; -using System.Collections; -using System.Globalization; -using System.IO; -using System.Net; -using System.Net.Sockets; -using System.Reflection; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using System.Threading; - -using Mono.Security.Protocol.Tls; - -public class State { - - static ArrayList handleList = new ArrayList (); - - private int id; - private HttpWebRequest request; - private ManualResetEvent handle; - private Stream stream; - private byte[] buffer; - private MemoryStream memory; - - public State (int id, HttpWebRequest req) - { - this.id = id; - request = req; - handle = new ManualResetEvent (false); - handleList.Add (handle); - } - - public int Id { - get { return id; } - } - - public HttpWebRequest Request { - get { return request; } - } - - public Stream Stream { - get { return stream; } - set { stream = value; } - } - - public byte[] Buffer { - get { - if (buffer == null) - buffer = new byte [256]; // really small on purpose - return buffer; - } - } - - public Stream Memory { - get { - if (memory == null) - memory = new MemoryStream (); - return memory; - } - } - - public void Complete () - { - handle.Set (); - } - - static public void WaitAll () - { - if (handleList.Count > 0) { - WaitHandle[] handles = (WaitHandle[]) handleList.ToArray (typeof (WaitHandle)); - WaitHandle.WaitAll (handles); - handleList.Clear (); - } - } -} - -public class MultiTest { - - static bool alone; - - public static void Main (string[] args) - { - if (args.Length == 0) { - Console.WriteLine ("usage: mono tlsaync.exe url1 [url ...]"); - return; - } else if (args.Length > 64) { - Console.WriteLine ("WaitHandle has a limit of 64 handles so you cannot process {0} URLs.", args.Length); - return; - } - - alone = (args.Length == 1); - ServicePointManager.CertificatePolicy = new TestCertificatePolicy (); - - int id = 1; - foreach (string url in args) { - Console.WriteLine ("GET #{0} at {1}", id, url); - HttpWebRequest wreq = (HttpWebRequest) WebRequest.Create (url); - State s = new State (id++, wreq); - wreq.BeginGetResponse (new AsyncCallback (ResponseCallback), s); - } - - State.WaitAll (); - } - - private static void ResponseCallback (IAsyncResult result) - { - State state = ((State) result.AsyncState); - HttpWebResponse response = (HttpWebResponse) state.Request.EndGetResponse (result); - state.Stream = response.GetResponseStream (); - state.Stream.BeginRead (state.Buffer, 0, state.Buffer.Length, new AsyncCallback (StreamCallBack), state); - } - - private static void StreamCallBack (IAsyncResult result) - { - State state = ((State) result.AsyncState); - int length = state.Stream.EndRead (result); - if (length > 0) { - state.Memory.Write (state.Buffer, 0, length); - state.Stream.BeginRead (state.Buffer, 0, state.Buffer.Length, new AsyncCallback (StreamCallBack), state); - } else { - state.Stream.Close (); - if (alone) { - state.Memory.Position = 0; - StreamReader sr = new StreamReader (state.Memory, Encoding.UTF8); - Console.WriteLine (sr.ReadToEnd ()); - } - Console.WriteLine ("END #{0}", state.Id); - state.Complete (); - } - } - - public class TestCertificatePolicy : ICertificatePolicy { - - public bool CheckValidationResult (ServicePoint sp, X509Certificate certificate, WebRequest request, int error) - { - // whatever the reason we do not stop the SSL connection - return true; - } - } -} diff --git a/mcs/class/Mono.Security/Test/tools/tlstest/tlsmulti.cs b/mcs/class/Mono.Security/Test/tools/tlstest/tlsmulti.cs deleted file mode 100644 index 8b196b14bf0..00000000000 --- a/mcs/class/Mono.Security/Test/tools/tlstest/tlsmulti.cs +++ /dev/null @@ -1,114 +0,0 @@ -// -// tlsmulti.cs: Multi-sessions TLS/SSL Test Program with async HttpWebRequest -// based on tlstest.cs -// -// Author: -// Sebastien Pouliot <sebastien@ximian.com> -// -// Copyright (C) 2004-2005 Novell (http://www.novell.com) -// - -using System; -using System.Collections; -using System.Globalization; -using System.IO; -using System.Net; -using System.Net.Sockets; -using System.Reflection; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using System.Threading; - -using Mono.Security.Protocol.Tls; - -public class State { - - static ArrayList handleList = new ArrayList (); - - private int id; - private HttpWebRequest request; - private ManualResetEvent handle; - - public State (int id, HttpWebRequest req) - { - this.id = id; - request = req; - handle = new ManualResetEvent (false); - handleList.Add (handle); - } - - public int Id { - get { return id; } - } - - public HttpWebRequest Request { - get { return request; } - } - - public void Complete () - { - handle.Set (); - } - - static public void WaitAll () - { - if (handleList.Count > 0) { - WaitHandle[] handles = (WaitHandle[]) handleList.ToArray (typeof (WaitHandle)); - WaitHandle.WaitAll (handles); - handleList.Clear (); - } - } -} - -public class MultiTest { - - static bool alone; - - public static void Main (string[] args) - { - if (args.Length == 0) { - Console.WriteLine ("usage: mono tlsmulti.exe url1 [url ...]"); - return; - } else if (args.Length > 64) { - Console.WriteLine ("WaitHandle has a limit of 64 handles so you cannot process {0} URLs.", args.Length); - return; - } - - alone = (args.Length == 1); - ServicePointManager.CertificatePolicy = new TestCertificatePolicy (); - - int id = 1; - foreach (string url in args) { - Console.WriteLine ("GET #{0} at {1}", id, url); - HttpWebRequest wreq = (HttpWebRequest) WebRequest.Create (url); - State s = new State (id++, wreq); - wreq.BeginGetResponse (new AsyncCallback (ResponseCallback), s); - } - - State.WaitAll (); - } - - private static void ResponseCallback (IAsyncResult result) - { - State state = ((State) result.AsyncState); - Console.WriteLine ("END #{0}", state.Id); - HttpWebResponse response = (HttpWebResponse) state.Request.EndGetResponse (result); - - Stream stream = response.GetResponseStream (); - StreamReader sr = new StreamReader (stream, Encoding.UTF8); - string data = sr.ReadToEnd (); - - if (alone) - Console.WriteLine (data); - state.Complete (); - } - - public class TestCertificatePolicy : ICertificatePolicy { - - public bool CheckValidationResult (ServicePoint sp, X509Certificate certificate, WebRequest request, int error) - { - // whatever the reason we do not stop the SSL connection - return true; - } - } -} diff --git a/mcs/class/Mono.Security/Test/tools/tlstest/tlssave.cs b/mcs/class/Mono.Security/Test/tools/tlstest/tlssave.cs deleted file mode 100644 index 25871046af8..00000000000 --- a/mcs/class/Mono.Security/Test/tools/tlstest/tlssave.cs +++ /dev/null @@ -1,145 +0,0 @@ -// -// tlssave.cs: Multi-sessions TLS/SSL Test Program which saves the URL to disk -// based on tlstest.cs, tlsmulti.cs and tlsasync.cs -// -// Author: -// Sebastien Pouliot <sebastien@ximian.com> -// -// Copyright (C) 2004-2005 Novell (http://www.novell.com) -// - -using System; -using System.Collections; -using System.Diagnostics; -using System.Globalization; -using System.IO; -using System.Net; -using System.Net.Sockets; -using System.Reflection; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using System.Threading; - -using Mono.Security.Protocol.Tls; - -public class State { - - static ArrayList handleList = new ArrayList (); - - private int id; - private HttpWebRequest request; - private ManualResetEvent handle; - private Stream stream; - private byte[] buffer; - private FileStream file; - - public State (int id, HttpWebRequest req) - { - this.id = id; - request = req; - handle = new ManualResetEvent (false); - handleList.Add (handle); - } - - public int Id { - get { return id; } - } - - public HttpWebRequest Request { - get { return request; } - } - - public Stream Stream { - get { return stream; } - set { stream = value; } - } - - public byte[] Buffer { - get { - if (buffer == null) - buffer = new byte [256]; // really small on purpose - return buffer; - } - } - - public Stream File { - get { - if (file == null) - file = new FileStream (id.ToString (), FileMode.Create); - return file; - } - } - - public void Complete () - { - if (file != null) - file.Close (); - handle.Set (); - } - - static public void WaitAll () - { - if (handleList.Count > 0) { - WaitHandle[] handles = (WaitHandle[]) handleList.ToArray (typeof (WaitHandle)); - WaitHandle.WaitAll (handles); - handleList.Clear (); - } - } -} - -public class SaveTest { - - public static void Main (string[] args) - { - if (args.Length == 0) { - Console.WriteLine ("usage: mono tlssave.exe url1 [url ...]"); - return; - } else if (args.Length > 64) { - Console.WriteLine ("WaitHandle has a limit of 64 handles so you cannot process {0} URLs.", args.Length); - return; - } - - ServicePointManager.CertificatePolicy = new TestCertificatePolicy (); - - int id = 1; - foreach (string url in args) { - Console.WriteLine ("GET #{0} at {1}", id, url); - HttpWebRequest wreq = (HttpWebRequest) WebRequest.Create (url); - State s = new State (id++, wreq); - wreq.BeginGetResponse (new AsyncCallback (ResponseCallback), s); - } - - State.WaitAll (); - } - - private static void ResponseCallback (IAsyncResult result) - { - State state = ((State) result.AsyncState); - HttpWebResponse response = (HttpWebResponse) state.Request.EndGetResponse (result); - state.Stream = response.GetResponseStream (); - state.Stream.BeginRead (state.Buffer, 0, state.Buffer.Length, new AsyncCallback (StreamCallBack), state); - } - - private static void StreamCallBack (IAsyncResult result) - { - State state = ((State) result.AsyncState); - int length = state.Stream.EndRead (result); - if (length > 0) { - state.File.Write (state.Buffer, 0, length); - state.Stream.BeginRead (state.Buffer, 0, state.Buffer.Length, new AsyncCallback (StreamCallBack), state); - } else { - state.Stream.Close (); - Console.WriteLine ("END #{0}", state.Id); - state.Complete (); - } - } - - public class TestCertificatePolicy : ICertificatePolicy { - - public bool CheckValidationResult (ServicePoint sp, X509Certificate certificate, WebRequest request, int error) - { - // whatever the reason we do not stop the SSL connection - return true; - } - } -} diff --git a/mcs/class/Mono.Security/Test/tools/tlstest/tlstest.cs b/mcs/class/Mono.Security/Test/tools/tlstest/tlstest.cs deleted file mode 100644 index c3920b5ed88..00000000000 --- a/mcs/class/Mono.Security/Test/tools/tlstest/tlstest.cs +++ /dev/null @@ -1,293 +0,0 @@ -// -// TlsTest.cs: TLS/SSL Test Program -// -// Author: -// Sebastien Pouliot <sebastien@xamarin.com> -// -// (C) 2004 Novell (http://www.novell.com) -// Copyright 2014 Xamarin Inc. (http://www.xamarin.com) -// - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Net; -using System.Net.Sockets; -using System.Reflection; -using System.Security.Cryptography.X509Certificates; -using System.Text; - -using Mono.Security.Protocol.Tls; - -public class TlsTest { - - public static void Usage (string message) - { - Console.WriteLine ("{0}tlstest - Copyright (c) 2004 Novell", Environment.NewLine); - if (message != null) { - Console.WriteLine ("{0}{1}{0}", Environment.NewLine, message); - } - Console.WriteLine ("Usage:"); - Console.WriteLine ("tlstest [protocol] [class] [credentials] [--x:x509 [--x:x509]] [--time] [--show] url [...]"); - Console.WriteLine ("{0}protocol (only applicable when using stream)", Environment.NewLine); - Console.WriteLine ("\t--any \tNegotiate protocol [default]"); - Console.WriteLine ("\t--ssl \tUse SSLv3"); - Console.WriteLine ("\t--ssl2 \tUse SSLv2 - unsupported on Mono"); - Console.WriteLine ("\t--ssl3 \tUse SSLv3"); - Console.WriteLine ("\t--tls \tUse TLSv1"); - Console.WriteLine ("\t--tls1 \tUse TLSv1"); - Console.WriteLine ("{0}class", Environment.NewLine); - Console.WriteLine ("\t--stream\tDirectly use the SslClientStream [default]"); - Console.WriteLine ("\t--web \tUse the WebRequest/WebResponse classes"); - Console.WriteLine ("{0}credentials", Environment.NewLine); - Console.WriteLine ("\t--basic:username:password:domain\tBasic Authentication"); - Console.WriteLine ("\t--digest:username:password:domain\tDigest Authentication"); - Console.WriteLine ("{0}options", Environment.NewLine); - Console.WriteLine ("\t--x:x509\tX.509 client certificate (multiple entries allowed"); - Console.WriteLine ("\t--time \tShow the time required for each page load"); - Console.WriteLine ("\t--show \tShow the web page content on screen"); - Console.WriteLine ("{0}\turl [...]\tOne, or more, URL to download{0}", Environment.NewLine); - } - - private static bool show; - private static bool time; - private static bool web; - private static Mono.Security.Protocol.Tls.SecurityProtocolType protocol = Mono.Security.Protocol.Tls.SecurityProtocolType.Default; - private static X509CertificateCollection certificates = new X509CertificateCollection (); - private static NetworkCredential basicCred; - private static NetworkCredential digestCred; - - 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 string GetWebPage (string url) - { - ServicePointManager.CertificatePolicy = new TestCertificatePolicy (); - ServicePointManager.SecurityProtocol = (System.Net.SecurityProtocolType) (int) protocol; - - Uri uri = new Uri (url); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (uri); - - if ((digestCred != null) || (basicCred != null)) { - CredentialCache cache = new CredentialCache (); - if (digestCred != null) - cache.Add (uri, "Digest", digestCred); - if (basicCred != null) - cache.Add (uri, "Basic", basicCred); - req.Credentials = cache; - } - - if (certificates.Count > 0) - req.ClientCertificates.AddRange (certificates); - - WebResponse resp = req.GetResponse (); - Stream stream = resp.GetResponseStream (); - StreamReader sr = new StreamReader (stream, Encoding.UTF8); - return sr.ReadToEnd (); - } - - public static string GetStreamPage (string url) - { - Uri uri = new Uri (url); - if (uri.Scheme != Uri.UriSchemeHttps) - throw new NotSupportedException ("Stream only works with HTTPS protocol"); - - 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, certificates); - ssl.ServerCertValidationDelegate += new CertificateValidationCallback (CertificateValidation); - - StreamWriter sw = new StreamWriter (ssl); - sw.WriteLine ("GET {0} HTTP/1.0{1}", uri.AbsolutePath, Environment.NewLine); - sw.Flush (); - - StreamReader sr = new StreamReader (ssl, Encoding.UTF8); - return sr.ReadToEnd (); - } - - private static NetworkCredential GetCredentials (string credentials) - { - string[] creds = credentials.Split (':'); - NetworkCredential nc = new NetworkCredential (); - nc.UserName = ((creds.Length > 0) ? creds [0] : String.Empty); - nc.Password = ((creds.Length > 1) ? creds [1] : String.Empty); - nc.Domain = ((creds.Length > 2) ? creds [2] : String.Empty); - return nc; - } - - private static void ShowCertificateError (int error) - { - string message = null; - switch (error) { - case -2146762490: - message = "CERT_E_PURPOSE 0x800B0106"; - break; - case -2146762481: - message = "CERT_E_CN_NO_MATCH 0x800B010F"; - break; - case -2146869223: - message = "TRUST_E_BASIC_CONSTRAINTS 0x80096019"; - break; - case -2146869232: - message = "TRUST_E_BAD_DIGEST 0x80096010"; - break; - case -2146762494: - message = "CERT_E_VALIDITYPERIODNESTING 0x800B0102"; - break; - case -2146762495: - message = "CERT_E_EXPIRED 0x800B0101"; - break; - case -2146762486: - message = "CERT_E_CHAINING 0x800B010A"; - break; - case -2146762487: - message = "CERT_E_UNTRUSTEDROOT 0x800B0109"; - break; - default: - message = "unknown (try WinError.h)"; - break; - } - Console.WriteLine ("Error #{0}: {1}", error, message); - } - - private static bool CertificateValidation (X509Certificate certificate, int[] certificateErrors) - { - if (certificateErrors.Length > 0) { - Console.WriteLine (certificate.ToString (true)); - // X509Certificate.ToString(true) doesn't show dates :-( - Console.WriteLine ("\tValid From: {0}", certificate.GetEffectiveDateString ()); - Console.WriteLine ("\tValid Until: {0}{1}", certificate.GetExpirationDateString (), Environment.NewLine); - // multiple errors are possible using SslClientStream - foreach (int error in certificateErrors) { - ShowCertificateError (error); - } - } - // whatever the reason we do not stop the SSL connection - return true; - } - - public class TestCertificatePolicy : ICertificatePolicy { - - public bool CheckValidationResult (ServicePoint sp, X509Certificate certificate, WebRequest request, int error) - { - if (error != 0) { - Console.WriteLine (certificate.ToString (true)); - // X509Certificate.ToString(true) doesn't show dates :-( - Console.WriteLine ("\tValid From: {0}", certificate.GetEffectiveDateString ()); - Console.WriteLine ("\tValid Until: {0}{1}", certificate.GetExpirationDateString (), Environment.NewLine); - - ShowCertificateError (error); - } - // whatever the reason we do not stop the SSL connection - return true; - } - } -} - |