/** * 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; }
/** * 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); }
/** * 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;