Minor nits and cleanup across SSLExtension classes
Summary: Correct spelling errors in comments and variable names, remove dead code.
--- a/src/java.base/share/classes/sun/security/ssl/PreSharedKeyExtension.java Thu Jun 07 21:55:35 2018 -0700
+++ b/src/java.base/share/classes/sun/security/ssl/PreSharedKeyExtension.java Thu Jun 07 21:57:21 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() {
--- a/src/java.base/share/classes/sun/security/ssl/SSLExtension.java Thu Jun 07 21:55:35 2018 -0700
+++ b/src/java.base/share/classes/sun/security/ssl/SSLExtension.java Thu Jun 07 21:57:21 2018 -0700
@@ -449,14 +449,16 @@
PreSharedKeyExtension.chOnLoadConsumer,
PreSharedKeyExtension.chOnLoadAbsence,
PreSharedKeyExtension.chOnTradeConsumer,
- null, null),
+ null,
+ PreSharedKeyExtension.chStringize),
SH_PRE_SHARED_KEY (0x0029, "pre_shared_key",
SSLHandshake.SERVER_HELLO,
ProtocolVersion.PROTOCOLS_OF_13,
PreSharedKeyExtension.shNetworkProducer,
PreSharedKeyExtension.shOnLoadConsumer,
PreSharedKeyExtension.shOnLoadAbsence,
- null, null, null);
+ null, null,
+ PreSharedKeyExtension.shStringize);
final int id;
final SSLHandshake handshakeType;