From 7ca7d8e7c5ee2e360049fada4a970be0c9ac776a Mon Sep 17 00:00:00 2001 From: JinhangZhang Date: Thu, 3 Oct 2024 00:47:50 -0400 Subject: [PATCH] update --- .../net/ssl/SSLSocket/ClientExcOnAlert.java | 93 +++++++++++++----- test/jdk/javax/net/ssl/SSLSocket/keystore.p12 | Bin 0 -> 2636 bytes 2 files changed, 69 insertions(+), 24 deletions(-) create mode 100644 test/jdk/javax/net/ssl/SSLSocket/keystore.p12 diff --git a/test/jdk/javax/net/ssl/SSLSocket/ClientExcOnAlert.java b/test/jdk/javax/net/ssl/SSLSocket/ClientExcOnAlert.java index 88e9f08edae..7e3647f4d73 100644 --- a/test/jdk/javax/net/ssl/SSLSocket/ClientExcOnAlert.java +++ b/test/jdk/javax/net/ssl/SSLSocket/ClientExcOnAlert.java @@ -31,6 +31,7 @@ * @bug 8242294 * @summary JSSE Client does not throw SSLException when an alert occurs during * handshaking. + * @library /test/lib * @run main/othervm ClientExcOnAlert TLSv1.2 * @run main/othervm ClientExcOnAlert TLSv1.3 */ @@ -58,6 +59,8 @@ import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; +import jdk.test.lib.Utils; + public class ClientExcOnAlert { // This is a PKCS#12 keystore created with the following command: // keytool -genkeypair -alias testcert -keyalg rsa -keysize 2048 @@ -69,7 +72,62 @@ public class ClientExcOnAlert { // file. private static int serverPort = -1; private static final String KEYSTORE_PASS = "password"; - // private static final String KEYSTORE_PEM_FIPS = ; + private static final String KEYSTORE_PEM_FIPS = + "MIIKSAIBAzCCCfIGCSqGSIb3DQEHAaCCCeMEggnfMIIJ2zCCBbIGCSqGSIb3DQEH\n" + + "AaCCBaMEggWfMIIFmzCCBZcGCyqGSIb3DQEMCgECoIIFQDCCBTwwZgYJKoZIhvcN\n" + + "AQUNMFkwOAYJKoZIhvcNAQUMMCsEFP7ZmvMWCdMoEl7dN3tGIJ/H07uaAgInEAIB\n" + + "IDAMBggqhkiG9w0CCQUAMB0GCWCGSAFlAwQBKg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TPex7rbKgMZltNdeppkjBA3hK7CdVv19iBW+T4Lb0K1JB\n" + + "M7ieGPIa0wh/DzI4e50w4bF53GZOTAVqlnlMxgmmuRsriQ/hJLeke42xgwkZtXMr\n" + + "lM3OlC3+nXjiK+JgBMr/3MQC2zQAehnSo1uW9/vpVHXmxMtcGak7efPwoAaeZqZl\n" + + "/+kXiTxXxSzEMlsQVbTWwjB8mLUu4vWnPbiqoRYIM1Q9QcEdnirjVnnOCEciAQGG\n" + + "Y11kdb2ENSHRX5NUOTBNMDEwDQYJYIZIAWUDBAIBBQAEIHhui4/QEqwZWT786fWa\n" + + "OWN+ZcmH2eWmED7W4LHvFpLfBBQyF4zTLMhBt0xov+nGx3UZWE/2xgICJxA="; private static final String KEYSTORE_PEM = "MIIJrwIBAzCCCWgGCSqGSIb3DQEHAaCCCVkEgglVMIIJUTCCBW0GCSqGSIb3DQEH\n" + "AaCCBV4EggVaMIIFVjCCBVIGCyqGSIb3DQEMCgECoIIE+zCCBPcwKQYKKoZIhvcN\n" + @@ -128,7 +186,8 @@ public class ClientExcOnAlert { static final Condition serverReady = lock.newCondition(); public static void main(String[] args) throws Exception { - printPEM(KEYSTORE_PEM); + System.setProperty("javax.net.ssl.trustStore", "keystore.p12"); + System.setProperty("javax.net.ssl.trustStorePassword", KEYSTORE_PASS); Thread serverThread = new Thread(() -> { try { doServerSide(); @@ -153,8 +212,14 @@ static void doServerSide() throws Exception { Thread.currentThread().setName("ServerThread"); SSLContext sslc = SSLContext.getInstance("TLS"); log("doServerSide start"); - KeyManagerFactory kmf = createKeyManagerFactory(KEYSTORE_PEM, - KEYSTORE_PASS); + KeyManagerFactory kmf; + if (!(Utils.isFIPS())) { + kmf = createKeyManagerFactory(KEYSTORE_PEM, + KEYSTORE_PASS); + } else { + kmf = createKeyManagerFactory(KEYSTORE_PEM_FIPS, + KEYSTORE_PASS); + } sslc.init(kmf.getKeyManagers(), null, null); SSLServerSocketFactory ssf = (SSLServerSocketFactory)sslc.getServerSocketFactory(); @@ -249,24 +314,4 @@ private static void log(String msgFmt, Object ... args) { sb.append(String.format(msgFmt, args)); System.out.println(sb.toString()); } - - private static void printPEM(String KEYSTORE_PEM) { - Base64.Decoder b64dec = Base64.getMimeDecoder(); - byte[] pemBytes = b64dec.decode(KEYSTORE_PEM); - - try { - CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); - X509Certificate cert = (X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(pemBytes)); - - System.out.println("Certificate:"); - System.out.println(" Subject: " + cert.getSubjectX500Principal().getName()); - System.out.println(" Issuer: " + cert.getIssuerX500Principal().getName()); - System.out.println(" Serial Number: " + cert.getSerialNumber()); - System.out.println(" Valid from: " + cert.getNotBefore()); - System.out.println(" Valid until: " + cert.getNotAfter()); - System.out.println(" Public Key Algorithm: " + cert.getPublicKey().getAlgorithm()); - } catch (Exception e) { - e.printStackTrace(); - } - } } \ No newline at end of file diff --git a/test/jdk/javax/net/ssl/SSLSocket/keystore.p12 b/test/jdk/javax/net/ssl/SSLSocket/keystore.p12 new file mode 100644 index 0000000000000000000000000000000000000000..1ef00155d70239555531107b6e4c93fea3ff3c48 GIT binary patch literal 2636 zcma)8S5y-U5=}xv2%Sh(5RfJ%m;@wrMFawZpn&wI(o_T~(j5l`#g0w&?{xdQo zrNNxPCo`zrFv@wj?JOoxTPUZS(vSfHNw9-}LP%zMhJRlK!5{#n06ok;0t>$m{-G~oSBj#6@{H<$n(eq{h~pYi!EZ>N*XCL0RaWn`HqH&_E?Bg%Qyc26BV zyp?B0H~?`E7*R53=8tapwT>-i_MbY!FNESg^o7^|dX@W2x}u=*7||})od2OXaR8OM zca!uyj&ZCa97hI+=CPh@nQ+tgyulJkLTIq(|5#SoX1InWI4?P0-q))~QyU+vxfpVy zJ~DlBW*S}NOtSA$np6momNDI`-eUd6e(vtT%Kl3Gp^Y52plf4Qz?vY&im>;h0%Q$i zUpraSt&l9Vid4OHgW@hfVix_7OeaAX_N?W6ATH1F$v9`5i5lzvm&E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