Skip to content

Commit

Permalink
8292739: Invalid legacy entries may be returned by Provider.getServic…
Browse files Browse the repository at this point in the history
…es() call

Reviewed-by: weijun
  • Loading branch information
Valerie Peng committed Aug 24, 2022
1 parent 568be58 commit 14623c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/java.base/share/classes/java/security/Provider.java
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,13 @@ public Set<Service> getServices() {
set.addAll(serviceMap.values());
}
if (!legacyMap.isEmpty()) {
set.addAll(legacyMap.values());
legacyMap.entrySet().forEach(entry -> {
if (!entry.getValue().isValid()) {
legacyMap.remove(entry.getKey(), entry.getValue());
} else {
set.add(entry.getValue());
}
});
}
serviceSet = Collections.unmodifiableSet(set);
servicesChanged = false;
Expand Down
15 changes: 12 additions & 3 deletions test/jdk/java/security/Provider/CaseSensitiveServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/*
* @test
* @bug 5097015 8130181 8279222
* @bug 5097015 8130181 8279222 8292739
* @summary make sure we correctly treat Provider string entries as case insensitive
* @author Andreas Sterbenz
*/
Expand All @@ -42,15 +42,23 @@ public class CaseSensitiveServices extends Provider {
put("MESSAGEDIGEST.BAZ", "com.Baz");
// reassign the DEF alias to algorithm Bar
put("ALg.aliaS.MESSAGEdigest.DEF", "Bar");
// invalid entry since it misses the corresponding impl class info
// e.g. put("MessageDigest.Invalid", "implClass");
put("MessageDigest.Invalid xYz", "aBc");
}

public static void main(String[] args) throws Exception {
Provider p = new CaseSensitiveServices();
System.out.println(p.getServices());

System.out.println("Services: " + p.getServices());

if (p.getServices().size() != 3) {
throw new Exception("services.size() should be 3");
}

if (p.getService("MessageDigest", "Invalid") != null) {
throw new Exception("Invalid service returned");
}
Service s = testService(p, "MessageDigest", "fOO");
String val = s.getAttribute("Xyz");
if ("aBc".equals(val) == false) {
Expand All @@ -70,7 +78,8 @@ public static void main(String[] args) throws Exception {
System.out.println("OK");
}

private static Service testService(Provider p, String type, String alg) throws Exception {
private static Service testService(Provider p, String type, String alg)
throws Exception {
System.out.println("Getting " + type + "." + alg + "...");
Service s = p.getService(type, alg);
System.out.println(s);
Expand Down

1 comment on commit 14623c6

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.