@@ -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