javax.net.ssl.SSLEngine.getSession()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(167)

本文整理了Java中javax.net.ssl.SSLEngine.getSession()方法的一些代码示例,展示了SSLEngine.getSession()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SSLEngine.getSession()方法的具体详情如下:
包路径:javax.net.ssl.SSLEngine
类名称:SSLEngine
方法名:getSession

SSLEngine.getSession介绍

[英]Returns the SSL session for this engine instance.
[中]返回此引擎实例的SSL会话。

代码示例

代码示例来源:origin: apache/kafka

  1. protected int applicationBufferSize() {
  2. return sslEngine.getSession().getApplicationBufferSize();
  3. }

代码示例来源:origin: apache/kafka

  1. protected int netReadBufferSize() {
  2. return sslEngine.getSession().getPacketBufferSize();
  3. }

代码示例来源:origin: apache/kafka

  1. private SSLConfigValidatorEngine(SslFactory sslFactory, SSLContext sslContext, Mode mode) {
  2. this.sslEngine = sslFactory.createSslEngine(sslContext, "localhost", 0); // these hints are not used for validation
  3. sslEngine.setUseClientMode(mode == Mode.CLIENT);
  4. appBuffer = ByteBuffer.allocate(sslEngine.getSession().getApplicationBufferSize());
  5. netBuffer = ByteBuffer.allocate(sslEngine.getSession().getPacketBufferSize());
  6. }

代码示例来源:origin: jersey/jersey

  1. ByteBuffer get() {
  2. if (buffer == null) {
  3. buffer = ByteBuffer.allocate(sslEngine.getSession().getPacketBufferSize());
  4. }
  5. return buffer;
  6. }

代码示例来源:origin: apache/nifi

  1. case BUFFER_OVERFLOW:
  2. final ByteBuffer tempBuffer = ByteBuffer.allocate(destinationBuffer.capacity() + sslEngine.getSession().getApplicationBufferSize());
  3. destinationBuffer.flip();
  4. tempBuffer.put(destinationBuffer);

代码示例来源:origin: apache/kafka

  1. case BUFFER_OVERFLOW:
  2. netBuffer.compact();
  3. netBuffer = Utils.ensureCapacity(netBuffer, sslEngine.getSession().getPacketBufferSize());
  4. netBuffer.flip();
  5. break;
  6. case OK: break;
  7. case BUFFER_OVERFLOW:
  8. appBuffer = Utils.ensureCapacity(appBuffer, sslEngine.getSession().getApplicationBufferSize());
  9. break;
  10. case BUFFER_UNDERFLOW:
  11. netBuffer = Utils.ensureCapacity(netBuffer, sslEngine.getSession().getPacketBufferSize());
  12. break;
  13. case CLOSED:

代码示例来源:origin: apache/mina

  1. ByteBuffer appBuffer = ByteBuffer.allocateDirect(sslEngine.getSession().getApplicationBufferSize());

代码示例来源:origin: apache/ignite

  1. /**
  2. * Allocate application buffer.
  3. */
  4. private ByteBuffer allocateAppBuff() {
  5. int netBufSize = sslEngine.getSession().getPacketBufferSize() + 50;
  6. int appBufSize = Math.max(sslEngine.getSession().getApplicationBufferSize() + 50, netBufSize * 2);
  7. ByteBuffer buf = ByteBuffer.allocate(appBufSize);
  8. buf.order(order);
  9. return buf;
  10. }

代码示例来源:origin: jersey/jersey

  1. void resize() {
  2. int increment = sslEngine.getSession().getPacketBufferSize();
  3. int newSize = buffer.position() + increment;
  4. ByteBuffer newBuffer = ByteBuffer.allocate(newSize);
  5. buffer.flip();
  6. newBuffer.flip();
  7. buffer = Utils.appendBuffers(newBuffer, buffer, newBuffer.limit(), 50);
  8. buffer.compact();
  9. }

代码示例来源:origin: apache/nifi

  1. case BUFFER_OVERFLOW:
  2. final ByteBuffer tempBuffer = ByteBuffer.allocate(encrypted.position() + sslEngine.getSession().getApplicationBufferSize());
  3. destinationBuffer.flip();
  4. tempBuffer.put(destinationBuffer);

代码示例来源:origin: igniterealtime/Openfire

  1. public TLSWrapper(ConnectionConfiguration configuration, boolean clientMode ) {
  2. try
  3. {
  4. final EncryptionArtifactFactory factory = new EncryptionArtifactFactory( configuration );
  5. if ( clientMode )
  6. {
  7. tlsEngine = factory.createClientModeSSLEngine();
  8. }
  9. else
  10. {
  11. tlsEngine = factory .createServerModeSSLEngine();
  12. }
  13. final SSLSession sslSession = tlsEngine.getSession();
  14. netBuffSize = sslSession.getPacketBufferSize();
  15. appBuffSize = sslSession.getApplicationBufferSize();
  16. }
  17. catch ( NoSuchAlgorithmException | KeyManagementException | KeyStoreException | UnrecoverableKeyException ex )
  18. {
  19. Log.error("TLSHandler startup problem. SSLContext initialisation failed.", ex );
  20. }
  21. }

代码示例来源:origin: apache/kafka

  1. protected int netWriteBufferSize() {
  2. return sslEngine.getSession().getPacketBufferSize();
  3. }

代码示例来源:origin: TooTallNate/Java-WebSocket

  1. /**
  2. * Enlarging a packet buffer (peerAppData or myAppData)
  3. *
  4. * @param buffer the buffer to enlarge
  5. * @return the enlarged buffer
  6. */
  7. private ByteBuffer enlargeApplicationBuffer( ByteBuffer buffer ) {
  8. return enlargeBuffer( buffer, engine.getSession().getApplicationBufferSize() );
  9. }

代码示例来源:origin: apache/geode

  1. NioSslEngine(SSLEngine engine, DMStats stats) {
  2. this.stats = stats;
  3. SSLSession session = engine.getSession();
  4. int appBufferSize = session.getApplicationBufferSize();
  5. int packetBufferSize = engine.getSession().getPacketBufferSize();
  6. this.myNetData = ByteBuffer.allocate(packetBufferSize);
  7. this.peerAppData = ByteBuffer.allocate(appBufferSize);
  8. this.engine = engine;
  9. }

代码示例来源:origin: TooTallNate/Java-WebSocket

  1. public SSLSocketChannel( SocketChannel inputSocketChannel, SSLEngine inputEngine, ExecutorService inputExecutor, SelectionKey key ) throws IOException {
  2. if( inputSocketChannel == null || inputEngine == null || executor == inputExecutor )
  3. throw new IllegalArgumentException( "parameter must not be null" );
  4. this.socketChannel = inputSocketChannel;
  5. this.engine = inputEngine;
  6. this.executor = inputExecutor;
  7. myNetData = ByteBuffer.allocate( engine.getSession().getPacketBufferSize() );
  8. peerNetData = ByteBuffer.allocate( engine.getSession().getPacketBufferSize() );
  9. this.engine.beginHandshake();
  10. if( doHandshake() ) {
  11. if( key != null ) {
  12. key.interestOps( key.interestOps() | SelectionKey.OP_WRITE );
  13. }
  14. } else {
  15. try {
  16. socketChannel.close();
  17. } catch ( IOException e ) {
  18. log.error("Exception during the closing of the channel", e);
  19. }
  20. }
  21. }

代码示例来源:origin: apache/nifi

  1. /**
  2. * Reads the given ByteBuffer of data and returns a new ByteBuffer (which is "flipped" / ready to be read). The newly returned
  3. * ByteBuffer will be written to be written via the {@link #write(ByteBuffer)} method. I.e., it will have already been encrypted, if
  4. * necessary, and any other decorations that need to be applied before sending will already have been applied.
  5. *
  6. * @param plaintext the data to be prepped
  7. * @return a ByteBuffer containing the prepared data
  8. * @throws IOException if a failure occurs while encrypting the data
  9. */
  10. public ByteBuffer prepareForWrite(final ByteBuffer plaintext) throws IOException {
  11. if (sslEngine == null) {
  12. return plaintext;
  13. }
  14. ByteBuffer prepared = ByteBuffer.allocate(Math.min(85, plaintext.capacity() - plaintext.position()));
  15. while (plaintext.hasRemaining()) {
  16. encrypt(plaintext);
  17. final int bytesRemaining = prepared.capacity() - prepared.position();
  18. if (bytesRemaining < destinationBuffer.remaining()) {
  19. final ByteBuffer temp = ByteBuffer.allocate(prepared.capacity() + sslEngine.getSession().getApplicationBufferSize());
  20. prepared.flip();
  21. temp.put(prepared);
  22. prepared = temp;
  23. }
  24. prepared.put(destinationBuffer);
  25. }
  26. prepared.flip();
  27. return prepared;
  28. }

代码示例来源:origin: apache/nifi

  1. public void write(final byte[] data, final int offset, final int len) throws IOException {
  2. logger.debug("{} Writing {} bytes of data", this, len);
  3. if (!connected) {
  4. connect();
  5. }
  6. int iterations = len / MAX_WRITE_SIZE;
  7. if (len % MAX_WRITE_SIZE > 0) {
  8. iterations++;
  9. }
  10. for (int i = 0; i < iterations; i++) {
  11. streamOutManager.clear();
  12. final int itrOffset = offset + i * MAX_WRITE_SIZE;
  13. final int itrLen = Math.min(len - itrOffset, MAX_WRITE_SIZE);
  14. final ByteBuffer byteBuffer = ByteBuffer.wrap(data, itrOffset, itrLen);
  15. final BufferStateManager buffMan = new BufferStateManager(byteBuffer, Direction.READ);
  16. final Status status = encryptAndWriteFully(buffMan);
  17. switch (status) {
  18. case BUFFER_OVERFLOW:
  19. streamOutManager.ensureSize(engine.getSession().getPacketBufferSize());
  20. appDataManager.ensureSize(engine.getSession().getApplicationBufferSize());
  21. continue;
  22. case OK:
  23. continue;
  24. case CLOSED:
  25. throw new IOException("Channel is closed");
  26. case BUFFER_UNDERFLOW:
  27. throw new AssertionError("Got Buffer Underflow but should not have...");
  28. }
  29. }
  30. }

代码示例来源:origin: redisson/redisson

  1. @Override
  2. int calculateWrapBufferCapacity(SslHandler handler, int pendingBytes, int numComponents) {
  3. return handler.engine.getSession().getPacketBufferSize();
  4. }

代码示例来源:origin: apache/nifi

  1. private Status encryptAndWriteFully(final BufferStateManager src) throws IOException {
  2. SSLEngineResult result = null;
  3. final ByteBuffer buff = src.prepareForRead(0);
  4. final ByteBuffer outBuff = streamOutManager.prepareForWrite(engine.getSession().getApplicationBufferSize());
  5. logger.trace("{} Encrypting {} bytes", this, buff.remaining());
  6. while (buff.remaining() > 0) {
  7. result = engine.wrap(buff, outBuff);
  8. if (result.getStatus() == Status.OK) {
  9. final ByteBuffer readableOutBuff = streamOutManager.prepareForRead(0);
  10. writeFully(readableOutBuff);
  11. streamOutManager.clear();
  12. } else {
  13. return result.getStatus();
  14. }
  15. }
  16. return result.getStatus();
  17. }

代码示例来源:origin: rapidoid/rapidoid

  1. public RapidoidTLS(SSLContext sslContext, RapidoidConnection conn) {
  2. this.sslContext = sslContext;
  3. this.conn = conn;
  4. this.engine = createServerEngine();
  5. SSLSession session = engine.getSession();
  6. int appBufferMax = session.getApplicationBufferSize();
  7. int netBufferMax = session.getPacketBufferSize();
  8. appIn = ByteBuffer.allocateDirect(appBufferMax + 64);
  9. netIn = ByteBuffer.allocateDirect(netBufferMax);
  10. netOut = ByteBuffer.allocateDirect(netBufferMax);
  11. }

相关文章