Skip to content

Commit

Permalink
Move reflection for PKCS11 class into the block that needs it.
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanLennox committed Sep 22, 2020
1 parent fa8a914 commit 4903647
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions src/main/java/org/jitsi/srtp/crypto/Aes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Expand Down

0 comments on commit 4903647

Please sign in to comment.