@@ -77,6 +77,8 @@ public final class RestrictedSecurity {
7777
7878 private static ProfileParser profileParser ;
7979
80+ private static boolean enableCheckHashes ;
81+
8082 private static RestrictedSecurityProperties restricts ;
8183
8284 private static final Set <String > unmodifiableProperties = new HashSet <>();
@@ -180,11 +182,20 @@ private static boolean isJarVerifierInStackTrace() {
180182 * extending profiles, instead of altering them, a digest of the profile
181183 * is calculated and compared to the expected value.
182184 */
183- private static void checkHashValues () {
185+ public static void checkHashValues () {
186+ checkHashValues (true );
187+ }
188+
189+ private static void checkHashValues (boolean fromProviders ) {
184190 ProfileParser parser = profileParser ;
185- if ((parser != null ) && !isJarVerifierInStackTrace ()) {
186- profileParser = null ;
187- parser .checkHashValues ();
191+ if (parser != null ) {
192+ if (fromProviders ) {
193+ enableCheckHashes = true ;
194+ }
195+ if (enableCheckHashes && !isJarVerifierInStackTrace ()) {
196+ profileParser = null ;
197+ parser .checkHashValues ();
198+ }
188199 }
189200 }
190201
@@ -257,7 +268,7 @@ public static boolean isFIPSEnabled() {
257268 */
258269 public static boolean isServiceAllowed (Service service ) {
259270 if (securityEnabled ) {
260- checkHashValues ();
271+ checkHashValues (false );
261272 return restricts .isRestrictedServiceAllowed (service , true );
262273 }
263274 return true ;
@@ -271,7 +282,7 @@ public static boolean isServiceAllowed(Service service) {
271282 */
272283 public static boolean canServiceBeRegistered (Service service ) {
273284 if (securityEnabled ) {
274- checkHashValues ();
285+ checkHashValues (false );
275286 return restricts .isRestrictedServiceAllowed (service , false );
276287 }
277288 return true ;
@@ -285,7 +296,7 @@ public static boolean canServiceBeRegistered(Service service) {
285296 */
286297 public static boolean isProviderAllowed (String providerName ) {
287298 if (securityEnabled ) {
288- checkHashValues ();
299+ checkHashValues (false );
289300 // Remove argument, e.g. -NSS-FIPS, if present.
290301 int pos = providerName .indexOf ('-' );
291302 if (pos >= 0 ) {
@@ -305,7 +316,7 @@ public static boolean isProviderAllowed(String providerName) {
305316 */
306317 public static boolean isProviderAllowed (Class <?> providerClazz ) {
307318 if (securityEnabled ) {
308- checkHashValues ();
319+ checkHashValues (false );
309320 String providerClassName = providerClazz .getName ();
310321
311322 // Check if the specified class extends java.security.Provider.
0 commit comments