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


Java Module类代码示例

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


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

示例1: unsetModule

import iaik.pkcs.pkcs11.Module; //导入依赖的package包/类
public Response unsetModule(HttpServletRequest req) {
	Module m = (Module) req.getSession().getAttribute("module");
	if(m == null)
		throw new WebApplicationException(
				Response.status(Status.BAD_REQUEST).entity(new ErrorEntity("Module not initialized")).build());
	try {
		m.finalize();
		
	} catch (Throwable e) {
		//throw new WebApplicationException(
		//		Response.status(Status.BAD_REQUEST).entity(new ErrorEntity("Module can't be finalized")).build());
	}
	req.getSession().removeAttribute("module");
	return Response.status(Status.NO_CONTENT).build();
	
}
 
开发者ID:klamouri,项目名称:PKCS11-WEB-API,代码行数:17,代码来源:ModuleWebServiceImplementation.java

示例2: init

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

示例3: getSlot

import iaik.pkcs.pkcs11.Module; //导入依赖的package包/类
private Slot getSlot(long slotID) throws Exception, Error{
    if(pkcs11Module==null)
        throw new Exception("pkcs11Module not initialized");
    Slot[] slotList = pkcs11Module.getSlotList(Module.SlotRequirement.TOKEN_PRESENT);
    for(Slot slot:slotList)
        if(slot.getSlotID()==slotID)
            return slot;
    throw new Exception("Slot not found");
}
 
开发者ID:damianofalcioni,项目名称:Websocket-Smart-Card-Signer,代码行数:10,代码来源:SmartCardAccessIaikImpl.java

示例4: close

import iaik.pkcs.pkcs11.Module; //导入依赖的package包/类
private static void close(String modulePath, Module module) {
    if (module == null) {
        return;
    }

    LOG.info("close", "close pkcs11 module: {}", modulePath);
    try {
        module.finalize(null);
    } catch (Throwable th) {
        LogUtil.error(LOG, th, "could not close module " + modulePath);
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:13,代码来源:IaikP11Module.java

示例5: nbSlot

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

示例6: reset

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

示例7: getLocalSession

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

示例8: toto

import iaik.pkcs.pkcs11.Module; //导入依赖的package包/类
@POST
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public String toto(Library l){
	try {
		Module m = Module.getInstance(l.getPath());
		if (m != null)
			return "PKCS11 Wrapper correctly setup";
		else
			return "Oops, there was a problem with the PKCS11 Wrapper";
	} catch (IOException e) {
		return "Oops, there was a problem with the PKCS11 Wrapper";
	}
}
 
开发者ID:klamouri,项目名称:PKCS11-WEB-API,代码行数:15,代码来源:TestPKCS11.java

示例9: slotInfos

import iaik.pkcs.pkcs11.Module; //导入依赖的package包/类
public SlotInfoResponse slotInfos(HttpServletRequest req, int idSlot, List<String> select) {
	SlotInfoResponse r = new SlotInfoResponse();
	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 (idSlot > 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());
		if (select.size() == 0)
			throw new WebApplicationException(Response.status(Status.BAD_REQUEST)
					.entity(new ErrorEntity("You didn't specified any select")).build());

		if (select.contains("*")) {
			select.clear();
			select.add("manufacturerID");
			select.add("slotDescription");
			select.add("isHardwareSlot");
			select.add("isRemovableDevice");
			select.add("isTokenPresent");
		}

		Slot s = slots[idSlot];

		if (select.contains("manufacturerID"))
			r.setManufacturerID(s.getSlotInfo().getManufacturerID().trim());
		if (select.contains("slotDescription"))
			r.setSlotDescription(s.getSlotInfo().getSlotDescription().trim());
		if (select.contains("isHardwareSlot"))
			r.setHardwareSlot(s.getSlotInfo().isHwSlot());
		if (select.contains("isRemovableDevice"))
			r.setRemovableDevice(s.getSlotInfo().isRemovableDevice());
		if (select.contains("isTokenPresent"))
			r.setTokenPresent(s.getSlotInfo().isTokenPresent());
		if (select.contains("idToken"))
			r.setIdToken(s.getToken().getTokenID());
		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,代码行数:46,代码来源:SlotWebServiceImplementation.java

示例10: tokenMechanisms

import iaik.pkcs.pkcs11.Module; //导入依赖的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.Module类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。