Source:
public static boolean doHandshake(final SocketChannel socketChannel, final SSLEngine sslEngine, final boolean isClient) throws IOException { if (socketChannel == null || sslEngine == null) { return false; } final int appBufferSize = sslEngine.getSession().getApplicationBufferSize(); final int netBufferSize = sslEngine.getSession().getPacketBufferSize(); ByteBuffer myAppData = ByteBuffer.allocate(appBufferSize); ByteBuffer peerAppData = ByteBuffer.allocate(appBufferSize); ByteBuffer myNetData = ByteBuffer.allocate(netBufferSize); ByteBuffer peerNetData = ByteBuffer.allocate(netBufferSize); long startTimeMills = System.currentTimeMillis(); HandshakeStatus handshakeStatus = sslEngine.getHandshakeStatus(); while (handshakeStatus != SSLEngineResult.HandshakeStatus.FINISHED && handshakeStatus != SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING) { long timeTaken = System.currentTimeMillis() - startTimeMills; if (timeTaken > 60000) { if (isClient && timeTaken > 120000) { s_logger.warn("SSL Handshake has taken more than 120s to connect to remote host: " + socketChannel.getRemoteAddress() + ". Please investigate this connection."); return false; } else { s_logger.warn("Aborting handshake process with client as SSL handshake has taken more than 60s for client: " + socketChannel.getRemoteAddress() + ". Malicious clients can degrade server responsiveness, please investigate this connection."); return false; } } switch (handshakeStatus) { case NEED_UNWRAP: if (!doHandshakeUnwrap(socketChannel, sslEngine, peerAppData, peerNetData, appBufferSize)) { return false; } break; case NEED_WRAP: if (!doHandshakeWrap(socketChannel, sslEngine, myAppData, myNetData, peerNetData, netBufferSize)) { return false; } break; case NEED_TASK: Runnable task; while ((task = sslEngine.getDelegatedTask()) != null) { new Thread(task).run(); } break; case FINISHED: break; case NOT_HANDSHAKING: break; default: throw new IllegalStateException("Invalid SSL status: " + handshakeStatus); } handshakeStatus = sslEngine.getHandshakeStatus(); } return true; }

Target:
public static boolean doHandshake(final SocketChannel socketChannel, final SSLEngine sslEngine, final boolean isClient) throws IOException { if (socketChannel == null || sslEngine == null) { return false; } final int appBufferSize = sslEngine.getSession().getApplicationBufferSize(); final int netBufferSize = sslEngine.getSession().getPacketBufferSize(); ByteBuffer myAppData = ByteBuffer.allocate(appBufferSize); ByteBuffer peerAppData = ByteBuffer.allocate(appBufferSize); ByteBuffer myNetData = ByteBuffer.allocate(netBufferSize); ByteBuffer peerNetData = ByteBuffer.allocate(netBufferSize); final long startTimeMills = System.currentTimeMillis(); HandshakeStatus handshakeStatus = sslEngine.getHandshakeStatus(); while (handshakeStatus != SSLEngineResult.HandshakeStatus.FINISHED && handshakeStatus != SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING) { final long timeTaken = System.currentTimeMillis() - startTimeMills; if (timeTaken > 60000L) { s_logger.warn("SSL Handshake has taken more than 60s to connect to: " + socketChannel.getRemoteAddress() + ". Please investigate this connection."); return false; } switch (handshakeStatus) { case NEED_UNWRAP: if (!doHandshakeUnwrap(socketChannel, sslEngine, peerAppData, peerNetData, appBufferSize)) { return false; } break; case NEED_WRAP: if (!doHandshakeWrap(socketChannel, sslEngine, myAppData, myNetData, peerNetData, netBufferSize)) { return false; } break; case NEED_TASK: Runnable task; while ((task = sslEngine.getDelegatedTask()) != null) { new Thread(task).run(); } break; case FINISHED: break; case NOT_HANDSHAKING: break; default: throw new IllegalStateException("Invalid SSL status: " + handshakeStatus); } handshakeStatus = sslEngine.getHandshakeStatus(); } return true; }