public void shutdown() { for (String pk11Lib : modules.keySet()) { try { modules.get(pk11Lib).close(); } catch (Throwable th) { LogUtil.error(LOG, th, "could not close PKCS11 Module " + pk11Lib); } } modules.clear(); services.clear(); }
public synchronized void refresh() throws P11TokenException { LOG.info("refreshing PKCS#11 module {}", module.getName()); List<P11SlotIdentifier> slotIds = module.getSlotIds(); for (P11SlotIdentifier slotId : slotIds) { P11Slot slot; try { slot = module.getSlot(slotId); } catch (P11TokenException ex) { LogUtil.warn(LOG, ex, "P11TokenException while initializing slot " + slotId); continue; } catch (Throwable th) { LOG.error("unexpected error while initializing slot " + slotId, th); continue; } slot.refresh(); } LOG.info("refreshed PKCS#11 module {}", module.getName()); } // method refresh
@Override public boolean isReadOnly() { return readOnly || super.isReadOnly(); }
public synchronized void refresh() throws P11TokenException { LOG.info("refreshing PKCS#11 module {}", module.getName()); List<P11SlotIdentifier> slotIds = module.slotIdentifiers(); for (P11SlotIdentifier slotId : slotIds) { P11Slot slot; try { slot = module.getSlot(slotId); } catch (P11TokenException ex) { LogUtil.warn(LOG, ex, "P11TokenException while initializing slot " + slotId); continue; } catch (Throwable th) { LOG.error("unexpected error while initializing slot " + slotId, th); continue; } slot.refresh(); } LOG.info("refreshed PKCS#11 module {}", module.getName()); } // method refresh
P11SlotIdentifier p11SlotId; if (slotId != null) { p11SlotId = module.getSlotIdForId(slotId); } else if (slotIndex != null) { p11SlotId = module.getSlotIdForIndex(slotIndex); } else { throw new RuntimeException("should not reach here"); slot = module.getSlot(p11SlotId); } catch (P11TokenException | XiSecurityException ex) { throw new ObjectCreationException(ex.getMessage(), ex);
public P11Slot getSlot(final P11SlotIdentifier slotId) throws P11TokenException { return module.getSlot(slotId); }
private void engineLoad(String moduleName) throws P11TokenException, XiSecurityException { P11CryptService p11Service = p11CryptServiceFactory.getP11CryptService(moduleName); P11Module module = p11Service.getModule(); List<P11SlotIdentifier> slotIds = module.getSlotIds(); for (P11SlotIdentifier slotId: slotIds) { P11Slot slot = module.getSlot(slotId); Set<P11ObjectIdentifier> identityIds = slot.getIdentityKeyIds(); for (P11ObjectIdentifier objId : identityIds) { P11Identity identity = slot.getIdentity(objId); X509Certificate[] chain = identity.certificateChain(); if (chain == null || chain.length == 0) { continue; } P11PrivateKey key = new P11PrivateKey(p11Service, identity.getId()); KeyCertEntry keyCertEntry = new KeyCertEntry(key, chain); keyCerts.put(moduleName + "#slotid-" + slotId.getId() + "#keyid-" + objId.getIdHex(), keyCertEntry); keyCerts.put(moduleName + "#slotid-" + slotId.getId() + "#keylabel-" + objId.getLabel(), keyCertEntry); keyCerts.put(moduleName + "#slotindex-" + slotId.getIndex() + "#keyid-" + objId.getIdHex(), keyCertEntry); keyCerts.put(moduleName + "#slotindex-" + slotId.getIndex() + "#keylabel-" + objId.getLabel(), keyCertEntry); } } } // method engineLoad
private void engineLoad(final String moduleName) throws P11TokenException, XiSecurityException { P11CryptService p11Service = p11CryptServiceFactory.getP11CryptService(moduleName); P11Module module = p11Service.module(); List<P11SlotIdentifier> slotIds = module.slotIdentifiers(); for (P11SlotIdentifier slotId: slotIds) { P11Slot slot = module.getSlot(slotId); Set<P11ObjectIdentifier> identityIds = slot.identityIdentifiers(); for (P11ObjectIdentifier objId : identityIds) { P11Identity identity = slot.getIdentity(objId); X509Certificate[] chain = identity.certificateChain(); if (chain == null || chain.length == 0) { continue; } P11PrivateKey key = new P11PrivateKey(p11Service, identity.identityId()); KeyCertEntry keyCertEntry = new KeyCertEntry(key, chain); keyCerts.put(moduleName + "#slotid-" + slotId.id() + "#keyid-" + objId.idHex(), keyCertEntry); keyCerts.put(moduleName + "#slotid-" + slotId.id() + "#keylabel-" + objId.label(), keyCertEntry); keyCerts.put(moduleName + "#slotindex-" + slotId.index() + "#keyid-" + objId.idHex(), keyCertEntry); keyCerts.put(moduleName + "#slotindex-" + slotId.index() + "#keylabel-" + objId.label(), keyCertEntry); } } } // method engineLoad
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; }
P11SlotIdentifier p11SlotId; if (slotId != null) { p11SlotId = module.getSlotIdForId(slotId); } else if (slotIndex != null) { p11SlotId = module.getSlotIdForIndex(slotIndex); } else { throw new IllegalStateException("should not reach here"); slot = module.getSlot(p11SlotId); } catch (P11TokenException | XiSecurityException ex) { throw new ObjectCreationException(ex.getMessage(), ex);
public P11Slot getSlot(P11SlotIdentifier slotId) throws P11TokenException { return module.getSlot(slotId); }
private void engineLoad(String moduleName) throws P11TokenException, XiSecurityException { P11CryptService p11Service = p11CryptServiceFactory.getP11CryptService(moduleName); P11Module module = p11Service.getModule(); List<P11SlotIdentifier> slotIds = module.getSlotIds(); for (P11SlotIdentifier slotId: slotIds) { P11Slot slot = module.getSlot(slotId); Set<P11ObjectIdentifier> identityIds = slot.getIdentityKeyIds(); for (P11ObjectIdentifier objId : identityIds) { P11Identity identity = slot.getIdentity(objId); X509Certificate[] chain = identity.certificateChain(); if (chain == null || chain.length == 0) { continue; } P11PrivateKey key = new P11PrivateKey(p11Service, identity.getId()); KeyCertEntry keyCertEntry = new KeyCertEntry(key, chain); keyCerts.put(moduleName + "#slotid-" + slotId.getId() + "#keyid-" + objId.getIdHex(), keyCertEntry); keyCerts.put(moduleName + "#slotid-" + slotId.getId() + "#keylabel-" + objId.getLabel(), keyCertEntry); keyCerts.put(moduleName + "#slotindex-" + slotId.getIndex() + "#keyid-" + objId.getIdHex(), keyCertEntry); keyCerts.put(moduleName + "#slotindex-" + slotId.getIndex() + "#keylabel-" + objId.getLabel(), keyCertEntry); } } } // method engineLoad
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; }
P11SlotIdentifier p11SlotId; if (slotId != null) { p11SlotId = module.getSlotIdForId(slotId); } else if (slotIndex != null) { p11SlotId = module.getSlotIdForIndex(slotIndex); } else { throw new RuntimeException("should not reach here"); slot = module.getSlot(p11SlotId); } catch (P11TokenException | XiSecurityException ex) { throw new ObjectCreationException(ex.getMessage(), ex);
public synchronized void refresh() throws P11TokenException { LOG.info("refreshing PKCS#11 module {}", module.getName()); List<P11SlotIdentifier> slotIds = module.getSlotIds(); for (P11SlotIdentifier slotId : slotIds) { P11Slot slot; try { slot = module.getSlot(slotId); } catch (P11TokenException ex) { LogUtil.warn(LOG, ex, "P11TokenException while initializing slot " + slotId); continue; } catch (Throwable th) { LOG.error("unexpected error while initializing slot " + slotId, th); continue; } slot.refresh(); } LOG.info("refreshed PKCS#11 module {}", module.getName()); } // method refresh
public P11Slot getSlot(P11SlotIdentifier slotId) throws P11TokenException { return module.getSlot(slotId); }
@Override public void close() { for (String pk11Lib : modules.keySet()) { try { modules.get(pk11Lib).close(); } catch (Throwable th) { LogUtil.error(LOG, th, "could not close PKCS11 Module " + pk11Lib); } } modules.clear(); factories.clear(); }
public P11Identity getIdentity(P11SlotIdentifier slotId, P11ObjectIdentifier keyId) throws P11TokenException { P11Slot slot = module.getSlot(slotId); return (slot == null) ? null : slot.getIdentity(keyId); }
public void shutdown() { for (String pk11Lib : modules.keySet()) { try { modules.get(pk11Lib).close(); } catch (Throwable th) { LogUtil.error(LOG, th, "could not close PKCS11 Module " + pk11Lib); } } modules.clear(); services.clear(); }
public P11Identity getIdentity(P11SlotIdentifier slotId, P11ObjectIdentifier keyId) throws P11TokenException { P11Slot slot = module.getSlot(slotId); return (slot == null) ? null : slot.getIdentity(keyId); }