< prev index next >

src/java.base/share/classes/sun/security/ssl/Debug.java

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.security.ssl;
  27 
  28 import java.io.PrintStream;
  29 import java.security.AccessController;
  30 import java.util.Locale;
  31 
  32 import sun.security.util.HexDumpEncoder;
  33 import java.nio.ByteBuffer;
  34 
  35 import sun.security.action.GetPropertyAction;
  36 
  37 /**
  38  * This class has be shamefully lifted from sun.security.util.Debug
  39  *
  40  * @author Gary Ellison
  41  */
  42 public class Debug {
  43 
  44     private String prefix;
  45 
  46     private static String args;
  47 
  48     static {
  49         args = java.security.AccessController.doPrivileged(
  50             new GetPropertyAction("javax.net.debug", ""));
  51         args = args.toLowerCase(Locale.ENGLISH);
  52         if (args.equals("help")) {
  53             Help();
  54         }
  55     }
  56 
  57     public static void Help()
  58     {
  59         System.err.println();
  60         System.err.println("all            turn on all debugging");
  61         System.err.println("ssl            turn on ssl debugging");
  62         System.err.println();
  63         System.err.println("The following can be used with ssl:");
  64         System.err.println("\trecord       enable per-record tracing");
  65         System.err.println("\thandshake    print each handshake message");
  66         System.err.println("\tkeygen       print key generation data");
  67         System.err.println("\tsession      print session activity");
  68         System.err.println("\tdefaultctx   print default SSL initialization");
  69         System.err.println("\tsslctx       print SSLContext tracing");
  70         System.err.println("\tsessioncache print session cache tracing");


 167     public static void println(PrintStream s, String name, byte[] data) {
 168         s.print(name + ":  { ");
 169         if (data == null) {
 170             s.print("null");
 171         } else {
 172             for (int i = 0; i < data.length; i++) {
 173                 if (i != 0) s.print(", ");
 174                 s.print(data[i] & 0x0ff);
 175             }
 176         }
 177         s.println(" }");
 178     }
 179 
 180     /**
 181      * Return the value of the boolean System property propName.
 182      *
 183      * Note use of doPrivileged(). Do make accessible to applications.
 184      */
 185     static boolean getBooleanProperty(String propName, boolean defaultValue) {
 186         // if set, require value of either true or false
 187         String b = AccessController.doPrivileged(
 188                 new GetPropertyAction(propName));
 189         if (b == null) {
 190             return defaultValue;
 191         } else if (b.equalsIgnoreCase("false")) {
 192             return false;
 193         } else if (b.equalsIgnoreCase("true")) {
 194             return true;
 195         } else {
 196             throw new RuntimeException("Value of " + propName
 197                 + " must either be 'true' or 'false'");
 198         }
 199     }
 200 
 201     static String toString(byte[] b) {
 202         return sun.security.util.Debug.toString(b);
 203     }
 204 
 205     static void printHex(String prefix, byte[] bytes) {
 206         HexDumpEncoder dump = new HexDumpEncoder();
 207 
 208         synchronized (System.out) {




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.security.ssl;
  27 
  28 import java.io.PrintStream;

  29 import java.util.Locale;
  30 
  31 import sun.security.util.HexDumpEncoder;
  32 import java.nio.ByteBuffer;
  33 
  34 import sun.security.action.GetPropertyAction;
  35 
  36 /**
  37  * This class has be shamefully lifted from sun.security.util.Debug
  38  *
  39  * @author Gary Ellison
  40  */
  41 public class Debug {
  42 
  43     private String prefix;
  44 
  45     private static String args;
  46 
  47     static {
  48         args = GetPropertyAction.getProperty("javax.net.debug", "");

  49         args = args.toLowerCase(Locale.ENGLISH);
  50         if (args.equals("help")) {
  51             Help();
  52         }
  53     }
  54 
  55     public static void Help()
  56     {
  57         System.err.println();
  58         System.err.println("all            turn on all debugging");
  59         System.err.println("ssl            turn on ssl debugging");
  60         System.err.println();
  61         System.err.println("The following can be used with ssl:");
  62         System.err.println("\trecord       enable per-record tracing");
  63         System.err.println("\thandshake    print each handshake message");
  64         System.err.println("\tkeygen       print key generation data");
  65         System.err.println("\tsession      print session activity");
  66         System.err.println("\tdefaultctx   print default SSL initialization");
  67         System.err.println("\tsslctx       print SSLContext tracing");
  68         System.err.println("\tsessioncache print session cache tracing");


 165     public static void println(PrintStream s, String name, byte[] data) {
 166         s.print(name + ":  { ");
 167         if (data == null) {
 168             s.print("null");
 169         } else {
 170             for (int i = 0; i < data.length; i++) {
 171                 if (i != 0) s.print(", ");
 172                 s.print(data[i] & 0x0ff);
 173             }
 174         }
 175         s.println(" }");
 176     }
 177 
 178     /**
 179      * Return the value of the boolean System property propName.
 180      *
 181      * Note use of doPrivileged(). Do make accessible to applications.
 182      */
 183     static boolean getBooleanProperty(String propName, boolean defaultValue) {
 184         // if set, require value of either true or false
 185         String b = GetPropertyAction.getProperty(propName);

 186         if (b == null) {
 187             return defaultValue;
 188         } else if (b.equalsIgnoreCase("false")) {
 189             return false;
 190         } else if (b.equalsIgnoreCase("true")) {
 191             return true;
 192         } else {
 193             throw new RuntimeException("Value of " + propName
 194                 + " must either be 'true' or 'false'");
 195         }
 196     }
 197 
 198     static String toString(byte[] b) {
 199         return sun.security.util.Debug.toString(b);
 200     }
 201 
 202     static void printHex(String prefix, byte[] bytes) {
 203         HexDumpEncoder dump = new HexDumpEncoder();
 204 
 205         synchronized (System.out) {


< prev index next >