appBuffer.clear();
// Prepare the net data for reading.
inNetBuffer.flip();
SSLEngineResult res;
do
{
if( log.isDebugEnabled() )
{
log.debug( session + " inNetBuffer: " + inNetBuffer );
log.debug( session + " appBuffer: " + appBuffer );
}
res = sslEngine.unwrap( inNetBuffer, appBuffer );
if( log.isDebugEnabled() )
{
log.debug( session + " Unwrap res:" + res );
}
}
while( res.getStatus() == SSLEngineResult.Status.OK &&
res.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_UNWRAP );
initialHandshakeStatus = res.getHandshakeStatus();
// If handshake finished, no data was produced, and the status is still ok,
// try to unwrap more
if (initialHandshakeStatus == SSLEngineResult.HandshakeStatus.FINISHED
&& appBuffer.position() == 0
&& res.getStatus() == SSLEngineResult.Status.OK
&& inNetBuffer.hasRemaining()) {
do {
if (log.isDebugEnabled()) {
log.debug( session + " extra handshake unwrap" );
log.debug( session + " inNetBuffer: " + inNetBuffer );
log.debug( session + " appBuffer: " + appBuffer );
}
res = sslEngine.unwrap(inNetBuffer, appBuffer);
if (log.isDebugEnabled()) {
log.debug( session + " Unwrap res:" + res );
}
} while (res.getStatus() == SSLEngineResult.Status.OK);
}
// If we are CLOSED, set flag
if( res.getStatus() == SSLEngineResult.Status.CLOSED )
{
closed = true;
}
// prepare to be written again
inNetBuffer.compact();
// prepare app data to be read
appBuffer.flip();
/*
* The status may be:
* OK - Normal operation
* OVERFLOW - Should never happen since the application buffer is
* sized to hold the maximum packet size.
* UNDERFLOW - Need to read more data from the socket. It's normal.
* CLOSED - The other peer closed the socket. Also normal.
*/
//initialHandshakeStatus = res.getHandshakeStatus();
return checkStatus( res.getStatus() );
}