@Override public Set<String> getModuleNames() { try { init(); } catch (InvalidConfException ex) { throw new IllegalStateException( "could not initialize P11CryptServiceFactory: " + ex.getMessage(), ex); } return moduleNames; }
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; }
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); }