Skip to content

Commit

Permalink
fix: Java 11+ PKCS11 provider setup (#5495)
Browse files Browse the repository at this point in the history
* fix: Java 11+ PKCS11 provider setup

Signed-off-by: MMaiero <[email protected]>

* chore: Updated copyright

Signed-off-by: MMaiero <[email protected]>

---------

Signed-off-by: MMaiero <[email protected]>
  • Loading branch information
MMaiero authored Oct 30, 2024
1 parent fecabd4 commit 1343592
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Eurotech and/or its affiliates and others
* Copyright (c) 2022, 2024 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -207,9 +207,9 @@ private Provider registerProviderJava8(final String config) throws KuraException
private Provider registerProviderJava9(final String config) throws KuraException {

try {
final Provider prototype = Security.getProvider("SunPKCS11");
Provider newProvider = Security.getProvider("SunPKCS11");

final Method configure = prototype.getClass().getMethod("configure", String.class);
final Method configure = Provider.class.getMethod("configure", String.class);

final File configFile = Files.createTempFile(null, null).toFile();

Expand All @@ -218,7 +218,9 @@ private Provider registerProviderJava9(final String config) throws KuraException
out.write(config.getBytes());
}

return (Provider) configure.invoke(prototype, configFile.getAbsolutePath());
newProvider = (Provider) configure.invoke(newProvider, configFile.getAbsolutePath());
Security.addProvider(newProvider);
return newProvider;
} finally {
Files.deleteIfExists(configFile.toPath());
}
Expand Down

0 comments on commit 1343592

Please sign in to comment.