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

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

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

SSLEngine.unwrap介绍

[英]Decodes the incoming network data buffer into the application data buffer. If a handshake has not been started yet, it will automatically be started.
[中]将传入的网络数据缓冲区解码为应用程序数据缓冲区。如果握手尚未开始,它将自动开始。

代码示例

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

  1. /**
  2. * performs the unwrap operation by unwrapping from {@link #inCrypt} to {@link #inData}
  3. **/
  4. private synchronized ByteBuffer unwrap() throws SSLException {
  5. int rem;
  6. //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)
  7. if(readEngineResult.getStatus() == SSLEngineResult.Status.CLOSED && sslEngine.getHandshakeStatus() == HandshakeStatus.NOT_HANDSHAKING){
  8. try {
  9. close();
  10. } catch (IOException e) {
  11. //Not really interesting
  12. }
  13. }
  14. do {
  15. rem = inData.remaining();
  16. readEngineResult = sslEngine.unwrap( inCrypt, inData );
  17. } while ( readEngineResult.getStatus() == SSLEngineResult.Status.OK && ( rem != inData.remaining() || sslEngine.getHandshakeStatus() == HandshakeStatus.NEED_UNWRAP ) );
  18. inData.flip();
  19. return inData;
  20. }

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

  1. result = sslEngine.unwrap(netReadBuffer, appReadBuffer);
  2. netReadBuffer.compact();
  3. handshakeStatus = result.getHandshakeStatus();
  4. if (result.getStatus() == SSLEngineResult.Status.OK &&
  5. result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
  6. handshakeStatus = runDelegatedTasks();
  7. cont = (result.getStatus() == SSLEngineResult.Status.OK &&
  8. handshakeStatus == HandshakeStatus.NEED_UNWRAP) ||
  9. (ignoreHandshakeStatus && netReadBuffer.position() != position);
  10. log.trace("SSLHandshake handshakeUnwrap: handshakeStatus {} status {}", handshakeStatus, result.getStatus());
  11. } while (netReadBuffer.position() != 0 && cont);

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

  1. case NEED_WRAP:
  2. handshakeResult = sslEngine.wrap(EMPTY_BUF, netBuffer);
  3. switch (handshakeResult.getStatus()) {
  4. case OK: break;
  5. case BUFFER_OVERFLOW:
  6. case CLOSED:
  7. default:
  8. throw new SSLException("Unexpected handshake status: " + handshakeResult.getStatus());
  9. return;
  10. handshakeResult = sslEngine.unwrap(peerEngine.netBuffer, appBuffer);
  11. peerEngine.netBuffer.compact();
  12. handshakeStatus = handshakeResult.getHandshakeStatus();
  13. switch (handshakeResult.getStatus()) {
  14. case OK: break;
  15. case BUFFER_OVERFLOW:

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

  1. final SSLEngineResult result = sslEngine.unwrap(encrypted, destinationBuffer);
  2. switch (result.getStatus()) {
  3. case OK:
  4. destinationBuffer.flip();

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

  1. @Override
  2. public synchronized ByteBuffer unwrap(ByteBuffer wrappedBuffer) throws IOException {
  3. checkClosed();
  4. // note that we do not clear peerAppData as it may hold a partial
  5. // message. TcpConduit, for instance, uses message chunking to
  6. // transmit large payloads and we may have read a partial chunk
  7. // during the previous unwrap
  8. // it's better to be pro-active about avoiding buffer overflows
  9. expandPeerAppData(wrappedBuffer);
  10. peerAppData.limit(peerAppData.capacity());
  11. while (wrappedBuffer.hasRemaining()) {
  12. SSLEngineResult unwrapResult = engine.unwrap(wrappedBuffer, peerAppData);
  13. switch (unwrapResult.getStatus()) {
  14. case BUFFER_OVERFLOW:
  15. expandPeerAppData(wrappedBuffer);
  16. break;
  17. case BUFFER_UNDERFLOW:
  18. // partial data - need to read more. When this happens the SSLEngine will not have
  19. // changed the buffer position
  20. wrappedBuffer.compact();
  21. return peerAppData;
  22. case OK:
  23. break;
  24. default:
  25. throw new SSLException("Error decrypting data: " + unwrapResult);
  26. }
  27. }
  28. wrappedBuffer.clear();
  29. return peerAppData;
  30. }

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

  1. SSLEngineResult result;
  2. try {
  3. result = engine.unwrap( peerNetData, peerAppData );
  4. } catch ( SSLException e ) {
  5. log.error("SSLExcpetion during unwrap", e);
  6. throw e;
  7. switch(result.getStatus()) {
  8. case OK:
  9. peerAppData.flip();
  10. return -1;
  11. default:
  12. throw new IllegalStateException( "Invalid SSL status: " + result.getStatus() );

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

  1. @Override
  2. SSLEngineResult unwrap(SslHandler handler, ByteBuf in, int readerIndex, int len, ByteBuf out)
  3. throws SSLException {
  4. int writerIndex = out.writerIndex();
  5. ByteBuffer inNioBuffer = toByteBuffer(in, readerIndex, len);
  6. int position = inNioBuffer.position();
  7. final SSLEngineResult result = handler.engine.unwrap(inNioBuffer,
  8. toByteBuffer(out, writerIndex, out.writableBytes()));
  9. out.writerIndex(writerIndex + result.bytesProduced());
  10. // This is a workaround for a bug in Android 5.0. Android 5.0 does not correctly update the
  11. // SSLEngineResult.bytesConsumed() in some cases and just return 0.
  12. //
  13. // See:
  14. // - https://android-review.googlesource.com/c/platform/external/conscrypt/+/122080
  15. // - https://github.com/netty/netty/issues/7758
  16. if (result.bytesConsumed() == 0) {
  17. int consumed = inNioBuffer.position() - position;
  18. if (consumed != result.bytesConsumed()) {
  19. // Create a new SSLEngineResult with the correct bytesConsumed().
  20. return new SSLEngineResult(
  21. result.getStatus(), result.getHandshakeStatus(), consumed, result.bytesProduced());
  22. }
  23. }
  24. return result;
  25. }

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

  1. SSLEngineResult unwrapResult = sslEngine.unwrap(netReadBuffer, appReadBuffer);
  2. netReadBuffer.compact();
  3. if (unwrapResult.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING && unwrapResult.getStatus() == Status.OK) {
  4. log.trace("Renegotiation requested, but it is not supported, channelId {}, " +
  5. "appReadBuffer pos {}, netReadBuffer pos {}, netWriteBuffer pos {}", channelId,
  6. if (unwrapResult.getStatus() == Status.OK) {
  7. read += readFromAppBuffer(dst);
  8. } else if (unwrapResult.getStatus() == Status.BUFFER_OVERFLOW) {
  9. int currentApplicationBufferSize = applicationBufferSize();
  10. appReadBuffer = Utils.ensureCapacity(appReadBuffer, currentApplicationBufferSize);

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

  1. /**
  2. * Performs raw unwrap from network read buffer.
  3. *
  4. * @return Result.
  5. * @throws SSLException If SSL exception occurs.
  6. */
  7. private SSLEngineResult unwrap0() throws SSLException {
  8. SSLEngineResult res;
  9. do {
  10. res = sslEngine.unwrap(inNetBuf, appBuf);
  11. if (log.isDebugEnabled())
  12. log.debug("Unwrapped raw data [status=" + res.getStatus() + ", handshakeStatus=" +
  13. res.getHandshakeStatus() + ", ses=" + ses + ']');
  14. if (res.getStatus() == Status.BUFFER_OVERFLOW)
  15. appBuf = expandBuffer(appBuf, appBuf.capacity() * 2);
  16. }
  17. while ((res.getStatus() == Status.OK || res.getStatus() == Status.BUFFER_OVERFLOW) &&
  18. (handshakeFinished && res.getHandshakeStatus() == NOT_HANDSHAKING || res.getHandshakeStatus() == NEED_UNWRAP));
  19. return res;
  20. }

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

  1. /**
  2. * Performs raw unwrap from network read buffer.
  3. *
  4. * @return Result.
  5. * @throws SSLException If SSL exception occurs.
  6. */
  7. private SSLEngineResult unwrap0() throws SSLException {
  8. SSLEngineResult res;
  9. do {
  10. res = sslEngine.unwrap(inNetBuf, appBuf);
  11. if (log.isDebugEnabled())
  12. log.debug("Unwrapped raw data [status=" + res.getStatus() + ", handshakeStatus=" +
  13. res.getHandshakeStatus() + ']');
  14. if (res.getStatus() == Status.BUFFER_OVERFLOW)
  15. appBuf = expandBuffer(appBuf, appBuf.capacity() * 2);
  16. }
  17. while ((res.getStatus() == OK || res.getStatus() == Status.BUFFER_OVERFLOW) &&
  18. (handshakeFinished && res.getHandshakeStatus() == NOT_HANDSHAKING
  19. || res.getHandshakeStatus() == NEED_UNWRAP));
  20. return res;
  21. }

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

  1. SSLEngineResult res;
  2. do {
  3. res = sslEngine.unwrap(inputBuffer, plain);
  4. } while (res.getStatus() == SSLEngineResult.Status.OK && res.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_UNWRAP
  5. && res.bytesProduced() == 0);
  6. status = res.getStatus();
  7. handshakeStatus = res.getHandshakeStatus();

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

  1. engineResult = engine.unwrap(handshakeBuffer, peerAppData);
  2. handshakeBuffer.compact();
  3. status = engineResult.getHandshakeStatus();
  4. if (engineResult.getStatus() == BUFFER_OVERFLOW) {
  5. peerAppData =
  6. expandWriteBuffer(TRACKED_RECEIVER, peerAppData, peerAppData.capacity() * 2,
  7. switch (engineResult.getStatus()) {
  8. case BUFFER_OVERFLOW:
  9. myNetData =
  10. logger.info("handshake terminated with illegal state due to {}", status);
  11. throw new IllegalStateException(
  12. "Unknown SSLEngineResult status: " + engineResult.getStatus());

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

  1. @Override
  2. SSLEngineResult unwrap(SslHandler handler, ByteBuf in, int readerIndex, int len, ByteBuf out)
  3. throws SSLException {
  4. int writerIndex = out.writerIndex();
  5. ByteBuffer inNioBuffer = toByteBuffer(in, readerIndex, len);
  6. int position = inNioBuffer.position();
  7. final SSLEngineResult result = handler.engine.unwrap(inNioBuffer,
  8. toByteBuffer(out, writerIndex, out.writableBytes()));
  9. out.writerIndex(writerIndex + result.bytesProduced());
  10. // This is a workaround for a bug in Android 5.0. Android 5.0 does not correctly update the
  11. // SSLEngineResult.bytesConsumed() in some cases and just return 0.
  12. //
  13. // See:
  14. // - https://android-review.googlesource.com/c/platform/external/conscrypt/+/122080
  15. // - https://github.com/netty/netty/issues/7758
  16. if (result.bytesConsumed() == 0) {
  17. int consumed = inNioBuffer.position() - position;
  18. if (consumed != result.bytesConsumed()) {
  19. // Create a new SSLEngineResult with the correct bytesConsumed().
  20. return new SSLEngineResult(
  21. result.getStatus(), result.getHandshakeStatus(), consumed, result.bytesProduced());
  22. }
  23. }
  24. return result;
  25. }

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

  1. result = engine.unwrap( peerNetData, peerAppData );
  2. peerNetData.compact();
  3. handshakeStatus = result.getHandshakeStatus();
  4. break;
  5. switch(result.getStatus()) {
  6. case OK:
  7. break;
  8. throw new IllegalStateException( "Invalid SSL status: " + result.getStatus() );
  9. break;
  10. switch(result.getStatus()) {
  11. case OK:
  12. myNetData.flip();

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

  1. final ByteBuffer appDataBuffer = appDataManager.prepareForWrite(engine.getSession().getApplicationBufferSize());
  2. try {
  3. SSLEngineResult unwrapResponse = engine.unwrap(streamInBuffer, appDataBuffer);
  4. logger.trace("{} When checking if closed, (handshake={}) Unwrap response: {}", this, handshaking, unwrapResponse);
  5. if (unwrapResponse.getStatus().equals(Status.CLOSED)) {

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

  1. result = tlsEngine.unwrap(incomingNetBB, appBB);
  2. incomingNetBB.compact();
  3. switch (result.getStatus()) {
  4. throw new IOException("Received" + result.getStatus()
  5. + "during initial handshaking");
  6. switch (result.getStatus()) {
  7. case OK:

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

  1. private boolean handleRead(ByteBuffer networkData) {
  2. try {
  3. applicationInputBuffer.clear();
  4. SSLEngineResult result = sslEngine.unwrap(networkData, applicationInputBuffer);
  5. switch (result.getStatus()) {
  6. case BUFFER_OVERFLOW: {

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

  1. if (wrapHelloResult.getStatus() == Status.BUFFER_OVERFLOW) {
  2. streamOutManager.prepareForWrite(engine.getSession().getApplicationBufferSize());
  3. continue;
  4. if (wrapHelloResult.getStatus() != Status.OK) {
  5. throw new SSLHandshakeException("Could not generate SSL Handshake information: SSLEngineResult: "
  6. + wrapHelloResult.toString());
  7. SSLEngineResult handshakeResponseResult = engine.unwrap(readableDataIn, appData);
  8. logger.trace("{} Handshake response after unwrapping: {}", this, handshakeResponseResult);
  9. if (handshakeResponseResult.getStatus() == Status.BUFFER_UNDERFLOW) {
  10. final ByteBuffer writableDataIn = streamInManager.prepareForWrite(engine.getSession().getPacketBufferSize());
  11. final int bytesRead = readData(writableDataIn);

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

  1. SSLEngineResult unwrapResponse = null;
  2. final ByteBuffer appDataBuffer = appDataManager.prepareForWrite(engine.getSession().getApplicationBufferSize());
  3. unwrapResponse = engine.unwrap(streamInBuffer, appDataBuffer);
  4. logger.trace("{} When reading data, (handshake={}) Unwrap response: {}", this, handshaking, unwrapResponse);
  5. switch (unwrapResponse.getStatus()) {
  6. case BUFFER_OVERFLOW:
  7. throw new SSLHandshakeException("Buffer Overflow, which is not allowed to happen from an unwrap");

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

  1. switch (result.getStatus()) {
  2. case BUFFER_OVERFLOW: {
  3. outputBuffer.resize();
  4. SSLEngineResult result = sslEngine.unwrap(networkData, applicationInputBuffer);
  5. switch (result.getStatus()) {
  6. case BUFFER_OVERFLOW: {

相关文章