Refine search
protected int netReadBufferSize() { return sslEngine.getSession().getPacketBufferSize(); }
protected int netWriteBufferSize() { return sslEngine.getSession().getPacketBufferSize(); }
@Override int calculateWrapBufferCapacity(SslHandler handler, int pendingBytes, int numComponents) { return handler.engine.getSession().getPacketBufferSize(); }
int getPacketBufferSize(SslHandler handler) { return handler.engine.getSession().getPacketBufferSize(); }
@Override int calculateWrapBufferCapacity(SslHandler handler, int pendingBytes, int numComponents) { return handler.engine.getSession().getPacketBufferSize(); }
int getPacketBufferSize(SslHandler handler) { return handler.engine.getSession().getPacketBufferSize(); }
ByteBuffer get() { if (buffer == null) { buffer = ByteBuffer.allocate(sslEngine.getSession().getPacketBufferSize()); } return buffer; }
private SSLConfigValidatorEngine(SslFactory sslFactory, SSLContext sslContext, Mode mode) { this.sslEngine = sslFactory.createSslEngine(sslContext, "localhost", 0); // these hints are not used for validation sslEngine.setUseClientMode(mode == Mode.CLIENT); appBuffer = ByteBuffer.allocate(sslEngine.getSession().getApplicationBufferSize()); netBuffer = ByteBuffer.allocate(sslEngine.getSession().getPacketBufferSize()); }
/** * Enlarging a packet buffer (peerNetData or myNetData) * * @param buffer the buffer to enlarge * @return the enlarged buffer */ private ByteBuffer enlargePacketBuffer( ByteBuffer buffer ) { return enlargeBuffer( buffer, engine.getSession().getPacketBufferSize() ); }
void resize() { int increment = sslEngine.getSession().getPacketBufferSize(); int newSize = buffer.position() + increment; ByteBuffer newBuffer = ByteBuffer.allocate(newSize); buffer.flip(); newBuffer.flip(); buffer = Utils.appendBuffers(newBuffer, buffer, newBuffer.limit(), 50); buffer.compact(); }
/** * Allocate application buffer. */ private ByteBuffer allocateAppBuff() { int netBufSize = sslEngine.getSession().getPacketBufferSize() + 50; int appBufSize = Math.max(sslEngine.getSession().getApplicationBufferSize() + 50, netBufSize * 2); ByteBuffer buf = ByteBuffer.allocate(appBufSize); buf.order(order); return buf; }
NioSslEngine(SSLEngine engine, DMStats stats) { this.stats = stats; SSLSession session = engine.getSession(); int appBufferSize = session.getApplicationBufferSize(); int packetBufferSize = engine.getSession().getPacketBufferSize(); this.myNetData = ByteBuffer.allocate(packetBufferSize); this.peerAppData = ByteBuffer.allocate(appBufferSize); this.engine = engine; }
/** * Handles {@link SSLEngineResult.Status#BUFFER_UNDERFLOW}. Will check if the buffer is already filled, and if there is no space problem * will return the same buffer, so the client tries to read again. If the buffer is already filled will try to enlarge the buffer either to * session's proposed size or to a larger capacity. A buffer underflow can happen only after an unwrap, so the buffer will always be a * peerNetData buffer. * * @param buffer - will always be peerNetData buffer. * @return The same buffer if there is no space problem or a new buffer with the same data but more space. */ private ByteBuffer handleBufferUnderflow( ByteBuffer buffer ) { if( engine.getSession().getPacketBufferSize() < buffer.limit() ) { return buffer; } else { ByteBuffer replaceBuffer = enlargePacketBuffer( buffer ); buffer.flip(); replaceBuffer.put( buffer ); return replaceBuffer; } }
public SSLSocketChannel( SocketChannel inputSocketChannel, SSLEngine inputEngine, ExecutorService inputExecutor, SelectionKey key ) throws IOException { if( inputSocketChannel == null || inputEngine == null || executor == inputExecutor ) throw new IllegalArgumentException( "parameter must not be null" ); this.socketChannel = inputSocketChannel; this.engine = inputEngine; this.executor = inputExecutor; myNetData = ByteBuffer.allocate( engine.getSession().getPacketBufferSize() ); peerNetData = ByteBuffer.allocate( engine.getSession().getPacketBufferSize() ); this.engine.beginHandshake(); if( doHandshake() ) { if( key != null ) { key.interestOps( key.interestOps() | SelectionKey.OP_WRITE ); } } else { try { socketChannel.close(); } catch ( IOException e ) { log.error("Exception during the closing of the channel", e); } } }
public RapidoidTLS(SSLContext sslContext, RapidoidConnection conn) { this.sslContext = sslContext; this.conn = conn; this.engine = createServerEngine(); SSLSession session = engine.getSession(); int appBufferMax = session.getApplicationBufferSize(); int netBufferMax = session.getPacketBufferSize(); appIn = ByteBuffer.allocateDirect(appBufferMax + 64); netIn = ByteBuffer.allocateDirect(netBufferMax); netOut = ByteBuffer.allocateDirect(netBufferMax); }
public boolean isDataAvailable() throws IOException { final ByteBuffer appDataBuffer = appDataManager.prepareForRead(1); final ByteBuffer streamDataBuffer = streamInManager.prepareForRead(1); if (appDataBuffer.remaining() > 0 || streamDataBuffer.remaining() > 0) { return true; } final ByteBuffer writableBuffer = streamInManager.prepareForWrite(engine.getSession().getPacketBufferSize()); final int bytesRead = channel.read(writableBuffer); return (bytesRead > 0); }
public SSLSocketChannel(final SSLContext sslContext, final String hostname, final int port, final InetAddress localAddress, final boolean client) throws IOException { this.socketAddress = new InetSocketAddress(hostname, port); this.channel = SocketChannel.open(); if (localAddress != null) { final SocketAddress localSocketAddress = new InetSocketAddress(localAddress, 0); this.channel.bind(localSocketAddress); } this.hostname = hostname; this.port = port; this.engine = sslContext.createSSLEngine(); this.engine.setUseClientMode(client); engine.setNeedClientAuth(true); streamInManager = new BufferStateManager(ByteBuffer.allocate(engine.getSession().getPacketBufferSize())); streamOutManager = new BufferStateManager(ByteBuffer.allocate(engine.getSession().getPacketBufferSize())); appDataManager = new BufferStateManager(ByteBuffer.allocate(engine.getSession().getApplicationBufferSize())); }
case BUFFER_OVERFLOW: netBuffer.compact(); netBuffer = Utils.ensureCapacity(netBuffer, sslEngine.getSession().getPacketBufferSize()); netBuffer.flip(); break; case OK: break; case BUFFER_OVERFLOW: appBuffer = Utils.ensureCapacity(appBuffer, sslEngine.getSession().getApplicationBufferSize()); break; case BUFFER_UNDERFLOW: netBuffer = Utils.ensureCapacity(netBuffer, sslEngine.getSession().getPacketBufferSize()); break; case CLOSED:
public SSLSocketChannel(final SSLContext sslContext, final SocketChannel socketChannel, final boolean client) throws IOException { if (!socketChannel.isConnected()) { throw new IllegalArgumentException("Cannot pass an un-connected SocketChannel"); } this.channel = socketChannel; this.socketAddress = socketChannel.getRemoteAddress(); final Socket socket = socketChannel.socket(); this.hostname = socket.getInetAddress().getHostName(); this.port = socket.getPort(); this.engine = sslContext.createSSLEngine(); this.engine.setUseClientMode(client); this.engine.setNeedClientAuth(true); streamInManager = new BufferStateManager(ByteBuffer.allocate(engine.getSession().getPacketBufferSize())); streamOutManager = new BufferStateManager(ByteBuffer.allocate(engine.getSession().getPacketBufferSize())); appDataManager = new BufferStateManager(ByteBuffer.allocate(engine.getSession().getApplicationBufferSize())); }
public SSLSocketChannel(final SSLEngine sslEngine, final SocketChannel socketChannel) throws IOException { if (!socketChannel.isConnected()) { throw new IllegalArgumentException("Cannot pass an un-connected SocketChannel"); } this.channel = socketChannel; this.socketAddress = socketChannel.getRemoteAddress(); final Socket socket = socketChannel.socket(); this.hostname = socket.getInetAddress().getHostName(); this.port = socket.getPort(); // don't set useClientMode or needClientAuth, use the engine as is and let the caller configure it this.engine = sslEngine; streamInManager = new BufferStateManager(ByteBuffer.allocate(engine.getSession().getPacketBufferSize())); streamOutManager = new BufferStateManager(ByteBuffer.allocate(engine.getSession().getPacketBufferSize())); appDataManager = new BufferStateManager(ByteBuffer.allocate(engine.getSession().getApplicationBufferSize())); }