private static void close(String modulePath, Module module) { if (module == null) { return; } LOG.info("close", "close pkcs11 module: {}", modulePath); try { module.finalize(null); } catch (Throwable th) { LogUtil.error(LOG, th, "could not close module " + modulePath); } } }
/** * Get an instance of this class by giving the name of the PKCS#11 module; * e.g. "slbck.dll". * * @param pkcs11ModuleName * The name of the module; e.g. "slbck.dll". * @return An instance of Module that is connected to the given PKCS#11 * module. * @exception IOException * If connecting to the named module fails. * @preconditions (pkcs11ModuleName <> null) * and (pkcs11ModuleName is a valid PKCS#11 module name) * @postconditions */ public static Module getInstance(String pkcs11ModuleName) throws IOException { Util.requireNonNull("pkcs11ModuleName", pkcs11ModuleName); File file = new File(pkcs11ModuleName); if (!file.exists()) { throw new FileNotFoundException( "File " + pkcs11ModuleName + " does not exist"); } if (!file.isFile()) { throw new IOException(pkcs11ModuleName + " is not a file"); } if (!file.canRead()) { throw new IOException("Can not read file " + pkcs11ModuleName + ""); } return new Module(pkcs11ModuleName); }
/** * Compares the slot ID and the module_ of this object with the slot ID and * module_ of the other object. Returns only true, if both are equal. * * @param otherObject * The other Slot object. * @return True, if other is an instance of Slot and the slot ID and module_ * of both objects are equal. False, otherwise. * @preconditions * @postconditions */ @Override public boolean equals(Object otherObject) { if (this == otherObject) { return true; } else if (!(otherObject instanceof Slot)) { return false; } Slot other = (Slot) otherObject; return (this.slotID == other.slotID) && this.module.equals(other.module); }
module = Module.getInstance(moduleConf.nativeLibrary()); } catch (IOException ex) { final String msg = "could not load the PKCS#11 module " + moduleConf.name(); module.initialize(new DefaultInitializeArgs()); } catch (PKCS11Exception ex) { if (ex.getErrorCode() != PKCS11Constants.CKR_CRYPTOKI_ALREADY_INITIALIZED) { if (LOG.isInfoEnabled()) { try { LOG.info("pkcs11.getInfo():\n{}", module.getInfo()); } catch (TokenException e2) { LOG.debug("module.getInfo()", e2);
Info info = module.getInfo(); this.description = StringUtil.concatObjects("PKCS#11 IAIK", "\n\tPath: ", library, slotList = module.getSlotList(Module.SlotRequirement.ALL_SLOTS); } catch (Throwable th) { final String msg = "could not getSlotList of module " + moduleConf.getName();
/** * Constructor taking the token and the session handle. * * @param token * The token this session operates with. * @param sessionHandle * The session handle to perform the operations with. * @preconditions (token <> null) * @postconditions */ protected Session(Token token, long sessionHandle) { this.token = Util.requireNonNull("token", token); this.module = token.getSlot().getModule(); this.pkcs11Module = module.getPKCS11Module(); this.sessionHandle = sessionHandle; }
slotList = module.getSlotList(Module.SlotRequirement.ALL_SLOTS); } catch (Throwable th) { final String msg = "could not getSlotList of module " + moduleConf.name();
module = Module.getInstance(moduleConf.getNativeLibrary()); } catch (IOException ex) { final String msg = "could not load the PKCS#11 module " + moduleConf.getName(); module.initialize(new DefaultInitializeArgs()); } catch (PKCS11Exception ex) { if (ex.getErrorCode() != PKCS11Constants.CKR_CRYPTOKI_ALREADY_INITIALIZED) { if (LOG.isInfoEnabled()) { try { LOG.info("pkcs11.getInfo():\n{}", module.getInfo()); } catch (TokenException e2) { LOG.debug("module.getInfo()", e2);
/** * Get information about this slot object. * * @return An object that contains information about this slot. * @exception TokenException * If reading the information fails. * @preconditions * @postconditions (result <> null) */ public SlotInfo getSlotInfo() throws TokenException { CK_SLOT_INFO ckSlotInfo; try { ckSlotInfo = module.getPKCS11Module().C_GetSlotInfo(slotID); } catch (sun.security.pkcs11.wrapper.PKCS11Exception ex) { throw new PKCS11Exception(ex); } return new SlotInfo(ckSlotInfo); }
private static void close(final String modulePath, final Module module) { if (module == null) { return; } LOG.info("close", "close pkcs11 module: {}", modulePath); try { module.finalize(null); } catch (Throwable th) { LogUtil.error(LOG, th, "could not close module " + modulePath); } } }
/** * Get information about this token. * * @return An object containing information about this token. * @exception TokenException * If reading the information fails. * @preconditions * @postconditions (result <> null) */ public TokenInfo getTokenInfo() throws TokenException { CK_TOKEN_INFO ckTokenInfo; try { ckTokenInfo = slot.getModule().getPKCS11Module() .C_GetTokenInfo(slot.getSlotID()); } catch (sun.security.pkcs11.wrapper.PKCS11Exception ex) { throw new PKCS11Exception(ex); } return new TokenInfo(ckTokenInfo); }
/** * Get the list of mechanisms that this token supports. An application can * use this method to determine, if this token supports the required * mechanism. * * @return An array of Mechanism objects. Each describes a mechanism that * this token can perform. This array may be empty but not null. * @exception TokenException * If reading the list of supported mechanisms fails. * @preconditions * @postconditions (result <> null) */ public Mechanism[] getMechanismList() throws TokenException { long[] mechanismIdList; try { mechanismIdList = slot.getModule().getPKCS11Module() .C_GetMechanismList(slot.getSlotID()); } catch (sun.security.pkcs11.wrapper.PKCS11Exception ex) { throw new PKCS11Exception(ex); } Mechanism[] mechanisms = new Mechanism[mechanismIdList.length]; for (int i = 0; i < mechanisms.length; i++) { mechanisms[i] = new Mechanism(mechanismIdList[i]); } return mechanisms; }
/** * Get more information about one supported mechanism. The application can * find out, e.g. if an algorithm supports the certain key length. * * @param mechanism * A mechanism that is supported by this token. * @return An information object about the concerned mechanism. * @exception TokenException * If reading the information fails, or if the mechanism is not * supported by this token. * @preconditions (mechanism <> null) * and (getMechanismList() contains mechanism) * @postconditions (result <> null) */ public MechanismInfo getMechanismInfo(Mechanism mechanism) throws TokenException { long mechanismCode = mechanism.getMechanismCode(); CK_MECHANISM_INFO ckMechanismInfo; try { ckMechanismInfo = slot.getModule().getPKCS11Module() .C_GetMechanismInfo(slot.getSlotID(), mechanismCode); } catch (sun.security.pkcs11.wrapper.PKCS11Exception ex) { throw new PKCS11Exception(ex); } return new MechanismInfo(ckMechanismInfo); }
sessionHandle = slot.getModule().getPKCS11Module() .C_OpenSession(slot.getSlotID(), flags, application, ckNotify); } catch (sun.security.pkcs11.wrapper.PKCS11Exception ex) {
Util.requireNonNull("attributes", attributes); PKCS11 pkcs11Module = session.getModule().getPKCS11Module(); long sessionHandle = session.getSessionHandle();
Util.requireNonNull("session", session); PKCS11 pkcs11Module = session.getModule().getPKCS11Module(); long sessionHandle = session.getSessionHandle(); long attributeCode = attribute.getCkAttribute().type;