in encryption/src/main/java/org/apache/solr/encryption/crypto/LightAesCtrEncrypter.java [140:178]
private static Hack hack() {
Hack hack = new Hack();
try {
Class<?> aesCryptClass = Class.forName("com.sun.crypto.provider.AESCrypt");
hack.aesCryptConstructor = aesCryptClass.getDeclaredConstructor();
hack.aesCryptConstructor.setAccessible(true);
hack.aesCryptInitMethod = aesCryptClass.getDeclaredMethod("init", boolean.class, String.class, byte[].class);
hack.aesCryptInitMethod.setAccessible(true);
Class<?> counterModeClass = Class.forName("com.sun.crypto.provider.CounterMode");
Class<?> symmetricCipherClass = Class.forName("com.sun.crypto.provider.SymmetricCipher");
hack.counterModeConstructor = counterModeClass.getDeclaredConstructor(symmetricCipherClass);
hack.counterModeConstructor.setAccessible(true);
Class<?> feedbackCipherClass = Class.forName("com.sun.crypto.provider.FeedbackCipher");
hack.counterIvField = feedbackCipherClass.getDeclaredField("iv");
hack.counterIvField.setAccessible(true);
hack.counterModeResetMethod = counterModeClass.getDeclaredMethod("reset");
hack.counterModeResetMethod.setAccessible(true);
hack.counterModeCryptMethod = counterModeClass.getDeclaredMethod("implCrypt", byte[].class, int.class, int.class, byte[].class, int.class);
hack.counterModeCryptMethod.setAccessible(true);
} catch (SecurityException se) {
hack.hackFailure = new UnsupportedOperationException(LightAesCtrEncrypter.class.getName() + " is not supported"
+ " because not all required permissions are given to the Encryption JAR file: " + se +
" [To support it, grant at least the following permissions:" +
" RuntimePermission(\"accessClassInPackage.com.sun.crypto.provider\") " +
" and ReflectPermission(\"suppressAccessChecks\")]", se);
} catch (ReflectiveOperationException | RuntimeException e) {
hack.hackFailure = new UnsupportedOperationException(LightAesCtrEncrypter.class.getName() + " is not supported"
+ " on this platform because internal Java APIs are not compatible with this Solr version: " + e, e);
}
if (hack.hackFailure != null) {
hack.aesCryptConstructor = null;
hack.aesCryptInitMethod = null;
hack.counterModeConstructor = null;
hack.counterIvField = null;
hack.counterModeResetMethod = null;
hack.counterModeCryptMethod = null;
}
return hack;
}