本文整理汇总了Java中javax.net.ssl.SSLEngineResult.Status.BUFFER_UNDERFLOW属性的典型用法代码示例。如果您正苦于以下问题:Java Status.BUFFER_UNDERFLOW属性的具体用法?Java Status.BUFFER_UNDERFLOW怎么用?Java Status.BUFFER_UNDERFLOW使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.net.ssl.SSLEngineResult.Status
的用法示例。
在下文中一共展示了Status.BUFFER_UNDERFLOW属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkResult
private void checkResult(SSLEngineResult result, boolean wrap)
throws SSLException {
handshakeStatus = result.getHandshakeStatus();
resultStatus = result.getStatus();
if (resultStatus != Status.OK &&
(wrap || resultStatus != Status.BUFFER_UNDERFLOW)) {
throw new SSLException("TODO");
}
if (wrap && result.bytesConsumed() != 0) {
throw new SSLException("TODO");
}
if (!wrap && result.bytesProduced() != 0) {
throw new SSLException("TODO");
}
}
示例2: SSLSocketChannel2
public SSLSocketChannel2( SocketChannel channel , SSLEngine sslEngine , ExecutorService exec , SelectionKey key ) throws IOException {
if( channel == null || sslEngine == null || exec == null )
throw new IllegalArgumentException( "parameter must not be null" );
this.socketChannel = channel;
this.sslEngine = sslEngine;
this.exec = exec;
readEngineResult = writeEngineResult = new SSLEngineResult( Status.BUFFER_UNDERFLOW, sslEngine.getHandshakeStatus(), 0, 0 ); // init to prevent NPEs
tasks = new ArrayList<Future<?>>( 3 );
if( key != null ) {
key.interestOps( key.interestOps() | SelectionKey.OP_WRITE );
this.selectionKey = key;
}
createBuffers( sslEngine.getSession() );
// kick off handshake
socketChannel.write( wrap( emptybuffer ) );// initializes res
processHandshake();
}
示例3: SSLSocketChannel2
public SSLSocketChannel2(SocketChannel channel, SSLEngine sslEngine, ExecutorService exec, SelectionKey key) throws IOException {
if (channel == null || sslEngine == null || exec == null) {
throw new IllegalArgumentException("parameter must not be null");
}
this.socketChannel = channel;
this.sslEngine = sslEngine;
this.exec = exec;
readEngineResult = writeEngineResult = new SSLEngineResult(Status.BUFFER_UNDERFLOW, sslEngine.getHandshakeStatus(), 0, 0); // init to prevent NPEs
tasks = new ArrayList<Future<?>>(3);
if (key != null) {
key.interestOps(key.interestOps() | SelectionKey.OP_WRITE);
this.selectionKey = key;
}
createBuffers(sslEngine.getSession());
// kick off handshake
socketChannel.write(wrap(emptybuffer));// initializes res
processHandshake();
}
示例4: SSLSocketChannel2
public SSLSocketChannel2( SocketChannel channel , SSLEngine sslEngine , ExecutorService exec , SelectionKey key ) throws IOException {
if( channel == null || sslEngine == null || exec == null )
throw new IllegalArgumentException( "parameter must not be null" );
this.socketChannel = channel;
this.sslEngine = sslEngine;
this.exec = exec;
readEngineResult = writeEngineResult = new SSLEngineResult( Status.BUFFER_UNDERFLOW, sslEngine.getHandshakeStatus(), 0, 0 ); // init to prevent NPEs
tasks = new ArrayList<Future<?>>( 3 );
if( key != null ) {
key.interestOps( key.interestOps() | SelectionKey.OP_WRITE );
this.selectionKey = key;
}
createBuffers( sslEngine.getSession() );
// kick off request
socketChannel.write( wrap( emptybuffer ) );// initializes res
processHandshake();
}
示例5: SSLSocketChannel
public SSLSocketChannel(SocketChannel channel, SSLEngine sslEngine, ExecutorService exec, SelectionKey key) throws IOException {
if(channel == null || sslEngine == null || exec == null)
throw new IllegalArgumentException("parameter must not be null");
this.socketChannel = channel;
this.sslEngine = sslEngine;
this.exec = exec;
readEngineResult = writeEngineResult = new SSLEngineResult(Status.BUFFER_UNDERFLOW, sslEngine.getHandshakeStatus(), 0, 0); // init to prevent NPEs
tasks = new ArrayList<Future<?>>(3);
if(key != null) {
key.interestOps(key.interestOps() | SelectionKey.OP_WRITE);
this.selectionKey = key;
}
createBuffers(sslEngine.getSession());
socketChannel.write(wrap(emptybuffer));
processHandshake();
}
示例6: SSLSocketChannel2
public SSLSocketChannel2(SocketChannel channel, SSLEngine sslEngine, ExecutorService exec, SelectionKey key) throws IOException {
if (channel == null || sslEngine == null || exec == null)
throw new IllegalArgumentException("parameter must not be null");
this.socketChannel = channel;
this.sslEngine = sslEngine;
this.exec = exec;
readEngineResult = writeEngineResult = new SSLEngineResult(Status.BUFFER_UNDERFLOW, sslEngine.getHandshakeStatus(), 0, 0); // init to prevent NPEs
tasks = new ArrayList<Future<?>>(3);
if (key != null) {
key.interestOps(key.interestOps() | SelectionKey.OP_WRITE);
this.selectionKey = key;
}
createBuffers(sslEngine.getSession());
// kick off handshake
socketChannel.write(wrap(emptybuffer));// initializes res
processHandshake();
}
示例7: 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;
}
示例8: getStatus
/**
* Returns the current status for this TLSHandler.
*
* @return the current TLSStatus
*/
public TLSStatus getStatus() {
if (tlsEngineResult != null && tlsEngineResult.getStatus() == Status.BUFFER_UNDERFLOW) {
return TLSStatus.UNDERFLOW;
} else {
if (tlsEngineResult != null && tlsEngineResult.getStatus() == Status.CLOSED) {
return TLSStatus.CLOSED;
} else {
switch (tlsEngine.getHandshakeStatus()) {
case NEED_WRAP:
return TLSStatus.NEED_WRITE;
case NEED_UNWRAP:
return TLSStatus.NEED_READ;
default:
return TLSStatus.OK;
}
}
}
}
示例9: SSLSocketChannel2
public SSLSocketChannel2( SocketChannel channel , SSLEngine sslEngine , ExecutorService exec , SelectionKey key ) throws IOException {
if( channel == null || sslEngine == null || exec == null )
throw new IllegalArgumentException( "parameter must not be null" );
this.socketChannel = channel;
this.sslEngine = sslEngine;
this.exec = exec;
readEngineResult = writeEngineResult = new SSLEngineResult( Status.BUFFER_UNDERFLOW, sslEngine.getHandshakeStatus(), 0, 0 ); // init to prevent NPEs
tasks = new ArrayList<Future<?>>( 3 );
if( key != null ) {
key.interestOps( key.interestOps() | SelectionKey.OP_WRITE );
this.selectionKey = key;
}
createBuffers( sslEngine.getSession() );
// kick off handshake
socketChannel.write( wrap( emptybuffer ) );// initializes res
processHandshake();
}
示例10: getStatus
/**
* Returns the current status for this TLSHandler.
*
* @return the current TLSStatus
*/
public TLSStatus getStatus() {
TLSStatus status = null;
if (tlsEngineResult != null && tlsEngineResult.getStatus() == Status.BUFFER_UNDERFLOW) {
status = TLSStatus.UNDERFLOW;
} else {
if (tlsEngineResult != null && tlsEngineResult.getStatus() == Status.CLOSED) {
status = TLSStatus.CLOSED;
} else {
switch (tlsEngine.getHandshakeStatus()) {
case NEED_WRAP:
status = TLSStatus.NEED_WRITE;
break;
case NEED_UNWRAP:
status = TLSStatus.NEED_READ;
break;
default:
status = TLSStatus.OK;
break;
}
}
}
return status;
}
示例11: processHandshake
private synchronized void processHandshake() throws IOException {
if (this.engineResult.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING) {
if (!this.tasks.isEmpty()) {
Iterator<Future<?>> it = this.tasks.iterator();
while (it.hasNext()) {
Future<?> f = (Future) it.next();
if (f.isDone()) {
it.remove();
} else if (isBlocking()) {
consumeFutureUninterruptible(f);
}
}
}
if (this.engineResult.getHandshakeStatus() == HandshakeStatus.NEED_UNWRAP) {
if (!isBlocking() || this.engineStatus == Status.BUFFER_UNDERFLOW) {
this.inCrypt.compact();
if (this.socketChannel.read(this.inCrypt) == -1) {
throw new IOException("connection closed unexpectedly by peer");
}
this.inCrypt.flip();
}
this.inData.compact();
unwrap();
if (this.engineResult.getHandshakeStatus() == HandshakeStatus.FINISHED) {
createBuffers(this.sslEngine.getSession());
}
}
consumeDelegatedTasks();
if (!$assertionsDisabled && this.engineResult.getHandshakeStatus() == HandshakeStatus.NOT_HANDSHAKING) {
throw new AssertionError();
} else if (this.tasks.isEmpty() || this.engineResult.getHandshakeStatus() == HandshakeStatus.NEED_WRAP) {
this.socketChannel.write(wrap(emptybuffer));
if (this.engineResult.getHandshakeStatus() == HandshakeStatus.FINISHED) {
createBuffers(this.sslEngine.getSession());
}
}
}
}
示例12: read
public int read(ByteBuffer dst) throws IOException {
if (!dst.hasRemaining()) {
return 0;
}
if (!isHandShakeComplete()) {
if (isBlocking()) {
while (!isHandShakeComplete()) {
processHandshake();
}
} else {
processHandshake();
if (!isHandShakeComplete()) {
return 0;
}
}
}
int purged = readRemaining(dst);
if (purged != 0) {
return purged;
}
if ($assertionsDisabled || this.inData.position() == 0) {
this.inData.clear();
if (this.inCrypt.hasRemaining()) {
this.inCrypt.compact();
} else {
this.inCrypt.clear();
}
if (((isBlocking() && this.inCrypt.position() == 0) || this.engineStatus == Status.BUFFER_UNDERFLOW) && this.socketChannel.read(this.inCrypt) == -1) {
return -1;
}
this.inCrypt.flip();
unwrap();
int transfered = transfereTo(this.inData, dst);
return (transfered == 0 && isBlocking()) ? read(dst) : transfered;
} else {
throw new AssertionError();
}
}
示例13: 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;
}
示例14: checkResult
private void checkResult(SSLEngineResult result, boolean wrap) throws SSLException {
handshakeStatus = result.getHandshakeStatus();
resultStatus = result.getStatus();
if (resultStatus != Status.OK && (wrap || resultStatus != Status.BUFFER_UNDERFLOW)) {
throw new SSLException("TODO");
}
if (wrap && result.bytesConsumed() != 0) {
throw new SSLException("TODO");
}
if (!wrap && result.bytesProduced() != 0) {
throw new SSLException("TODO");
}
}
示例15: decrypt
public ReuseableMergedByteBuffers decrypt(final MergedByteBuffers bb) throws EncryptionException {
final ReuseableMergedByteBuffers mbb = new ReuseableMergedByteBuffers(false);
if(!this.startedHandshake.get()) {
mbb.add(bb);
return mbb;
}
encryptedReadBuffers.add(bb);
final ByteBuffer encBB = encryptedReadBuffers.pullBuffer(encryptedReadBuffers.remaining());
while(encBB.remaining() > 0) {
int lastSize = encBB.remaining();
final ByteBuffer dbb = getDecryptedByteBuffer();
final ByteBuffer newBB = dbb.duplicate();
SSLEngineResult res;
try {
res = ssle.unwrap(encBB, dbb);
//We have to check both each time till complete
if(! handshakeFuture.isDone()) {
processHandshake(res.getHandshakeStatus());
processHandshake(ssle.getHandshakeStatus());
}
} catch (SSLException e) {
throw new EncryptionException(e);
}
newBB.limit(dbb.position());
if(newBB.hasRemaining()) {
mbb.add(newBB);
} else if (res.getStatus() == Status.BUFFER_UNDERFLOW || (lastSize > 0 && lastSize == encBB.remaining())) {
if(encBB.hasRemaining()) {
encryptedReadBuffers.add(encBB);
}
break;
}
}
return mbb;
}