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()); }); }
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(); }
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."); } }