本文整理汇总了Java中javax.net.ssl.SSLEngineResult.Status.BUFFER_OVERFLOW属性的典型用法代码示例。如果您正苦于以下问题:Java Status.BUFFER_OVERFLOW属性的具体用法?Java Status.BUFFER_OVERFLOW怎么用?Java Status.BUFFER_OVERFLOW使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.net.ssl.SSLEngineResult.Status
的用法示例。
在下文中一共展示了Status.BUFFER_OVERFLOW属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unwrap0
/**
* Performs raw unwrap from network read buffer.
*
* @return Result.
* @throws SSLException If SSL exception occurs.
*/
private SSLEngineResult unwrap0() throws SSLException {
SSLEngineResult res;
do {
res = sslEngine.unwrap(inNetBuf, appBuf);
if (log.isDebugEnabled())
log.debug("Unwrapped raw data [status=" + res.getStatus() + ", handshakeStatus=" +
res.getHandshakeStatus() + ']');
if (res.getStatus() == Status.BUFFER_OVERFLOW)
appBuf = expandBuffer(appBuf, appBuf.capacity() * 2);
}
while ((res.getStatus() == OK || res.getStatus() == Status.BUFFER_OVERFLOW) &&
(handshakeFinished && res.getHandshakeStatus() == NOT_HANDSHAKING
|| res.getHandshakeStatus() == NEED_UNWRAP));
return res;
}
示例2: doCallbackIncreaseBufferProcess
protected SSLEngineResult doCallbackIncreaseBufferProcess(HandshakeCallback callback,
HandshakeBuffer hb) throws SSLException, WebSocketException {
SSLEngineResult res = null;
do {
res = callback.execute(hb);
if (log.isLoggable(Level.FINER)) {
log.finer("res: \n" + res);
log.finer("buffer: " + hb);
}
if (res.getStatus() == Status.BUFFER_OVERFLOW) {
increaseBuffer(hb, hb.localBuffer);
} else if (res.getStatus() == Status.BUFFER_UNDERFLOW) {
increaseBuffer(hb, hb.netBuffer);
}
if (res.getStatus() != Status.BUFFER_OVERFLOW) {
break;
}
} while (true);
return res;
}
示例3: wrapClose
private int wrapClose(final Buffer pool, final int offset, final int length) throws SSLException {
int encLength = 0;
initWrap();
SSLEngineResult res;
do {
res = sslEngine.wrap(localAppData, localNetDataForPeer);
LOG.log("--CLOSE-- wrap " + res);
switch (res.getStatus()) {
case CLOSED:
case OK: {
encLength += fillBuffer(localNetDataForPeer, pool);
localNetDataForPeer.compact();
break;
}
case BUFFER_OVERFLOW: {
localNetDataForPeer = handleBufferOverFlow(sslEngine.getSession().getPacketBufferSize(), localNetDataForPeer);
break;
}
case BUFFER_UNDERFLOW: {
throw new RuntimeException("NOT EXPECTING THIS BUFFER_UNDERFLOW");
}
}
} while (res.getStatus() == Status.BUFFER_OVERFLOW || !sslEngine.isOutboundDone());
return encLength;
}
示例4: closeOutbound
/**
* Start SSL shutdown process.
*
* @return <tt>true</tt> if shutdown process is started.
* <tt>false</tt> if shutdown process is already finished.
* @throws SSLException on errors
*/
boolean closeOutbound() throws SSLException {
if (sslEngine == null || sslEngine.isOutboundDone()) {
return false;
}
sslEngine.closeOutbound();
createOutNetBuffer(0);
for (;;) {
SSLEngineResult result = sslEngine.wrap(SimpleBufferAllocator.emptyBuffer.buf(), outNetBuffer.buf());
if (result.getStatus() != Status.BUFFER_OVERFLOW) {
if (result.getStatus() != Status.CLOSED) {
throw new SSLException("Improper close state: " + result);
}
break;
}
outNetBuffer = IoBuffer.reallocate(outNetBuffer, outNetBuffer.capacity() << 1);
outNetBuffer.limit(outNetBuffer.capacity());
}
outNetBuffer.flip();
return true;
}
示例5: write
/**
* Writes a sequence of bytes to this channel from the given buffer.
*
* @param src The buffer from which bytes are to be retrieved
* @return The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream
* @throws IOException If some other I/O error occurs
*/
@Override
public int write(ByteBuffer src) throws IOException {
int written = 0;
if (closing) throw new IllegalStateException("Channel is in closing state");
if (!handshakeComplete) return written;
if (!flush(netWriteBuffer))
return written;
netWriteBuffer.clear();
SSLEngineResult wrapResult = sslEngine.wrap(src, netWriteBuffer);
netWriteBuffer.flip();
//handle ssl renegotiation
if (wrapResult.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING && wrapResult.getStatus() == Status.OK) {
renegotiate();
return written;
}
if (wrapResult.getStatus() == Status.OK) {
written = wrapResult.bytesConsumed();
flush(netWriteBuffer);
} else if (wrapResult.getStatus() == Status.BUFFER_OVERFLOW) {
int currentNetWriteBufferSize = netWriteBufferSize();
netWriteBuffer.compact();
netWriteBuffer = Utils.ensureCapacity(netWriteBuffer, currentNetWriteBufferSize);
netWriteBuffer.flip();
if (netWriteBuffer.limit() >= currentNetWriteBufferSize)
throw new IllegalStateException("SSL BUFFER_OVERFLOW when available data size (" + netWriteBuffer.limit() + ") >= network buffer size (" + currentNetWriteBufferSize + ")");
} else if (wrapResult.getStatus() == Status.BUFFER_UNDERFLOW) {
throw new IllegalStateException("SSL BUFFER_UNDERFLOW during write");
} else if (wrapResult.getStatus() == Status.CLOSED) {
throw new EOFException();
}
return written;
}
示例6: wrap
private void wrap( ByteBuffer source )
throws IOException
{
final SSLResult result = new SSLResult( source.capacity() );
result.log = sslEngine.wrap( source, result.buffer );
while ( result.log.getStatus() == Status.BUFFER_OVERFLOW ) {
final int appSize = sslEngine.getSession().getApplicationBufferSize();
// Resize "result.buffer" if needed
if ( appSize > result.buffer.capacity() ) {
final ByteBuffer b = ByteBuffer.allocate( appSize );
result.buffer.flip();
b.put( result.buffer );
result.buffer = b;
} else {
result.buffer.compact();
}
result.log = sslEngine.wrap( source, result.buffer );
}
// must be Status.OK or Status.CLOSED here
if ( result.log.bytesProduced() > 0 ) {
final WritableByteChannel outputChannel = Channels.newChannel( outputStream );
result.buffer.flip();
while ( result.buffer.hasRemaining() )
outputChannel.write( result.buffer );
outputStream.flush();
}
}
示例7: unwrap
/**
* Method description
*
*
* @param net
* @param app
*
*
*
* @throws SSLException
*/
public ByteBuffer unwrap(ByteBuffer net, ByteBuffer app) throws SSLException {
ByteBuffer out = app;
out.order(app.order());
tlsEngineResult = tlsEngine.unwrap(net, out);
if (log.isLoggable(Level.FINEST)) {
log.log(Level.FINEST, "{0}, unwrap() tlsEngineRsult.getStatus() = {1}, "
+ "tlsEngineRsult.getHandshakeStatus() = {2}", new Object[] { debugId, tlsEngineResult.getStatus(),
tlsEngineResult.getHandshakeStatus() });
}
if (tlsEngineResult.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.FINISHED) {
if (eventHandler != null) {
eventHandler.handshakeCompleted(this);
}
}
if (tlsEngineResult.getStatus() == Status.BUFFER_OVERFLOW) {
out = resizeApplicationBuffer(net, out);
tlsEngineResult = tlsEngine.unwrap(net, out);
}
if (tlsEngineResult.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
doTasks();
if (log.isLoggable(Level.FINEST)) {
log.log(Level.FINEST, "unwrap() doTasks(), handshake: {0}, {1}", new Object[] { tlsEngine.getHandshakeStatus(),
debugId });
}
}
return out;
}
示例8: tearDownSSLConnection
private void tearDownSSLConnection() throws Exception
{
SSLEngineResult result = engine.wrap(ByteBuffer.allocate(0), netData);
Status status = result.getStatus();
int read = result.bytesProduced();
while (status != Status.CLOSED)
{
if (status == Status.BUFFER_OVERFLOW)
{
netData.clear();
}
if(read > 0)
{
int limit = netData.limit();
netData.limit(netData.position());
netData.position(netData.position() - read);
ByteBuffer data = netData.slice();
netData.limit(limit);
netData.position(netData.position() + read);
delegate.send(data);
flush();
}
result = engine.wrap(ByteBuffer.allocate(0), netData);
status = result.getStatus();
read = result.bytesProduced();
}
}
示例9: encrypt
/**
* Encrypt provided buffer. Encrypted data returned by getOutNetBuffer().
*
* @param src data to encrypt
* @throws SSLException on errors
*/
void encrypt(ByteBuffer src) throws SSLException {
if (!handshakeComplete) {
throw new IllegalStateException();
}
if (!src.hasRemaining()) {
if (outNetBuffer == null) {
outNetBuffer = IoBuffer.allocate(0);
}
return;
}
createOutNetBuffer(src.remaining());
// Loop until there is no more data in src
while (src.hasRemaining()) {
SSLEngineResult result = sslEngine.wrap(src, outNetBuffer.buf());
if (result.getStatus() == Status.OK) {
if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
doTasks();
}
} else if (result.getStatus() == Status.BUFFER_OVERFLOW) {
outNetBuffer = IoBuffer.reallocate(outNetBuffer, outNetBuffer.capacity() << 1);
outNetBuffer.limit(outNetBuffer.capacity());
} else {
throw new SSLException("SSLEngine error during encrypt: " + result.getStatus() + " src: " + src + "outNetBuffer: " + outNetBuffer);
}
}
outNetBuffer.flip();
}
示例10: checkStatus
private void checkStatus(SSLEngineResult res) throws SSLException {
Status status = res.getStatus();
/*
* 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.
*/
if (status == Status.BUFFER_OVERFLOW) {
throw new SSLException("SSLEngine error during decrypt: " + status + " inNetBuffer: " + inNetBuffer + "appBuffer: " + appBuffer);
}
}
示例11: run
@Override
public void run() {
long written = 0;
try {
for (int i = offset; i < offset + length; i++) {
ByteBuffer src = srcs[i];
while (src.hasRemaining()) {
socketWriteBuffer.clear();
// Encrypt the data
SSLEngineResult r = sslEngine.wrap(src, socketWriteBuffer);
written += r.bytesConsumed();
Status s = r.getStatus();
if (s == Status.OK || s == Status.BUFFER_OVERFLOW) {
// Need to write out the bytes and may need to read from
// the source again to empty it
} else {
// Status.BUFFER_UNDERFLOW - only happens on unwrap
// Status.CLOSED - unexpected
throw new IllegalStateException(sm.getString(
"asyncChannelWrapperSecure.statusWrap"));
}
// Check for tasks
if (r.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
Runnable runnable = sslEngine.getDelegatedTask();
while (runnable != null) {
runnable.run();
runnable = sslEngine.getDelegatedTask();
}
}
socketWriteBuffer.flip();
// Do the write
int toWrite = r.bytesProduced();
while (toWrite > 0) {
Future<Integer> f =
socketChannel.write(socketWriteBuffer);
Integer socketWrite = f.get();
toWrite -= socketWrite.intValue();
}
}
}
if (writing.compareAndSet(true, false)) {
future.complete(Long.valueOf(written));
} else {
future.fail(new IllegalStateException(sm.getString(
"asyncChannelWrapperSecure.wrongStateWrite")));
}
} catch (Exception e) {
future.fail(e);
}
}
示例12: recvAndUnwrap
WrapperResult recvAndUnwrap(ByteBuffer dst) throws IOException {
Status status;
WrapperResult r = new WrapperResult();
r.buf = dst;
if (closed) {
throw new IOException ("Engine is closed");
}
boolean needData;
if (u_remaining > 0) {
unwrap_src.compact();
unwrap_src.flip();
needData = false;
} else {
unwrap_src.clear();
needData = true;
}
synchronized (unwrapLock) {
int x;
do {
if (needData) {
x = chan.read (unwrap_src);
if (x == -1) {
throw new IOException ("connection closed for reading");
}
unwrap_src.flip();
}
r.result = engine.unwrap (unwrap_src, r.buf);
status = r.result.getStatus();
if (status == Status.BUFFER_UNDERFLOW) {
if (unwrap_src.limit() == unwrap_src.capacity()) {
/* buffer not big enough */
unwrap_src = realloc (
unwrap_src, false, BufType.PACKET
);
} else {
/* Buffer not full, just need to read more
* data off the channel. Reset pointers
* for reading off SocketChannel
*/
unwrap_src.position (unwrap_src.limit());
unwrap_src.limit (unwrap_src.capacity());
}
needData = true;
} else if (status == Status.BUFFER_OVERFLOW) {
r.buf = realloc (r.buf, true, BufType.APPLICATION);
needData = false;
} else if (status == Status.CLOSED) {
closed = true;
r.buf.flip();
return r;
}
} while (status != Status.OK);
}
u_remaining = unwrap_src.remaining();
return r;
}
示例13: run
@Override
public void run() {
long written = 0;
try {
for (int i = offset; i < offset + length; i++) {
ByteBuffer src = srcs[i];
while (src.hasRemaining()) {
socketWriteBuffer.clear();
// Encrypt the data
SSLEngineResult r = sslEngine.wrap(src, socketWriteBuffer);
written += r.bytesConsumed();
Status s = r.getStatus();
if (s == Status.OK || s == Status.BUFFER_OVERFLOW) {
// Need to write out the bytes and may need to read
// from
// the source again to empty it
} else {
// Status.BUFFER_UNDERFLOW - only happens on unwrap
// Status.CLOSED - unexpected
throw new IllegalStateException(sm.getString("asyncChannelWrapperSecure.statusWrap"));
}
// Check for tasks
if (r.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
Runnable runnable = sslEngine.getDelegatedTask();
while (runnable != null) {
runnable.run();
runnable = sslEngine.getDelegatedTask();
}
}
socketWriteBuffer.flip();
// Do the write
int toWrite = r.bytesProduced();
while (toWrite > 0) {
Future<Integer> f = socketChannel.write(socketWriteBuffer);
Integer socketWrite = f.get();
toWrite -= socketWrite.intValue();
}
}
}
if (writing.compareAndSet(true, false)) {
future.complete(Long.valueOf(written));
} else {
future.fail(new IllegalStateException(sm.getString("asyncChannelWrapperSecure.wrongStateWrite")));
}
} catch (Exception e) {
future.fail(e);
}
}
示例14: recvAndUnwrap
WrapperResult recvAndUnwrap(ByteBuffer dst) throws IOException {
Status status;
WrapperResult r = new WrapperResult();
r.buf = dst;
if (closed) {
throw new IOException ("Engine is closed");
}
boolean needData;
if (u_remaining > 0) {
unwrap_src.compact();
unwrap_src.flip();
needData = false;
} else {
unwrap_src.clear();
needData = true;
}
synchronized (unwrapLock) {
int x;
do {
if (needData) {
do {
x = chan.read (unwrap_src);
} while (x == 0);
if (x == -1) {
throw new IOException ("connection closed for reading");
}
unwrap_src.flip();
}
r.result = engine.unwrap (unwrap_src, r.buf);
status = r.result.getStatus();
if (status == Status.BUFFER_UNDERFLOW) {
if (unwrap_src.limit() == unwrap_src.capacity()) {
/* buffer not big enough */
unwrap_src = realloc (
unwrap_src, false, BufType.PACKET
);
} else {
/* Buffer not full, just need to read more
* data off the channel. Reset pointers
* for reading off SocketChannel
*/
unwrap_src.position (unwrap_src.limit());
unwrap_src.limit (unwrap_src.capacity());
}
needData = true;
} else if (status == Status.BUFFER_OVERFLOW) {
r.buf = realloc (r.buf, true, BufType.APPLICATION);
needData = false;
} else if (status == Status.CLOSED) {
closed = true;
r.buf.flip();
return r;
}
} while (status != Status.OK);
}
u_remaining = unwrap_src.remaining();
return r;
}
示例15: unwrap
private byte[] unwrap(ByteBuffer[] encryptedBuffers, SSLEngine engine) throws IOException {
ByteArrayOutputStream cleartextStream = new ByteArrayOutputStream();
int decryptedBufferSize = 8192;
final ByteBuffer encryptedBuffer = combine(encryptedBuffers);
final ByteBuffer decryptedBuffer = bufferType.newBuffer(decryptedBufferSize);
while (encryptedBuffer.hasRemaining()) {
if (!decryptedBuffer.hasRemaining()) {
decryptedBuffer.clear();
}
int prevPos = decryptedBuffer.position();
SSLEngineResult unwrapResult = engine.unwrap(encryptedBuffer, decryptedBuffer);
SSLEngineResult.Status status = unwrapResult.getStatus();
switch (status) {
case BUFFER_OVERFLOW:
case OK: {
break;
}
default: { throw new RuntimeException("Unexpected SSLEngine status: " + status); }
}
int newPos = decryptedBuffer.position();
int bytesProduced = unwrapResult.bytesProduced();
assertEquals(bytesProduced, newPos - prevPos);
// Add any generated bytes to the output stream.
if (bytesProduced > 0 || status == Status.BUFFER_OVERFLOW) {
byte[] decryptedBytes = new byte[unwrapResult.bytesProduced()];
// Read the chunk that was just written to the output array.
int limit = decryptedBuffer.limit();
decryptedBuffer.limit(newPos);
decryptedBuffer.position(prevPos);
decryptedBuffer.get(decryptedBytes);
// Restore the position and limit.
decryptedBuffer.limit(limit);
// Write the decrypted bytes to the stream.
cleartextStream.write(decryptedBytes);
}
}
return cleartextStream.toByteArray();
}