@Override public void close() { if (p11ModuleFactoryRegister != null) { try { p11ModuleFactoryRegister.close(); } catch (Throwable th) { LOG.error("error while closing P11ModuleFactoryRegister", th); } p11ModuleFactoryRegister = null; } if (p11CryptServiceFactory != null) { try { p11CryptServiceFactory.close(); } catch (Throwable th) { LOG.error("error while closing P11CryptServiceFactory", th); } this.p11CryptServiceFactory = null; } }
@Override public Set<String> getModuleNames() { try { init(); } catch (InvalidConfException ex) { throw new IllegalStateException( "could not initialize P11CryptServiceFactory: " + ex.getMessage(), ex); } return moduleNames; }
private void initSecurityPkcs11(String pkcs11ConfFile, SignerFactoryRegisterImpl signerFactoryRegister) throws InvalidConfException { p11ModuleFactoryRegister = new P11ModuleFactoryRegisterImpl(); p11ModuleFactoryRegister.registFactory(new EmulatorP11ModuleFactory()); p11ModuleFactoryRegister.registFactory(new IaikP11ModuleFactory()); p11ModuleFactoryRegister.registFactory(new ProxyP11ModuleFactory()); p11CryptServiceFactory = new P11CryptServiceFactoryImpl(); p11CryptServiceFactory.setP11ModuleFactoryRegister(p11ModuleFactoryRegister); p11CryptServiceFactory.setPasswordResolver(passwordResolver); p11CryptServiceFactory.setPkcs11ConfFile(pkcs11ConfFile); p11CryptServiceFactory.init(); P11SignerFactory p11SignerFactory = new P11SignerFactory(); p11SignerFactory.setSecurityFactory(securityFactory); p11SignerFactory.setP11CryptServiceFactory(p11CryptServiceFactory); signerFactoryRegister.registFactory(p11SignerFactory); }
public synchronized P11CryptService getP11CryptService(String moduleName) throws XiSecurityException, P11TokenException { try { init(); } catch (InvalidConfException ex) { throw new IllegalStateException( "could not initialize P11CryptServiceFactory: " + ex.getMessage(), ex); } if (moduleConfs == null) { throw new IllegalStateException("please set pkcs11ConfFile and then call init() first"); } final String name = getModuleName(moduleName); P11ModuleConf conf = moduleConfs.get(name); if (conf == null) { throw new XiSecurityException("PKCS#11 module " + name + " is not defined"); } P11CryptService instance = services.get(name); if (instance == null) { P11Module p11Module = p11ModuleFactoryRegister.getP11Module(conf); instance = new P11CryptService(p11Module); LOG.info("added PKCS#11 module {}\n{}", name, instance.getModule().getDescription()); services.put(name, instance); } return instance; }
public synchronized P11CryptService getP11CryptService(String moduleName) throws XiSecurityException, P11TokenException { if (p11Conf == null) { throw new IllegalStateException("please set pkcs11ConfFile and then call init() first"); } final String name = getModuleName(moduleName); P11ModuleConf conf = p11Conf.getModuleConf(name); if (conf == null) { throw new XiSecurityException("PKCS#11 module " + name + " is not defined"); } P11CryptService instance = services.get(moduleName); if (instance == null) { P11Module p11Module = p11ModuleFactoryRegister.getP11Module(conf); instance = new P11CryptService(p11Module); LOG.info("added PKCS#11 module {}\n{}", moduleName, instance.getModule().getDescription()); services.put(moduleName, instance); } return instance; }
public synchronized P11CryptService getP11CryptService(final String moduleName) throws XiSecurityException, P11TokenException { if (p11Conf == null) { throw new IllegalStateException("please set pkcs11ConfFile and then call init() first"); } final String name = getModuleName(moduleName); P11ModuleConf conf = p11Conf.moduleConf(name); if (conf == null) { throw new XiSecurityException("PKCS#11 module " + name + " is not defined"); } P11CryptService instance = services.get(moduleName); if (instance != null) { return instance; } String nativeLib = conf.nativeLibrary(); P11Module p11Module = modules.get(nativeLib); if (p11Module == null) { if (StringUtil.startsWithIgnoreCase(nativeLib, ProxyP11Module.PREFIX)) { p11Module = ProxyP11Module.getInstance(conf); } else if (StringUtil.startsWithIgnoreCase(nativeLib, EmulatorP11Module.PREFIX)) { p11Module = EmulatorP11Module.getInstance(conf); } else { p11Module = IaikP11Module.getInstance(conf); } } modules.put(nativeLib, p11Module); instance = new P11CryptService(p11Module); services.put(moduleName, instance); return instance; }