@Override public void close(boolean force) throws IOException { try { close(); } finally { if (force || closed) { closed = true; sc.socket().close(); sc.close(); } } }
if ( handshakeComplete ) return 0; //we have done our initial handshake if (!flush(netOutBuffer)) return SelectionKey.OP_WRITE; //we still have data to write handshake = handshakeWrap(write); if ( handshake.getStatus() == Status.OK ){ if (handshakeStatus == HandshakeStatus.NEED_TASK) handshakeStatus = tasks(); } else { if ( handshakeStatus != HandshakeStatus.NEED_UNWRAP || (!flush(netOutBuffer)) ) { handshake = handshakeUnwrap(read); if ( handshake.getStatus() == Status.OK ) { if (handshakeStatus == HandshakeStatus.NEED_TASK) handshakeStatus = tasks(); } else if ( handshake.getStatus() == Status.BUFFER_UNDERFLOW ){ handshakeStatus = tasks(); break;
public void reset(SSLEngine engine) throws IOException { this.sslEngine = engine; reset(); } @Override
/** * Performs the WRAP function * @param doWrite boolean * @return the result * @throws IOException An IO error occurred */ protected SSLEngineResult handshakeWrap(boolean doWrite) throws IOException { //this should never be called with a network buffer that contains data //so we can clear it here. netOutBuffer.clear(); //perform the wrap getBufHandler().configureWriteBufferForRead(); SSLEngineResult result = sslEngine.wrap(getBufHandler().getWriteBuffer(), netOutBuffer); //prepare the results to be written netOutBuffer.flip(); //set the status handshakeStatus = result.getHandshakeStatus(); //optimization, if we do have a writable channel, write it now if ( doWrite ) flush(netOutBuffer); return result; }
} else { if ( (!this.isSendFile()) && (src != bufHandler.getWriteBuffer()) ) throw new IllegalArgumentException("You can only write using the application write buffer provided by the handler."); if (!flush(netOutBuffer)) { if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) tasks(); } else { throw new IOException("Unable to wrap data, invalid engine state: " +result.getStatus()); flush(netOutBuffer);
if (getBufHandler().getReadBuffer().position()>0 && getBufHandler().getReadBuffer().position()<getBufHandler().getReadBuffer().limit()) throw new IOException("Application input buffer still contains data. Data would have been lost."); if (getBufHandler().getWriteBuffer().position()>0 && getBufHandler().getWriteBuffer().position()<getBufHandler().getWriteBuffer().limit()) throw new IOException("Application output buffer still contains data. Data would have been lost."); reset(); boolean isReadable = true; boolean isWriteable = true; try { while (handshaking) { int hsStatus = this.handshake(isReadable, isWriteable); switch (hsStatus) { case -1 : throw new EOFException("EOF during handshake."); key = getIOChannel().register(selector, hsStatus); } else {
sslEngine.closeOutbound(); if (!flush(netOutBuffer)) { throw new IOException("Remaining data in the network buffer, can't send SSL close message, force a close with close(true) instead"); SSLEngineResult handshake = sslEngine.wrap(getEmptyBuf(), netOutBuffer); flush(netOutBuffer);
@Override public boolean flushOutbound() throws IOException { int remaining = netOutBuffer.remaining(); flush(netOutBuffer); int remaining2= netOutBuffer.remaining(); return remaining2 < remaining; }
Math.max(appbufsize,socketProperties.getAppWriteBufSize()), socketProperties.getDirectBuffer()); channel = new SecureNioChannel(socket, engine, bufhandler, selectorPool); } else { if ( channel instanceof SecureNioChannel ) { SSLEngine engine = createSSLEngine(); ((SecureNioChannel)channel).reset(engine); } else { channel.reset();
@Override public void doClientAuth(SSLSupport sslSupport) throws IOException { SecureNioChannel sslChannel = (SecureNioChannel) getSocket(); SSLEngine engine = sslChannel.getSslEngine(); if (!engine.getNeedClientAuth()) { // Need to re-negotiate SSL connection engine.setNeedClientAuth(true); sslChannel.rehandshake(getEndpoint().getConnectionTimeout()); ((JSSESupport) sslSupport).setSession(engine.getSession()); } }
result.getHandshakeStatus() == HandshakeStatus.NEED_TASK ) { initHandshakeStatus = tasks();
checkInterruptStatus(); if (src == this.netOutBuffer) { if (!flush(netOutBuffer)) { if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) tasks(); } else { throw new IOException(sm.getString("channel.nio.ssl.wrapFail", result.getStatus())); flush(netOutBuffer);
/** * {@inheritDoc} * @param clientCertProvider Ignored for this implementation */ @Override public SSLSupport getSslSupport(String clientCertProvider) { if (getSocket() instanceof SecureNioChannel) { SecureNioChannel ch = (SecureNioChannel) getSocket(); SSLSession session = ch.getSslEngine().getSession(); return ((NioEndpoint) getEndpoint()).getSslImplementation().getSSLSupport(session); } else { return null; } }
public int read(ByteBuffer dst) throws IOException { if (dst != getBufHandler().getReadBuffer() && (getAppReadBufHandler() == null || dst != getAppReadBufHandler().getByteBuffer())) { throw new IllegalArgumentException(sm.getString("channel.nio.ssl.invalidBuffer")); tasks(); if (dst == getBufHandler().getReadBuffer()) { getBufHandler().expand(sslEngine.getSession().getApplicationBufferSize()); dst = getBufHandler().getReadBuffer(); } else if (dst == getAppReadBufHandler().getByteBuffer()) { getAppReadBufHandler() .expand(sslEngine.getSession().getApplicationBufferSize()); dst = getAppReadBufHandler().getByteBuffer(); } else {
getBufHandler().configureReadBufferForWrite(); result = sslEngine.unwrap(netInBuffer, getBufHandler().getReadBuffer()); result.getHandshakeStatus() == HandshakeStatus.NEED_TASK ) { handshakeStatus = tasks();
socketProperties.getDirectBuffer()); if (isSSLEnabled()) { channel = new SecureNioChannel(socket, bufhandler, selectorPool, this); } else { channel = new NioChannel(socket, bufhandler);
} else { if ( (!this.isSendFile()) && (src != bufHandler.getWriteBuffer()) ) throw new IllegalArgumentException("You can only write using the application write buffer provided by the handler."); if (!flush(netOutBuffer)) { if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) tasks(); } else { throw new IOException("Unable to wrap data, invalid engine state: " +result.getStatus()); flush(netOutBuffer);
if (getBufHandler().getReadBuffer().position()>0 && getBufHandler().getReadBuffer().position()<getBufHandler().getReadBuffer().limit()) throw new IOException("Application input buffer still contains data. Data would have been lost."); if (getBufHandler().getWriteBuffer().position()>0 && getBufHandler().getWriteBuffer().position()<getBufHandler().getWriteBuffer().limit()) throw new IOException("Application output buffer still contains data. Data would have been lost."); reset(); boolean isReadable = true; boolean isWriteable = true; try { while (handshaking) { int hsStatus = this.handshake(isReadable, isWriteable); switch (hsStatus) { case -1 : throw new EOFException("EOF during handshake."); key = getIOChannel().register(selector, hsStatus); } else { key.interestOps(hsStatus);
sslEngine.closeOutbound(); if (!flush(netOutBuffer)) { throw new IOException("Remaining data in the network buffer, can't send SSL close message, force a close with close(true) instead"); SSLEngineResult handshake = sslEngine.wrap(getEmptyBuf(), netOutBuffer); flush(netOutBuffer);
@Override public boolean flushOutbound() throws IOException { int remaining = netOutBuffer.remaining(); flush(netOutBuffer); int remaining2= netOutBuffer.remaining(); return remaining2 < remaining; }