Skip to content

Commit

Permalink
u
Browse files Browse the repository at this point in the history
  • Loading branch information
JinhangZhang committed Jul 31, 2024
1 parent 8d80cd4 commit 3aff26a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 23 deletions.
13 changes: 11 additions & 2 deletions test/jdk/javax/net/ssl/SSLSession/JSSERenegotiate.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.net.*;
import java.security.Security;
import javax.net.ssl.*;
import java.security.KeyStore;

import jdk.test.lib.Utils;
import jdk.test.lib.security.SecurityUtils;
Expand Down Expand Up @@ -209,10 +210,15 @@ public static void main(String[] args) throws Exception {
"/" + trustStoreFile;

if ((Utils.isFIPS() && Utils.getFipsProfile().equals("OpenJCEPlusFIPS.FIPS140-3-Test-TLS"))) {
keyFilename = Utils.revertJKSToPKCS12(keyFilename, passwd);
trustFilename = Utils.revertJKSToPKCS12(trustFilename, passwd);
// keyFilename = Utils.revertJKSToPKCS12(keyFilename, passwd);
// trustFilename = Utils.revertJKSToPKCS12(trustFilename, passwd);
suite1 = "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256";
suite2 = "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384";
System.setProperty("keystore.type", "JKS");
System.out.println("javax.net.ssl.keyStoreType: " + System.getProperty("javax.net.ssl.keyStoreType"));
System.setProperty("javax.net.ssl.keyStoreType","JKS");
System.out.println("javax.net.ssl.keyStoreType: " + System.getProperty("javax.net.ssl.keyStoreType"));
System.out.println("FIPS - Default KeyStore type: " + keyStoreType);
} else {
suite1 = "SSL_RSA_WITH_NULL_MD5";
suite2 = "SSL_RSA_WITH_NULL_SHA";
Expand All @@ -226,10 +232,13 @@ public static void main(String[] args) throws Exception {
if (debug)
System.setProperty("javax.net.debug", "all");

String keyStoreType = KeyStore.getDefaultType();
System.out.println("Default KeyStore type: " + keyStoreType);
/*
* Start the tests.
*/
new JSSERenegotiate();
System.out.println(1/0);
}

Thread clientThread = null;
Expand Down
5 changes: 1 addition & 4 deletions test/jdk/javax/net/ssl/SSLSession/RenegotiateTLS13.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
8 changes: 4 additions & 4 deletions test/jdk/javax/net/ssl/SSLSession/ResumeTLS13withSNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
32 changes: 25 additions & 7 deletions test/jdk/javax/net/ssl/ServerName/SSLSocketSNISensitive.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ public class SSLSocketSNISensitive {
*/
static boolean debug = false;

static String[] signatureAlgos = new String[5];

/*
* Define the server side of the test.
*
Expand Down Expand Up @@ -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-----", "")
Expand All @@ -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();
}
Expand Down Expand Up @@ -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<signatureAlgos.length; i++) {
if (signatureAlgos[i].contains("MD5")
&& e instanceof javax.net.ssl.SSLHandshakeException
&& "no cipher suites in common".equals(e.getMessage())) {
System.out.println("Expected exception msg: <no cipher suites in common> is caught.");
return;
}
}
}
e.printStackTrace();
return;
}
}

Thread clientThread = null;
Expand Down
2 changes: 1 addition & 1 deletion test/jdk/javax/net/ssl/TLS/TestJSSE.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static void main(String... args) throws Exception {
client(srv.getPort(), clnProtocol, cipher, args);
} catch (Exception e) {
if (isFIPS && customProfile.equals("OpenJCEPlusFIPS.FIPS140-3-Test-TLS")) {
System.out.println("1");
System.out.println("111111111111111");
if ((protocolUsedInHandShake == null
|| !TLS_CIPHERSUITES.containsKey(cipher)
|| !TLS_CIPHERSUITES.get(cipher).equals(protocolUsedInHandShake))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
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) {

Expand All @@ -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"));
Expand All @@ -129,7 +134,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);
}
}
Expand Down

0 comments on commit 3aff26a

Please sign in to comment.