private Session openSession(final boolean rwSession) throws P11TokenException { Session session; try { session = slot.getToken().openSession(Token.SessionType.SERIAL_SESSION, rwSession, null, null); } catch (TokenException ex) { throw new P11TokenException(ex.getMessage(), ex); } countSessions.incrementAndGet(); return session; }
/** * Get an object for handling the token that is currently present in this * slot, or null, if there is no token present. * * @return The object for accessing the token. Or null, if none is present * in this slot. * @exception TokenException * If determining if a token is present fails. * @preconditions * @postconditions */ public Token getToken() throws TokenException { Token token = null; if (getSlotInfo().isTokenPresent()) { token = new Token(this); } return token; }
/** * Compares the sessionHandle and token of this object with the other * object. Returns only true, if those are equal in both objects. * * @param otherObject * The other Session object. * @return True, if other is an instance of Token and the session handles * and tokens of both objects are equal. False, otherwise. * @preconditions * @postconditions */ @Override public boolean equals(Object otherObject) { if (this == otherObject) { return true; } else if (!(otherObject instanceof Session)) { return false; } Session other = (Session) otherObject; if (this.sessionHandle != other.sessionHandle) { return false; } return this.token.equals(other.token); }
private void login(final Session session) throws P11TokenException { boolean isSessionLoggedIn = checkSessionLoggedIn(session); if (isSessionLoggedIn) { return; } boolean loginRequired; try { loginRequired = session.getToken().getTokenInfo().isLoginRequired(); } catch (TokenException ex) { LogUtil.error(LOG, ex, "could not check whether LoginRequired of token"); loginRequired = true; } LOG.debug("loginRequired: {}", loginRequired); if (!loginRequired) { return; } if (CollectionUtil.isEmpty(password)) { singleLogin(session, null); } else { for (char[] singlePwd : password) { singleLogin(session, singlePwd); } } }
Mechanism[] mechanisms; try { mechanisms = slot.getToken().getMechanismList(); } catch (TokenException ex) { throw new P11TokenException("could not getMechanismList: " + ex.getMessage(), ex);
/** * 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; }
private void login(Session session) throws P11TokenException { boolean isSessionLoggedIn = checkSessionLoggedIn(session); if (isSessionLoggedIn) { return; } boolean loginRequired; try { loginRequired = session.getToken().getTokenInfo().isLoginRequired(); } catch (TokenException ex) { LogUtil.error(LOG, ex, "could not check whether LoginRequired of token"); loginRequired = true; } LOG.debug("loginRequired: {}", loginRequired); if (!loginRequired) { return; } if (CollectionUtil.isEmpty(password)) { singleLogin(session, null); } else { for (char[] singlePwd : password) { singleLogin(session, singlePwd); } } }
Mechanism[] mechanisms; try { mechanisms = slot.getToken().getMechanismList(); } catch (TokenException ex) { throw new P11TokenException("could not getMechanismList: " + ex.getMessage(), ex);
private void firstLogin(Session session, List<char[]> password) throws P11TokenException { try { boolean isProtectedAuthenticationPath = session.getToken().getTokenInfo().isProtectedAuthenticationPath(); if (isProtectedAuthenticationPath || CollectionUtil.isEmpty(password)) { LOG.info("verify on PKCS11Module with PROTECTED_AUTHENTICATION_PATH"); singleLogin(session, null); } else { LOG.info("verify on PKCS11Module with PIN"); for (char[] singlePwd : password) { singleLogin(session, singlePwd); } this.password = password; } } catch (PKCS11Exception ex) { // 0x100: user already logged in if (ex.getErrorCode() != 0x100) { throw new P11TokenException(ex.getMessage(), ex); } } catch (TokenException ex) { throw new P11TokenException(ex.getMessage(), ex); } }
private Session openSession() throws P11TokenException { Session session; try { boolean rw = !isReadOnly(); session = slot.getToken().openSession(Token.SessionType.SERIAL_SESSION, rw, null, null); } catch (TokenException ex) { throw new P11TokenException(ex.getMessage(), ex); } countSessions.incrementAndGet(); return session; }
private void firstLogin(final Session session, final List<char[]> password) throws P11TokenException { try { boolean isProtectedAuthenticationPath = session.getToken().getTokenInfo().isProtectedAuthenticationPath(); if (isProtectedAuthenticationPath || CollectionUtil.isEmpty(password)) { LOG.info("verify on PKCS11Module with PROTECTED_AUTHENTICATION_PATH"); singleLogin(session, null); } else { LOG.info("verify on PKCS11Module with PIN"); for (char[] singlePwd : password) { singleLogin(session, singlePwd); } this.password = password; } } catch (PKCS11Exception ex) { // 0x100: user already logged in if (ex.getErrorCode() != 0x100) { throw new P11TokenException(ex.getMessage(), ex); } } catch (TokenException ex) { throw new P11TokenException(ex.getMessage(), ex); } }
maxSessionCount2 = token.getTokenInfo().getMaxSessionCount(); } catch (TokenException ex) { throw new P11TokenException("could not get tokenInfo: " + ex.getMessage(), ex);
maxSessionCount2 = token.getTokenInfo().getMaxSessionCount(); } catch (TokenException ex) { throw new P11TokenException("could not get tokenInfo: " + ex.getMessage(), ex);