Skip to content
Permalink
Browse files

8243010: Test support: Customizable Hex Printer

Reviewed-by: lancea, dfuchs, weijun
  • Loading branch information
Roger Riggs
Roger Riggs committed Apr 16, 2020
1 parent d2e0d0e commit bdf672659cee13d95abc246de7cde469cf8fc07d
@@ -163,9 +163,6 @@ public static void main(String[] args) throws Exception {
*/
private static void deserialize(byte[] bytes) throws Exception {

//System.out.println("\nSerialized RefAddr object: ");
//System.out.println(new sun.security.util.HexDumpEncoder().encode(bytes));

ObjectInputStream objectStream =
new ObjectInputStream(new ByteArrayInputStream(bytes));
Object object = objectStream.readObject();
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
/*
* @test
* @bug 6911951 7150092
* @library /test/lib
* @summary NTLM should be a supported Java SASL mechanism
* @modules java.base/sun.security.util
* java.security.sasl
@@ -32,7 +33,7 @@
import javax.security.sasl.*;
import javax.security.auth.callback.*;
import java.util.*;
import sun.security.util.HexDumpEncoder;
import jdk.test.lib.hexdump.HexPrinter;

public class NTLMTest {

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

while (!clnt.isComplete() || !srv.isComplete()) {
challenge = srv.evaluateResponse(response);
response = null;
if (challenge != null) {
System.out.println("Challenge:");
new HexDumpEncoder().encodeBuffer(challenge, System.out);
HexPrinter.simple().format(challenge);
response = clnt.evaluateChallenge(challenge);
}
if (response != null) {
System.out.println("Response:");
new HexDumpEncoder().encodeBuffer(response, System.out);
HexPrinter.simple().format(response);
}
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -43,7 +43,7 @@

import java.util.concurrent.*;

import sun.security.util.HexDumpEncoder;
import jdk.test.lib.hexdump.HexPrinter;

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

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

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

HexDumpEncoder dump = new HexDumpEncoder();

synchronized (System.out) {
System.out.println(prefix);
try {
ByteBuffer bb = ByteBuffer.wrap(bytes, offset, length);
dump.encodeBuffer(bb, System.out);
HexPrinter.simple().format(bytes, offset, length);
} catch (Exception e) {
// ignore
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -30,13 +30,15 @@
* @test
* @bug 8215790 8219389
* @summary Verify exception
* @library /test/lib
* @modules java.base/sun.security.util
* @run main/othervm ClientHelloBufferUnderflowException
*/

import sun.security.util.HexDumpEncoder;
import javax.net.ssl.SSLHandshakeException;

import jdk.test.lib.hexdump.HexPrinter;

public class ClientHelloBufferUnderflowException extends ClientHelloInterOp {
/*
* Main entry point for this test.
@@ -75,7 +77,7 @@ public static void main(String args[]) throws Exception {

System.out.println("The ClientHello message used");
try {
(new HexDumpEncoder()).encodeBuffer(bytes, System.out);
HexPrinter.simple().format(bytes);
} catch (Exception e) {
// ignore
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -30,13 +30,15 @@
* @test
* @bug 8169362
* @summary Interop automated testing with Chrome
* @library /test/lib
* @modules jdk.crypto.ec
* java.base/sun.security.util
* @run main/othervm ClientHelloChromeInterOp
*/

import java.util.Base64;
import sun.security.util.HexDumpEncoder;
import jdk.test.lib.hexdump.HexPrinter;


public class ClientHelloChromeInterOp extends ClientHelloInterOp {
// The ClientHello message.
@@ -63,10 +65,9 @@ public static void main(String args[]) throws Exception {

// Dump the hex codes of the ClientHello message so that developers
// can easily check whether the message is captured correct or not.
HexDumpEncoder dump = new HexDumpEncoder();
System.out.println("The ClientHello message used");
try {
dump.encodeBuffer(bytes, System.out);
HexPrinter.simple().format(bytes);
} catch (Exception e) {
// ignore
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -32,7 +32,7 @@
*/

import sun.security.jgss.GSSUtil;
import sun.security.util.HexDumpEncoder;
import jdk.test.lib.hexdump.HexPrinter;

// The basic krb5 test skeleton you can copy from
public class MSOID2 {
@@ -72,7 +72,7 @@ public static void main(String[] args) throws Exception {
nt[pos] = (byte)newLen;
}
t = nt;
new HexDumpEncoder().encodeBuffer(t, System.out);
HexPrinter.simple().format(t);
}
if (t != null || !s.x().isEstablished()) t = s.take(t);
if (c.x().isEstablished() && s.x().isEstablished()) break;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,6 +23,7 @@
/*
* @test
* @bug 8014628
* @library /test/lib
* @modules java.base/sun.security.util
* java.security.jgss/sun.security.krb5.internal.crypto.dk:+open
* @summary https://tools.ietf.org/html/rfc8009 Test Vectors
@@ -33,7 +34,7 @@
import java.util.Arrays;

import sun.security.krb5.internal.crypto.dk.AesSha2DkCrypto;
import sun.security.util.HexDumpEncoder;
import jdk.test.lib.hexdump.HexPrinter;

public class KerberosAesSha2 {

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

private static void dump(byte[] data) throws Exception {
new HexDumpEncoder().encodeBuffer(data, System.err);
HexPrinter.simple().dest(System.err).format(data);
}
}
@@ -35,7 +35,7 @@
import javax.crypto.*;

import jdk.test.lib.SecurityTools;
import sun.security.util.HexDumpEncoder;
import jdk.test.lib.hexdump.HexPrinter;

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

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

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

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

Cipher rsa3 = Cipher.getInstance("RSA/ECB/PKCS1Padding", "SunMSCAPI");
rsa3.init(Cipher.DECRYPT_MODE, myPrKey);
byte[] decrypted = rsa3.doFinal(encrypted);
System.out.println("Decrypted first ciphertext using RSA Cipher from " +
rsa3.getProvider().getName() + " JCE provider\n");
System.out.println(hde.encode(decrypted) + "\n");
System.out.println(hp.toString(decrypted) + "\n");
if (! Arrays.equals(plain, decrypted)) {
throw new Exception("First decrypted ciphertext does not match " +
"original plaintext");
@@ -115,7 +115,7 @@ static void run() throws Exception {
decrypted = rsa3.doFinal(encrypted2);
System.out.println("Decrypted second ciphertext using RSA Cipher from "
+ rsa3.getProvider().getName() + " JCE provider\n");
System.out.println(hde.encode(decrypted) + "\n");
System.out.println(hp.toString(decrypted) + "\n");
if (! Arrays.equals(plain, decrypted)) {
throw new Exception("Second decrypted ciphertext does not match " +
"original plaintext");
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
* @test
* @bug 8048357
* @summary test PKCS7 data signing, encoding and verification
* @library /test/lib
* @modules java.base/sun.security.pkcs
* java.base/sun.security.util
* java.base/sun.security.x509
@@ -40,7 +41,6 @@
import java.security.SignatureException;
import java.security.cert.X509Certificate;
import java.util.Date;
import sun.security.util.HexDumpEncoder;
import sun.security.pkcs.ContentInfo;
import sun.security.pkcs.PKCS7;
import sun.security.pkcs.SignerInfo;
@@ -55,11 +55,10 @@
import sun.security.x509.X509CertImpl;
import sun.security.x509.X509CertInfo;
import sun.security.x509.X509Key;
import jdk.test.lib.hexdump.HexPrinter;

public class SignerOrder {

static final HexDumpEncoder hexDump = new HexDumpEncoder();

//signer infos
static final byte[] data1 = "12345".getBytes();
static final byte[] data2 = "abcde".getBytes();
@@ -120,7 +119,7 @@ static void printSignerInfos(SignerInfo signerInfo) throws IOException {
signerInfo.derEncode(strm);
System.out.println("SignerInfo, length: "
+ strm.toByteArray().length);
System.out.println(hexDump.encode(strm.toByteArray()));
HexPrinter.simple().format(strm.toByteArray());
System.out.println("\n");
strm.reset();
}
@@ -131,7 +130,7 @@ static void printSignerInfos(SignerInfo[] signerInfos) throws IOException {
signerInfos[i].derEncode(strm);
System.out.println("SignerInfo[" + i + "], length: "
+ strm.toByteArray().length);
System.out.println(hexDump.encode(strm.toByteArray()));
HexPrinter.simple().format(strm.toByteArray());
System.out.println("\n");
strm.reset();
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
* @test
* @bug 8048357
* @summary PKCS8 Standards Conformance Tests
* @library /test/lib
* @requires (os.family != "solaris")
* @modules java.base/sun.security.pkcs
* java.base/sun.security.util
@@ -42,18 +43,16 @@
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.util.Arrays;
import sun.security.util.HexDumpEncoder;
import sun.security.pkcs.PKCS8Key;
import sun.security.provider.DSAPrivateKey;
import sun.security.util.DerOutputStream;
import sun.security.util.DerValue;
import sun.security.x509.AlgorithmId;
import jdk.test.lib.hexdump.HexPrinter;
import static java.lang.System.out;

public class PKCS8Test {

static final HexDumpEncoder hexDump = new HexDumpEncoder();

static final DerOutputStream derOutput = new DerOutputStream();

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

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

0 comments on commit bdf6726

Please sign in to comment.
You can’t perform that action at this time.