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.util; 27 28 import java.io.PrintStream; 29 import java.math.BigInteger; 30 import java.util.regex.Pattern; 31 import java.util.regex.Matcher; 32 import java.util.Locale; 33 import sun.security.action.GetPropertyAction; 34 35 /** 36 * A utility class for debugging. 37 * 38 * @author Roland Schemers 39 */ 40 public class Debug { 41 42 private String prefix; 43 44 private static String args; 45 46 static { 47 args = GetPropertyAction.privilegedGetProperty("java.security.debug"); 48 49 String args2 = GetPropertyAction 50 .privilegedGetProperty("java.security.auth.debug"); 51 52 if (args == null) { 53 args = args2; 54 } else { 55 if (args2 != null) 56 args = args + "," + args2; 57 } 58 59 if (args != null) { 60 args = marshal(args); 61 if (args.equals("help")) { 62 Help(); 63 } 64 } 65 } 66 67 public static void Help() 68 { 69 System.err.println(); 70 System.err.println("all turn on all debugging"); 200 201 public void println() 202 { 203 System.err.println(prefix + ":"); 204 } 205 206 /** 207 * print a message to stderr that is prefixed with the prefix. 208 */ 209 210 public static void println(String prefix, String message) 211 { 212 System.err.println(prefix + ": "+message); 213 } 214 215 /** 216 * PrintStream for debug methods. Currently only System.err is supported. 217 */ 218 public PrintStream getPrintStream() { 219 return System.err; 220 } 221 222 /** 223 * return a hexadecimal printed representation of the specified 224 * BigInteger object. the value is formatted to fit on lines of 225 * at least 75 characters, with embedded newlines. Words are 226 * separated for readability, with eight words (32 bytes) per line. 227 */ 228 public static String toHexString(BigInteger b) { 229 String hexValue = b.toString(16); 230 StringBuilder sb = new StringBuilder(hexValue.length()*2); 231 232 if (hexValue.startsWith("-")) { 233 sb.append(" -"); 234 hexValue = hexValue.substring(1); 235 } else { 236 sb.append(" "); // four spaces 237 } 238 if ((hexValue.length()%2) != 0) { 239 // add back the leading 0 | 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.util; 27 28 import java.io.PrintStream; 29 import java.math.BigInteger; 30 import java.util.regex.Pattern; 31 import java.util.regex.Matcher; 32 import java.util.Locale; 33 34 import jdk.internal.event.EventHelper; 35 import jdk.internal.event.SecurityPropertyEvent; 36 import sun.security.action.GetPropertyAction; 37 38 /** 39 * A utility class for debugging. 40 * 41 * @author Roland Schemers 42 */ 43 public class Debug { 44 45 private String prefix; 46 47 private static String args; 48 private static final String DEBUG_PROP_STRING = "java.security.debug"; 49 private static final String AUTH_DEBUG_PROP_STRING = "java.security.auth.debug"; 50 51 static { 52 args = GetPropertyAction.privilegedGetProperty(DEBUG_PROP_STRING); 53 recordPropertyEvent(DEBUG_PROP_STRING, args); 54 55 56 String args2 = GetPropertyAction 57 .privilegedGetProperty(AUTH_DEBUG_PROP_STRING); 58 recordPropertyEvent(AUTH_DEBUG_PROP_STRING, args2); 59 60 if (args == null) { 61 args = args2; 62 } else { 63 if (args2 != null) 64 args = args + "," + args2; 65 } 66 67 if (args != null) { 68 args = marshal(args); 69 if (args.equals("help")) { 70 Help(); 71 } 72 } 73 } 74 75 public static void Help() 76 { 77 System.err.println(); 78 System.err.println("all turn on all debugging"); 208 209 public void println() 210 { 211 System.err.println(prefix + ":"); 212 } 213 214 /** 215 * print a message to stderr that is prefixed with the prefix. 216 */ 217 218 public static void println(String prefix, String message) 219 { 220 System.err.println(prefix + ": "+message); 221 } 222 223 /** 224 * PrintStream for debug methods. Currently only System.err is supported. 225 */ 226 public PrintStream getPrintStream() { 227 return System.err; 228 } 229 230 public static void recordPropertyEvent(String prop, String val) { 231 if (val == null) 232 return; 233 234 SecurityPropertyEvent spe = new SecurityPropertyEvent(); 235 if (spe.isEnabled() || EventHelper.isLoggingSecurity()) { 236 EventHelper.commitSecurityPropertyEvent(spe, prop, val); 237 } 238 } 239 240 /** 241 * return a hexadecimal printed representation of the specified 242 * BigInteger object. the value is formatted to fit on lines of 243 * at least 75 characters, with embedded newlines. Words are 244 * separated for readability, with eight words (32 bytes) per line. 245 */ 246 public static String toHexString(BigInteger b) { 247 String hexValue = b.toString(16); 248 StringBuilder sb = new StringBuilder(hexValue.length()*2); 249 250 if (hexValue.startsWith("-")) { 251 sb.append(" -"); 252 hexValue = hexValue.substring(1); 253 } else { 254 sb.append(" "); // four spaces 255 } 256 if ((hexValue.length()%2) != 0) { 257 // add back the leading 0 |