Skip to content

Commit da01b1d

Browse files
committed
Decryption failed or bad mac record in Android 5.0
Motivation: Android 5.0 (API version 21) has a bug which not correctly set the bytesConsumed of SSLEngineResult when HandshakeStatus is FINISHED. Because of this we need to special handle the status and so workaround the Android bug. Modifications: - Break the unwrap for (;;) loop when HandshakeStatus is FINISHED and bytesConsumed == 0 && bytesProduced == 0. Result: SslHandler works with all known version of Android.
1 parent 9ae155d commit da01b1d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

handler/src/main/java/io/netty/handler/ssl/SslHandler.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,19 @@ private boolean unwrap(
10731073
case FINISHED:
10741074
setHandshakeSuccess();
10751075
wrapLater = true;
1076-
continue;
1076+
1077+
// We 'break' here and NOT 'continue' as android API version 21 has a bug where they consume
1078+
// data from the buffer but NOT correctly set the SSLEngineResult.bytesConsumed().
1079+
// Because of this it will raise an exception on the next iteration of the for loop on android
1080+
// API version 21. Just doing a break will work here as produced and consumed will both be 0
1081+
// and so we break out of the complete for (;;) loop and so call decode(...) again later on.
1082+
// On other platforms this will have no negative effect as we will just continue with the
1083+
// for (;;) loop if something was either consumed or produced.
1084+
//
1085+
// See:
1086+
// - https://github.com/netty/netty/issues/4116
1087+
// - https://code.google.com/p/android/issues/detail?id=198639&thanks=198639&ts=1452501203
1088+
break;
10771089
case NOT_HANDSHAKING:
10781090
if (setHandshakeSuccessIfStillHandshaking()) {
10791091
wrapLater = true;

0 commit comments

Comments
 (0)