Refine search
@Override SSLEngineResult unwrap(SslHandler handler, ByteBuf in, int readerIndex, int len, ByteBuf out) throws SSLException { int writerIndex = out.writerIndex(); ByteBuffer inNioBuffer = toByteBuffer(in, readerIndex, len); int position = inNioBuffer.position(); final SSLEngineResult result = handler.engine.unwrap(inNioBuffer, toByteBuffer(out, writerIndex, out.writableBytes())); out.writerIndex(writerIndex + result.bytesProduced()); // This is a workaround for a bug in Android 5.0. Android 5.0 does not correctly update the // SSLEngineResult.bytesConsumed() in some cases and just return 0. // // See: // - https://android-review.googlesource.com/c/platform/external/conscrypt/+/122080 // - https://github.com/netty/netty/issues/7758 if (result.bytesConsumed() == 0) { int consumed = inNioBuffer.position() - position; if (consumed != result.bytesConsumed()) { // Create a new SSLEngineResult with the correct bytesConsumed(). return new SSLEngineResult( result.getStatus(), result.getHandshakeStatus(), consumed, result.bytesProduced()); } } return result; }
/** * Convert a {@link SSLEngineResult} into a {@link String}, this is needed * because the supplied method includes a log-breaking newline. */ public static String resultToString(final SSLEngineResult result) { return String.format("status=%s,handshakeStatus=%s,bytesConsumed=%d,bytesConsumed=%d", result.getStatus(), result.getHandshakeStatus(), result.bytesProduced(), result.bytesConsumed()); }
private void log(String str, SSLEngineResult result) { if (!logging) { return; } if (resultOnce) { resultOnce = false; Log.info("The format of the SSLEngineResult is: \n" + "\t\"getStatus() / getHandshakeStatus()\" +\n" + "\t\"bytesConsumed() / bytesProduced()\"\n"); } HandshakeStatus hsStatus = result.getHandshakeStatus(); Log.info(str + result.getStatus() + "/" + hsStatus + ", " + result.bytesConsumed() + "/" + result.bytesProduced() + " bytes"); if (hsStatus == HandshakeStatus.FINISHED) { Log.info("\t...ready for application data"); } }
@Override SSLEngineResult unwrap(SslHandler handler, ByteBuf in, int readerIndex, int len, ByteBuf out) throws SSLException { int writerIndex = out.writerIndex(); ByteBuffer inNioBuffer = toByteBuffer(in, readerIndex, len); int position = inNioBuffer.position(); final SSLEngineResult result = handler.engine.unwrap(inNioBuffer, toByteBuffer(out, writerIndex, out.writableBytes())); out.writerIndex(writerIndex + result.bytesProduced()); // This is a workaround for a bug in Android 5.0. Android 5.0 does not correctly update the // SSLEngineResult.bytesConsumed() in some cases and just return 0. // // See: // - https://android-review.googlesource.com/c/platform/external/conscrypt/+/122080 // - https://github.com/netty/netty/issues/7758 if (result.bytesConsumed() == 0) { int consumed = inNioBuffer.position() - position; if (consumed != result.bytesConsumed()) { // Create a new SSLEngineResult with the correct bytesConsumed(). return new SSLEngineResult( result.getStatus(), result.getHandshakeStatus(), consumed, result.bytesProduced()); } } return result; }
SSLEngineResult result = engine.wrap(in0, out0); in.skipBytes(result.bytesConsumed()); out.writerIndex(out.writerIndex() + result.bytesProduced()); switch (result.getStatus()) { case BUFFER_OVERFLOW: out.ensureWritable(engine.getSession().getPacketBufferSize());
do { res = sslEngine.unwrap(inputBuffer, plain); } while (res.getStatus() == SSLEngineResult.Status.OK && res.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_UNWRAP && res.bytesProduced() == 0); status = res.getStatus(); handshakeStatus = res.getHandshakeStatus();
int limit = byteBuffer.limit(); SSLEngineResult res = delegate.wrap(byteBuffers, i, i1, byteBuffer); if(!ourHelloSent && res.bytesProduced() > 0) { if(delegate.getUseClientMode() && applicationProtocols != null && !applicationProtocols.isEmpty()) { ourHelloSent = true; int old = newData.limit(); newData.limit(newData.position() + byteBuffer.remaining()); res = new SSLEngineResult(res.getStatus(), res.getHandshakeStatus(), res.bytesConsumed(), newData.remaining()); byteBuffer.put(newData); newData.limit(old); bufferedWrapData = newData; } else { res = new SSLEngineResult(res.getStatus(), res.getHandshakeStatus(), res.bytesConsumed(), newData.remaining()); byteBuffer.put(newData); if(res.bytesProduced() > 0) { ourHelloSent = true;
SSLEngineResult result = engine.wrap(in0, out0); in.skipBytes(result.bytesConsumed()); out.writerIndex(out.writerIndex() + result.bytesProduced()); switch (result.getStatus()) { case BUFFER_OVERFLOW: out.ensureWritable(engine.getSession().getPacketBufferSize());
assert ! Thread.holdsLock(getUnwrapLock()); log.logf(FQCN, Logger.Level.TRACE, null, "Wrap result is %s", result); switch (result.getStatus()) { case BUFFER_UNDERFLOW: { assert result.bytesConsumed() == 0; assert result.bytesProduced() == 0; assert result.bytesProduced() == 0; final ByteBuffer buffer = sendBuffer.getResource(); if (buffer.position() == 0) { if (result.bytesProduced() > 0) { if (! doFlush()) { return false; throw msg.unexpectedWrapResult(result.getStatus());
SSLEngineResult result = sslEngine.unwrap(networkData, applicationInputBuffer); switch (result.getStatus()) { case BUFFER_OVERFLOW: { if (result.bytesProduced() > 0) { applicationInputBuffer.flip(); upstreamFilter.onRead(applicationInputBuffer);
private void debug(String msg, SSLEngineResult result) { if (debugging) { SSLEngineResult.HandshakeStatus handshakeStatus = result.getHandshakeStatus(); debug(U.frmt("%s (status = %s:%s, consumed=%s, produced=%s)", msg, result.getStatus(), handshakeStatus, result.bytesConsumed(), result.bytesProduced())); if (handshakeStatus.equals(SSLEngineResult.HandshakeStatus.FINISHED)) { debug("\n<<< HANDSHAKE FINISHED >>>\n"); } } }
if (result.bytesProduced() > 0 || result.getStatus() == Status.BUFFER_UNDERFLOW || !closing && result.getStatus() == Status.CLOSED || result.getHandshakeStatus() != statusCondition) { boolean wasClosed = result.getStatus() == Status.CLOSED; return new UnwrapResult(result.bytesProduced(), result.getHandshakeStatus(), wasClosed); if (result.getStatus() == Status.BUFFER_OVERFLOW) {
assert Thread.holdsLock(getUnwrapLock()); log.logf(FQCN, Logger.Level.TRACE, null, "Unwrap result is %s", result); switch (result.getStatus()) { case BUFFER_OVERFLOW: { assert result.bytesConsumed() == 0; assert result.bytesProduced() == 0; assert result.bytesProduced() == 0; throw msg.unexpectedUnwrapResult(result.getStatus());
final Status status = result.getStatus(); final HandshakeStatus handshakeStatus = result.getHandshakeStatus(); final int produced = result.bytesProduced(); final int consumed = result.bytesConsumed();
final Status status = result.getStatus(); final HandshakeStatus handshakeStatus = result.getHandshakeStatus(); final int produced = result.bytesProduced(); final int consumed = result.bytesConsumed();
if (result.bytesProduced() > 0) { outNetBuf.flip(); int remaining = outNetBuf.remaining(); offerEncryptedWriteRequest(encryptedWrite); offered = true; } else if (result.getStatus() == Status.CLOSED) { case FINISHED: setHandshakeSuccess(channel); if (result.getStatus() == Status.CLOSED) { success = false; case NOT_HANDSHAKING: setHandshakeSuccessIfStillHandshaking(channel); if (result.getStatus() == Status.CLOSED) { success = false;
switch (result.getStatus()) { case CLOSED: if (result.getStatus() == Status.BUFFER_UNDERFLOW || result.bytesConsumed() == 0 && result.bytesProduced() == 0) { if (nioInNetBuf.hasRemaining() && !engine.isInboundDone()) { + " status=" + result.getStatus() + " handshakeStatus=" + result.getHandshakeStatus() + " consumed=" + result.bytesConsumed() + " produced=" + result.bytesProduced() + " remaining=" + nioInNetBuf.remaining() + " data=" + ChannelBuffers.hexDump(ChannelBuffers.wrappedBuffer(nioInNetBuf)));
if (userBuffers != null) { result = engine.unwrap(this.dataToUnwrap.getBuffer(), userBuffers, off, len); if (result.getStatus() == SSLEngineResult.Status.BUFFER_OVERFLOW) { unwrapBufferUsed = true; bytesProduced = result.bytesProduced() > 0; } else { unwrapBufferUsed = true; bytesProduced = result.bytesProduced() > 0; && result.getStatus() != SSLEngineResult.Status.BUFFER_UNDERFLOW && dataToUnwrap.getBuffer().remaining() != dataToUnwrapLength) { state |= FLAG_DATA_TO_UNWRAP; if (result.getStatus() == SSLEngineResult.Status.CLOSED) { if(dataToUnwrap != null) { dataToUnwrap.close();
if (TRACE_SSL) msg.tracef("TLS wrap from %s to %s", Buffers.debugString(srcs, srcOff, srcLen), Buffers.debugString(sendBuffer)); result = engine.wrap(srcs, srcOff, srcLen, sendBuffer); WRAP_RESULT: switch (result.getStatus()) { case BUFFER_UNDERFLOW: { assert result.bytesConsumed() == 0; assert result.bytesProduced() == 0; assert result.bytesProduced() == 0; if (TRACE_SSL) msg.trace("TLS wrap operation OVERFLOW"); if (sendBuffer.position() == 0) { if (allAreClear(state, WRITE_FLAG_SHUTDOWN) && result.bytesProduced() == 0) { if (goal == IO_GOAL_FLUSH) { if (TRACE_SSL) msg.tracef("TLS wrap operation OK consumed: %d produced: %d", result.bytesConsumed(), result.bytesProduced()); state &= ~(WRITE_FLAG_NEEDS_READ | READ_FLAG_NEEDS_WRITE); final int consumed = result.bytesConsumed(); result = engine.unwrap(receiveBuffer, realDsts, 0, dstLen + 1); final long userProduced = preRem - Buffers.remaining(dsts, dstOff, dstLen); switch (result.getStatus()) { case BUFFER_OVERFLOW: { assert result.bytesConsumed() == 0; assert result.bytesProduced() == 0; assert userProduced == 0; if (TRACE_SSL) msg.trace("TLS unwrap operation OVERFLOW"); assert result.bytesProduced() == 0; assert userProduced == 0;
@Override SSLEngineResult unwrap(SslHandler handler, ByteBuf in, int readerIndex, int len, ByteBuf out) throws SSLException { int writerIndex = out.writerIndex(); ByteBuffer inNioBuffer = toByteBuffer(in, readerIndex, len); int position = inNioBuffer.position(); final SSLEngineResult result = handler.engine.unwrap(inNioBuffer, toByteBuffer(out, writerIndex, out.writableBytes())); out.writerIndex(writerIndex + result.bytesProduced()); // This is a workaround for a bug in Android 5.0. Android 5.0 does not correctly update the // SSLEngineResult.bytesConsumed() in some cases and just return 0. // // See: // - https://android-review.googlesource.com/c/platform/external/conscrypt/+/122080 // - https://github.com/netty/netty/issues/7758 if (result.bytesConsumed() == 0) { int consumed = inNioBuffer.position() - position; if (consumed != result.bytesConsumed()) { // Create a new SSLEngineResult with the correct bytesConsumed(). return new SSLEngineResult( result.getStatus(), result.getHandshakeStatus(), consumed, result.bytesProduced()); } } return result; }