本文整理匯總了Java中javax.net.ssl.SSLEngineResult.Status.CLOSED屬性的典型用法代碼示例。如果您正苦於以下問題:Java Status.CLOSED屬性的具體用法?Java Status.CLOSED怎麽用?Java Status.CLOSED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類javax.net.ssl.SSLEngineResult.Status
的用法示例。
在下文中一共展示了Status.CLOSED屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendData
/**
* send the data in the given ByteBuffer. If a handshake is needed
* then this is handled within this method. When this call returns,
* all of the given user data has been sent and any handshake has been
* completed. Caller should check if engine has been closed.
*/
WrapperResult sendData (ByteBuffer[] src, int offset, int len) throws IOException {
WrapperResult r = WrapperResult.createOK();
while (countBytes(src, offset, len) > 0) {
r = wrapper.wrapAndSend(src, offset, len, false);
Status status = r.result.getStatus();
if (status == Status.CLOSED) {
doClosure ();
return r;
}
HandshakeStatus hs_status = r.result.getHandshakeStatus();
if (hs_status != HandshakeStatus.FINISHED &&
hs_status != HandshakeStatus.NOT_HANDSHAKING)
{
doHandshake(hs_status);
}
}
return r;
}
示例2: recvData
/**
* read data thru the engine into the given ByteBuffer. If the
* given buffer was not large enough, a new one is allocated
* and returned. This call handles handshaking automatically.
* Caller should check if engine has been closed.
*/
WrapperResult recvData (ByteBuffer dst) throws IOException {
/* we wait until some user data arrives */
int mark = dst.position();
WrapperResult r = null;
int pos = dst.position();
while (dst.position() == pos) {
r = wrapper.recvAndUnwrap (dst);
dst = (r.buf != dst) ? r.buf: dst;
Status status = r.result.getStatus();
if (status == Status.CLOSED) {
doClosure ();
return r;
}
HandshakeStatus hs_status = r.result.getHandshakeStatus();
if (hs_status != HandshakeStatus.FINISHED &&
hs_status != HandshakeStatus.NOT_HANDSHAKING)
{
doHandshake (hs_status);
}
}
Utils.flipToMark(dst, mark);
return r;
}
示例3: unwrap
/**
* performs the unwrap operation by unwrapping from {@link #inCrypt} to {@link #inData}
**/
private synchronized ByteBuffer unwrap() throws SSLException {
int rem;
//There are some ssl test suites, which get around the selector.select() call, which cause an infinite unwrap and 100% cpu usage (see #459 and #458)
if(readEngineResult.getStatus() == Status.CLOSED && sslEngine.getHandshakeStatus() == HandshakeStatus.NOT_HANDSHAKING){
try {
close();
} catch (IOException e) {
//Not really interesting
}
}
do {
rem = inData.remaining();
readEngineResult = sslEngine.unwrap( inCrypt, inData );
} while ( readEngineResult.getStatus() == Status.OK && ( rem != inData.remaining() || sslEngine.getHandshakeStatus() == HandshakeStatus.NEED_UNWRAP ) );
inData.flip();
return inData;
}
示例4: write
public int write( ByteBuffer src ) throws IOException {
if( !isHandShakeComplete() ) {
processHandshake();
return 0;
}
// assert ( bufferallocations > 1 ); //see #190
//if( bufferallocations <= 1 ) {
// createBuffers( sslEngine.getSession() );
//}
int num = socketChannel.write( wrap( src ) );
if (writeEngineResult.getStatus() == Status.CLOSED) {
throw new EOFException("Connection is closed");
}
return num;
}
示例5: readRemaining
/**
* {@link #read(ByteBuffer)} may not be to leave all buffers(inData, inCrypt)
**/
private int readRemaining( ByteBuffer dst ) throws SSLException {
if( inData.hasRemaining() ) {
return transfereTo( inData, dst );
}
if( !inData.hasRemaining() )
inData.clear();
// test if some bytes left from last read (e.key. BUFFER_UNDERFLOW)
if( inCrypt.hasRemaining() ) {
unwrap();
int amount = transfereTo( inData, dst );
if (readEngineResult.getStatus() == Status.CLOSED) {
return -1;
}
if( amount > 0 )
return amount;
}
return 0;
}
示例6: 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;
}
}
}
}
示例7: 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;
}
示例8: 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;
}
示例9: shutdown
public void shutdown() throws IOException {
//if (!shutdown) {
// sslEngine.closeOutbound();
// shutdown = true;
//}
if (outNetBB.hasRemaining() && tryFlush(outNetBB)) {
//return false;
}
/*
* By RFC 2616, we can "fire and forget" our close_notify
* message, so that's what we'll do here.
*/
for(int i = 0; i<3 && !engine.isInboundDone(); i++){ //3 retry
engine.closeOutbound();
outNetBB.clear();
SSLEngineResult result = engine.wrap(hsBB, outNetBB);
if (result.getStatus() != Status.CLOSED) {
throw new SSLException("Improper close state");
}
outNetBB.flip();
/*
* We won't wait for a select here, but if this doesn't work,
* we'll cycle back through on the next select.
*/
if (outNetBB.hasRemaining()) {
tryFlush(outNetBB);
}
}
conn.setTLS(null);
}
示例10: 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;
}
示例11: write
@Override
long write(ByteBuffer[] buffers, int start, int number) throws IOException {
//debugPrint("Send", buffers, start, number);
long l = countBytes(buffers, start, number);
WrapperResult r = sslDelegate.sendData(buffers, start, number);
if (r.result.getStatus() == Status.CLOSED) {
if (l > 0) {
throw new IOException("SSLHttpConnection closed");
}
}
return l;
}
示例12: doClosure
void doClosure () throws IOException {
try {
handshaking.lock();
ByteBuffer tmp = allocate(BufType.APPLICATION);
WrapperResult r;
do {
tmp.clear();
tmp.flip ();
r = wrapper.wrapAndSend(tmp, true);
} while (r.result.getStatus() != Status.CLOSED);
} finally {
handshaking.unlock();
}
}
示例13: write
@Override public void write(byte[] buf, int off, int len) throws IOException
{
if (!initialHandshakeDone
|| engine.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING)
{
doHandshake();
if (handshakeException != null)
throw handshakeException;
}
int k = 0;
while (k < len)
{
synchronized (engine)
{
int l = Math.min(len-k, getSession().getApplicationBufferSize());
ByteBuffer in = ByteBuffer.wrap(buf, off+k, l);
SSLEngineResult result = engine.wrap(in, buffer);
if (result.getStatus() == Status.CLOSED)
return;
if (result.getStatus() != Status.OK)
throw new SSLException("unexpected SSL state " + result.getStatus());
buffer.flip();
out.write(buffer.array(), 0, buffer.limit());
k += result.bytesConsumed();
buffer.clear();
}
}
}
示例14: read
@Override public int read(byte[] buf, int off, int len) throws IOException
{
if (!initialHandshakeDone ||
engine.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING)
{
doHandshake();
if (handshakeException != null)
throw handshakeException;
}
if (!appBuffer.hasRemaining())
{
int x = in.read();
if (x == -1)
return -1;
inBuffer.clear();
inBuffer.put((byte) x);
inBuffer.putInt(in.readInt());
int reclen = inBuffer.getShort(3) & 0xFFFF;
in.readFully(inBuffer.array(), 5, reclen);
inBuffer.position(0).limit(reclen + 5);
synchronized (engine)
{
appBuffer.clear();
SSLEngineResult result = engine.unwrap(inBuffer, appBuffer);
Status status = result.getStatus();
if (status == Status.CLOSED && result.bytesProduced() == 0)
return -1;
}
inBuffer.compact();
appBuffer.flip();
}
int l = Math.min(len, appBuffer.remaining());
appBuffer.get(buf, off, l);
return l;
}
示例15: handshakeWrapLogic
public static void handshakeWrapLogic(SSLConnection cc, Pipe<NetPayloadSchema> target, ByteBuffer buffer, boolean isServer, long arrivalTime) {
try {
do {
if (!Pipe.hasRoomForWrite(target)) {
return; //unable to complete, try again later
}
final ByteBuffer[] targetBuffers = Pipe.wrappedWritingBuffers(Pipe.storeBlobWorkingHeadPosition(target), target);
final Status status = SSLUtil.wrapResultStatusState(target, buffer, cc, noDatas, targetBuffers, isServer, arrivalTime);
if (Status.OK == status) {
Pipe.confirmLowLevelWrite(target, Pipe.sizeOf(target, NetPayloadSchema.MSG_ENCRYPTED_200));
Pipe.publishWrites(target);
} else {
//connection was closed before handshake completed
//already closed, NOTE we should release this from reserved pipe pools
//no need to cancel wrapped buffer it was already done by wrapResultStatusState
cc.close();
if (Status.CLOSED != status) {
//not expected case so log this
logger.warn("HANDSHAKE unable to wrap {} {} {} ",status, cc.getClass().getSimpleName(), cc.getEngine(), new Exception());
}
return;
}
} while(cc.getEngine().getHandshakeStatus() == HandshakeStatus.NEED_WRAP);
} catch (SSLException e) {
//logger.error("unable to wrap ", e);
Pipe.unstoreBlobWorkingHeadPosition(target);
}
}