use of javax.net.ssl.SSLEngineResult in project rabbitmq-java-client by rabbitmq.
the class SslEngineHelper method write.
public static void write(WritableByteChannel socketChannel, SSLEngine engine, ByteBuffer plainOut, ByteBuffer cypherOut) throws IOException {
while (plainOut.hasRemaining()) {
cypherOut.clear();
SSLEngineResult result = engine.wrap(plainOut, cypherOut);
switch(result.getStatus()) {
case OK:
cypherOut.flip();
while (cypherOut.hasRemaining()) {
socketChannel.write(cypherOut);
}
break;
case BUFFER_OVERFLOW:
throw new SSLException("Buffer overflow occured after a wrap.");
case BUFFER_UNDERFLOW:
throw new SSLException("Buffer underflow occured after a wrap.");
case CLOSED:
throw new SSLException("Buffer closed");
default:
throw new IllegalStateException("Invalid SSL status: " + result.getStatus());
}
}
}
use of javax.net.ssl.SSLEngineResult in project ignite by apache.
the class BlockingSslHandler method unwrapHandshake.
/**
* Unwraps handshake data and processes it.
*
* @return Status.
* @throws SSLException If SSL exception occurred while unwrapping.
* @throws GridNioException If failed to pass event to the next filter.
*/
private Status unwrapHandshake() throws SSLException, IgniteCheckedException {
// Flip input buffer so we can read the collected data.
readFromNet();
inNetBuf.flip();
SSLEngineResult res = unwrap0();
handshakeStatus = res.getHandshakeStatus();
checkStatus(res);
// try to unwrap more
if (handshakeStatus == FINISHED && res.getStatus() == OK && inNetBuf.hasRemaining()) {
res = unwrap0();
handshakeStatus = res.getHandshakeStatus();
// prepare to be written again
inNetBuf.compact();
renegotiateIfNeeded(res);
} else if (res.getStatus() == BUFFER_UNDERFLOW) {
inNetBuf.compact();
inNetBuf = expandBuffer(inNetBuf, inNetBuf.capacity() * 2);
} else
// prepare to be written again
inNetBuf.compact();
return res.getStatus();
}
use of javax.net.ssl.SSLEngineResult in project ignite by apache.
the class BlockingSslHandler method unwrapData.
/**
* Unwraps user data to the application buffer.
*
* @throws SSLException If failed to process SSL data.
* @throws GridNioException If failed to pass events to the next filter.
*/
private void unwrapData() throws IgniteCheckedException, SSLException {
if (log.isDebugEnabled())
log.debug("Unwrapping received data.");
// Flip buffer so we can read it.
inNetBuf.flip();
SSLEngineResult res = unwrap0();
// prepare to be written again
inNetBuf.compact();
checkStatus(res);
renegotiateIfNeeded(res);
}
use of javax.net.ssl.SSLEngineResult in project ignite by apache.
the class GridNioSslHandler method unwrapData.
/**
* Unwraps user data to the application buffer.
*
* @throws SSLException If failed to process SSL data.
* @throws GridNioException If failed to pass events to the next filter.
*/
private void unwrapData() throws IgniteCheckedException, SSLException {
if (log.isDebugEnabled())
log.debug("Unwrapping received data: " + ses);
// Flip buffer so we can read it.
inNetBuf.flip();
SSLEngineResult res = unwrap0();
// prepare to be written again
inNetBuf.compact();
checkStatus(res);
renegotiateIfNeeded(res);
}
use of javax.net.ssl.SSLEngineResult in project ignite by apache.
the class GridNioSslHandler method unwrapHandshake.
/**
* Unwraps handshake data and processes it.
*
* @return Status.
* @throws SSLException If SSL exception occurred while unwrapping.
* @throws GridNioException If failed to pass event to the next filter.
*/
private Status unwrapHandshake() throws SSLException, IgniteCheckedException {
// Flip input buffer so we can read the collected data.
inNetBuf.flip();
SSLEngineResult res = unwrap0();
handshakeStatus = res.getHandshakeStatus();
checkStatus(res);
// try to unwrap more
if (handshakeStatus == FINISHED && res.getStatus() == Status.OK && inNetBuf.hasRemaining()) {
res = unwrap0();
handshakeStatus = res.getHandshakeStatus();
// prepare to be written again
inNetBuf.compact();
renegotiateIfNeeded(res);
} else
// prepare to be written again
inNetBuf.compact();
return res.getStatus();
}
Aggregations