8207846: Generalize the jdk.net.includeInExceptions security property
authorchegar
Wed, 25 Jul 2018 10:08:39 +0100
changeset 51236 a90d8198d7e4
parent 51235 049b2037b5d8
child 51237 ea900a7dc7d7
8207846: Generalize the jdk.net.includeInExceptions security property Reviewed-by: alanb, michaelm, rriggs, mullan
src/java.base/share/classes/sun/net/util/SocketExceptions.java
src/java.base/share/conf/security/java.security
test/jdk/java/net/Socket/ExceptionText.java
--- a/src/java.base/share/classes/sun/net/util/SocketExceptions.java	Tue Jul 24 12:12:16 2018 -0700
+++ b/src/java.base/share/classes/sun/net/util/SocketExceptions.java	Wed Jul 25 10:08:39 2018 +0100
@@ -44,7 +44,7 @@
      * The property value is a comma separated list of
      * case insignificant category names.
      */
-    private static final String enhancedTextPropname = "jdk.net.includeInExceptions";
+    private static final String enhancedTextPropname = "jdk.includeInExceptions";
 
     private static final boolean enhancedExceptionText = initTextProp();
 
--- a/src/java.base/share/conf/security/java.security	Tue Jul 24 12:12:16 2018 -0700
+++ b/src/java.base/share/conf/security/java.security	Wed Jul 25 10:08:39 2018 +0100
@@ -1061,14 +1061,22 @@
   java.base/java.security.KeyRep$Type;java.base/javax.crypto.spec.SecretKeySpec;!*
 
 #
-# Enhanced exception message text
+# Enhanced exception message information
+#
+# By default, exception messages should not include potentially sensitive
+# information such as file names, host names, or port numbers. This property
+# accepts one or more comma separated values, each of which represents a
+# category of enhanced exception message information to enable. Values are
+# case-insensitive. Leading and trailing whitespaces, surrounding each value,
+# are ignored. Unknown values are ignored.
 #
-# By default, socket exception messages do not include potentially sensitive
-# information such as hostnames or port numbers. This property may be set to one
-# or more values, separated by commas, and with no white-space. Each value
-# represents a category of enhanced information. Currently, the only category defined
-# is "hostInfo" which enables more detailed information in the IOExceptions
-# thrown by java.net.Socket and also the socket types in the java.nio.channels package.
-# The setting in this file can be overridden by a system property of the same name
-# and with the same syntax and possible values.
-#jdk.net.includeInExceptions=hostInfo
+# The categories are:
+#
+#  hostInfo - IOExceptions thrown by java.net.Socket and the socket types in the
+#             java.nio.channels package will contain enhanced exception
+#             message information
+#
+# The property setting in this file can be overridden by a system property of
+# the same name, with the same syntax and possible values.
+#
+#jdk.includeInExceptions=hostInfo
--- a/test/jdk/java/net/Socket/ExceptionText.java	Tue Jul 24 12:12:16 2018 -0700
+++ b/test/jdk/java/net/Socket/ExceptionText.java	Wed Jul 25 10:08:39 2018 +0100
@@ -25,18 +25,43 @@
  * @test
  * @library /test/lib
  * @build jdk.test.lib.Utils
- * @bug 8204233
+ * @bug 8204233 8207846
  * @summary Add configurable option for enhanced socket IOException messages
- * @run main/othervm ExceptionText
- * @run main/othervm -Djdk.net.includeInExceptions= ExceptionText
- * @run main/othervm -Djdk.net.includeInExceptions=hostInfo ExceptionText
- * @run main/othervm -Djdk.net.includeInExceptions=somethingElse ExceptionText
+ * @run main/othervm
+ *       ExceptionText
+ *       WITHOUT_Enhanced_Text
+ * @run main/othervm
+ *       -Djdk.includeInExceptions=
+ *       ExceptionText
+ *       WITHOUT_Enhanced_Text
+ * @run main/othervm
+ *       -Djdk.includeInExceptions=somethingElse
+ *       ExceptionText
+ *       WITHOUT_Enhanced_Text
+ * @run main/othervm
+ *       -Djdk.includeInExceptions=blah,blah,blah,
+ *       ExceptionText
+ *       WITHOUT_Enhanced_Text
+ * @run main/othervm
+ *       -Djdk.includeInExceptions=hostInfo
+ *       ExceptionText
+ *       expectEnhancedText
+ * @run main/othervm
+ *       -Djdk.includeInExceptions=foo,hostinfo,bar
+ *       ExceptionText
+ *       expectEnhancedText
+ * @run main/othervm
+ *       -Djdk.includeInExceptions=",HOSTINFO,"
+ *       ExceptionText
+ *       expectEnhancedText
  */
 
-import java.net.*;
 import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.nio.channels.AsynchronousSocketChannel;
 import java.nio.channels.ClosedChannelException;
-import java.nio.channels.*;
+import java.nio.channels.SocketChannel;
 import java.util.concurrent.ExecutionException;
 import jdk.test.lib.Utils;
 
@@ -44,16 +69,15 @@
 
     enum TestTarget {SOCKET, CHANNEL, ASYNC_CHANNEL};
 
-    static boolean propEnabled() {
-        String val = System.getProperty("jdk.net.includeInExceptions");
-        if ("hostinfo".equalsIgnoreCase(val))
-            return true;
-        return false;
-    }
-
     public static void main(String args[]) throws Exception {
-        boolean prop = propEnabled();
-        test(prop);
+        String passOrFail = args[0];
+        boolean expectEnhancedText;
+        if (passOrFail.equals("expectEnhancedText")) {
+            expectEnhancedText = true;
+        } else {
+            expectEnhancedText = false;
+        }
+        test(expectEnhancedText);
     }
 
     static final InetSocketAddress dest  = Utils.refusingEndpoint();