|
1 | 1 | /*
|
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * The Universal Permissive License (UPL), Version 1.0
|
@@ -62,6 +62,7 @@ public void afterRegistration(AfterRegistrationAccess access) {
|
62 | 62 |
|
63 | 63 | // Register runtime reflection here, not in a config, so it can be easily disabled
|
64 | 64 | String[] reflectiveClasses = new String[]{
|
| 65 | + // BouncyCastle looks up the classes below |
65 | 66 | "org.bouncycastle.jcajce.provider.asymmetric.COMPOSITE$Mappings",
|
66 | 67 | "org.bouncycastle.jcajce.provider.asymmetric.DH$Mappings",
|
67 | 68 | "org.bouncycastle.jcajce.provider.asymmetric.DSA$Mappings",
|
@@ -160,9 +161,37 @@ public void afterRegistration(AfterRegistrationAccess access) {
|
160 | 161 |
|
161 | 162 | for (String name : reflectiveClasses) {
|
162 | 163 | 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); |
166 | 195 | }
|
167 | 196 | }
|
168 | 197 | }
|
|
0 commit comments