0N/A/*
2998N/A * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.security.ssl;
0N/A
0N/Aimport java.io.PrintStream;
0N/Aimport java.security.AccessController;
2998N/Aimport java.util.Locale;
0N/A
0N/Aimport sun.security.action.GetPropertyAction;
0N/A
0N/A/**
0N/A * This class has be shamefully lifted from sun.security.util.Debug
0N/A *
0N/A * @author Gary Ellison
0N/A */
0N/Apublic class Debug {
0N/A
0N/A private String prefix;
0N/A
0N/A private static String args;
0N/A
0N/A static {
0N/A args = java.security.AccessController.doPrivileged(
0N/A new GetPropertyAction("javax.net.debug", ""));
2998N/A args = args.toLowerCase(Locale.ENGLISH);
0N/A if (args.equals("help")) {
0N/A Help();
0N/A }
0N/A }
0N/A
0N/A public static void Help()
0N/A {
0N/A System.err.println();
0N/A System.err.println("all turn on all debugging");
0N/A System.err.println("ssl turn on ssl debugging");
0N/A System.err.println();
0N/A System.err.println("The following can be used with ssl:");
0N/A System.err.println("\trecord enable per-record tracing");
0N/A System.err.println("\thandshake print each handshake message");
0N/A System.err.println("\tkeygen print key generation data");
0N/A System.err.println("\tsession print session activity");
0N/A System.err.println("\tdefaultctx print default SSL initialization");
0N/A System.err.println("\tsslctx print SSLContext tracing");
0N/A System.err.println("\tsessioncache print session cache tracing");
0N/A System.err.println("\tkeymanager print key manager tracing");
0N/A System.err.println("\ttrustmanager print trust manager tracing");
0N/A System.err.println("\tpluggability print pluggability tracing");
0N/A System.err.println();
0N/A System.err.println("\thandshake debugging can be widened with:");
0N/A System.err.println("\tdata hex dump of each handshake message");
0N/A System.err.println("\tverbose verbose handshake message printing");
0N/A System.err.println();
0N/A System.err.println("\trecord debugging can be widened with:");
0N/A System.err.println("\tplaintext hex dump of record plaintext");
0N/A System.err.println("\tpacket print raw SSL/TLS packets");
0N/A System.err.println();
0N/A System.exit(0);
0N/A }
0N/A
0N/A /**
0N/A * Get a Debug object corresponding to whether or not the given
0N/A * option is set. Set the prefix to be the same as option.
0N/A */
0N/A
0N/A public static Debug getInstance(String option)
0N/A {
0N/A return getInstance(option, option);
0N/A }
0N/A
0N/A /**
0N/A * Get a Debug object corresponding to whether or not the given
0N/A * option is set. Set the prefix to be prefix.
0N/A */
0N/A public static Debug getInstance(String option, String prefix)
0N/A {
0N/A if (isOn(option)) {
0N/A Debug d = new Debug();
0N/A d.prefix = prefix;
0N/A return d;
0N/A } else {
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * True if the property "javax.net.debug" contains the
0N/A * string "option".
0N/A */
0N/A public static boolean isOn(String option)
0N/A {
0N/A if (args == null) {
0N/A return false;
0N/A } else {
0N/A int n = 0;
2998N/A option = option.toLowerCase(Locale.ENGLISH);
0N/A
0N/A if (args.indexOf("all") != -1) {
0N/A return true;
0N/A } else if ((n = args.indexOf("ssl")) != -1) {
0N/A if (args.indexOf("sslctx", n) == -1) {
0N/A // don't enable data and plaintext options by default
0N/A if (!(option.equals("data")
0N/A || option.equals("packet")
0N/A || option.equals("plaintext"))) {
0N/A return true;
0N/A }
0N/A }
0N/A }
0N/A return (args.indexOf(option) != -1);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * print a message to stderr that is prefixed with the prefix
0N/A * created from the call to getInstance.
0N/A */
0N/A
0N/A public void println(String message)
0N/A {
0N/A System.err.println(prefix + ": "+message);
0N/A }
0N/A
0N/A /**
0N/A * print a blank line to stderr that is prefixed with the prefix.
0N/A */
0N/A
0N/A public void println()
0N/A {
0N/A System.err.println(prefix + ":");
0N/A }
0N/A
0N/A /**
0N/A * print a message to stderr that is prefixed with the prefix.
0N/A */
0N/A
0N/A public static void println(String prefix, String message)
0N/A {
0N/A System.err.println(prefix + ": "+message);
0N/A }
0N/A
1870N/A public static void println(PrintStream s, String name, byte[] data) {
0N/A s.print(name + ": { ");
0N/A if (data == null) {
0N/A s.print("null");
0N/A } else {
0N/A for (int i = 0; i < data.length; i++) {
0N/A if (i != 0) s.print(", ");
0N/A s.print(data[i] & 0x0ff);
0N/A }
0N/A }
0N/A s.println(" }");
0N/A }
0N/A
0N/A /**
0N/A * Return the value of the boolean System property propName.
0N/A *
0N/A * Note use of doPrivileged(). Do make accessible to applications.
0N/A */
0N/A static boolean getBooleanProperty(String propName, boolean defaultValue) {
0N/A // if set, require value of either true or false
0N/A String b = AccessController.doPrivileged(
0N/A new GetPropertyAction(propName));
0N/A if (b == null) {
0N/A return defaultValue;
0N/A } else if (b.equalsIgnoreCase("false")) {
0N/A return false;
0N/A } else if (b.equalsIgnoreCase("true")) {
0N/A return true;
0N/A } else {
0N/A throw new RuntimeException("Value of " + propName
0N/A + " must either be 'true' or 'false'");
0N/A }
0N/A }
0N/A
0N/A static String toString(byte[] b) {
0N/A return sun.security.util.Debug.toString(b);
0N/A }
0N/A}