From 4903647180d9de7a7f04368e6aa7f42bd0aa1151 Mon Sep 17 00:00:00 2001 From: Jonathan Lennox Date: Mon, 21 Sep 2020 13:02:27 -0400 Subject: [PATCH] Move reflection for PKCS11 class into the block that needs it. --- src/main/java/org/jitsi/srtp/crypto/Aes.java | 55 ++++++++++---------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/jitsi/srtp/crypto/Aes.java b/src/main/java/org/jitsi/srtp/crypto/Aes.java index d423bb9..9e40bd2 100644 --- a/src/main/java/org/jitsi/srtp/crypto/Aes.java +++ b/src/main/java/org/jitsi/srtp/crypto/Aes.java @@ -899,43 +899,44 @@ public static synchronized Provider getProvider() { try { - Class clazz - = Class.forName("sun.security.pkcs11.SunPKCS11"); - - if (Provider.class.isAssignableFrom(clazz)) + try { - try + /* Java 9+. PKCS11 configuration is set using the + * configure method. + * Use reflection so we can build with JDK 8. */ + Method configureMethod = + Provider.class.getMethod("configure", String.class); + + Provider prototype = + Security.getProvider("SunPKCS11"); + if (prototype != null) { - /* Java 9+. PKCS11 configuration is set using the - * configure method. - * Use reflection so we can build with JDK 8. */ - Method configureMethod = - Provider.class.getMethod("configure", String.class); - - Provider prototype = - Security.getProvider("SunPKCS11"); - if (prototype != null) - { - provider - = (Provider) - configureMethod.invoke(prototype, getConfiguration()); - } + provider + = (Provider) + configureMethod.invoke(prototype, getConfiguration()); } - catch (Exception e) - { - logger.debug("Unable to construct PKCS11 provider: " + e.getMessage()); - } - finally + } + catch (Exception e) + { + logger.debug("Unable to construct PKCS11 provider: " + e.getMessage()); + } + finally + { + /* Java 8. PKCS11 configuration is passed as a constructor parameter. */ + if (provider == null) { - /* Java 8. PKCS11 configuration is passed as a constructor parameter. */ - if (provider == null) + Class clazz + = Class.forName("sun.security.pkcs11.SunPKCS11"); + + if (Provider.class.isAssignableFrom(clazz)) { Constructor contructor = clazz.getConstructor(String.class); provider = (Provider) - contructor.newInstance(getConfiguration()); + contructor + .newInstance(getConfiguration()); } } }