當前位置: 首頁>>代碼示例>>Java>>正文


Java TokenException類代碼示例

本文整理匯總了Java中iaik.pkcs.pkcs11.TokenException的典型用法代碼示例。如果您正苦於以下問題:Java TokenException類的具體用法?Java TokenException怎麽用?Java TokenException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TokenException類屬於iaik.pkcs.pkcs11包,在下文中一共展示了TokenException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkSessionLoggedIn

import iaik.pkcs.pkcs11.TokenException; //導入依賴的package包/類
private static boolean checkSessionLoggedIn(Session session) throws P11TokenException {
    SessionInfo info;
    try {
        info = session.getSessionInfo();
    } catch (TokenException ex) {
        throw new P11TokenException(ex.getMessage(), ex);
    }
    if (LOG.isTraceEnabled()) {
        LOG.debug("SessionInfo: {}", info);
    }

    State state = info.getState();
    long deviceError = info.getDeviceError();

    LOG.debug("to be verified PKCS11Module: state = {}, deviceError: {}", state, deviceError);

    boolean isRwSessionLoggedIn = state.equals(State.RW_USER_FUNCTIONS);
    boolean isRoSessionLoggedIn = state.equals(State.RO_USER_FUNCTIONS);

    boolean sessionLoggedIn = ((isRoSessionLoggedIn || isRwSessionLoggedIn)
            && deviceError == 0);
    LOG.debug("sessionLoggedIn: {}", sessionLoggedIn);
    return sessionLoggedIn;
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:25,代碼來源:IaikP11Slot.java

示例2: removeCerts0

import iaik.pkcs.pkcs11.TokenException; //導入依賴的package包/類
@Override
protected void removeCerts0(P11ObjectIdentifier objectId) throws P11TokenException {
    X509PublicKeyCertificate[] existingCerts = getCertificateObjects(objectId.id(),
            objectId.labelChars());
    if (existingCerts == null || existingCerts.length == 0) {
        LOG.warn("could not find certificates " + objectId);
        return;
    }

    Session session = borrowWritableSession();
    try {
        for (X509PublicKeyCertificate cert : existingCerts) {
            session.destroyObject(cert);
        }
    } catch (TokenException ex) {
        throw new P11TokenException(ex.getMessage(), ex);
    } finally {
        returnWritableSession(session);
    }
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:21,代碼來源:IaikP11Slot.java

示例3: idExists

import iaik.pkcs.pkcs11.TokenException; //導入依賴的package包/類
private static boolean idExists(Session session, byte[] keyId) throws P11TokenException {
    Key key = new Key();
    key.getId().setByteArrayValue(keyId);

    Object[] objects;
    try {
        session.findObjectsInit(key);
        objects = session.findObjects(1);
        session.findObjectsFinal();
        if (objects.length > 0) {
            return true;
        }

        X509PublicKeyCertificate cert = new X509PublicKeyCertificate();
        cert.getId().setByteArrayValue(keyId);

        session.findObjectsInit(cert);
        objects = session.findObjects(1);
        session.findObjectsFinal();
    } catch (TokenException ex) {
        throw new P11TokenException(ex.getMessage(), ex);
    }

    return objects.length > 0;
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:26,代碼來源:IaikP11Slot.java

示例4: labelExists

import iaik.pkcs.pkcs11.TokenException; //導入依賴的package包/類
private static boolean labelExists(Session session, String keyLabel) throws P11TokenException {
    ParamUtil.requireNonBlank("keyLabel", keyLabel);
    Key key = new Key();
    key.getLabel().setCharArrayValue(keyLabel.toCharArray());

    Object[] objects;
    try {
        session.findObjectsInit(key);
        objects = session.findObjects(1);
        session.findObjectsFinal();
        if (objects.length > 0) {
            return true;
        }

        X509PublicKeyCertificate cert = new X509PublicKeyCertificate();
        cert.getLabel().setCharArrayValue(keyLabel.toCharArray());

        session.findObjectsInit(cert);
        objects = session.findObjects(1);
        session.findObjectsFinal();
    } catch (TokenException ex) {
        throw new P11TokenException(ex.getMessage(), ex);
    }

    return objects.length > 0;
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:27,代碼來源:IaikP11Slot.java

示例5: init

import iaik.pkcs.pkcs11.TokenException; //導入依賴的package包/類
public Response init(HttpServletRequest req, InitTokenBeanRequest r, int idToken) {
	Module m = (Module) req.getSession().getAttribute("module");
	if (m == null)
		throw new WebApplicationException(
				Response.status(Status.UNAUTHORIZED).entity(new ErrorEntity("Module is not initialized")).build());
	try {
		Slot[] slots;
		slots = m.getSlotList(Module.SlotRequirement.ALL_SLOTS);
		if (idToken > slots.length)
			throw new WebApplicationException(Response.status(Status.BAD_REQUEST)
					.entity(new ErrorEntity("You're trying to use an out of range ID for the token")).build());
		Token t = slots[idToken].getToken();
		if (t.getTokenInfo().isTokenInitialized())
			throw new WebApplicationException(Response.status(Status.UNAUTHORIZED)
					.entity(new ErrorEntity("Your token is already initialized")).build());
		t.initToken(r.getPinSO().toCharArray(), r.getLabel());
	} catch (TokenException e) {
		throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR)
				.entity(new ErrorEntity("Ooops- Problem while retriving the slots")).build());
	}

	return Response.status(Status.NO_CONTENT).build();

}
 
開發者ID:klamouri,項目名稱:PKCS11-WEB-API,代碼行數:25,代碼來源:TokenWebServiceImplementation.java

示例6: logout

import iaik.pkcs.pkcs11.TokenException; //導入依賴的package包/類
public Response logout(HttpServletRequest req, int idToken) {
	@SuppressWarnings("unchecked")
	Map<Integer, Session> map = (Map<Integer, Session>) req.getSession().getAttribute("session");
	if (map !=null && map.get(Integer.valueOf(idToken)) != null){
		Session s = map.get(Integer.valueOf(idToken));
		try {
			s.getToken().closeAllSessions();
		} catch (TokenException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		req.getSession().removeAttribute("session");
		return Response.status(Status.NO_CONTENT).build();
	}
		
	else
		return Response.status(Status.UNAUTHORIZED).build();
}
 
開發者ID:klamouri,項目名稱:PKCS11-WEB-API,代碼行數:19,代碼來源:SessionWebServiceImplementation.java

示例7: singleSign

import iaik.pkcs.pkcs11.TokenException; //導入依賴的package包/類
private byte[] singleSign(long mechanism, P11Params parameters, byte[] content,
        IaikP11Identity identity) throws P11TokenException {
    Key signingKey = identity.signingKey();
    Mechanism mechanismObj = getMechanism(mechanism, parameters);
    if (LOG.isTraceEnabled()) {
        LOG.debug("sign with signing key:\n{}", signingKey);
    }

    ConcurrentBagEntry<Session> session0 = borrowSession();
    if (session0 == null) {
        throw new P11TokenException("no idle session available");
    }

    byte[] signature;
    try {
        Session session = session0.value();
        synchronized (session) {
            session.signInit(mechanismObj, signingKey);
            signature = session.sign(content);
        }
    } catch (TokenException ex) {
        throw new P11TokenException(ex.getMessage(), ex);
    } finally {
        sessions.requite(session0);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("signature:\n{}", Hex.toHexString(signature));
    }
    return signature;
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:32,代碼來源:IaikP11Slot.java

示例8: openSession

import iaik.pkcs.pkcs11.TokenException; //導入依賴的package包/類
private Session openSession(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;
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:12,代碼來源:IaikP11Slot.java

示例9: login

import iaik.pkcs.pkcs11.TokenException; //導入依賴的package包/類
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);
        }
    }
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:28,代碼來源:IaikP11Slot.java

示例10: singleLogin

import iaik.pkcs.pkcs11.TokenException; //導入依賴的package包/類
private void singleLogin(Session session, char[] pin) throws P11TokenException {
    char[] tmpPin = pin;
    // some driver does not accept null PIN
    if (pin == null) {
        tmpPin = new char[]{};
    }

    try {
        session.login(userType, tmpPin);
    } catch (TokenException ex) {
        throw new P11TokenException(ex.getMessage(), ex);
    }
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:14,代碼來源:IaikP11Slot.java

示例11: removeObjects

import iaik.pkcs.pkcs11.TokenException; //導入依賴的package包/類
private int removeObjects(Storage template, String desc) throws P11TokenException {
    Session session = borrowWritableSession();
    try {
        List<Storage> objects = getObjects(session, template);
        for (Storage obj : objects) {
            session.destroyObject(obj);
        }
        return objects.size();
    } catch (TokenException ex) {
        LogUtil.error(LOG, ex, "could not remove " + desc);
        throw new P11TokenException(ex.getMessage(), ex);
    } finally {
        returnWritableSession(session);
    }
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:16,代碼來源:IaikP11Slot.java

示例12: addCert0

import iaik.pkcs.pkcs11.TokenException; //導入依賴的package包/類
@Override
protected void addCert0(P11ObjectIdentifier objectId, X509Certificate cert)
        throws P11TokenException {
    X509PublicKeyCertificate newCaCertTemp = createPkcs11Template(
            new X509Cert(cert), objectId.id(), objectId.labelChars());
    Session session = borrowWritableSession();
    try {
        session.createObject(newCaCertTemp);
    } catch (TokenException ex) {
        throw new P11TokenException(ex.getMessage(), ex);
    } finally {
        returnWritableSession(session);
    }
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:15,代碼來源:IaikP11Slot.java

示例13: createSecretKey0

import iaik.pkcs.pkcs11.TokenException; //導入依賴的package包/類
@Override
protected P11Identity createSecretKey0(long keyType, byte[] keyValue, String label,
        P11NewKeyControl control) throws P11TokenException {
    // The SecretKey class does not support the specification of valueLen
    // So we use GenericSecretKey and set the KeyType manual.
    ValuedSecretKey template = new ValuedSecretKey(keyType);
    template.getToken().setBooleanValue(true);
    template.getLabel().setCharArrayValue(label.toCharArray());
    template.getSign().setBooleanValue(true);
    template.getSensitive().setBooleanValue(true);
    template.getExtractable().setBooleanValue(control.isExtractable());
    template.getValue().setByteArrayValue(keyValue);
    template.getValueLen().setLongValue((long) keyValue.length);

    SecretKey key;
    Session session = borrowWritableSession();
    try {
        if (labelExists(session, label)) {
            throw new IllegalArgumentException(
                    "label " + label + " exists, please specify another one");
        }

        byte[] id = generateKeyId(session);
        template.getId().setByteArrayValue(id);
        try {
            key = (SecretKey) session.createObject(template);
        } catch (TokenException ex) {
            throw new P11TokenException("could not create secret key", ex);
        }

        P11ObjectIdentifier objId = new P11ObjectIdentifier(id, label);
        P11EntityIdentifier entityId = new P11EntityIdentifier(slotId, objId);

        return new IaikP11Identity(this, entityId, key);
    } finally {
        returnWritableSession(session);
    }
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:39,代碼來源:IaikP11Slot.java

示例14: nbSlot

import iaik.pkcs.pkcs11.TokenException; //導入依賴的package包/類
public NbSlotBeanResponse nbSlot(HttpServletRequest req) {
	NbSlotBeanResponse r = new NbSlotBeanResponse();
	Module m = (Module) req.getSession().getAttribute("module");
	if (m == null)
		throw new WebApplicationException(
				Response.status(Status.UNAUTHORIZED).entity(new ErrorEntity("Module is not initialized")).build());
	try {
		r.setNbSlot(m.getSlotList(Module.SlotRequirement.ALL_SLOTS).length);
		return r;
	} catch (TokenException e) {
		throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR)
				.entity(new ErrorEntity("Ooops- Problem while retriving the slots")).build());
	}
}
 
開發者ID:klamouri,項目名稱:PKCS11-WEB-API,代碼行數:15,代碼來源:SlotWebServiceImplementation.java

示例15: reset

import iaik.pkcs.pkcs11.TokenException; //導入依賴的package包/類
public Response reset(HttpServletRequest req, InitTokenBeanRequest r, int idToken) {
	Module m = (Module) req.getSession().getAttribute("module");
	if (m == null)
		throw new WebApplicationException(
				Response.status(Status.UNAUTHORIZED).entity(new ErrorEntity("Module is not initialized")).build());
	try {
		Slot[] slots;
		slots = m.getSlotList(Module.SlotRequirement.ALL_SLOTS);
		if (idToken > slots.length)
			throw new WebApplicationException(Response.status(Status.BAD_REQUEST)
					.entity(new ErrorEntity("You're trying to use an out of range ID for the token")).build());
		Token t = slots[idToken].getToken();
		if (!t.getTokenInfo().isTokenInitialized())
			throw new WebApplicationException(Response.status(Status.UNAUTHORIZED)
					.entity(new ErrorEntity("Your token is not initialized")).build());

		if (t.getTokenInfo().isProtectedAuthenticationPath()) {
			t.initToken(null, r.getLabel());
		} else {
			t.initToken(r.getPinSO().toCharArray(), r.getLabel());
		}

	} catch (TokenException ee) {
		if (ee.getMessage().equals("CKR_SESSION_EXISTS"))
			throw new WebApplicationException(Response.status(Status.BAD_REQUEST)
					.entity(new ErrorEntity("You should not be logged")).build());
		throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR)
				.entity(new ErrorEntity("Ooops- Problem while retriving the slots")).build());
	}

	return Response.status(Status.NO_CONTENT).build();

}
 
開發者ID:klamouri,項目名稱:PKCS11-WEB-API,代碼行數:34,代碼來源:TokenWebServiceImplementation.java


注:本文中的iaik.pkcs.pkcs11.TokenException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。