473832 SslConnection flips back buffers on handshake exception

This commit is contained in:
Greg Wilkins 2015-07-30 12:09:11 +10:00
parent 837d1a74bb
commit 370abc9df1
1 changed files with 19 additions and 4 deletions

View File

@ -513,8 +513,15 @@ public class SslConnection extends AbstractConnection
// Let's unwrap even if we have no net data because in that // Let's unwrap even if we have no net data because in that
// case we want to fall through to the handshake handling // case we want to fall through to the handshake handling
int pos = BufferUtil.flipToFill(app_in); int pos = BufferUtil.flipToFill(app_in);
SSLEngineResult unwrapResult = _sslEngine.unwrap(_encryptedInput, app_in); SSLEngineResult unwrapResult;
try
{
unwrapResult = _sslEngine.unwrap(_encryptedInput, app_in);
}
finally
{
BufferUtil.flipToFlush(app_in, pos); BufferUtil.flipToFlush(app_in, pos);
}
if (DEBUG) if (DEBUG)
LOG.debug("{} unwrap {}", SslConnection.this, unwrapResult); LOG.debug("{} unwrap {}", SslConnection.this, unwrapResult);
@ -726,10 +733,18 @@ public class SslConnection extends AbstractConnection
// We call sslEngine.wrap to try to take bytes from appOut buffers and encrypt them into the _netOut buffer // We call sslEngine.wrap to try to take bytes from appOut buffers and encrypt them into the _netOut buffer
BufferUtil.compact(_encryptedOutput); BufferUtil.compact(_encryptedOutput);
int pos = BufferUtil.flipToFill(_encryptedOutput); int pos = BufferUtil.flipToFill(_encryptedOutput);
SSLEngineResult wrapResult = _sslEngine.wrap(appOuts, _encryptedOutput); SSLEngineResult wrapResult;
try
{
wrapResult=_sslEngine.wrap(appOuts, _encryptedOutput);
}
finally
{
BufferUtil.flipToFlush(_encryptedOutput, pos);
}
if (DEBUG) if (DEBUG)
LOG.debug("{} wrap {}", SslConnection.this, wrapResult); LOG.debug("{} wrap {}", SslConnection.this, wrapResult);
BufferUtil.flipToFlush(_encryptedOutput, pos);
if (wrapResult.bytesConsumed()>0) if (wrapResult.bytesConsumed()>0)
consumed+=wrapResult.bytesConsumed(); consumed+=wrapResult.bytesConsumed();
Status wrapResultStatus = wrapResult.getStatus(); Status wrapResultStatus = wrapResult.getStatus();