CryptoHelper { void doHandshake() throws IOException { checkEngine(); _engine.beginHandshake(); performHandshake(); } CryptoHelper(ConnectOptions options); void initializeEngine(SocketChannel socketChannel); static final String[] CLIENT_PROTOCOLS; static final String ENDPOINT_IDENTIFICATION_ALGORITHM; public SSLEngine _engine; }
@Test public void shouldDoHandshakeWhenCertificateCommonNameIsValid() throws IOException { startServer(VALID_CERTIFICATE); createCryptoHelper(VALID_CERTIFICATE); cryptoHelper.doHandshake(); writeLine(cryptoHelper); }
@Test(expected = SSLHandshakeException.class) public void shouldFailHandshakeWhenCertificateCommonNameIsInvalid() throws IOException { startServer(INVALID_CERTIFICATE); createCryptoHelper(INVALID_CERTIFICATE); cryptoHelper.doHandshake(); writeLine(cryptoHelper); }
@Test public void shouldUseTLS1_2Version() throws IOException, ExecutionException, InterruptedException { CompletableFuture<String> protocolFuture = new CompletableFuture<>(); startServer(VALID_CERTIFICATE, null, socket -> protocolFuture.complete(((SSLSocketImpl) socket).getSession().getProtocol())); createCryptoHelper(VALID_CERTIFICATE); cryptoHelper.doHandshake(); writeLine(cryptoHelper); assertEquals("TLSv1.2", protocolFuture.get()); }
@Test(expected = SSLHandshakeException.class) public void shouldFailHandshakeIfServerDoesntSupportTLS1_2() throws IOException, ExecutionException, InterruptedException { CompletableFuture<String> protocolFuture = new CompletableFuture<>(); startServer(VALID_CERTIFICATE, "TLSv1.1", socket -> protocolFuture.complete(((SSLSocketImpl) socket).getSession().getProtocol())); createCryptoHelper(VALID_CERTIFICATE); cryptoHelper.doHandshake(); writeLine(cryptoHelper); assertEquals("TLSv1.2", protocolFuture.get()); }