void handshake(SslEngineValidator peerValidator) throws SSLException {
            SSLEngineResult.HandshakeStatus handshakeStatus = sslEngine.getHandshakeStatus();
            while (true) {
                switch (handshakeStatus) {
                    case NEED_WRAP:
                        handshakeResult = sslEngine.wrap(EMPTY_BUF, netBuffer);
                        switch (handshakeResult.getStatus()) {
                            case OK: break;
                            case BUFFER_OVERFLOW:
                                if (netBuffer.position() != 0) // Wait for peer to consume previously wrapped data
                                    return;
                                netBuffer.compact();
                                netBuffer = Utils.ensureCapacity(netBuffer, sslEngine.getSession().getPacketBufferSize());
                                netBuffer.flip();
                                break;
                            case BUFFER_UNDERFLOW:
                            case CLOSED:
                            default:
                                throw new SSLException("Unexpected handshake status: " + handshakeResult.getStatus());
                        }
                        return;
                    case NEED_UNWRAP:
                        handshakeStatus = unwrap(peerValidator, true);
                        if (handshakeStatus == null) return;
                        break;
                    case NEED_TASK:
                        sslEngine.getDelegatedTask().run();
                        handshakeStatus = sslEngine.getHandshakeStatus();
                        break;
                    case FINISHED:
                        return;
                    case NOT_HANDSHAKING:
                        if (handshakeResult.getHandshakeStatus() != SSLEngineResult.HandshakeStatus.FINISHED)
                            throw new SSLException("Did not finish handshake, handshake status: " + handshakeResult.getHandshakeStatus());
                        else if (peerValidator.netBuffer.position() != 0) {
                            unwrap(peerValidator, false);
                        }
                        return;
                    default:
                        throw new IllegalStateException("Unexpected handshake status: " + handshakeStatus);
                }
            }
        }
Validator used to verify dynamic update of keystore used in inter-broker communication.
The validator checks that a successful handshake can be performed using the keystore and
truststore configured on this SslFactory.
clients/src/main/java/org/apache/kafka/common/security/ssl/SslFactory.java