Exemplo n.º 1
0
        public void TestClientCertificateValidation()
        {
            ISocket4Factory sslSocketFactory = new SslSocketFactory(new StandardSocket4Factory(), ServerCertificate());
            var serverSocket = sslSocketFactory.CreateServerSocket(0);

            ThreadPool.QueueUserWorkItem(delegate { serverSocket.Accept(); });

            var clientSocketFactory = new SslSocketFactory(new StandardSocket4Factory(), delegate { return false; });

            Assert.Expect(typeof (AuthenticationException),
                delegate { clientSocketFactory.CreateSocket("localhost", serverSocket.GetLocalPort()); });
        }
Exemplo n.º 2
0
		public void Test()
		{
			ISocket4Factory sslSocketFactory = new SslSocketFactory(new StandardSocket4Factory(), ServerCertificate());
			IServerSocket4 serverSocket = sslSocketFactory.CreateServerSocket(0);

			PassThroughSocketFactory clientEncryptedContentsSocketFactory = NewPassThroughSocketFactory();
			PassThroughSocketFactory clientPassThroughSocketFactory = new PassThroughSocketFactory(new SslSocketFactory(clientEncryptedContentsSocketFactory, ValidateServerCertificate));

			Thread clientThread = StartClient(serverSocket.GetLocalPort(), clientPassThroughSocketFactory);

			string msg = ReadString(serverSocket.Accept());

			Assert.AreEqual(Message, msg);
			AssertAreNotEqual(clientEncryptedContentsSocketFactory.LastClient.Written, clientPassThroughSocketFactory.LastClient.Written);

			clientThread.Join();
		}
Exemplo n.º 3
0
		public void TestServerReadSocketTimeout()
		{
			Thread server = new Thread(delegate(object serverSocket)
			{
				ISocket4 client = AsServerSocket(serverSocket).Accept();
				client.SetSoTimeout(1000);
				Assert.Expect(typeof(Exception), delegate
				{
					client.Read(new byte[1], 0, 1);
				});
			});

			int serverTimeout = MinutesToMiliseconds(5);
			ISocket4Factory clientSocketFactory = new SslSocketFactory(new StandardSocket4Factory(), delegate { return true; });

			AssertTimeoutBehavior(server, serverTimeout, clientSocketFactory);
		}
Exemplo n.º 4
0
		private void AssertTimeoutBehavior(Thread serverTrigger, int serverTimeout, ISocket4Factory clientSocketFactory)
		{
			ISocket4Factory sslSocketFactory = new SslSocketFactory(new StandardSocket4Factory(), ServerCertificate());
			IServerSocket4 serverSocket = sslSocketFactory.CreateServerSocket(0);
			serverSocket.SetSoTimeout(serverTimeout);

			serverTrigger.IsBackground = true;
			serverTrigger.Start(serverSocket);

			ISocket4 clientSocket = clientSocketFactory.CreateSocket("localhost", serverSocket.GetLocalPort());

			if (!serverTrigger.Join(MinutesToMiliseconds(2)))
			{
				serverTrigger.Abort();
				Assert.Fail("Server thread should have timedout.");
			}
		}