X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;ds=sidebyside;f=tests%2Forg%2Fcacert%2Fgigi%2FTestSSL.java;h=c39b20f5b07505cb9219c1ed22f6317616e96c38;hb=2233a655b4ef4c1122a406e83a0e6334b9fd49b6;hp=2ae757f9e8e129462c3292ff7edcce87a107fad5;hpb=4f528c2a8ac9c63db3fa78c02b5fbbb7bcb6504f;p=gigi.git diff --git a/tests/org/cacert/gigi/TestSSL.java b/tests/org/cacert/gigi/TestSSL.java index 2ae757f9..c39b20f5 100644 --- a/tests/org/cacert/gigi/TestSSL.java +++ b/tests/org/cacert/gigi/TestSSL.java @@ -6,15 +6,18 @@ import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; import java.security.NoSuchAlgorithmException; + import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngineResult; -import javax.net.ssl.SSLException; import javax.net.ssl.SSLEngineResult.HandshakeStatus; +import javax.net.ssl.SSLException; +import org.cacert.gigi.testUtils.InitTruststore; +import org.cacert.gigi.testUtils.ManagedTest; import org.junit.Test; -public class TestSSL { +public class TestSSL extends ManagedTest { private ByteBuffer in; private ByteBuffer inC; private ByteBuffer outC; @@ -22,13 +25,13 @@ public class TestSSL { static { InitTruststore.run(); } + @Test - public void testClientIntitiatedRenegotiation() - throws NoSuchAlgorithmException, IOException { + public void testClientIntitiatedRenegotiation() throws NoSuchAlgorithmException, IOException { SSLContext sc = SSLContext.getDefault(); SSLEngine se = sc.createSSLEngine(); - SocketChannel s = SocketChannel.open(new InetSocketAddress("localhost", - 443)); + String[] serverParts = getServerName().split(":", 2); + SocketChannel s = SocketChannel.open(new InetSocketAddress(serverParts[0], Integer.parseInt(serverParts[1]))); in = ByteBuffer.allocate(se.getSession().getApplicationBufferSize()); inC = ByteBuffer.allocate(se.getSession().getPacketBufferSize()); @@ -43,34 +46,33 @@ public class TestSSL { se.beginHandshake(); try { work(se, s); - throw new Error( - "Client re-negotiation failed (possible DoS vurnability"); + throw new Error("Client re-negotiation succeded (possible DoS vulnerability"); } catch (EOFException e) { // Cool, server closed connection } } - private void work(SSLEngine se, SocketChannel s) throws SSLException, - IOException { + + private void work(SSLEngine se, SocketChannel s) throws SSLException, IOException { while (se.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING - && se.getHandshakeStatus() != HandshakeStatus.FINISHED) { + && se.getHandshakeStatus() != HandshakeStatus.FINISHED) { switch (se.getHandshakeStatus()) { - case NEED_WRAP : - wrap(se, s); - break; - case NEED_UNWRAP : - unwrap(se, s); - break; - case NEED_TASK : - se.getDelegatedTask().run(); - break; - default : - System.out.println(se.getHandshakeStatus()); + case NEED_WRAP: + wrap(se, s); + break; + case NEED_UNWRAP: + unwrap(se, s); + break; + case NEED_TASK: + se.getDelegatedTask().run(); + break; + default: + System.out.println(se.getHandshakeStatus()); } } } - private SSLEngineResult unwrap(SSLEngine se, SocketChannel s) - throws IOException, SSLException { + + private SSLEngineResult unwrap(SSLEngine se, SocketChannel s) throws IOException, SSLException { if (inC.remaining() == 0) { inC.clear(); s.read(inC); @@ -91,8 +93,8 @@ public class TestSSL { } return result; } - private SSLEngineResult wrap(SSLEngine se, SocketChannel s) - throws SSLException, IOException { + + private SSLEngineResult wrap(SSLEngine se, SocketChannel s) throws SSLException, IOException { outC.clear(); SSLEngineResult result = se.wrap(out, outC); outC.flip();