From eed38e110fa9771a4bc1e8210cb6a2b9669670f2 Mon Sep 17 00:00:00 2001 From: JinhangZhang Date: Mon, 29 Jul 2024 01:08:04 -0400 Subject: [PATCH] u --- .../net/ssl/DTLS/DTLSWontNegotiateV10.java | 17 +++--- .../javax/net/ssl/SSLEngine/LargeBufs.java | 29 +++------ .../net/ssl/SSLSession/JSSERenegotiate.java | 1 - .../net/ssl/SSLSession/RenegotiateTLS13.java | 5 +- .../ssl/SSLSession/ResumeTLS13withSNI.java | 8 +-- .../ssl/ServerName/SSLSocketSNISensitive.java | 32 +++++++--- .../javax/net/ssl/TLS/CipherTestUtils.java | 17 +----- test/jdk/javax/net/ssl/TLS/JSSEClient.java | 3 + test/jdk/javax/net/ssl/TLS/TestJSSE.java | 48 +++++++++------ .../net/ssl/TLSv13/ClientHelloKeyShares.java | 61 ++++++++++++------- .../SystemPropCipherSuitesOrder.java | 27 ++++++-- 11 files changed, 137 insertions(+), 111 deletions(-) diff --git a/test/jdk/javax/net/ssl/DTLS/DTLSWontNegotiateV10.java b/test/jdk/javax/net/ssl/DTLS/DTLSWontNegotiateV10.java index a26669001e4..2b66182244c 100644 --- a/test/jdk/javax/net/ssl/DTLS/DTLSWontNegotiateV10.java +++ b/test/jdk/javax/net/ssl/DTLS/DTLSWontNegotiateV10.java @@ -78,6 +78,13 @@ public static void main(String[] args) throws Exception { break; } catch (SocketTimeoutException exc) { System.out.println("The server timed-out waiting for packets from the client."); + } catch (javax.net.ssl.SSLHandshakeException sslhe) { + if (Utils.isFIPS() && !SecurityUtils.TLS_PROTOCOLS.contains(args[0])) { + if ("No appropriate protocol (protocol is disabled or cipher suites are inappropriate)".equals(sslhe.getMessage())) { + System.out.println("Expected exception msg: is caught"); + return; + } + } } } if (tries == totalAttempts) { @@ -102,15 +109,7 @@ private static void runServer(String protocol) throws Exception { clientProcess = builder.inheritIO().start(); server.run(); System.out.println("Success: DTLSv1.0 connection was not established."); - // } catch (javax.net.ssl.SSLHandshakeException sslhe) { - // if ((Utils.isFIPS() - // && Utils.getFipsProfile().equals("OpenJCEPlusFIPS.FIPS140-3-Test-TLS")) - // && !SecurityUtils.TLS_PROTOCOLS.contains(args[0])) { - // if ("No appropriate protocol (protocol is disabled or cipher suites are inappropriate)".equals(sslhe.getMessage())) { - // System.out.println("Expected exception msg: is caught"); - // return; - // } - // } + } finally { if (clientProcess != null) { clientProcess.destroy(); diff --git a/test/jdk/javax/net/ssl/SSLEngine/LargeBufs.java b/test/jdk/javax/net/ssl/SSLEngine/LargeBufs.java index d72dd47f648..b8d776d5ba0 100644 --- a/test/jdk/javax/net/ssl/SSLEngine/LargeBufs.java +++ b/test/jdk/javax/net/ssl/SSLEngine/LargeBufs.java @@ -111,8 +111,6 @@ private void runTest(String cipher) throws Exception { result1 = ssle1.wrap(appOut1, oneToTwo); result2 = ssle2.wrap(appOut2, twoToOne); - System.out.println("result1.bytesConsumed() is: " + result1.bytesConsumed()); - if ((result1.bytesConsumed() != 0) && (result1.bytesConsumed() != appBufferMax) && (result1.bytesConsumed() != OFFSET)) { @@ -143,8 +141,6 @@ private void runTest(String cipher) throws Exception { result1 = ssle1.unwrap(twoToOne, appIn1); result2 = ssle2.unwrap(oneToTwo, appIn2); - System.out.println("result1.bytesProduced() is: " + result1.bytesProduced()); - if ((result1.bytesProduced() != 0) && (result1.bytesProduced() != appBufferMax) && (result1.bytesProduced() != 2 * OFFSET)) { @@ -188,29 +184,21 @@ private void runTest(String cipher) throws Exception { } public static void main(String args[]) throws Exception { - // reset the security property to make sure that the algorithms - // and keys used in this test are not disabled. - if (!(Utils.isFIPS() && Utils.getFipsProfile().equals("OpenJCEPlusFIPS.FIPS140-3-Test-TLS"))) { - Security.setProperty("jdk.tls.disabledAlgorithms", ""); - } - LargeBufs test; - if (!(Utils.isFIPS() && Utils.getFipsProfile().equals("OpenJCEPlusFIPS.FIPS140-3-Test-TLS"))) { + if (!(Utils.isFIPS())) { + // reset the security property to make sure that the algorithms + // and keys used in this test are not disabled. + Security.setProperty("jdk.tls.disabledAlgorithms", ""); test = new LargeBufs(); test.runTest("SSL_RSA_WITH_RC4_128_MD5"); - } - - if (!(Utils.isFIPS() && Utils.getFipsProfile().equals("OpenJCEPlusFIPS.FIPS140-3-Test-TLS"))) { test = new LargeBufs(); test.runTest("SSL_RSA_WITH_3DES_EDE_CBC_SHA"); - } - - if ((Utils.isFIPS() && Utils.getFipsProfile().equals("OpenJCEPlusFIPS.FIPS140-3-Test-TLS"))) { + } else { test = new LargeBufs(); test.runTest("TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"); test = new LargeBufs(); - test.runTest("TLS_AES_128_GCM_SHA256"); + test.runTest("TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"); } System.out.println("Test Passed."); @@ -264,7 +252,6 @@ private void createBuffers() { // that the ability to concume or produce applicaton data upto // the size. 16384 is the default JSSE implementation maximum // application size that could be consumed and produced. - // appBufferMax = 16384; appBufferMax = 16384; netBufferMax = session.getPacketBufferSize(); @@ -329,5 +316,5 @@ private static void log(String str) { if (debug) { System.out.println(str); } - } -} + } +} \ No newline at end of file diff --git a/test/jdk/javax/net/ssl/SSLSession/JSSERenegotiate.java b/test/jdk/javax/net/ssl/SSLSession/JSSERenegotiate.java index b65c8206edd..4ce0281b82c 100644 --- a/test/jdk/javax/net/ssl/SSLSession/JSSERenegotiate.java +++ b/test/jdk/javax/net/ssl/SSLSession/JSSERenegotiate.java @@ -225,7 +225,6 @@ public static void main(String[] args) throws Exception { if (debug) System.setProperty("javax.net.debug", "all"); - /* * Start the tests. */ diff --git a/test/jdk/javax/net/ssl/SSLSession/RenegotiateTLS13.java b/test/jdk/javax/net/ssl/SSLSession/RenegotiateTLS13.java index aeaea5afb2d..48d8e448524 100644 --- a/test/jdk/javax/net/ssl/SSLSession/RenegotiateTLS13.java +++ b/test/jdk/javax/net/ssl/SSLSession/RenegotiateTLS13.java @@ -63,8 +63,6 @@ public class RenegotiateTLS13 { // Server done flag static boolean done = false; - static String keystoreType = System.getProperty("javax.net.ssl.keyStore"); - // Main server code void doServerSide() throws Exception { @@ -148,7 +146,6 @@ public static void main(String[] args) throws Exception { if ((Utils.isFIPS() && Utils.getFipsProfile().equals("OpenJCEPlusFIPS.FIPS140-3-Test-TLS"))) { keyFilename = Utils.revertJKSToPKCS12(keyFilename, passwd); trustFilename = Utils.revertJKSToPKCS12(trustFilename, passwd); - keystoreType = "PKCS12"; } System.setProperty("javax.net.ssl.keyStore", keyFilename); @@ -290,7 +287,7 @@ SSLContext initContext() throws Exception { System.out.println("Using TLS13"); SSLContext sc = SSLContext.getInstance("TLSv1.3"); KeyStore ks = KeyStore.getInstance( - new File(keystoreType), + new File(System.getProperty("javax.net.ssl.keyStore")), passwd.toCharArray()); KeyManagerFactory kmf = KeyManagerFactory.getInstance( KeyManagerFactory.getDefaultAlgorithm()); diff --git a/test/jdk/javax/net/ssl/SSLSession/ResumeTLS13withSNI.java b/test/jdk/javax/net/ssl/SSLSession/ResumeTLS13withSNI.java index 6bef0440702..8def6c86a17 100644 --- a/test/jdk/javax/net/ssl/SSLSession/ResumeTLS13withSNI.java +++ b/test/jdk/javax/net/ssl/SSLSession/ResumeTLS13withSNI.java @@ -93,10 +93,10 @@ public static void main(String args[]) throws Exception { System.setProperty("javax.net.debug", "ssl:handshake"); } - if ((Utils.isFIPS() && Utils.getFipsProfile().equals("OpenJCEPlusFIPS.FIPS140-3-Test-TLS"))) { - keyFilename = Utils.revertJKSToPKCS12(keyFilename, "passphrase"); - trustFilename = Utils.revertJKSToPKCS12(trustFilename, "passphrase"); - } + // if ((Utils.isFIPS() && Utils.getFipsProfile().equals("OpenJCEPlusFIPS.FIPS140-3-Test-TLS"))) { + // keyFilename = Utils.revertJKSToPKCS12(keyFilename, "passphrase"); + // trustFilename = Utils.revertJKSToPKCS12(trustFilename, "passphrase"); + // } KeyManagerFactory kmf = makeKeyManagerFactory(keyFilename, passphrase); diff --git a/test/jdk/javax/net/ssl/ServerName/SSLSocketSNISensitive.java b/test/jdk/javax/net/ssl/ServerName/SSLSocketSNISensitive.java index 7c0c44de57e..53f78719f9d 100644 --- a/test/jdk/javax/net/ssl/ServerName/SSLSocketSNISensitive.java +++ b/test/jdk/javax/net/ssl/ServerName/SSLSocketSNISensitive.java @@ -254,6 +254,8 @@ public class SSLSocketSNISensitive { */ static boolean debug = false; + static String[] signatureAlgos = new String[5]; + /* * Define the server side of the test. * @@ -366,7 +368,7 @@ private static void parseArguments(String[] args) { clientRequestedHostname = args[1]; } - private static void printCert(String trustedCertStr) { + private static void printCert(String trustedCertStr, int index) { try { // Remove the "BEGIN CERTIFICATE" and "END CERTIFICATE" lines and any whitespace String cleanedCert = trustedCertStr.replace("-----BEGIN CERTIFICATE-----", "") @@ -391,6 +393,7 @@ private static void printCert(String trustedCertStr) { System.out.println("Signature Algorithm: " + cert.getSigAlgName()); System.out.println("Version: " + cert.getVersion()); + signatureAlgos[index] = cert.getSigAlgName(); } catch (Exception e) { e.printStackTrace(); } @@ -486,19 +489,34 @@ public static void main(String[] args) throws Exception { parseArguments(args); System.out.println("Now printing trustedCertStr=================="); - printCert(trustedCertStr); + printCert(trustedCertStr, 0); System.out.println("Now printing targetCertStr_A=================="); - printCert(targetCertStr_A); + printCert(targetCertStr_A, 1); System.out.println("Now printing targetCertStr_B=================="); - printCert(targetCertStr_B); + printCert(targetCertStr_B, 2); System.out.println("Now printing targetCertStr_C=================="); - printCert(targetCertStr_C); + printCert(targetCertStr_C, 3); System.out.println("Now printing targetCertStr_D=================="); - printCert(targetCertStr_D); + printCert(targetCertStr_D, 4); /* * Start the tests. */ - new SSLSocketSNISensitive(); + try { + new SSLSocketSNISensitive(); + } catch (Exception e) { + if (Utils.isFIPS() && Utils.getFipsProfile().equals("OpenJCEPlusFIPS.FIPS140-3-Test-TLS")) { + for (int i=0; i is caught."); + return; + } + } + } + e.printStackTrace(); + return; + } } Thread clientThread = null; diff --git a/test/jdk/javax/net/ssl/TLS/CipherTestUtils.java b/test/jdk/javax/net/ssl/TLS/CipherTestUtils.java index 8fffada9093..826faf50b69 100644 --- a/test/jdk/javax/net/ssl/TLS/CipherTestUtils.java +++ b/test/jdk/javax/net/ssl/TLS/CipherTestUtils.java @@ -74,7 +74,7 @@ public class CipherTestUtils { public static final SecureRandom secureRandom = new SecureRandom(); public static char[] PASSWORD = "passphrase".toCharArray(); private static final List TESTS = new ArrayList<>(3); - private static final List EXCEPTIONS + public static final List EXCEPTIONS = Collections.synchronizedList(new ArrayList<>(1)); private static final String CLIENT_PUBLIC_KEY @@ -316,21 +316,6 @@ private CipherTestUtils() throws Exception { TLS_PROTOCOLS.add("TLSv1.2"); TLS_PROTOCOLS.add("TLSv1.3"); - TLS_CIPHERSUITES.put("TLS_AES_128_GCM_SHA256", "TLSv1.3"); - TLS_CIPHERSUITES.put("TLS_AES_256_GCM_SHA384", "TLSv1.3"); - TLS_CIPHERSUITES.put("TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLSv1.2"); - TLS_CIPHERSUITES.put("TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLSv1.2"); - TLS_CIPHERSUITES.put("TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", "TLSv1.2"); - TLS_CIPHERSUITES.put("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLSv1.2"); - TLS_CIPHERSUITES.put("TLS_DHE_RSA_WITH_AES_256_GCM_SHA384", "TLSv1.2"); - TLS_CIPHERSUITES.put("TLS_DHE_RSA_WITH_AES_128_GCM_SHA256", "TLSv1.2"); - TLS_CIPHERSUITES.put("TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384", "TLSv1.2"); - TLS_CIPHERSUITES.put("TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384", "TLSv1.2"); - TLS_CIPHERSUITES.put("TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", "TLSv1.2"); - TLS_CIPHERSUITES.put("TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "TLSv1.2"); - TLS_CIPHERSUITES.put("TLS_DHE_RSA_WITH_AES_256_CBC_SHA256", "TLSv1.2"); - TLS_CIPHERSUITES.put("TLS_DHE_RSA_WITH_AES_128_CBC_SHA256", "TLSv1.2"); - factory = (SSLSocketFactory) SSLSocketFactory.getDefault(); KeyStore serverKeyStore = createServerKeyStore(SERVER_PUBLIC_KEY, SERVER_PRIVATE_KEY); diff --git a/test/jdk/javax/net/ssl/TLS/JSSEClient.java b/test/jdk/javax/net/ssl/TLS/JSSEClient.java index 00a8ad0671c..be2ea12f8ff 100644 --- a/test/jdk/javax/net/ssl/TLS/JSSEClient.java +++ b/test/jdk/javax/net/ssl/TLS/JSSEClient.java @@ -30,6 +30,7 @@ import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; +import java.util.*; class JSSEClient extends CipherTestUtils.Client { @@ -42,6 +43,8 @@ class JSSEClient extends CipherTestUtils.Client { private final String host; private final String protocol; + private static final Map TLS_CIPHERSUITES = new HashMap<>(); + JSSEClient(CipherTestUtils cipherTest, String host, int port, String protocols, String ciphersuite) throws Exception { super(cipherTest, ciphersuite); diff --git a/test/jdk/javax/net/ssl/TLS/TestJSSE.java b/test/jdk/javax/net/ssl/TLS/TestJSSE.java index 4af7557e206..769e376faf4 100644 --- a/test/jdk/javax/net/ssl/TLS/TestJSSE.java +++ b/test/jdk/javax/net/ssl/TLS/TestJSSE.java @@ -21,6 +21,8 @@ * questions. */ +import java.lang.reflect.Field; + import java.util.List; import java.util.ArrayList; import java.util.Arrays; @@ -35,7 +37,6 @@ public class TestJSSE { private static final String LOCAL_IP = InetAddress.getLoopbackAddress().getHostAddress(); private static boolean isFIPS = Boolean.parseBoolean(System.getProperty("semeru.fips")); - private static String customProfile = System.getProperty("semeru.customprofile"); private static final Map TLS_CIPHERSUITES = new HashMap<>(); private static String checkIfProtocolIsUsedInCommonFIPS(String srvProtocol, String clnProtocol) { @@ -66,7 +67,7 @@ private static String checkIfProtocolIsUsedInCommonFIPS(String srvProtocol, Stri public static void main(String... args) throws Exception { // enable debug output - System.setProperty("javax.net.debug", "ssl,record"); + // System.setProperty("javax.net.debug", "ssl,record"); String srvProtocol = System.getProperty("SERVER_PROTOCOL"); String clnProtocol = System.getProperty("CLIENT_PROTOCOL"); @@ -87,7 +88,7 @@ public static void main(String... args) throws Exception { // reset the security property to make sure that the algorithms // and keys used in this test are not disabled. String protocolUsedInHandShake = null; - if (!(isFIPS && customProfile.equals("OpenJCEPlusFIPS.FIPS140-3-Test-TLS"))) { + if (!(isFIPS)) { Security.setProperty("jdk.tls.disabledAlgorithms", ""); } else { TLS_CIPHERSUITES.put("TLS_AES_128_GCM_SHA256", "TLSv1.3"); @@ -96,34 +97,41 @@ public static void main(String... args) throws Exception { TLS_CIPHERSUITES.put("TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLSv1.2"); TLS_CIPHERSUITES.put("TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", "TLSv1.2"); TLS_CIPHERSUITES.put("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLSv1.2"); - TLS_CIPHERSUITES.put("TLS_DHE_RSA_WITH_AES_256_GCM_SHA384", "TLSv1.2"); - TLS_CIPHERSUITES.put("TLS_DHE_RSA_WITH_AES_128_GCM_SHA256", "TLSv1.2"); TLS_CIPHERSUITES.put("TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384", "TLSv1.2"); TLS_CIPHERSUITES.put("TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384", "TLSv1.2"); TLS_CIPHERSUITES.put("TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", "TLSv1.2"); TLS_CIPHERSUITES.put("TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "TLSv1.2"); - TLS_CIPHERSUITES.put("TLS_DHE_RSA_WITH_AES_256_CBC_SHA256", "TLSv1.2"); - TLS_CIPHERSUITES.put("TLS_DHE_RSA_WITH_AES_128_CBC_SHA256", "TLSv1.2"); protocolUsedInHandShake = checkIfProtocolIsUsedInCommonFIPS(srvProtocol, clnProtocol); } try (CipherTestUtils.Server srv = server(srvProtocol, cipher, args)) { client(srv.getPort(), clnProtocol, cipher, args); } catch (Exception e) { - if (isFIPS && customProfile.equals("OpenJCEPlusFIPS.FIPS140-3-Test-TLS")) { - System.out.println("1"); - if ((protocolUsedInHandShake == null - || !TLS_CIPHERSUITES.containsKey(cipher) - || !TLS_CIPHERSUITES.get(cipher).equals(protocolUsedInHandShake)) - && e instanceof javax.net.ssl.SSLHandshakeException - && "No appropriate protocol (protocol is disabled or cipher suites are inappropriate)".equals(e.getMessage())) { - if (args.length >= 1 && args[0].equals("javax.net.ssl.SSLHandshakeException")) { - System.out.println("Expected exception msg: is caught"); - return; - } else { - System.out.println("Expected exception msg: is caught"); - return; + if (isFIPS) { + if (protocolUsedInHandShake == null || !TLS_CIPHERSUITES.containsKey(cipher) + || (protocolUsedInHandShake != null && !TLS_CIPHERSUITES.get(cipher).equals(protocolUsedInHandShake))) { + for (int i=0; i= 1 && args[0].equals("javax.net.ssl.SSLHandshakeException")) { + System.out.println("Expected exception msg from client: is caught"); + } else { + System.out.println("Expected exception msg from client: is caught"); + } + } + if ((CipherTestUtils.EXCEPTIONS.get(CipherTestUtils.EXCEPTIONS.size()-1) instanceof java.net.SocketException)) { + System.out.println("im here-1"); + if ("Socket closed".equals(CipherTestUtils.EXCEPTIONS.get(CipherTestUtils.EXCEPTIONS.size()-1).getMessage())) { + System.out.println("im here-2"); + System.out.println("Expected exception msg from server: is caught"); + } + } } + System.out.println("================================"); } } } diff --git a/test/jdk/javax/net/ssl/TLSv13/ClientHelloKeyShares.java b/test/jdk/javax/net/ssl/TLSv13/ClientHelloKeyShares.java index 118b6320ca6..ba41360a0c5 100644 --- a/test/jdk/javax/net/ssl/TLSv13/ClientHelloKeyShares.java +++ b/test/jdk/javax/net/ssl/TLSv13/ClientHelloKeyShares.java @@ -69,29 +69,22 @@ public static void main(String args[]) throws Exception { List expectedKeyShares = new ArrayList<>(); Arrays.stream(args).forEach(arg -> expectedKeyShares.add(Integer.valueOf(arg))); - - if (Utils.isFIPS() && Utils.getFipsProfile().equals("OpenJCEPlusFIPS.FIPS140-3-Test-TLS")) { - String namedGroups = System.getProperty("jdk.tls.namedGroups"); + if (Utils.isFIPS()) { expectedKeyShares.clear(); - if (namedGroups == null) { - expectedKeyShares.add(23); - expectedKeyShares.add(256); - } else if (namedGroups.equals("secp384r1,secp521r1,x448,ffdhe2048")){ - expectedKeyShares.add(24); - expectedKeyShares.add(256); - } else if (namedGroups.equals("sect163k1,sect163r1,x25519")){ - System.out.println("System property jdk.tls.namedGroups(sect163k1,sect163r1,x25519) contains no supported named groups"); - return; - } else if (namedGroups.equals("sect163k1,sect163r1,secp256r1")){ - expectedKeyShares.add(23); - } else if (namedGroups.equals("sect163k1,sect163r1,ffdhe2048,ffdhe3072,ffdhe4096")){ - expectedKeyShares.add(256); - } else if (namedGroups.equals("sect163k1,ffdhe2048,x25519,secp256r1")){ - expectedKeyShares.add(256); - expectedKeyShares.add(23); - } else if (namedGroups.equals("secp256r1,secp384r1,ffdhe2048,x25519")){ + Map supportKeyShares = new HashMap<>(); + supportKeyShares.put("secp256r1", 23); + supportKeyShares.put("secp384r1", 24); + supportKeyShares.put("secp521r1", 25); + + if (System.getProperty("jdk.tls.namedGroups") == null) { expectedKeyShares.add(23); - expectedKeyShares.add(256); + } else { + for (String nameGroup: System.getProperty("jdk.tls.namedGroups").split(",")) { + if (supportKeyShares.containsKey(nameGroup)) { + expectedKeyShares.add(supportKeyShares.get(nameGroup)); + break; + } + } } } @@ -104,7 +97,19 @@ public static void main(String args[]) throws Exception { ByteBuffer.allocateDirect(session.getPacketBufferSize()); // Create and check the ClientHello message - SSLEngineResult clientResult = engine.wrap(clientOut, cTOs); + SSLEngineResult clientResult = null; + try { + clientResult = engine.wrap(clientOut, cTOs); + } catch (java.lang.ExceptionInInitializerError eiie) { + Throwable cause = eiie.getCause(); + if (cause instanceof java.lang.IllegalArgumentException) { + if (Utils.isFIPS() + && ("System property jdk.tls.namedGroups(" + System.getProperty("jdk.tls.namedGroups") + ") contains no supported named groups").equals(cause.getMessage())) { + System.out.println("Expected msg is caught."); + return; + } + } + } logResult("client wrap: ", clientResult); if (clientResult.getStatus() != SSLEngineResult.Status.OK) { throw new RuntimeException("Client wrap got status: " + @@ -177,6 +182,7 @@ private static void checkClientHello(ByteBuffer data, int ver_major = Byte.toUnsignedInt(data.get()); int ver_minor = Byte.toUnsignedInt(data.get()); int recLen = Short.toUnsignedInt(data.getShort()); + System.out.println("TLS record header length: " + recLen); // Simple sanity checks if (type != 22) { @@ -191,6 +197,7 @@ private static void checkClientHello(ByteBuffer data, int msgHdr = data.getInt(); int msgType = (msgHdr >> 24) & 0x000000FF; int msgLen = msgHdr & 0x00FFFFFF; + System.out.println("handshake message header length: " + msgLen); // More simple sanity checks if (msgType != 1) { @@ -203,18 +210,21 @@ private static void checkClientHello(ByteBuffer data, // Jump past the session ID (if there is one) int sessLen = Byte.toUnsignedInt(data.get()); if (sessLen != 0) { + System.out.println("session ID is not null, length is: " + sessLen); data.position(data.position() + sessLen); } // Jump past the cipher suites int csLen = Short.toUnsignedInt(data.getShort()); if (csLen != 0) { + System.out.println("cipher suites ID is not null, length is: " + csLen); data.position(data.position() + csLen); } // ...and the compression int compLen = Byte.toUnsignedInt(data.get()); if (compLen != 0) { + System.out.println("compression is not null, length is: " + compLen); data.position(data.position() + compLen); } @@ -224,22 +234,26 @@ private static void checkClientHello(ByteBuffer data, boolean foundSupVer = false; boolean foundKeyShare = false; int extsLen = Short.toUnsignedInt(data.getShort()); + System.out.println("extsLen is: " + extsLen); List supGrpList = new ArrayList<>(); List chKeyShares = new ArrayList<>(); while (data.hasRemaining()) { int extType = Short.toUnsignedInt(data.getShort()); int extLen = Short.toUnsignedInt(data.getShort()); boolean foundTLS13 = false; + System.out.println("extension type is: " + extType); switch (extType) { case HELLO_EXT_SUPP_GROUPS: + System.out.println("This extType is HELLO_EXT_SUPP_GROUPS. extension type is: " + extType); int supGrpLen = Short.toUnsignedInt(data.getShort()); for (int remain = supGrpLen; remain > 0; remain -= 2) { supGrpList.add(Short.toUnsignedInt(data.getShort())); } break; case HELLO_EXT_SUPP_VERS: + System.out.println("This extType is HELLO_EXT_SUPP_VERS. extension type is: " + extType); foundSupVer = true; - int supVerLen = Byte.toUnsignedInt(data.get()); + int supVerLen = Byte.toUnsignedInt(data.get()); // 04 for (int remain = supVerLen; remain > 0; remain -= 2) { foundTLS13 |= (Short.toUnsignedInt(data.getShort()) == TLS_PROT_VER_13); @@ -251,6 +265,7 @@ private static void checkClientHello(ByteBuffer data, } break; case HELLO_EXT_KEY_SHARE: + System.out.println("This extType is HELLO_EXT_KEY_SHARE. extension type is: " + extType); foundKeyShare = true; int ksListLen = Short.toUnsignedInt(data.getShort()); System.out.println("ksListLen before while-loop is: " + ksListLen); diff --git a/test/jdk/javax/net/ssl/sanity/ciphersuites/SystemPropCipherSuitesOrder.java b/test/jdk/javax/net/ssl/sanity/ciphersuites/SystemPropCipherSuitesOrder.java index 24648673938..1b1df796ba1 100644 --- a/test/jdk/javax/net/ssl/sanity/ciphersuites/SystemPropCipherSuitesOrder.java +++ b/test/jdk/javax/net/ssl/sanity/ciphersuites/SystemPropCipherSuitesOrder.java @@ -78,12 +78,12 @@ public class SystemPropCipherSuitesOrder extends SSLSocketTemplate { private final String protocol; - private static String[] servercipherSuites; - private static String[] clientcipherSuites; + private static String[] servercipherSuites = null; + private static String[] clientcipherSuites = null; public static void main(String[] args) { - if (Utils.isFIPS() && Utils.getFipsProfile().equals("OpenJCEPlusFIPS.FIPS140-3-Test-TLS")) { + if (Utils.isFIPS()) { // if (!SecurityUtils.TLS_PROTOCOLS.contains(args[0])) { // System.out.println(args[0] + " is not supported in FIPS 140-3."); // return; @@ -106,8 +106,13 @@ public static void main(String[] args) { } } } - servercipherSuites = tmpServer.toArray(new String[0]); - clientcipherSuites = tmpClient.toArray(new String[0]); + if (tmpClient.size() != 0) { + clientcipherSuites = tmpClient.toArray(new String[0]); + } + if (tmpServer.size() != 0) { + servercipherSuites = tmpServer.toArray(new String[0]); + } + } else { servercipherSuites = toArray(System.getProperty("jdk.tls.server.cipherSuites")); @@ -120,6 +125,16 @@ public static void main(String[] args) { try { new SystemPropCipherSuitesOrder(args[0]).run(); + } catch (javax.net.ssl.SSLHandshakeException sslhe) { + if (Utils.isFIPS()) { + if (!SecurityUtils.TLS_PROTOCOLS.contains(args[0]) + || (servercipherSuites == null && clientcipherSuites == null)) { + if ("No appropriate protocol (protocol is disabled or cipher suites are inappropriate)".equals(sslhe.getMessage())) { + System.out.println("Expected exception msg: is caught."); + return; + } + } + } } catch (Exception e) { throw new RuntimeException(e); } @@ -129,7 +144,7 @@ private SystemPropCipherSuitesOrder(String protocol) { this.protocol = protocol; // Re-enable protocol if disabled. if (protocol.equals("TLSv1") || protocol.equals("TLSv1.1")) { - if (!(Utils.isFIPS() && Utils.getFipsProfile().equals("OpenJCEPlusFIPS"))) { + if (!(Utils.isFIPS() && Utils.getFipsProfile().equals("OpenJCEPlusFIPS.FIPS140-3-Test-TLS"))) { SecurityUtils.removeFromDisabledTlsAlgs(protocol); } }