Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tavianator/96e9daab0fd1a45f11f2 to your computer and use it in GitHub Desktop.
Save tavianator/96e9daab0fd1a45f11f2 to your computer and use it in GitHub Desktop.
Jetty SSL patch for Android bug 93740
From ef19df89a9ee7be2d9c092bcc24cd80a79d35499 Mon Sep 17 00:00:00 2001
From: Tavian Barnes <tavianator@tavianator.com>
Date: Wed, 7 Jan 2015 16:32:51 -0500
Subject: [PATCH 1/1] Don't trust the bytesConsumed() value from
SSLEngine.unwrap().
Android 5.0 always returns 0 instead of the actual number of bytes.
Compute it from the byte buffer positions instead.
https://code.google.com/p/android/issues/detail?id=93740
https://android-review.googlesource.com/#/c/122080/
---
.../src/main/java/org/eclipse/jetty/io/nio/SslConnection.java | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SslConnection.java b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SslConnection.java
index 3d27606..7b6923a 100644
--- a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SslConnection.java
+++ b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SslConnection.java
@@ -520,6 +520,7 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
ByteBuffer bbuf=extractByteBuffer(buffer);
final SSLEngineResult result;
+ final int bytesConsumed;
synchronized(bbuf)
{
@@ -534,15 +535,17 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
in_buffer.limit(_inbound.putIndex());
result=_engine.unwrap(in_buffer,bbuf);
+ // Can't trust result.bytesConsumed() due to https://code.google.com/p/android/issues/detail?id=93740
+ bytesConsumed = in_buffer.position() - _inbound.getIndex();
if (_logger.isDebugEnabled())
_logger.debug("{} unwrap {} {} consumed={} produced={}",
_session,
result.getStatus(),
result.getHandshakeStatus(),
- result.bytesConsumed(),
+ bytesConsumed,
result.bytesProduced());
- _inbound.skip(result.bytesConsumed());
+ _inbound.skip(bytesConsumed);
_inbound.compact();
buffer.setPutIndex(buffer.putIndex()+result.bytesProduced());
}
@@ -592,7 +595,7 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
//if (LOG.isDebugEnabled() && result.bytesProduced()>0)
// LOG.debug("{} unwrapped '{}'",_session,buffer);
- return result.bytesConsumed()>0 || result.bytesProduced()>0;
+ return bytesConsumed>0 || result.bytesProduced()>0;
}
--
2.2.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment