void handshake(NextFilter nextFilter) throws SSLException {
  for (; ; ) {
switch (handshakeStatus) {
case FINISHED:
case NOT_HANDSHAKING:
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("{} processing the FINISHED state",sslFilter.getSessionInfo(session));
      }
    session.setAttribute(SslFilter.SSL_SESSION,sslEngine.getSession());
  handshakeComplete=true;
if (firstSSLNegociation && session.containsAttribute(SslFilter.USE_NOTIFICATION)) {
  firstSSLNegociation=false;
  scheduleMessageReceived(nextFilter,SslFilter.SESSION_SECURED);
}
if (LOGGER.isDebugEnabled()) {
if (!isOutboundDone()) {
  LOGGER.debug("{} is now secured",sslFilter.getSessionInfo(session));
}
 else {
  LOGGER.debug("{} is not secured yet",sslFilter.getSessionInfo(session));
}
}
return;
case NEED_TASK:
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} processing the NEED_TASK state",sslFilter.getSessionInfo(session));
}
handshakeStatus=doTasks();
break;
case NEED_UNWRAP:
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} processing the NEED_UNWRAP state",sslFilter.getSessionInfo(session));
}
Status status=unwrapHandshake(nextFilter);
if (status == Status.BUFFER_UNDERFLOW && handshakeStatus != HandshakeStatus.FINISHED || isInboundDone()) {
return;
}
break;
case NEED_WRAP:
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} processing the NEED_WRAP state",sslFilter.getSessionInfo(session));
}
if (outNetBuffer != null && outNetBuffer.hasRemaining()) {
return;
}
SSLEngineResult result;
createOutNetBuffer(0);
for (; ; ) {
result=sslEngine.wrap(emptyBuffer.buf(),outNetBuffer.buf());
if (result.getStatus() == Status.BUFFER_OVERFLOW) {
outNetBuffer.capacity(outNetBuffer.capacity() << 1);
outNetBuffer.limit(outNetBuffer.capacity());
}
 else {
break;
}
}
outNetBuffer.flip();
handshakeStatus=result.getHandshakeStatus();
writeNetBuffer(nextFilter);
break;
default :
String msg="Invalid Handshaking State" + handshakeStatus + " while processing the Handshake for session "+ session.getId();
LOGGER.error(msg);
throw new IllegalStateException(msg);
}
}
}

void handshake ( NextFilter nextFilter ) throws SSLException { for ( ; ; ) { switch ( handshakeStatus ) { case FINISHED : case NOT_HANDSHAKING : if ( LOGGER . isDebugEnabled ( ) ) { LOGGER . debug ( "{} processing the FINISHED state" , sslFilter . getSessionInfo ( session ) ) ; } session . setAttribute ( SslFilter . SSL_SESSION , sslEngine . getSession ( ) ) ; handshakeComplete = true ; if ( firstSSLNegociation && session . containsAttribute ( SslFilter . USE_NOTIFICATION ) ) { firstSSLNegociation = false ; scheduleMessageReceived ( nextFilter , SslFilter . SESSION_SECURED ) ; } if ( LOGGER . isDebugEnabled ( ) ) { if ( ! isOutboundDone ( ) ) { LOGGER . debug ( "{} is now secured" , sslFilter . getSessionInfo ( session ) ) ; } else { LOGGER . debug ( "{} is not secured yet" , sslFilter . getSessionInfo ( session ) ) ; } } return ; case NEED_TASK : if ( LOGGER . isDebugEnabled ( ) ) { LOGGER . debug ( "{} processing the NEED_TASK state" , sslFilter . getSessionInfo ( session ) ) ; } handshakeStatus = doTasks ( ) ; break ; case NEED_UNWRAP : if ( LOGGER . isDebugEnabled ( ) ) { LOGGER . debug ( "{} processing the NEED_UNWRAP state" , sslFilter . getSessionInfo ( session ) ) ; } Status status = unwrapHandshake ( nextFilter ) ; if ( status == Status . BUFFER_UNDERFLOW && handshakeStatus != HandshakeStatus . FINISHED || isInboundDone ( ) ) { return ; } break ; case NEED_WRAP : if ( LOGGER . isDebugEnabled ( ) ) { LOGGER . debug ( "{} processing the NEED_WRAP state" , sslFilter . getSessionInfo ( session ) ) ; } if ( outNetBuffer != null && outNetBuffer . hasRemaining ( ) ) { return ; } SSLEngineResult result ; createOutNetBuffer ( 0 ) ; for ( ; ; ) { result = sslEngine . wrap ( emptyBuffer . buf ( ) , outNetBuffer . buf ( ) ) ; if ( result . getStatus ( ) == Status . BUFFER_OVERFLOW ) { outNetBuffer . capacity ( outNetBuffer . capacity ( ) << 1 ) ; outNetBuffer . limit ( outNetBuffer . capacity ( ) ) ; } else { break ; } } outNetBuffer . flip ( ) ; handshakeStatus = result . getHandshakeStatus ( ) ; writeNetBuffer ( nextFilter ) ; break ; default : String msg = "Invalid Handshaking State" + handshakeStatus + " while processing the Handshake for session " + session . getId ( ) ; LOGGER . error ( msg ) ; throw new IllegalStateException ( msg ) ; } } }
perform any handshaking processing .
