当前位置: 首页>>代码示例>>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;未经允许,请勿转载。