summaryrefslogtreecommitdiffstats
path: root/cadi
diff options
context:
space:
mode:
authorManjunath Ranganathaiah <manjunath.ranganathaiah@intel.com>2018-04-04 12:45:08 -0700
committerManjunath Ranganathaiah <manjunath.ranganathaiah@intel.com>2018-04-04 12:54:43 -0700
commitcf77c7b244f0b64990dfb46a205ea97d5c1f9f40 (patch)
tree8f38dcabe783eb55e663ca67880b661b726f8f7a /cadi
parentc36423577d5b8501af78cc2f8a7db1e43eacdf0d (diff)
Add pkcs11 provider for given config
Change-Id: I0a4d06bea7333eab58d6744a1ccf628501a973eb Issue-ID: AAF-203 Signed-off-by: Manjunath Ranganathaiah <manjunath.ranganathaiah@intel.com>
Diffstat (limited to 'cadi')
-rw-r--r--cadi/aaf/src/main/java/org/onap/aaf/cadi/cm/Factory.java40
1 files changed, 19 insertions, 21 deletions
diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/cm/Factory.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/cm/Factory.java
index e969fab3..b7c085b0 100644
--- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/cm/Factory.java
+++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/cm/Factory.java
@@ -60,6 +60,8 @@ import java.security.spec.X509EncodedKeySpec;
import java.util.Collection;
import java.util.List;
+import sun.security.pkcs11.SunPKCS11;
+
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
@@ -458,28 +460,24 @@ public class Factory {
* @throws CertException
*/
public static synchronized Provider getSecurityProvider(String providerType, String[][] params) throws CertException {
- Provider p = Security.getProvider(providerType);
- if(p!=null) {
- switch(providerType) {
- case "PKCS12":
-
- break;
- case "PKCS11": // PKCS11 only known to be supported by Sun
- try {
- Class<?> clsSunPKCS11 = Class.forName("sun.security.pkcs11.SunPKCS11");
- Constructor<?> cnst = clsSunPKCS11.getConstructor(String.class);
- Object sunPKCS11 = cnst.newInstance(params[0][0]);
- if (sunPKCS11==null) {
- throw new CertException("SunPKCS11 Provider cannot be constructed for " + params[0][0]);
- }
- Security.addProvider((Provider)sunPKCS11);
- } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- throw new CertException(e);
+ Provider p = null;
+ switch(providerType) {
+ case "PKCS12":
+ p = Security.getProvider(providerType);
+ break;
+ case "PKCS11": // PKCS11 only known to be supported by Sun
+ try {
+ p = new SunPKCS11(params[0][0]);
+ if (p==null) {
+ throw new CertException("SunPKCS11 Provider cannot be constructed for " + params[0][0]);
}
- break;
- default:
- throw new CertException(providerType + " is not a known Security Provider for your JDK.");
- }
+ Security.addProvider(p);
+ } catch (SecurityException | IllegalArgumentException e) {
+ throw new CertException(e);
+ }
+ break;
+ default:
+ throw new CertException(providerType + " is not a known Security Provider for your JDK.");
}
return p;
}