Skip to content

Commit 741b340

Browse files
committed
8243010: Test support: Customizable Hex Printer
Reviewed-by: mbaesken Backport-of: bdf6726
1 parent 518e797 commit 741b340

File tree

16 files changed

+1655
-58
lines changed

16 files changed

+1655
-58
lines changed

test/jdk/com/sun/jndi/ldap/Base64Test.java

-3
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,6 @@ public static void main(String[] args) throws Exception {
163163
*/
164164
private static void deserialize(byte[] bytes) throws Exception {
165165

166-
//System.out.println("\nSerialized RefAddr object: ");
167-
//System.out.println(new sun.security.util.HexDumpEncoder().encode(bytes));
168-
169166
ObjectInputStream objectStream =
170167
new ObjectInputStream(new ByteArrayInputStream(bytes));
171168
Object object = objectStream.readObject();

test/jdk/com/sun/security/sasl/ntlm/NTLMTest.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
2424
/*
2525
* @test
2626
* @bug 6911951 7150092
27+
* @library /test/lib
2728
* @summary NTLM should be a supported Java SASL mechanism
2829
* @modules java.base/sun.security.util
2930
* java.security.sasl
@@ -32,7 +33,7 @@
3233
import javax.security.sasl.*;
3334
import javax.security.auth.callback.*;
3435
import java.util.*;
35-
import sun.security.util.HexDumpEncoder;
36+
import jdk.test.lib.hexdump.HexPrinter;
3637

3738
public class NTLMTest {
3839

@@ -312,20 +313,20 @@ private static void handshake(SaslClient clnt, SaslServer srv)
312313
byte[] response = (clnt.hasInitialResponse()
313314
? clnt.evaluateChallenge(EMPTY) : EMPTY);
314315
System.out.println("Initial:");
315-
new HexDumpEncoder().encodeBuffer(response, System.out);
316+
HexPrinter.simple().format(response);
316317
byte[] challenge;
317318

318319
while (!clnt.isComplete() || !srv.isComplete()) {
319320
challenge = srv.evaluateResponse(response);
320321
response = null;
321322
if (challenge != null) {
322323
System.out.println("Challenge:");
323-
new HexDumpEncoder().encodeBuffer(challenge, System.out);
324+
HexPrinter.simple().format(challenge);
324325
response = clnt.evaluateChallenge(challenge);
325326
}
326327
if (response != null) {
327328
System.out.println("Response:");
328-
new HexDumpEncoder().encodeBuffer(response, System.out);
329+
HexPrinter.simple().format(response);
329330
}
330331
}
331332

test/jdk/javax/net/ssl/DTLS/DTLSOverDatagram.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -43,7 +43,7 @@
4343

4444
import java.util.concurrent.*;
4545

46-
import sun.security.util.HexDumpEncoder;
46+
import jdk.test.lib.hexdump.HexPrinter;
4747

4848
/**
4949
* An example to show the way to use SSLEngine in datagram connections.
@@ -688,12 +688,11 @@ public String call() throws Exception {
688688
}
689689

690690
final static void printHex(String prefix, ByteBuffer bb) {
691-
HexDumpEncoder dump = new HexDumpEncoder();
692691

693692
synchronized (System.out) {
694693
System.out.println(prefix);
695694
try {
696-
dump.encodeBuffer(bb.slice(), System.out);
695+
HexPrinter.simple().format(bb.slice());
697696
} catch (Exception e) {
698697
// ignore
699698
}
@@ -704,13 +703,10 @@ final static void printHex(String prefix, ByteBuffer bb) {
704703
final static void printHex(String prefix,
705704
byte[] bytes, int offset, int length) {
706705

707-
HexDumpEncoder dump = new HexDumpEncoder();
708-
709706
synchronized (System.out) {
710707
System.out.println(prefix);
711708
try {
712-
ByteBuffer bb = ByteBuffer.wrap(bytes, offset, length);
713-
dump.encodeBuffer(bb, System.out);
709+
HexPrinter.simple().format(bytes, offset, length);
714710
} catch (Exception e) {
715711
// ignore
716712
}

test/jdk/javax/net/ssl/interop/ClientHelloBufferUnderflowException.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,13 +30,15 @@
3030
* @test
3131
* @bug 8215790 8219389
3232
* @summary Verify exception
33+
* @library /test/lib
3334
* @modules java.base/sun.security.util
3435
* @run main/othervm ClientHelloBufferUnderflowException
3536
*/
3637

37-
import sun.security.util.HexDumpEncoder;
3838
import javax.net.ssl.SSLHandshakeException;
3939

40+
import jdk.test.lib.hexdump.HexPrinter;
41+
4042
public class ClientHelloBufferUnderflowException extends ClientHelloInterOp {
4143
/*
4244
* Main entry point for this test.
@@ -75,7 +77,7 @@ protected byte[] createClientHelloMessage() {
7577

7678
System.out.println("The ClientHello message used");
7779
try {
78-
(new HexDumpEncoder()).encodeBuffer(bytes, System.out);
80+
HexPrinter.simple().format(bytes);
7981
} catch (Exception e) {
8082
// ignore
8183
}

test/jdk/javax/net/ssl/interop/ClientHelloChromeInterOp.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,13 +30,15 @@
3030
* @test
3131
* @bug 8169362
3232
* @summary Interop automated testing with Chrome
33+
* @library /test/lib
3334
* @modules jdk.crypto.ec
3435
* java.base/sun.security.util
3536
* @run main/othervm ClientHelloChromeInterOp
3637
*/
3738

3839
import java.util.Base64;
39-
import sun.security.util.HexDumpEncoder;
40+
import jdk.test.lib.hexdump.HexPrinter;
41+
4042

4143
public class ClientHelloChromeInterOp extends ClientHelloInterOp {
4244
// The ClientHello message.
@@ -63,10 +65,9 @@ protected byte[] createClientHelloMessage() {
6365

6466
// Dump the hex codes of the ClientHello message so that developers
6567
// can easily check whether the message is captured correct or not.
66-
HexDumpEncoder dump = new HexDumpEncoder();
6768
System.out.println("The ClientHello message used");
6869
try {
69-
dump.encodeBuffer(bytes, System.out);
70+
HexPrinter.simple().format(bytes);
7071
} catch (Exception e) {
7172
// ignore
7273
}

test/jdk/sun/security/krb5/auto/MSOID2.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -32,7 +32,7 @@
3232
*/
3333

3434
import sun.security.jgss.GSSUtil;
35-
import sun.security.util.HexDumpEncoder;
35+
import jdk.test.lib.hexdump.HexPrinter;
3636

3737
// The basic krb5 test skeleton you can copy from
3838
public class MSOID2 {
@@ -72,7 +72,7 @@ public static void main(String[] args) throws Exception {
7272
nt[pos] = (byte)newLen;
7373
}
7474
t = nt;
75-
new HexDumpEncoder().encodeBuffer(t, System.out);
75+
HexPrinter.simple().format(t);
7676
}
7777
if (t != null || !s.x().isEstablished()) t = s.take(t);
7878
if (c.x().isEstablished() && s.x().isEstablished()) break;

test/jdk/sun/security/krb5/etype/KerberosAesSha2.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,6 +23,7 @@
2323
/*
2424
* @test
2525
* @bug 8014628
26+
* @library /test/lib
2627
* @modules java.base/sun.security.util
2728
* java.security.jgss/sun.security.krb5.internal.crypto.dk:+open
2829
* @summary https://tools.ietf.org/html/rfc8009 Test Vectors
@@ -33,7 +34,7 @@
3334
import java.util.Arrays;
3435

3536
import sun.security.krb5.internal.crypto.dk.AesSha2DkCrypto;
36-
import sun.security.util.HexDumpEncoder;
37+
import jdk.test.lib.hexdump.HexPrinter;
3738

3839
public class KerberosAesSha2 {
3940

@@ -204,6 +205,6 @@ private static void check(byte[] b1, byte[] b2) throws Exception {
204205
}
205206

206207
private static void dump(byte[] data) throws Exception {
207-
new HexDumpEncoder().encodeBuffer(data, System.err);
208+
HexPrinter.simple().dest(System.err).format(data);
208209
}
209210
}

test/jdk/sun/security/mscapi/PublicKeyInterop.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import javax.crypto.*;
3636

3737
import jdk.test.lib.SecurityTools;
38-
import sun.security.util.HexDumpEncoder;
38+
import jdk.test.lib.hexdump.HexPrinter;
3939

4040
/*
4141
* Confirm interoperability of RSA public keys between SunMSCAPI and SunJCE
@@ -84,29 +84,29 @@ static void run() throws Exception {
8484
System.out.println();
8585

8686
byte[] plain = new byte[] {0x01, 0x02, 0x03, 0x04, 0x05};
87-
HexDumpEncoder hde = new HexDumpEncoder();
88-
System.out.println("Plaintext:\n" + hde.encode(plain) + "\n");
87+
HexPrinter hp = HexPrinter.simple();
88+
System.out.println("Plaintext:\n" + hp.toString(plain) + "\n");
8989

9090
Cipher rsa = Cipher.getInstance("RSA/ECB/PKCS1Padding");
9191
rsa.init(Cipher.ENCRYPT_MODE, myPuKey);
9292
byte[] encrypted = rsa.doFinal(plain);
9393
System.out.println("Encrypted plaintext using RSA Cipher from " +
9494
rsa.getProvider().getName() + " JCE provider\n");
95-
System.out.println(hde.encode(encrypted) + "\n");
95+
System.out.println(hp.toString(encrypted) + "\n");
9696

9797
Cipher rsa2 = Cipher.getInstance("RSA/ECB/PKCS1Padding", "SunMSCAPI");
9898
rsa2.init(Cipher.ENCRYPT_MODE, myPuKey);
9999
byte[] encrypted2 = rsa2.doFinal(plain);
100100
System.out.println("Encrypted plaintext using RSA Cipher from " +
101101
rsa2.getProvider().getName() + " JCE provider\n");
102-
System.out.println(hde.encode(encrypted2) + "\n");
102+
System.out.println(hp.toString(encrypted2) + "\n");
103103

104104
Cipher rsa3 = Cipher.getInstance("RSA/ECB/PKCS1Padding", "SunMSCAPI");
105105
rsa3.init(Cipher.DECRYPT_MODE, myPrKey);
106106
byte[] decrypted = rsa3.doFinal(encrypted);
107107
System.out.println("Decrypted first ciphertext using RSA Cipher from " +
108108
rsa3.getProvider().getName() + " JCE provider\n");
109-
System.out.println(hde.encode(decrypted) + "\n");
109+
System.out.println(hp.toString(decrypted) + "\n");
110110
if (! Arrays.equals(plain, decrypted)) {
111111
throw new Exception("First decrypted ciphertext does not match " +
112112
"original plaintext");
@@ -115,7 +115,7 @@ static void run() throws Exception {
115115
decrypted = rsa3.doFinal(encrypted2);
116116
System.out.println("Decrypted second ciphertext using RSA Cipher from "
117117
+ rsa3.getProvider().getName() + " JCE provider\n");
118-
System.out.println(hde.encode(decrypted) + "\n");
118+
System.out.println(hp.toString(decrypted) + "\n");
119119
if (! Arrays.equals(plain, decrypted)) {
120120
throw new Exception("Second decrypted ciphertext does not match " +
121121
"original plaintext");

test/jdk/sun/security/pkcs/pkcs7/SignerOrder.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
2525
* @test
2626
* @bug 8048357
2727
* @summary test PKCS7 data signing, encoding and verification
28+
* @library /test/lib
2829
* @modules java.base/sun.security.pkcs
2930
* java.base/sun.security.util
3031
* java.base/sun.security.x509
@@ -40,7 +41,6 @@
4041
import java.security.SignatureException;
4142
import java.security.cert.X509Certificate;
4243
import java.util.Date;
43-
import sun.security.util.HexDumpEncoder;
4444
import sun.security.pkcs.ContentInfo;
4545
import sun.security.pkcs.PKCS7;
4646
import sun.security.pkcs.SignerInfo;
@@ -55,11 +55,10 @@
5555
import sun.security.x509.X509CertImpl;
5656
import sun.security.x509.X509CertInfo;
5757
import sun.security.x509.X509Key;
58+
import jdk.test.lib.hexdump.HexPrinter;
5859

5960
public class SignerOrder {
6061

61-
static final HexDumpEncoder hexDump = new HexDumpEncoder();
62-
6362
//signer infos
6463
static final byte[] data1 = "12345".getBytes();
6564
static final byte[] data2 = "abcde".getBytes();
@@ -120,7 +119,7 @@ static void printSignerInfos(SignerInfo signerInfo) throws IOException {
120119
signerInfo.derEncode(strm);
121120
System.out.println("SignerInfo, length: "
122121
+ strm.toByteArray().length);
123-
System.out.println(hexDump.encode(strm.toByteArray()));
122+
HexPrinter.simple().format(strm.toByteArray());
124123
System.out.println("\n");
125124
strm.reset();
126125
}
@@ -131,7 +130,7 @@ static void printSignerInfos(SignerInfo[] signerInfos) throws IOException {
131130
signerInfos[i].derEncode(strm);
132131
System.out.println("SignerInfo[" + i + "], length: "
133132
+ strm.toByteArray().length);
134-
System.out.println(hexDump.encode(strm.toByteArray()));
133+
HexPrinter.simple().format(strm.toByteArray());
135134
System.out.println("\n");
136135
strm.reset();
137136
}

test/jdk/sun/security/pkcs/pkcs8/PKCS8Test.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* @test
2626
* @bug 8048357
2727
* @summary PKCS8 Standards Conformance Tests
28+
* @library /test/lib
2829
* @requires (os.family != "solaris")
2930
* @modules java.base/sun.security.pkcs
3031
* java.base/sun.security.util
@@ -42,18 +43,16 @@
4243
import java.math.BigInteger;
4344
import java.security.InvalidKeyException;
4445
import java.util.Arrays;
45-
import sun.security.util.HexDumpEncoder;
4646
import sun.security.pkcs.PKCS8Key;
4747
import sun.security.provider.DSAPrivateKey;
4848
import sun.security.util.DerOutputStream;
4949
import sun.security.util.DerValue;
5050
import sun.security.x509.AlgorithmId;
51+
import jdk.test.lib.hexdump.HexPrinter;
5152
import static java.lang.System.out;
5253

5354
public class PKCS8Test {
5455

55-
static final HexDumpEncoder hexDump = new HexDumpEncoder();
56-
5756
static final DerOutputStream derOutput = new DerOutputStream();
5857

5958
static final String FORMAT = "PKCS#8";
@@ -281,6 +280,6 @@ public static void main(String[] args)
281280

282281
static void dumpByteArray(String nm, byte[] bytes) throws IOException {
283282
out.println(nm + " length: " + bytes.length);
284-
hexDump.encodeBuffer(bytes, out);
283+
HexPrinter.simple().dest(out).format(bytes);
285284
}
286285
}

0 commit comments

Comments
 (0)