Skip to content

Commit 5ce9e78

Browse files
committed
Fix profiles with same name beginnings being treated as one
Fix the issue where profiles with the same beginnings of profile name are treated as a single profile. Signed-off-by: Tao Liu <[email protected]>
1 parent 9181864 commit 5ce9e78

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.stream.Collectors;
5050
import java.util.stream.Stream;
5151

52+
import compiler.lib.ir_framework.driver.irmatching.irrule.constraint.Constraint;
5253
import sun.security.util.Debug;
5354

5455
/**
@@ -345,9 +346,10 @@ private static void getProfileID(Properties props) {
345346
}
346347
String defaultMatch = null;
347348
boolean profileExists = false;
349+
String profilePrefix = potentialProfileID + '.';
348350
for (Object keyObject : props.keySet()) {
349351
if (keyObject instanceof String key) {
350-
if (key.startsWith(potentialProfileID)) {
352+
if (key.startsWith(profilePrefix)) {
351353
profileExists = true;
352354
if (key.endsWith(".desc.default")) {
353355
// Check if property is set to true.

closed/test/jdk/openj9/internal/security/TestProperties.java

+22
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@
4343

4444
public class TestProperties {
4545

46+
private static Stream<Arguments> patternMatches_expectedExitValue0() {
47+
return Stream.of(
48+
// 1 - Test property - Same beginnings of the profile name without version.
49+
Arguments.of("Test-Profile-SameStartWithoutVersion",
50+
System.getProperty("test.src") + "/property-java.security",
51+
"(?s)(?=.*Sun)(?=.*\\bSunJCE\\b)(?=.*SunJSSE)")
52+
);
53+
}
54+
4655
private static Stream<Arguments> patternMatches_expectedExitValue1() {
4756
return Stream.of(
4857
// 1 - Test profile - base profile misspell properties.
@@ -155,6 +164,19 @@ private static Stream<Arguments> patternMatches_expectedExitValue1() {
155164
);
156165
}
157166

167+
@ParameterizedTest
168+
@MethodSource("patternMatches_expectedExitValue0")
169+
public void shouldContain_expectedExitValue0(String customprofile, String securityPropertyFile, String expected) throws Exception {
170+
OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJava(
171+
"-Dsemeru.fips=true",
172+
"-Dsemeru.customprofile=" + customprofile,
173+
"-Djava.security.properties=" + securityPropertyFile,
174+
"TestProperties"
175+
);
176+
outputAnalyzer.reportDiagnosticSummary();
177+
outputAnalyzer.shouldHaveExitValue(0).shouldMatch(expected);
178+
}
179+
158180
@ParameterizedTest
159181
@MethodSource("patternMatches_expectedExitValue1")
160182
public void shouldContain_expectedExitValue1(String customprofile, String securityPropertyFile, String expected) throws Exception {

closed/test/jdk/openj9/internal/security/property-java.security

+36
Original file line numberDiff line numberDiff line change
@@ -525,3 +525,39 @@ RestrictedSecurity.Test-Profile-ConstraintChanged_3.Base.jce.provider.1 = com.s
525525

526526
RestrictedSecurity.Test-Profile-ConstraintChanged_3.Base.securerandom.provider = OpenJCEPlusFIPS
527527
RestrictedSecurity.Test-Profile-ConstraintChanged_3.Base.securerandom.algorithm = SHA512DRBG
528+
529+
#
530+
# Test-Profile-SameStartWithoutVersion
531+
# Test property - Same beginnings of the profile name without version
532+
#
533+
RestrictedSecurity.Test-Profile-SameStartWithoutVersion.desc.name = Test-Profile-SameStartWithoutVersion
534+
RestrictedSecurity.Test-Profile-SameStartWithoutVersion.desc.default = true
535+
RestrictedSecurity.Test-Profile-SameStartWithoutVersion.desc.fips = true
536+
RestrictedSecurity.Test-Profile-SameStartWithoutVersion.desc.hash = SHA256:2c893d75043da09c3dba8d8b24cb71dc1c7ceac5fb8bf362a35847418a933a06
537+
RestrictedSecurity.Test-Profile-SameStartWithoutVersion.desc.number = Certificate #XXX
538+
RestrictedSecurity.Test-Profile-SameStartWithoutVersion.desc.policy = https://csrc.nist.gov/projects/cryptographic-module-validation-program/certificate/
539+
RestrictedSecurity.Test-Profile-SameStartWithoutVersion.desc.sunsetDate = 2026-09-21
540+
RestrictedSecurity.Test-Profile-SameStartWithoutVersion.fips.mode = 140-3
541+
542+
RestrictedSecurity.Test-Profile-SameStartWithoutVersion.jce.provider.1 = sun.security.provider.Sun
543+
RestrictedSecurity.Test-Profile-SameStartWithoutVersion.jce.provider.2 = com.sun.crypto.provider.SunJCE
544+
RestrictedSecurity.Test-Profile-SameStartWithoutVersion.jce.provider.3 = sun.security.ssl.SunJSSE
545+
546+
RestrictedSecurity.Test-Profile-SameStartWithoutVersion.securerandom.provider = OpenJCEPlusFIPS
547+
RestrictedSecurity.Test-Profile-SameStartWithoutVersion.securerandom.algorithm = SHA512DRBG
548+
549+
RestrictedSecurity.Test-Profile-SameStartWithoutVersionPart.desc.name = Test-Profile-SameStartWithoutVersionPart
550+
RestrictedSecurity.Test-Profile-SameStartWithoutVersionPart.desc.default = true
551+
RestrictedSecurity.Test-Profile-SameStartWithoutVersionPart.desc.fips = true
552+
RestrictedSecurity.Test-Profile-SameStartWithoutVersionPart.desc.hash = SHA256:2c893d75043da09c3dba8d8b24cb71dc1c7ceac5fb8bf362a35847418a933a06
553+
RestrictedSecurity.Test-Profile-SameStartWithoutVersionPart.desc.number = Certificate #XXX
554+
RestrictedSecurity.Test-Profile-SameStartWithoutVersionPart.desc.policy = https://csrc.nist.gov/projects/cryptographic-module-validation-program/certificate/
555+
RestrictedSecurity.Test-Profile-SameStartWithoutVersionPart.desc.sunsetDate = 2026-09-21
556+
RestrictedSecurity.Test-Profile-SameStartWithoutVersionPart.fips.mode = 140-3
557+
558+
RestrictedSecurity.Test-Profile-SameStartWithoutVersionPart.jce.provider.1 = sun.security.provider.Sun
559+
RestrictedSecurity.Test-Profile-SameStartWithoutVersionPart.jce.provider.2 = com.sun.crypto.provider.SunJCE
560+
RestrictedSecurity.Test-Profile-SameStartWithoutVersionPart.jce.provider.3 = sun.security.ssl.SunJSSE
561+
562+
RestrictedSecurity.Test-Profile-SameStartWithoutVersionPart.securerandom.provider = OpenJCEPlusFIPS
563+
RestrictedSecurity.Test-Profile-SameStartWithoutVersionPart.securerandom.algorithm = SHA512DRBG

0 commit comments

Comments
 (0)