Skip to content

Commit 912c82e

Browse files
committed
sun.security.x509.AlgorithmId.get(String) isn't thread-safe and can lead to null be returned for an algorithm that should be present. This commit aims to work around this problem by avoiding the call to AlgorithmId.get(String). It does so by configuring the PKCS12 key protection algorithm to one that starts with pbewithhmacsha (case insensitive). This short-circuits the logic in PKCS12KeyStore.mapPBEAlgorithmToOID(String) and avoids the call to AlgorithmId.get(String). Thanks again to @dreis2211 for the suggestion. The work around is only used when building with Java 8 as the problem was fixed in Java 9. Closes gh-26252
1 parent a470c1a commit 912c82e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import io.spring.javaformat.gradle.FormatTask;
3030
import io.spring.javaformat.gradle.SpringJavaFormatPlugin;
31+
import org.gradle.api.JavaVersion;
3132
import org.gradle.api.Project;
3233
import org.gradle.api.artifacts.Configuration;
3334
import org.gradle.api.artifacts.ConfigurationContainer;
@@ -141,6 +142,10 @@ private void configureTestConventions(Project project) {
141142
withOptionalBuildJavaHome(project, (javaHome) -> test.setExecutable(javaHome + "/bin/java"));
142143
test.useJUnitPlatform();
143144
test.setMaxHeapSize("1024M");
145+
if (buildingWithJava8(project)) {
146+
test.systemProperty("java.security.properties",
147+
getClass().getClassLoader().getResource("jdk-8156584-security.properties"));
148+
}
144149
});
145150
project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> project.getDependencies()
146151
.add(JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME, "org.junit.platform:junit-platform-launcher"));
@@ -153,6 +158,10 @@ private void configureTestConventions(Project project) {
153158
}));
154159
}
155160

161+
private boolean buildingWithJava8(Project project) {
162+
return (!project.hasProperty("buildJavaHome")) && JavaVersion.current() == JavaVersion.VERSION_1_8;
163+
}
164+
156165
private boolean isCi() {
157166
return Boolean.parseBoolean(System.getenv("CI"));
158167
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
keystore.pkcs12.keyProtectionAlgorithm=PBEWithHmacSHA256AndAES_256

0 commit comments

Comments
 (0)