Skip to content

Commit 3f229f5

Browse files
committed
OPENJDK-2123: Algorithms lockdown
Introduce RedHatFIPSFilter, a lightweight Security Providers Filter that uses an allow-list approach to enable non-cryptographic utilities from the providers that also implement uncertified cryptographic primitives, which should be avoided in a FIPS setup. RedHatFIPSFilter is enabled through the __redhat_fips_filter__ boolean security property.
1 parent 0395df6 commit 3f229f5

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/java.base/share/classes/java/security/Provider.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,39 @@ public Set<Service> getServices() {
12031203
return serviceSet;
12041204
}
12051205

1206+
/* vvvvvvvvvvvvvvvvvvvvvvvvvvvvv FIPS PATCH vvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
1207+
private static final class RedHatFIPSFilter {
1208+
static final boolean IS_ON = Boolean.parseBoolean(
1209+
Security.getProperty("__redhat_fips_filter__"));
1210+
private static final Set<String> ANY_SERVICE_TYPE = Set.of();
1211+
private static final Map<String, Set<String>> ALLOW_LIST = Map.of(
1212+
"SunPKCS11-FIPS", ANY_SERVICE_TYPE,
1213+
"SUN", Set.of(
1214+
"AlgorithmParameterGenerator",
1215+
"AlgorithmParameters", "CertificateFactory",
1216+
"CertPathBuilder", "CertPathValidator", "CertStore",
1217+
"Configuration", "KeyStore"),
1218+
"SunEC", Set.of(
1219+
"AlgorithmParameters", "KeyFactory"),
1220+
"SunJSSE", ANY_SERVICE_TYPE,
1221+
"SunJCE", Set.of(
1222+
"AlgorithmParameters",
1223+
"AlgorithmParameterGenerator", "KeyFactory",
1224+
"SecretKeyFactory"),
1225+
"SunRsaSign", Set.of(
1226+
"KeyFactory", "AlgorithmParameters"),
1227+
"XMLDSig", ANY_SERVICE_TYPE
1228+
);
1229+
1230+
static boolean isAllowed(String provName, String serviceType) {
1231+
Set<String> allowedServiceTypes = ALLOW_LIST.get(provName);
1232+
return allowedServiceTypes != null &&
1233+
(allowedServiceTypes == ANY_SERVICE_TYPE ||
1234+
allowedServiceTypes.contains(serviceType));
1235+
}
1236+
}
1237+
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FIPS PATCH ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
1238+
12061239
/**
12071240
* Add a service. If a service of the same type with the same algorithm
12081241
* name exists, and it was added using {@link #putService putService()},
@@ -1231,6 +1264,15 @@ protected void putService(Service s) {
12311264
("service.getProvider() must match this Provider object");
12321265
}
12331266
String type = s.getType();
1267+
/* vvvvvvvvvvvvvvvvvvvvvvvvvvv FIPS PATCH vvvvvvvvvvvvvvvvvvvvvvvvvvv */
1268+
if (RedHatFIPSFilter.IS_ON && !RedHatFIPSFilter.isAllowed(name, type)) {
1269+
if (debug != null) {
1270+
debug.println("The previous " + name + ".putService() call " +
1271+
"was skipped by " + RedHatFIPSFilter.class.getName());
1272+
}
1273+
return;
1274+
}
1275+
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^ FIPS PATCH ^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
12341276
String algorithm = s.getAlgorithm();
12351277
ServiceKey key = new ServiceKey(type, algorithm, true);
12361278
implRemoveService(serviceMap.get(key));

0 commit comments

Comments
 (0)