src/java.base/share/classes/sun/security/ssl/PreSharedKeyExtension.java
branchJDK-8145252-TLS13-branch
changeset 56703 33a2451070d3
parent 56702 75527e40bdfd
child 56708 25178bb3e8f5
--- a/src/java.base/share/classes/sun/security/ssl/PreSharedKeyExtension.java	Thu Jun 07 21:16:21 2018 -0700
+++ b/src/java.base/share/classes/sun/security/ssl/PreSharedKeyExtension.java	Thu Jun 07 22:04:52 2018 -0700
@@ -53,6 +53,8 @@
             new CHPreSharedKeyAbsence();
     static final HandshakeConsumer chOnTradeConsumer =
             new CHPreSharedKeyUpdate();
+    static final SSLStringize chStringize =
+            new CHPreSharedKeyStringize();
 
     static final HandshakeProducer shNetworkProducer =
             new SHPreSharedKeyProducer();
@@ -60,6 +62,8 @@
             new SHPreSharedKeyConsumer();
     static final HandshakeAbsence shOnLoadAbsence =
             new SHPreSharedKeyAbsence();
+    static final SSLStringize shStringize =
+            new SHPreSharedKeyStringize();
 
     private static final class PskIdentity {
         final byte[] identity;
@@ -234,6 +238,25 @@
     }
 
     private static final
+            class CHPreSharedKeyStringize implements SSLStringize {
+        @Override
+        public String toString(ByteBuffer buffer) {
+            try {
+                // As the HandshakeContext parameter of CHPreSharedKeySpec
+                // constructor is used for fatal alert only, we can use
+                // null HandshakeContext here as we don't care about exception.
+                //
+                // Please take care of this code if the CHPreSharedKeySpec
+                // constructor is updated in the future.
+                return (new CHPreSharedKeySpec(null, buffer)).toString();
+            } catch (Exception ex) {
+                // For debug logging only, so please swallow exceptions.
+                return ex.getMessage();
+            }
+        }
+    }
+
+    private static final
             class SHPreSharedKeySpec implements SSLExtensionSpec {
         final int selectedIdentity;
 
@@ -276,6 +299,25 @@
     }
 
     private static final
+            class SHPreSharedKeyStringize implements SSLStringize {
+        @Override
+        public String toString(ByteBuffer buffer) {
+            try {
+                // As the HandshakeContext parameter of SHPreSharedKeySpec
+                // constructor is used for fatal alert only, we can use
+                // null HandshakeContext here as we don't care about exception.
+                //
+                // Please take care of this code if the SHPreSharedKeySpec
+                // constructor is updated in the future.
+                return (new SHPreSharedKeySpec(null, buffer)).toString();
+            } catch (Exception ex) {
+                // For debug logging only, so please swallow exceptions.
+                return ex.getMessage();
+            }
+        }
+    }
+
+    private static final
             class CHPreSharedKeyConsumer implements ExtensionConsumer {
         // Prevent instantiation of this class.
         private CHPreSharedKeyConsumer() {