当前位置: 首页>>代码示例>>Java>>正文


Java Token类代码示例

本文整理汇总了Java中iaik.pkcs.pkcs11.Token的典型用法代码示例。如果您正苦于以下问题:Java Token类的具体用法?Java Token怎么用?Java Token使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Token类属于iaik.pkcs.pkcs11包,在下文中一共展示了Token类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import iaik.pkcs.pkcs11.Token; //导入依赖的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

示例2: getCertificateList

import iaik.pkcs.pkcs11.Token; //导入依赖的package包/类
public ArrayList<CertificateData> getCertificateList(long slotID) throws Exception, Error{
    ArrayList<CertificateData> ret = new ArrayList<CertificateData>();
    
    session = getSlot(slotID).getToken().openSession(Token.SessionType.SERIAL_SESSION, Token.SessionReadWriteBehavior.RO_SESSION, null, null);
    try {
        session.findObjectsInit(new X509PublicKeyCertificate());
        iaik.pkcs.pkcs11.objects.Object[] publicKeyCertificateObjectList = session.findObjects(1024);

        for(iaik.pkcs.pkcs11.objects.Object publicKeyCertificateObject : publicKeyCertificateObjectList){
            X509PublicKeyCertificate publicKeyCertificate = (X509PublicKeyCertificate) publicKeyCertificateObject;
            byte[] id = publicKeyCertificate.getId().getByteArrayValue();
            byte[] label = publicKeyCertificate.getLabel().toString(false).getBytes();
            byte[] certBytes = publicKeyCertificate.getValue().getByteArrayValue();
            X509Certificate cert = X509Utils.getX509Certificate(certBytes);
            if(!(cert.getKeyUsage()[0] || cert.getKeyUsage()[1]))
                continue;
            
            CertificateData cd = new CertificateData();
            cd.certID = id;
            cd.certLABEL = label;
            cd.cert = cert;
            ret.add(cd);
        }
        
        return ret;
    } finally {
        session.closeSession();
        session = null;
    }
}
 
开发者ID:damianofalcioni,项目名称:Websocket-Smart-Card-Signer,代码行数:31,代码来源:SmartCardAccessIaikImpl.java

示例3: login

import iaik.pkcs.pkcs11.Token; //导入依赖的package包/类
public long login(long slotID, String pin) throws Exception, Error{
    Token token = getSlot(slotID).getToken();
    session = token.openSession(Token.SessionType.SERIAL_SESSION, Token.SessionReadWriteBehavior.RO_SESSION, null, null);
    if (token.getTokenInfo().isLoginRequired()){
        if (token.getTokenInfo().isProtectedAuthenticationPath())
            session.login(Session.UserType.USER, null);
        else
            session.login(Session.UserType.USER, pin.toCharArray());
    }
    return session.getSessionHandle();
}
 
开发者ID:damianofalcioni,项目名称:Websocket-Smart-Card-Signer,代码行数:12,代码来源:SmartCardAccessIaikImpl.java

示例4: openSession

import iaik.pkcs.pkcs11.Token; //导入依赖的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

示例5: reset

import iaik.pkcs.pkcs11.Token; //导入依赖的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

示例6: getLocalSession

import iaik.pkcs.pkcs11.Token; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static Session getLocalSession(HttpServletRequest req, 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 = 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 slot")).build());
		Slot s = slots[idToken];
		Token t = s.getToken();
		TokenInfo tInfo = t.getTokenInfo();
		Session sess;
		if(tInfo.isLoginRequired()){
			// Recup session log
			Map<Integer, Session> map = (Map<Integer, Session>) req.getSession().getAttribute("session");
			if (map != null && map.get(Integer.valueOf(idToken)) != null)
				sess = map.get(Integer.valueOf(idToken));
			else
				throw new WebApplicationException(Response.status(Status.UNAUTHORIZED)
						.entity(new ErrorEntity("You need to be logged into the token to continue")).build());
		}
		else{
			//Recup session non log
			sess = t.openSession(Token.SessionType.SERIAL_SESSION, Token.SessionReadWriteBehavior.RW_SESSION, null, null);
		}
		return sess;
	} catch (TokenException e) {
		e.printStackTrace();
		throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR)
				.entity(new ErrorEntity("Ooops- Problem while retriving the session")).build());
	}
}
 
开发者ID:klamouri,项目名称:PKCS11-WEB-API,代码行数:37,代码来源:SessionWebServiceImplementation.java

示例7: tokenMechanisms

import iaik.pkcs.pkcs11.Token; //导入依赖的package包/类
public TokenMechanismsBeanResponse tokenMechanisms(HttpServletRequest req, int idToken, List<String> select) {
	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[] slotList = m.getSlotList(Module.SlotRequirement.ALL_SLOTS);
		Token tok = slotList[idToken].getToken();
		Mechanism[] mechList = tok.getMechanismList();
		TokenMechanismsBeanResponse b = new TokenMechanismsBeanResponse();
		if (select.size() == 0 || select.contains("*")){
			select.clear();
			select.add("Digest");
			select.add("FullEncryptDecrypt");
			select.add("FullSignVerify");
			select.add("KeyDerivation");
			select.add("KeyGeneration");
			select.add("KeyPairGeneration");
			select.add("SignVerifyRecover");
			select.add("SingleOperationEncryptDecrypt");
			select.add("SingleOperationSignVerify");
			select.add("WrapUnwrap");
			select.add("Other");
		}
		for(Mechanism mech : mechList){
			if(mech.isDigestMechanism() && select.contains("Digest")) {
				b.addDigest(mech.getName());
			}
			if(mech.isFullEncryptDecryptMechanism() && select.contains("FullEncryptDecrypt")) {
				b.addFullEncryptDecrypt(mech.getName());
			}
			if(mech.isFullSignVerifyMechanism() && select.contains("FullSignVerify")) {
				b.addFullSignVerify(mech.getName());
			}
			if(mech.isKeyDerivationMechanism() && select.contains("KeyDerivation")) {
				b.addKeyDerivation(mech.getName());
			}
			if(mech.isKeyGenerationMechanism() && select.contains("KeyGeneration")) {
				b.addKeyGeneration(mech.getName());
			}
			if(mech.isKeyPairGenerationMechanism() && select.contains("KeyPairGeneration")) {
				b.addKeyPairGeneration(mech.getName());
			}
			if(mech.isSignVerifyRecoverMechanism() && select.contains("SignVerifyRecover")) {
				b.addSignVerifyRecover(mech.getName());
			}
			if(mech.isSingleOperationEncryptDecryptMechanism() && select.contains("SingleOperationEncryptDecrypt")) {
				b.addSingleOperationEncryptDecrypt(mech.getName());
			}
			if(mech.isSingleOperationSignVerifyMechanism() && select.contains("SingleOperationSignVerify")) {
				b.addSingleOperationSignVerify(mech.getName());
			}
			if(mech.isWrapUnwrapMechanism() && select.contains("WrapUnwrap")) {
				b.addWrapUnwrap(mech.getName());
			}
			if(!mech.isDigestMechanism() && 
					!mech.isFullEncryptDecryptMechanism() &&
					!mech.isFullSignVerifyMechanism() &&
					!mech.isKeyDerivationMechanism() &&
					!mech.isKeyGenerationMechanism() &&
					!mech.isKeyPairGenerationMechanism() &&
					!mech.isSignVerifyRecoverMechanism() &&
					!mech.isSingleOperationEncryptDecryptMechanism() &&
					!mech.isSingleOperationSignVerifyMechanism() &&
					!mech.isWrapUnwrapMechanism() &&
					select.contains("Other")){
				if(!mech.getName().contains("Unknwon mechanism with code:")){ //thanks for bad spelling "unknwon"
					b.addOther(mech.getName());
				}
			}


		}
		return b;
	} catch (TokenException e) {
		throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR)
				.entity(new ErrorEntity("Unable to retrieve slot list")).build());
	}
}
 
开发者ID:klamouri,项目名称:PKCS11-WEB-API,代码行数:80,代码来源:TokenMechanismWebServiceImplementation.java


注:本文中的iaik.pkcs.pkcs11.Token类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。