Skip to content

Commit aec0008

Browse files
martinuygnu-andrew
authored andcommitted
RH2134669: Add missing attributes when registering services in FIPS mode. (openjdk#19)
Reviewed-by: @franferrax, @gnu-andrew
1 parent 00c76e2 commit aec0008

File tree

3 files changed

+92
-14
lines changed

3 files changed

+92
-14
lines changed

src/java.base/share/classes/sun/security/provider/SunEntries.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,19 @@ public final class SunEntries {
192192
add(p, "Signature", "SHA3-512withDSAinP1363Format",
193193
"sun.security.provider.DSA$SHA3_512withDSAinP1363Format");
194194

195-
attrs.clear();
196-
attrs.put("ImplementedIn", "Software");
197-
addWithAlias(p, "Signature", "HSS/LMS", "sun.security.provider.HSS", attrs);
198-
/*
199-
* Key Pair Generator engines
200-
*/
201-
attrs.clear();
202-
attrs.put("ImplementedIn", "Software");
203-
attrs.put("KeySize", "2048"); // for DSA KPG and APG only
195+
}
204196

197+
attrs.clear();
198+
attrs.put("ImplementedIn", "Software");
199+
addWithAlias(p, "Signature", "HSS/LMS", "sun.security.provider.HSS", attrs);
200+
/*
201+
* Key Pair Generator engines
202+
*/
203+
attrs.clear();
204+
attrs.put("ImplementedIn", "Software");
205+
attrs.put("KeySize", "2048"); // for DSA KPG and APG only
206+
207+
if (!systemFipsEnabled) {
205208
String dsaKPGImplClass = "sun.security.provider.DSAKeyPairGenerator$";
206209
dsaKPGImplClass += (useLegacyDSA? "Legacy" : "Current");
207210
addWithAlias(p, "KeyPairGenerator", "DSA", dsaKPGImplClass, attrs);

src/java.base/share/classes/sun/security/rsa/SunRsaSignEntries.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,9 @@ public SunRsaSignEntries(Provider p) {
6161
// start populating content using the specified provider
6262
// common attribute map
6363
HashMap<String, String> attrs = new HashMap<>(3);
64-
if (!systemFipsEnabled) {
65-
attrs.put("SupportedKeyClasses",
66-
"java.security.interfaces.RSAPublicKey" +
67-
"|java.security.interfaces.RSAPrivateKey");
68-
}
64+
attrs.put("SupportedKeyClasses",
65+
"java.security.interfaces.RSAPublicKey" +
66+
"|java.security.interfaces.RSAPrivateKey");
6967

7068
add(p, "KeyFactory", "RSA",
7169
"sun.security.rsa.RSAKeyFactory$Legacy",
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2022, Red Hat, Inc.
3+
*
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*/
24+
25+
import java.security.Provider;
26+
import java.security.Security;
27+
28+
/*
29+
* @test
30+
* @bug 9999999
31+
* @requires (jdk.version.major >= 8)
32+
* @run main/othervm/timeout=30 Main
33+
* @author Martin Balao (mbalao@redhat.com)
34+
*/
35+
36+
public final class VerifyMissingAttributes {
37+
38+
private static final String[] svcAlgImplementedIn = {
39+
"AlgorithmParameterGenerator.DSA",
40+
"AlgorithmParameters.DSA",
41+
"CertificateFactory.X.509",
42+
"KeyStore.JKS",
43+
"KeyStore.CaseExactJKS",
44+
"KeyStore.DKS",
45+
"CertStore.Collection",
46+
"CertStore.com.sun.security.IndexedCollection"
47+
};
48+
49+
public static void main(String[] args) throws Throwable {
50+
Provider sunProvider = Security.getProvider("SUN");
51+
for (String svcAlg : svcAlgImplementedIn) {
52+
String filter = svcAlg + " ImplementedIn:Software";
53+
doQuery(sunProvider, filter);
54+
}
55+
if (Double.parseDouble(
56+
System.getProperty("java.specification.version")) >= 17) {
57+
String filter = "KeyFactory.RSASSA-PSS SupportedKeyClasses:" +
58+
"java.security.interfaces.RSAPublicKey" +
59+
"|java.security.interfaces.RSAPrivateKey";
60+
doQuery(Security.getProvider("SunRsaSign"), filter);
61+
}
62+
System.out.println("TEST PASS - OK");
63+
}
64+
65+
private static void doQuery(Provider expectedProvider, String filter)
66+
throws Exception {
67+
if (expectedProvider == null) {
68+
throw new Exception("Provider not found.");
69+
}
70+
Provider[] providers = Security.getProviders(filter);
71+
if (providers == null || providers.length != 1 ||
72+
providers[0] != expectedProvider) {
73+
throw new Exception("Failure retrieving the provider with this" +
74+
" query: " + filter);
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)