appBuffer.clear();
// Prepare the net data for reading.
inNetBuffer.flip();
SSLEngineResult res;
do {
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " inNetBuffer: " + inNetBuffer);
SessionLog.debug(session, " appBuffer: " + appBuffer);
}
res = sslEngine.unwrap(inNetBuffer, appBuffer);
if (SessionLog.isDebugEnabled(session)) {
SessionLog.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 (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " extra handshake unwrap");
SessionLog.debug(session, " inNetBuffer: " + inNetBuffer);
SessionLog.debug(session, " appBuffer: " + appBuffer);
}
res = sslEngine.unwrap(inNetBuffer, appBuffer);
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " Unwrap res:" + res);
}
} while (res.getStatus() == SSLEngineResult.Status.OK);
}
// 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());
}