code: public void handshake(NextFilter nextFilter) throws SSLException {
          for (;;) {
              switch (handshakeStatus) {
                  case FINISHED :
                      session.setAttribute(
                              SslFilter.SSL_SESSION, sslEngine.getSession());
                      handshakeComplete = true;
                      
                      if (!initialHandshakeComplete
                              && session.containsAttribute(SslFilter.USE_NOTIFICATION)) {
                          // SESSION_SECURED is fired only when it's the first handshake.
                          // (i.e. renegotiation shouldn't trigger SESSION_SECURED.)
                          initialHandshakeComplete = true;
                          scheduleMessageReceived(nextFilter,
                                  SslFilter.SESSION_SECURED);
                      }
                      
                      return;
                      
                  case NEED_TASK :
                      handshakeStatus = doTasks();
                      break;
                      
                  case NEED_UNWRAP :
                      // we need more data read
                      SSLEngineResult.Status status = unwrapHandshake(nextFilter);
                      
                      if (status == SSLEngineResult.Status.BUFFER_UNDERFLOW &&
                              handshakeStatus != SSLEngineResult.HandshakeStatus.FINISHED ||
                              isInboundDone()) {
                          // We need more data or the session is closed
                          return;
                      }
                      
                      break;
  
                  case NEED_WRAP :
                      // First make sure that the out buffer is completely empty. Since we
                      // cannot call wrap with data left on the buffer
                      if (outNetBuffer != null && outNetBuffer.hasRemaining()) {
                          return;
                      }
  
                      SSLEngineResult result;
                      createOutNetBuffer(0);
                      
                      for (;;) {
                          result = sslEngine.wrap(emptyBuffer.buf(), outNetBuffer.buf());
                          if (result.getStatus() == SSLEngineResult.Status.BUFFER_OVERFLOW) {
                              outNetBuffer.capacity(outNetBuffer.capacity() << 1);
                              outNetBuffer.limit(outNetBuffer.capacity());
                          } else {
                              break;
                          }
                      }
  
                      outNetBuffer.flip();
                      handshakeStatus = result.getHandshakeStatus();
                      writeNetBuffer(nextFilter);
                      break;
              
                  default :
                      throw new IllegalStateException("Invalid Handshaking State"
                              + handshakeStatus);
              }
          }
      }
docs: Perform any handshaking processing.