Skip to content

Commit 04e4f00

Browse files
authored
Merge pull request #448 from KostasTsiounis/constraints_stack_strict
Allow multiple constraints for each algorithm
2 parents 886f542 + b7fb781 commit 04e4f00

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ boolean isRestrictedServiceAllowed(Service service, boolean checkUse) {
805805
if (debug != null) {
806806
debug.println("Security constraints check of provider.");
807807
}
808+
constraints:
808809
for (Constraint constraint : constraints) {
809810
String cType = constraint.type;
810811
String cAlgorithm = constraint.algorithm;
@@ -823,14 +824,14 @@ boolean isRestrictedServiceAllowed(Service service, boolean checkUse) {
823824
if (debug != null) {
824825
debug.println("The constraint doesn't apply to the service type.");
825826
}
826-
continue;
827+
continue constraints;
827828
}
828829
if (!isAsterisk(cAlgorithm) && !algorithm.equalsIgnoreCase(cAlgorithm)) {
829830
// The constraint doesn't apply to the service algorithm.
830831
if (debug != null) {
831832
debug.println("The constraint doesn't apply to the service algorithm.");
832833
}
833-
continue;
834+
continue constraints;
834835
}
835836

836837
// For type and algorithm match, and attribute is not *.
@@ -852,7 +853,8 @@ boolean isRestrictedServiceAllowed(Service service, boolean checkUse) {
852853
+ "\nagainst the service attribute value: " + sValue);
853854
}
854855
if ((sValue == null) || !cValue.equalsIgnoreCase(sValue)) {
855-
// If any attribute doesn't match, return service is not allowed.
856+
// If any of the attributes don't match,
857+
// then this constraint doesn't match so move on.
856858
if (debug != null) {
857859
debug.println("Attributes don't match!");
858860
debug.println("The following service:"
@@ -861,7 +863,7 @@ boolean isRestrictedServiceAllowed(Service service, boolean checkUse) {
861863
+ "\n\tAttribute: " + cAttribute
862864
+ "\nis NOT allowed in provider: " + providerClassName);
863865
}
864-
return false;
866+
continue constraints;
865867
}
866868
if (debug != null) {
867869
debug.println("Attributes match!");
@@ -919,7 +921,7 @@ boolean isRestrictedServiceAllowed(Service service, boolean checkUse) {
919921
}
920922

921923
// If nothing matching the accepted uses is found in the call stack,
922-
// this service is not allowed.
924+
// then this constraint doesn't match so move on.
923925
if (!found) {
924926
if (debug != null) {
925927
debug.println("Classes in call stack are not part of accepted uses!");
@@ -930,7 +932,7 @@ boolean isRestrictedServiceAllowed(Service service, boolean checkUse) {
930932
+ "\n\tAccepted uses: " + cAcceptedUses
931933
+ "\nis NOT allowed in provider: " + providerClassName);
932934
}
933-
return false;
935+
continue constraints;
934936
}
935937
}
936938

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

+10
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ private static void getInstances() throws Exception {
7272
KeyManagerFactory.getInstance("SunX509");
7373
TrustManagerFactory.getInstance("SunX509");
7474
SSLContext.getInstance("TLSv1.3");
75+
76+
// Since there are three constraints for MD5, with only the middle one
77+
// allowing for use by this class, successfully getting the algorithm
78+
// verifies that all constraints are checked.
79+
MessageDigest.getInstance("MD5");
80+
81+
// Since there are three constraints for SHA512withECDSA, with only the
82+
// middle one having the correct attributes, successfully getting the
83+
// algorithm verifies that all constraints are checked.
84+
Signature.getInstance("SHA512withECDSA");
7585
}
7686

7787
@Test

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
RestrictedSecurity.TestConstraints.Version.desc.name = Test Base Profile
2222
RestrictedSecurity.TestConstraints.Version.desc.default = false
2323
RestrictedSecurity.TestConstraints.Version.desc.fips = false
24-
RestrictedSecurity.TestConstraints.Version.desc.hash = SHA256:3162e55fbeed3c2453ebdacd854243eb8b9af3769a84bf66bb12614f9076ea64
24+
RestrictedSecurity.TestConstraints.Version.desc.hash = SHA256:235727d782ff9e04d875627c694d509b758ed7c037eaf5aed8dcd014f2602af2
2525
RestrictedSecurity.TestConstraints.Version.desc.number = Certificate #XXX
2626
RestrictedSecurity.TestConstraints.Version.desc.policy =
2727
RestrictedSecurity.TestConstraints.Version.fips.mode = test
@@ -33,12 +33,24 @@ RestrictedSecurity.TestConstraints.Version.jce.provider.1 = sun.security.provide
3333
{CertPathBuilder, PKIX, *, FullClassName:TestConstraintsSuccess}, \
3434
{CertPathValidator, PKIX, *, FullClassName:TestConstraintsSuccess}, \
3535
{SecureRandom, SHA1PRNG, *, FullClassName:TestConstraintsSuccess}, \
36+
{MessageDigest, MD5, *, FullClassName:NonExistingClass}, \
37+
{MessageDigest, MD5, *, FullClassName:TestConstraintsSuccess}, \
38+
{MessageDigest, MD5, *, FullClassName:AnotherNonExistingClass}, \
3639
{MessageDigest, SHA-256, *}, \
3740
{MessageDigest, SHA-512, *, FullClassName:TestConstraintsSuccess}, \
3841
{KeyStore, PKCS12, *, FullClassName:TestConstraintsSuccess}]
3942
RestrictedSecurity.TestConstraints.Version.jce.provider.2 = sun.security.ec.SunEC [ \
4043
{AlgorithmParameters, EC, *, ModuleAndFullClassName:java.base/java.security.KeyPairGenerator}, \
4144
{Signature, SHA256withECDSA, *, FullClassName:TestConstraintsSuccess}, \
45+
{Signature, SHA512withECDSA, ImplementedIn=Software: \
46+
SupportedKeyClasses=java.security.interfaces.ECPublicKey|java.security.interfaces.ECPrivateKey: \
47+
KeySize=255, FullClassName:TestConstraintsSuccess}, \
48+
{Signature, SHA512withECDSA, ImplementedIn=Software: \
49+
SupportedKeyClasses=java.security.interfaces.ECPublicKey|java.security.interfaces.ECPrivateKey: \
50+
KeySize=256, FullClassName:TestConstraintsSuccess}, \
51+
{Signature, SHA512withECDSA, ImplementedIn=Software: \
52+
SupportedKeyClasses=java.security.interfaces.ECPublicKey|java.security.interfaces.ECPrivateKey: \
53+
KeySize=257, FullClassName:TestConstraintsSuccess}, \
4254
{KeyPairGenerator, EC, *, FullClassName:TestConstraintsSuccess}, \
4355
{KeyAgreement, ECDH, *, FullClassName:TestConstraintsSuccess}, \
4456
{KeyFactory, EC, *, FullClassName:TestConstraintsSuccess}]

0 commit comments

Comments
 (0)