Refine search
protected int applicationBufferSize() { return sslEngine.getSession().getApplicationBufferSize(); }
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 (peerAppData or myAppData) * * @param buffer the buffer to enlarge * @return the enlarged buffer */ private ByteBuffer enlargeApplicationBuffer( ByteBuffer buffer ) { return enlargeBuffer( buffer, engine.getSession().getApplicationBufferSize() ); }
/** * 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; }
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); }
case BUFFER_OVERFLOW: final ByteBuffer tempBuffer = ByteBuffer.allocate(destinationBuffer.capacity() + sslEngine.getSession().getApplicationBufferSize()); destinationBuffer.flip(); tempBuffer.put(destinationBuffer);
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:
case BUFFER_OVERFLOW: final ByteBuffer tempBuffer = ByteBuffer.allocate(encrypted.position() + sslEngine.getSession().getApplicationBufferSize()); destinationBuffer.flip(); tempBuffer.put(destinationBuffer);
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())); }
/** * Reads the given ByteBuffer of data and returns a new ByteBuffer (which is "flipped" / ready to be read). The newly returned * ByteBuffer will be written to be written via the {@link #write(ByteBuffer)} method. I.e., it will have already been encrypted, if * necessary, and any other decorations that need to be applied before sending will already have been applied. * * @param plaintext the data to be prepped * @return a ByteBuffer containing the prepared data * @throws IOException if a failure occurs while encrypting the data */ public ByteBuffer prepareForWrite(final ByteBuffer plaintext) throws IOException { if (sslEngine == null) { return plaintext; } ByteBuffer prepared = ByteBuffer.allocate(Math.min(85, plaintext.capacity() - plaintext.position())); while (plaintext.hasRemaining()) { encrypt(plaintext); final int bytesRemaining = prepared.capacity() - prepared.position(); if (bytesRemaining < destinationBuffer.remaining()) { final ByteBuffer temp = ByteBuffer.allocate(prepared.capacity() + sslEngine.getSession().getApplicationBufferSize()); prepared.flip(); temp.put(prepared); prepared = temp; } prepared.put(destinationBuffer); } prepared.flip(); return prepared; }
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())); }
applicationInputBuffer = ByteBuffer.allocate(sslEngine.getSession().getApplicationBufferSize()); networkOutputBuffer = ByteBuffer.allocate(sslEngine.getSession().getPacketBufferSize());
private Status encryptAndWriteFully(final BufferStateManager src) throws IOException { SSLEngineResult result = null; final ByteBuffer buff = src.prepareForRead(0); final ByteBuffer outBuff = streamOutManager.prepareForWrite(engine.getSession().getApplicationBufferSize()); logger.trace("{} Encrypting {} bytes", this, buff.remaining()); while (buff.remaining() > 0) { result = engine.wrap(buff, outBuff); if (result.getStatus() == Status.OK) { final ByteBuffer readableOutBuff = streamOutManager.prepareForRead(0); writeFully(readableOutBuff); streamOutManager.clear(); } else { return result.getStatus(); } } return result.getStatus(); }
public TLSWrapper(ConnectionConfiguration configuration, boolean clientMode ) { try { final EncryptionArtifactFactory factory = new EncryptionArtifactFactory( configuration ); if ( clientMode ) { tlsEngine = factory.createClientModeSSLEngine(); } else { tlsEngine = factory .createServerModeSSLEngine(); } final SSLSession sslSession = tlsEngine.getSession(); netBuffSize = sslSession.getPacketBufferSize(); appBuffSize = sslSession.getApplicationBufferSize(); } catch ( NoSuchAlgorithmException | KeyManagementException | KeyStoreException | UnrecoverableKeyException ex ) { Log.error("TLSHandler startup problem. SSLContext initialisation failed.", ex ); } }
int netBufSize = sslEngine.getSession().getPacketBufferSize() + 50; outNetBuf.limit(0); int appBufSize = Math.max(sslEngine.getSession().getApplicationBufferSize() + 50, netBufSize * 2);
final ByteBuffer tempBuffer = ByteBuffer.allocate(unwrapBuffer.capacity() + sslEngine.getSession().getApplicationBufferSize()); tempBuffer.put(unwrapBuffer); unwrapBuffer = tempBuffer;
final ByteBuffer outboundBuffer = streamOutManager.prepareForWrite(engine.getSession().getApplicationBufferSize()); final SSLEngineResult handshakeResult = engine.wrap(appDataOut, outboundBuffer);
@Before public void setUp() throws Exception { mockEngine = mock(SSLEngine.class); SSLSession mockSession = mock(SSLSession.class); when(mockEngine.getSession()).thenReturn(mockSession); when(mockSession.getPacketBufferSize()).thenReturn(netBufferSize); when(mockSession.getApplicationBufferSize()).thenReturn(appBufferSize); mockStats = mock(DMStats.class); nioSslEngine = new NioSslEngine(mockEngine, mockStats); spyNioSslEngine = spy(nioSslEngine); }