Skip to content

Commit dfef1f2

Browse files
authored
Merge pull request #991 from KostasTsiounis/checkhash_problem
Check RestrictedSecurity profile hash after Providers init
2 parents 1e3ffdd + 15ae5b3 commit dfef1f2

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

closed/src/java.base/share/classes/openj9/internal/security/RestrictedSecurity.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

src/java.base/share/classes/sun/security/jca/Providers.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ private Providers() {
111111
// triggers a getInstance() call (although that should not happen)
112112
providerList = ProviderList.EMPTY;
113113
providerList = ProviderList.fromSecurityProperties();
114+
RestrictedSecurity.checkHashValues();
114115
}
115116

116117
// Return Sun provider.

0 commit comments

Comments
 (0)