TLS 1.3, incorrect encode of NewSessionTicket for empty extension JDK-8145252-TLS13-branch
authorxuelei
Thu, 17 May 2018 09:00:47 -0700
branchJDK-8145252-TLS13-branch
changeset 56568 7fe8ce3c78b6
parent 56567 45e123c0de3b
child 56569 5d5c590054c1
TLS 1.3, incorrect encode of NewSessionTicket for empty extension
src/java.base/share/classes/sun/security/ssl/NewSessionTicket.java
--- a/src/java.base/share/classes/sun/security/ssl/NewSessionTicket.java	Wed May 16 22:13:16 2018 -0700
+++ b/src/java.base/share/classes/sun/security/ssl/NewSessionTicket.java	Thu May 17 09:00:47 2018 -0700
@@ -106,8 +106,13 @@
 
         @Override
         public int messageLength() {
-            return 8 + ticketNonce.length + 1 + ticket.length
-                + 2 + extensions.length();
+            int extLen = extensions.length();
+            if (extLen == 0) {
+                extLen = 2;     // empty extensions
+            }
+
+            return 8 + ticketNonce.length + 1 +
+                       ticket.length + 2 + extLen;
         }
 
         @Override
@@ -116,7 +121,13 @@
             hos.putInt32(ticketAgeAdd);
             hos.putBytes8(ticketNonce);
             hos.putBytes16(ticket);
-            extensions.send(hos);
+
+            // Is it an empty extensions?
+            if (extensions.length() == 0) {
+                hos.putInt16(0);
+            } else {
+                extensions.send(hos);
+            }
         }
 
         @Override