IAIK PKCS11 wrapper support for Virtual Slot (HA)

71 Views Asked by At

Session logic implemented with IAIK seems to be on top of token, but in case of Virtual Slot (like Luna HSM High Availability) where there is no token present how to obtain a session via the IAIK Java PKCS11 wrapper? Please find the code snippet as below which I use for non HA slots. In the below code if I change the Module.SlotRequirement.TOKEN_PRESENT to Module.SlotRequirement.ALL_SLOTS it will return me the HA slot, but the HA slot will not have a token as it is a virtual slot and hence I am not able to create a session for HA slot with IAIK wrapper

private Session initSession(Module wrapper, int slotId) throws Exception {
    Session session = null;
    try {
        Slot[] slots = wrapper.getSlotList(Module.SlotRequirement.TOKEN_PRESENT);
        Slot selectedSlot = slots[slotId];
        if (selectedSlot == null) {
            throw new Exception("Invalid slot Id" + slotId);
        }
        Token token = selectedSlot.getToken();
        if (token == null) {
            throw new Exception("There is no valid token present in the select slot.");
        }
        Long tokenID = new Long(token.getTokenID());
        TokenInfo tokenInfo = token.getTokenInfo();
        session = token.openSession(Token.SessionType.SERIAL_SESSION,
                Token.SessionReadWriteBehavior.RW_SESSION, null, null);
    } 
0

There are 0 best solutions below