From 58cc444e69adead98c25a5823860812ac328081d Mon Sep 17 00:00:00 2001 From: Artur Barashev Date: Mon, 31 Mar 2025 09:59:10 -0400 Subject: [PATCH 1/5] 8272875: Change the default key manager to PKIX --- .../share/classes/javax/net/ssl/KeyManagerFactory.java | 2 +- src/java.base/share/conf/security/java.security | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/java.base/share/classes/javax/net/ssl/KeyManagerFactory.java b/src/java.base/share/classes/javax/net/ssl/KeyManagerFactory.java index 652a20c837705..b591d5a30e4dc 100644 --- a/src/java.base/share/classes/javax/net/ssl/KeyManagerFactory.java +++ b/src/java.base/share/classes/javax/net/ssl/KeyManagerFactory.java @@ -64,7 +64,7 @@ public class KeyManagerFactory { public static final String getDefaultAlgorithm() { String type = Security.getProperty("ssl.KeyManagerFactory.algorithm"); if (type == null) { - type = "SunX509"; + type = "NewSunX509"; } return type; } diff --git a/src/java.base/share/conf/security/java.security b/src/java.base/share/conf/security/java.security index 693d19438f6da..a5df0c4d2f785 100644 --- a/src/java.base/share/conf/security/java.security +++ b/src/java.base/share/conf/security/java.security @@ -320,7 +320,7 @@ security.overridePropertiesFile=true # Determines the default key and trust manager factory algorithms for # the javax.net.ssl package. # -ssl.KeyManagerFactory.algorithm=SunX509 +ssl.KeyManagerFactory.algorithm=NewSunX509 ssl.TrustManagerFactory.algorithm=PKIX # From c80fc6a8ab9e775b1ce456f12834e5b11ff5085d Mon Sep 17 00:00:00 2001 From: Artur Barashev Date: Thu, 17 Apr 2025 10:56:05 -0400 Subject: [PATCH 2/5] Use standard PKIX alias --- .../share/classes/javax/net/ssl/KeyManagerFactory.java | 2 +- src/java.base/share/conf/security/java.security | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/java.base/share/classes/javax/net/ssl/KeyManagerFactory.java b/src/java.base/share/classes/javax/net/ssl/KeyManagerFactory.java index b591d5a30e4dc..6c38e9577daf1 100644 --- a/src/java.base/share/classes/javax/net/ssl/KeyManagerFactory.java +++ b/src/java.base/share/classes/javax/net/ssl/KeyManagerFactory.java @@ -64,7 +64,7 @@ public class KeyManagerFactory { public static final String getDefaultAlgorithm() { String type = Security.getProperty("ssl.KeyManagerFactory.algorithm"); if (type == null) { - type = "NewSunX509"; + type = "PKIX"; } return type; } diff --git a/src/java.base/share/conf/security/java.security b/src/java.base/share/conf/security/java.security index e5826f549cfba..826e3b4a21d1d 100644 --- a/src/java.base/share/conf/security/java.security +++ b/src/java.base/share/conf/security/java.security @@ -320,7 +320,7 @@ security.overridePropertiesFile=true # Determines the default key and trust manager factory algorithms for # the javax.net.ssl package. # -ssl.KeyManagerFactory.algorithm=NewSunX509 +ssl.KeyManagerFactory.algorithm=PKIX ssl.TrustManagerFactory.algorithm=PKIX # From 19a2ad1d5501abbdda72dde0e833d1da8fc7856f Mon Sep 17 00:00:00 2001 From: Artur Barashev Date: Fri, 18 Apr 2025 12:56:29 -0400 Subject: [PATCH 3/5] Rework unit tests --- .../rmi/ssl/SSLSocketParametersTest.java | 34 ++-- test/jdk/javax/rmi/ssl/keystore | Bin 1364 -> 0 bytes test/jdk/javax/rmi/ssl/truststore | Bin 661 -> 0 bytes .../https/HttpsClient/ServerIdentityTest.java | 178 +++++++++++++++--- .../www/protocol/https/HttpsClient/dnsstore | Bin 1418 -> 0 bytes .../www/protocol/https/HttpsClient/ipstore | Bin 1413 -> 0 bytes .../sun/security/tools/keytool/PrintSSL.java | 6 +- .../test/lib/security/CertificateBuilder.java | 21 +++ 8 files changed, 186 insertions(+), 53 deletions(-) delete mode 100644 test/jdk/javax/rmi/ssl/keystore delete mode 100644 test/jdk/javax/rmi/ssl/truststore delete mode 100644 test/jdk/sun/net/www/protocol/https/HttpsClient/dnsstore delete mode 100644 test/jdk/sun/net/www/protocol/https/HttpsClient/ipstore diff --git a/test/jdk/javax/rmi/ssl/SSLSocketParametersTest.java b/test/jdk/javax/rmi/ssl/SSLSocketParametersTest.java index 6da3289458751..ead2473f8e361 100644 --- a/test/jdk/javax/rmi/ssl/SSLSocketParametersTest.java +++ b/test/jdk/javax/rmi/ssl/SSLSocketParametersTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2025, 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,7 +24,8 @@ /* * @test * @bug 5016500 - * @library /test/lib/ + * @library /javax/net/ssl/templates + * /test/lib/ * @summary Test SslRmi[Client|Server]SocketFactory SSL socket parameters. * @run main/othervm SSLSocketParametersTest 1 * @run main/othervm SSLSocketParametersTest 2 @@ -36,8 +37,6 @@ */ import jdk.test.lib.Asserts; -import java.io.IOException; -import java.io.File; import java.io.Serializable; import java.lang.ref.Reference; import java.rmi.ConnectIOException; @@ -49,13 +48,18 @@ import javax.rmi.ssl.SslRMIClientSocketFactory; import javax.rmi.ssl.SslRMIServerSocketFactory; -public class SSLSocketParametersTest implements Serializable { +public class SSLSocketParametersTest extends SSLContextTemplate implements + Serializable { + + public SSLSocketParametersTest() throws Exception { + SSLContext.setDefault(createServerSSLContext()); + } public interface Hello extends Remote { String sayHello() throws RemoteException; } - public class HelloImpl implements Hello { + public static class HelloImpl implements Hello { public String sayHello() { return "Hello World!"; } @@ -134,23 +138,7 @@ public void runTest(int testNumber) throws Exception { } public static void main(String[] args) throws Exception { - // Set keystore properties (server-side) - // - final String keystore = System.getProperty("test.src") + - File.separator + "keystore"; - System.out.println("KeyStore = " + keystore); - System.setProperty("javax.net.ssl.keyStore", keystore); - System.setProperty("javax.net.ssl.keyStorePassword", "password"); - - // Set truststore properties (client-side) - // - final String truststore = System.getProperty("test.src") + - File.separator + "truststore"; - System.out.println("TrustStore = " + truststore); - System.setProperty("javax.net.ssl.trustStore", truststore); - System.setProperty("javax.net.ssl.trustStorePassword", "trustword"); - SSLSocketParametersTest test = new SSLSocketParametersTest(); test.runTest(Integer.parseInt(args[0])); } -} \ No newline at end of file +} diff --git a/test/jdk/javax/rmi/ssl/keystore b/test/jdk/javax/rmi/ssl/keystore deleted file mode 100644 index 05f535645827bae28d6168fe4ad38f55b4faa076..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1364 zcmezO_TO6u1_mY|W&~rFl+x@}AnVJnxrbPQ61xqWn6?}6v2kg$F|sgfF$pp@x>ho1^r&%56_HAo+kX-fS_qrLG%Yn5yK^;n~6$t&>v*xw~)X3eP!zSgL%KOtM?csA62-VTT4$i1_bl&AJ8J4Kf~ ziYq>~>~z7T=JwQ&`THIyDly((cmBuZsJWL9R9dwM*e?9V^W<2oX~rE?2@~@Z_DXF{XSl#`RkR;Szp|kbZYS*iaruy^P zST}Z@wO{qwyZOTFL-+qoSh8dGH)oMlb>{<@F6u5daCMvdGfKYnm+_yf)kmFuzP$0; zUO$K9wCIbL!f!l{|DreY@0nkf-PE&2@iS+ksfS&YmU@(7le43t zh=CADhFzFDI5DpzQNcMUu_)0{-ar;4$|WooT$-ogo0(jcUtC#SlA2qrqu`mBtY^q; zzztHsEzII&6zmG)G7Gb~0P~oEoH(z6v4M$^v7xbnk%2*!IIppRfu(^3luLgHHO@y4 z6JR!HZtP_+XzXNaY-HGfCcO30-Nk>C&t^D3kre0H7s|HG%zJ|HgZJC_FP+00a)3{8 z>dl}fM{>-U?K)u?^slWj`}isG>HM2}Hf@xwP3+FPCH2Eu?D39r?N9aJ&br)Lbi`95G5&Q? z%Y`i+Gi`!B4lzGva^Ygy+7q!NgeN#ov?O}MlGRgNvaYtgc(UBxPV3kQ^@DF}rhYtg zZtpz@_BOUjDzmggY+H9)n(a*vTbg~J;Y+sM;`SA@pBVj}A|Xg7Aa)+xIV>!y0mcPjKqZpe09g%$Myt zVHovdhjZj%K8IQPahLD-cyDL3^t-z{g1PXojrhM3%^3}^cKpjWE!;bG@5VE8^P1m# zwVl1{7ZbDj&;h%LjZ8wTCJ4`e`e`SF!W;o6r?AX#*@B;x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dhtA%ZlfHpx^Ipzn_Ci`VZQX{^ zPFWJ2iPx52yK{Emr09;d_Z5Em)ZdX-Z?=hiUS+dULQCmxp;kdoV#BiCiQ6+Yu5McQ z!u#LSNbhZb6z1zbNn0zc=TYXeLVoY*u#LOlrcZA>FjG8oj=|jHdv5s}Hx*t60MwgF ATL1t6 diff --git a/test/jdk/sun/net/www/protocol/https/HttpsClient/ipstore b/test/jdk/sun/net/www/protocol/https/HttpsClient/ipstore deleted file mode 100644 index 04a9508e0a1c4472d60ffc5f2e3fcaa87812093f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1413 zcmezO_TO6u1_mY|W&~rl;?$zD)FL4J+1bf~>wr?b44Rm>8St@jX|pl1FlsRgGBUC< zurx6(5}mDfMEY-j<1~%bH$S*H`r-XsZ` z9+D8eY5i5Fx!@;v>8C9YJS`_ys=Qsv$h#u5SC+}k^R`1>@?tjCwbFMlOy%c!%Rg=D z<(X6bW8QImoc!Cn%0S}bjwrJiKjJt|ca~du3Y9GR&q9{=?AY^BzZi|%T(ZY0jGTHso*D9j~(Ev+h%{^!QV-b%6{Abm}cL1=F+#z zzN>gv-dSCF!gAf@UF)AldrtfP=G5iXHx;ZYHwq^1Uve|=cjy+s1IFF6kF4L9ANXl? zZ1?A|&ssr|mz}p~M67N}TN?7Nr%ox<>*=%ONhPU?tdFu@v(4w9kRX3bxp80k=YK+Z zjBiSHijPQY_8H0a$93mp^ZzJZ-V#*t=)vw8Ij`(C$!-n1 z?7(zi^2rB}DJIINRomsO&i|cz|Z3)qnZoOTaZ!9rOKkcco#?IYQMjuWr zEH+qm#=xt;`=k4J|Ep7tg{Dnf&VJHtq5K+aGd4s26vZn>PHRKDD>r9+lJu;ts+zv+ z!%CLxJ3hR*GEL)fcPi`0UZvyJbItxscdED@C`fu@syBaT>$lEb(`JHGG;4&OsevUh zA-4b%a)Ut=IJMe5+P?ELGP1BT7*rW@8*s8QhqABsgiezN4lR&yo4*+nZqh1wCbQ!cJ?a_RkEyDl)Oe zKXL}^70!giL5(3VUaUKO(LcZpNdJu diff --git a/test/jdk/sun/security/tools/keytool/PrintSSL.java b/test/jdk/sun/security/tools/keytool/PrintSSL.java index 7cdc0a4577104..70c0fafac02ee 100644 --- a/test/jdk/sun/security/tools/keytool/PrintSSL.java +++ b/test/jdk/sun/security/tools/keytool/PrintSSL.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2025, 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 @@ -53,8 +53,8 @@ public static void main(String[] args) throws Throwable { // make sure that "-printcert" works with weak algorithms OutputAnalyzer out = SecurityTools.keytool("-genkeypair " + "-keystore keystore -storepass passphrase " - + "-keypass passphrase -keyalg rsa -keysize 1024 " - + "-sigalg MD5withRSA -alias rsa_alias -dname CN=Server"); + + "-keypass passphrase -keyalg rsa -keysize 2048 " + + "-sigalg SHA256withRSA -alias rsa_alias -dname CN=Server"); System.out.println(out.getOutput()); out.shouldHaveExitValue(0); diff --git a/test/lib/jdk/test/lib/security/CertificateBuilder.java b/test/lib/jdk/test/lib/security/CertificateBuilder.java index 60358c9a4eabf..c86fe1049200c 100644 --- a/test/lib/jdk/test/lib/security/CertificateBuilder.java +++ b/test/lib/jdk/test/lib/security/CertificateBuilder.java @@ -43,6 +43,7 @@ import sun.security.x509.AlgorithmId; import sun.security.x509.AuthorityInfoAccessExtension; import sun.security.x509.AuthorityKeyIdentifierExtension; +import sun.security.x509.IPAddressName; import sun.security.x509.SubjectKeyIdentifierExtension; import sun.security.x509.BasicConstraintsExtension; import sun.security.x509.CertificateSerialNumber; @@ -233,6 +234,26 @@ public CertificateBuilder addSubjectAltNameDNSExt(List dnsNames) return this; } + /** + * Helper method to add IPAddress types for the SAN extension + * + * @param IPAddresses A {@code List} of names to add as IPAddress + * types + * @throws IOException if an encoding error occurs. + */ + public CertificateBuilder addSubjectAltNameIPExt(List IPAddresses) + throws IOException { + if (!IPAddresses.isEmpty()) { + GeneralNames gNames = new GeneralNames(); + for (String name : IPAddresses) { + gNames.add(new GeneralName(new IPAddressName(name))); + } + addExtension(new SubjectAlternativeNameExtension(false, + gNames)); + } + return this; + } + /** * Helper method to add one or more OCSP URIs to the Authority Info Access * certificate extension. Location strings can be in two forms: From e5e83514e3af4db23dde0143f109a111a090b7fd Mon Sep 17 00:00:00 2001 From: Artur Barashev Date: Thu, 24 Apr 2025 14:21:26 -0400 Subject: [PATCH 4/5] Skip explicit KeyPair initialization and let the provider default set it --- .../net/www/protocol/https/HttpsClient/ServerIdentityTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/test/jdk/sun/net/www/protocol/https/HttpsClient/ServerIdentityTest.java b/test/jdk/sun/net/www/protocol/https/HttpsClient/ServerIdentityTest.java index 5164acd66a5e2..5803da2510a6d 100644 --- a/test/jdk/sun/net/www/protocol/https/HttpsClient/ServerIdentityTest.java +++ b/test/jdk/sun/net/www/protocol/https/HttpsClient/ServerIdentityTest.java @@ -144,7 +144,6 @@ private static void initialize(String[] args) throws Exception { hostname = args[1]; KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); - kpg.initialize(2048); KeyPair caKeys = kpg.generateKeyPair(); KeyPair serverKeys = kpg.generateKeyPair(); KeyPair clientKeys = kpg.generateKeyPair(); From 2b0c5525262ca1f87a956d98ab5900d6ad137189 Mon Sep 17 00:00:00 2001 From: Artur Barashev Date: Tue, 29 Apr 2025 17:47:45 -0400 Subject: [PATCH 5/5] Address review comments --- test/jdk/javax/rmi/ssl/SSLSocketParametersTest.java | 3 +-- test/jdk/sun/security/tools/keytool/PrintSSL.java | 10 ++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/test/jdk/javax/rmi/ssl/SSLSocketParametersTest.java b/test/jdk/javax/rmi/ssl/SSLSocketParametersTest.java index ead2473f8e361..3aa7a98c39403 100644 --- a/test/jdk/javax/rmi/ssl/SSLSocketParametersTest.java +++ b/test/jdk/javax/rmi/ssl/SSLSocketParametersTest.java @@ -48,8 +48,7 @@ import javax.rmi.ssl.SslRMIClientSocketFactory; import javax.rmi.ssl.SslRMIServerSocketFactory; -public class SSLSocketParametersTest extends SSLContextTemplate implements - Serializable { +public class SSLSocketParametersTest extends SSLContextTemplate { public SSLSocketParametersTest() throws Exception { SSLContext.setDefault(createServerSSLContext()); diff --git a/test/jdk/sun/security/tools/keytool/PrintSSL.java b/test/jdk/sun/security/tools/keytool/PrintSSL.java index 70c0fafac02ee..0a29b83159cc3 100644 --- a/test/jdk/sun/security/tools/keytool/PrintSSL.java +++ b/test/jdk/sun/security/tools/keytool/PrintSSL.java @@ -39,6 +39,7 @@ import java.net.ServerSocket; import java.nio.file.Files; import java.nio.file.Paths; +import java.security.Security; import java.util.concurrent.CountDownLatch; import javax.net.ssl.SSLServerSocketFactory; import javax.net.ssl.SSLSocket; @@ -48,13 +49,18 @@ public class PrintSSL { public static void main(String[] args) throws Throwable { + // Using "SunX509" KeyManager which doesn't check peer supported + // signature algorithms, so we can make keytool print certificate + // with weak MD5withRSA signature algorithm. + Security.setProperty("ssl.KeyManagerFactory.algorithm", "SunX509"); + Files.deleteIfExists(Paths.get("keystore")); // make sure that "-printcert" works with weak algorithms OutputAnalyzer out = SecurityTools.keytool("-genkeypair " + "-keystore keystore -storepass passphrase " - + "-keypass passphrase -keyalg rsa -keysize 2048 " - + "-sigalg SHA256withRSA -alias rsa_alias -dname CN=Server"); + + "-keypass passphrase -keyalg rsa -keysize 1024 " + + "-sigalg MD5withRSA -alias rsa_alias -dname CN=Server"); System.out.println(out.getOutput()); out.shouldHaveExitValue(0);