Search in sources :

Example 1 with P11Module

use of org.xipki.security.pkcs11.P11Module in project xipki by xipki.

the class XiKeyStoreSpi method engineLoad.

private void engineLoad(String moduleName) throws P11TokenException, XiSecurityException {
    P11CryptService p11Service = p11CryptServiceFactory.getP11CryptService(moduleName);
    P11Module module = p11Service.getModule();
    List<P11SlotIdentifier> slotIds = module.getSlotIds();
    for (P11SlotIdentifier slotId : slotIds) {
        P11Slot slot = module.getSlot(slotId);
        Set<P11ObjectIdentifier> identityIds = slot.getIdentityIdentifiers();
        for (P11ObjectIdentifier objId : identityIds) {
            P11Identity identity = slot.getIdentity(objId);
            X509Certificate[] chain = identity.certificateChain();
            if (chain == null || chain.length == 0) {
                continue;
            }
            P11PrivateKey key = new P11PrivateKey(p11Service, identity.getIdentityId());
            KeyCertEntry keyCertEntry = new KeyCertEntry(key, chain);
            keyCerts.put(moduleName + "#slotid-" + slotId.getId() + "#keyid-" + objId.getIdHex(), keyCertEntry);
            keyCerts.put(moduleName + "#slotid-" + slotId.getId() + "#keylabel-" + objId.getLabel(), keyCertEntry);
            keyCerts.put(moduleName + "#slotindex-" + slotId.getIndex() + "#keyid-" + objId.getIdHex(), keyCertEntry);
            keyCerts.put(moduleName + "#slotindex-" + slotId.getIndex() + "#keylabel-" + objId.getLabel(), keyCertEntry);
        }
    }
}
Also used : P11Module(org.xipki.security.pkcs11.P11Module) P11SlotIdentifier(org.xipki.security.pkcs11.P11SlotIdentifier) P11Slot(org.xipki.security.pkcs11.P11Slot) P11Identity(org.xipki.security.pkcs11.P11Identity) P11CryptService(org.xipki.security.pkcs11.P11CryptService) P11ObjectIdentifier(org.xipki.security.pkcs11.P11ObjectIdentifier) X509Certificate(java.security.cert.X509Certificate)

Example 2 with P11Module

use of org.xipki.security.pkcs11.P11Module in project xipki by xipki.

the class P11TokenInfoCmd method execute0.

@Override
protected Object execute0() throws Exception {
    P11Module module = getP11Module(moduleName);
    println("module: " + moduleName);
    println(module.getDescription());
    List<P11SlotIdentifier> slots = module.getSlotIds();
    if (slotIndex == null) {
        output(slots);
        return null;
    }
    P11Slot slot = getSlot(moduleName, slotIndex);
    println("Details of slot");
    slot.showDetails(System.out, verbose);
    System.out.println();
    System.out.flush();
    return null;
}
Also used : P11Module(org.xipki.security.pkcs11.P11Module) P11SlotIdentifier(org.xipki.security.pkcs11.P11SlotIdentifier) P11Slot(org.xipki.security.pkcs11.P11Slot)

Example 3 with P11Module

use of org.xipki.security.pkcs11.P11Module in project xipki by xipki.

the class BSpeedP11Action method getSlot.

protected P11Slot getSlot() throws XiSecurityException, P11TokenException, IllegalCmdParamException {
    P11CryptService p11Service = p11CryptServiceFactory.getP11CryptService(moduleName);
    if (p11Service == null) {
        throw new IllegalCmdParamException("undefined module " + moduleName);
    }
    P11Module module = p11Service.getModule();
    P11SlotIdentifier slotId = module.getSlotIdForIndex(slotIndex);
    return module.getSlot(slotId);
}
Also used : P11Module(org.xipki.security.pkcs11.P11Module) P11SlotIdentifier(org.xipki.security.pkcs11.P11SlotIdentifier) IllegalCmdParamException(org.xipki.console.karaf.IllegalCmdParamException) P11CryptService(org.xipki.security.pkcs11.P11CryptService)

Example 4 with P11Module

use of org.xipki.security.pkcs11.P11Module in project xipki by xipki.

the class SecurityAction method getSlot.

protected P11Slot getSlot(String moduleName, int slotIndex) throws XiSecurityException, P11TokenException, IllegalCmdParamException {
    P11Module module = getP11Module(moduleName);
    P11SlotIdentifier slotId = module.getSlotIdForIndex(slotIndex);
    return module.getSlot(slotId);
}
Also used : P11Module(org.xipki.security.pkcs11.P11Module) P11SlotIdentifier(org.xipki.security.pkcs11.P11SlotIdentifier)

Example 5 with P11Module

use of org.xipki.security.pkcs11.P11Module in project xipki by xipki.

the class SpeedP11Action method getSlot.

protected P11Slot getSlot() throws XiSecurityException, P11TokenException, IllegalCmdParamException {
    P11CryptService p11Service = p11CryptServiceFactory.getP11CryptService(moduleName);
    if (p11Service == null) {
        throw new IllegalCmdParamException("undefined module " + moduleName);
    }
    P11Module module = p11Service.getModule();
    P11SlotIdentifier slotId = module.getSlotIdForIndex(slotIndex);
    return module.getSlot(slotId);
}
Also used : P11Module(org.xipki.security.pkcs11.P11Module) P11SlotIdentifier(org.xipki.security.pkcs11.P11SlotIdentifier) IllegalCmdParamException(org.xipki.console.karaf.IllegalCmdParamException) P11CryptService(org.xipki.security.pkcs11.P11CryptService)

Aggregations

P11Module (org.xipki.security.pkcs11.P11Module)7 P11SlotIdentifier (org.xipki.security.pkcs11.P11SlotIdentifier)6 P11CryptService (org.xipki.security.pkcs11.P11CryptService)4 P11Slot (org.xipki.security.pkcs11.P11Slot)3 IllegalCmdParamException (org.xipki.console.karaf.IllegalCmdParamException)2 P11TokenException (org.xipki.security.exception.P11TokenException)2 P11ObjectIdentifier (org.xipki.security.pkcs11.P11ObjectIdentifier)2 DefaultInitializeArgs (iaik.pkcs.pkcs11.DefaultInitializeArgs)1 Module (iaik.pkcs.pkcs11.Module)1 TokenException (iaik.pkcs.pkcs11.TokenException)1 PKCS11Exception (iaik.pkcs.pkcs11.wrapper.PKCS11Exception)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 PublicKey (java.security.PublicKey)1 X509Certificate (java.security.cert.X509Certificate)1 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)1 ObjectCreationException (org.xipki.common.ObjectCreationException)1 XiSecurityException (org.xipki.security.exception.XiSecurityException)1 AbstractP11Module (org.xipki.security.pkcs11.AbstractP11Module)1 P11ContentSignerBuilder (org.xipki.security.pkcs11.P11ContentSignerBuilder)1