Skip to content

Commit 786878c

Browse files
timfeljovanstevanovic
authored andcommitted
[GR-65034] Adapt BouncyCastleFeature to changes in JDK 25+23.
PullRequest: graalpython/3806
2 parents 9a742db + c6f50c2 commit 786878c

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/BouncyCastleFeature.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -62,6 +62,7 @@ public void afterRegistration(AfterRegistrationAccess access) {
6262

6363
// Register runtime reflection here, not in a config, so it can be easily disabled
6464
String[] reflectiveClasses = new String[]{
65+
// BouncyCastle looks up the classes below
6566
"org.bouncycastle.jcajce.provider.asymmetric.COMPOSITE$Mappings",
6667
"org.bouncycastle.jcajce.provider.asymmetric.DH$Mappings",
6768
"org.bouncycastle.jcajce.provider.asymmetric.DSA$Mappings",
@@ -160,9 +161,37 @@ public void afterRegistration(AfterRegistrationAccess access) {
160161

161162
for (String name : reflectiveClasses) {
162163
try {
163-
RuntimeReflection.register(Class.forName(name).getConstructor());
164-
} catch (NoSuchMethodException | SecurityException | ClassNotFoundException e) {
165-
throw new RuntimeException("Could not register " + name + " constructor for reflective access!", e);
164+
RuntimeReflection.register(Class.forName(name));
165+
RuntimeReflection.register(Class.forName(name).getConstructors());
166+
} catch (SecurityException | ClassNotFoundException e) {
167+
throw new RuntimeException("Could not register " + name + " for reflective access!", e);
168+
}
169+
}
170+
171+
// SSLBasicKeyDerivation looks up the classes below reflectively since jdk-25+23
172+
// See https://github.com/openjdk/jdk/pull/24393
173+
reflectiveClasses = new String[]{
174+
"com.sun.crypto.provider.HKDFKeyDerivation$HKDFSHA256",
175+
"com.sun.crypto.provider.HKDFKeyDerivation$HKDFSHA384",
176+
"com.sun.crypto.provider.HKDFKeyDerivation$HKDFSHA512",
177+
"sun.security.pkcs11.P11HKDF",
178+
};
179+
for (String name : reflectiveClasses) {
180+
try {
181+
Class.forName(name);
182+
} catch (SecurityException | ClassNotFoundException e) {
183+
return;
184+
}
185+
}
186+
// For backwards compatibility with older JDKs, we only do this if we found
187+
// all those classes
188+
Security.addProvider(Security.getProvider("SunJCE"));
189+
for (String name : reflectiveClasses) {
190+
try {
191+
RuntimeReflection.register(Class.forName(name));
192+
RuntimeReflection.register(Class.forName(name).getConstructors());
193+
} catch (SecurityException | ClassNotFoundException e) {
194+
throw new RuntimeException("Could not register " + name + " for reflective access!", e);
166195
}
167196
}
168197
}

0 commit comments

Comments
 (0)