jdk/src/java.base/share/classes/sun/security/ssl/Debug.java
author ascarpino
Wed, 08 Feb 2017 12:08:28 -0800
changeset 43701 fe8c324ba97c
parent 41820 3d8c88d00c9f
permissions -rw-r--r--
8160655: Fix denyAfter and usage types for security properties Reviewed-by: mullan, xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
41820
3d8c88d00c9f 8167680: DTLS implementation bugs
xuelei
parents: 37781
diff changeset
     2
 * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4236
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4236
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4236
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4236
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4236
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.ssl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.PrintStream;
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    29
import java.util.Locale;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
34687
d302ed125dc9 8144995: Move sun.misc.HexDumpEncoder to sun.security.util
chegar
parents: 30904
diff changeset
    31
import sun.security.util.HexDumpEncoder;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    32
import java.nio.ByteBuffer;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    33
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * This class has be shamefully lifted from sun.security.util.Debug
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @author Gary Ellison
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class Debug {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private String prefix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static String args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    static {
37781
71ed5645f17c 8155775: Re-examine naming of privileged methods to access System properties
redestad
parents: 37593
diff changeset
    48
        args = GetPropertyAction.privilegedGetProperty("javax.net.debug", "");
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    49
        args = args.toLowerCase(Locale.ENGLISH);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        if (args.equals("help")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            Help();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public static void Help()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        System.err.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        System.err.println("all            turn on all debugging");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        System.err.println("ssl            turn on ssl debugging");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        System.err.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        System.err.println("The following can be used with ssl:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        System.err.println("\trecord       enable per-record tracing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        System.err.println("\thandshake    print each handshake message");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        System.err.println("\tkeygen       print key generation data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        System.err.println("\tsession      print session activity");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        System.err.println("\tdefaultctx   print default SSL initialization");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        System.err.println("\tsslctx       print SSLContext tracing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        System.err.println("\tsessioncache print session cache tracing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        System.err.println("\tkeymanager   print key manager tracing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        System.err.println("\ttrustmanager print trust manager tracing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        System.err.println("\tpluggability print pluggability tracing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        System.err.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        System.err.println("\thandshake debugging can be widened with:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        System.err.println("\tdata         hex dump of each handshake message");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        System.err.println("\tverbose      verbose handshake message printing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        System.err.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        System.err.println("\trecord debugging can be widened with:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        System.err.println("\tplaintext    hex dump of record plaintext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        System.err.println("\tpacket       print raw SSL/TLS packets");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        System.err.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        System.exit(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Get a Debug object corresponding to whether or not the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * option is set. Set the prefix to be the same as option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static Debug getInstance(String option)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        return getInstance(option, option);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Get a Debug object corresponding to whether or not the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * option is set. Set the prefix to be prefix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public static Debug getInstance(String option, String prefix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        if (isOn(option)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            Debug d = new Debug();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            d.prefix = prefix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * True if the property "javax.net.debug" contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * string "option".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public static boolean isOn(String option)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (args == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            int n = 0;
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
   119
            option = option.toLowerCase(Locale.ENGLISH);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            if (args.indexOf("all") != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            } else if ((n = args.indexOf("ssl")) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                if (args.indexOf("sslctx", n) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    // don't enable data and plaintext options by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    if (!(option.equals("data")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                        || option.equals("packet")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                        || option.equals("plaintext"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            return (args.indexOf(option) != -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * print a message to stderr that is prefixed with the prefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * created from the call to getInstance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public void println(String message)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        System.err.println(prefix + ": "+message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
41820
3d8c88d00c9f 8167680: DTLS implementation bugs
xuelei
parents: 37781
diff changeset
   148
     * Print a message to stdout.
3d8c88d00c9f 8167680: DTLS implementation bugs
xuelei
parents: 37781
diff changeset
   149
     */
3d8c88d00c9f 8167680: DTLS implementation bugs
xuelei
parents: 37781
diff changeset
   150
    static void log(String message) {
3d8c88d00c9f 8167680: DTLS implementation bugs
xuelei
parents: 37781
diff changeset
   151
        System.out.println(Thread.currentThread().getName() + ": " + message);
3d8c88d00c9f 8167680: DTLS implementation bugs
xuelei
parents: 37781
diff changeset
   152
    }
3d8c88d00c9f 8167680: DTLS implementation bugs
xuelei
parents: 37781
diff changeset
   153
3d8c88d00c9f 8167680: DTLS implementation bugs
xuelei
parents: 37781
diff changeset
   154
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * print a blank line to stderr that is prefixed with the prefix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public void println()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        System.err.println(prefix + ":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * print a message to stderr that is prefixed with the prefix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public static void println(String prefix, String message)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        System.err.println(prefix + ": "+message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
4236
02f52c723b79 6894643: Separate out dependency on Kerberos
vinnie
parents: 2
diff changeset
   171
    public static void println(PrintStream s, String name, byte[] data) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        s.print(name + ":  { ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if (data == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            s.print("null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            for (int i = 0; i < data.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                if (i != 0) s.print(", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                s.print(data[i] & 0x0ff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        s.println(" }");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Return the value of the boolean System property propName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
37781
71ed5645f17c 8155775: Re-examine naming of privileged methods to access System properties
redestad
parents: 37593
diff changeset
   187
     * Note use of privileged action. Do NOT make accessible to applications.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    static boolean getBooleanProperty(String propName, boolean defaultValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        // if set, require value of either true or false
37781
71ed5645f17c 8155775: Re-examine naming of privileged methods to access System properties
redestad
parents: 37593
diff changeset
   191
        String b = GetPropertyAction.privilegedGetProperty(propName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (b == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        } else if (b.equalsIgnoreCase("false")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        } else if (b.equalsIgnoreCase("true")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            throw new RuntimeException("Value of " + propName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                + " must either be 'true' or 'false'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    static String toString(byte[] b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return sun.security.util.Debug.toString(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   207
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   208
    static void printHex(String prefix, byte[] bytes) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   209
        HexDumpEncoder dump = new HexDumpEncoder();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   210
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   211
        synchronized (System.out) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   212
            System.out.println(prefix);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   213
            try {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   214
                dump.encodeBuffer(bytes, System.out);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   215
            } catch (Exception e) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   216
                // ignore
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   217
            }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   218
            System.out.flush();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   219
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   220
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   221
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   222
    static void printHex(String prefix, ByteBuffer bb) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   223
        HexDumpEncoder dump = new HexDumpEncoder();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   224
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   225
        synchronized (System.out) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   226
            System.out.println(prefix);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   227
            try {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   228
                dump.encodeBuffer(bb.slice(), System.out);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   229
            } catch (Exception e) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   230
                // ignore
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   231
            }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   232
            System.out.flush();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   233
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   234
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   235
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   236
    static void printHex(String prefix, byte[] bytes, int offset, int length) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   237
        HexDumpEncoder dump = new HexDumpEncoder();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   238
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   239
        synchronized (System.out) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   240
            System.out.println(prefix);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   241
            try {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   242
                ByteBuffer bb = ByteBuffer.wrap(bytes, offset, length);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   243
                dump.encodeBuffer(bb, System.out);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   244
            } catch (Exception e) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   245
                // ignore
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   246
            }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   247
            System.out.flush();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   248
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   249
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
}