Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
JinhangZhang committed Oct 3, 2024
1 parent ef573cd commit 7ca7d8e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 24 deletions.
93 changes: 69 additions & 24 deletions test/jdk/javax/net/ssl/SSLSocket/ClientExcOnAlert.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand All @@ -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" +
"IDAMBggqhkiG9w0CCQUAMB0GCWCGSAFlAwQBKgQQ6TSt7X56b5cBa+8RqrGDdASC\n" +
"BNCvTQBv3HX+NF9HoA8ugwD0Cg3bsbtcAC6GrBc99BP6blahV4L6AhbNUNOb3N/9\n" +
"UXjB1OObzBP9gOCDfsvKhbr5r6D5K62lvP8twyW/pMuoks0xm/VSmJyMCtSthX6x\n" +
"BIOhDiLA2G1GclENe5gtQRCk9uc28QhLSIJn42dA90q6Mv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mLUu4vWnPbiqoRYIM1Q9QcEdnirjVnnOCEciAQGG\n" +
"Y11kdb2ENSHRX5NUOTBNMDEwDQYJYIZIAWUDBAIBBQAEIHhui4/QEqwZWT786fWa\n" +
"OWN+ZcmH2eWmED7W4LHvFpLfBBQyF4zTLMhBt0xov+nGx3UZWE/2xgICJxA=";
private static final String KEYSTORE_PEM =
"MIIJrwIBAzCCCWgGCSqGSIb3DQEHAaCCCVkEgglVMIIJUTCCBW0GCSqGSIb3DQEH\n" +
"AaCCBV4EggVaMIIFVjCCBVIGCyqGSIb3DQEMCgECoIIE+zCCBPcwKQYKKoZIhvcN\n" +
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
}
}
Binary file added test/jdk/javax/net/ssl/SSLSocket/keystore.p12
Binary file not shown.

0 comments on commit 7ca7d8e

Please sign in to comment.