Search in sources :

Example 21 with P11TokenException

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

the class EmulatorP11Slot method saveP11Entity.

private P11Identity saveP11Entity(KeyPair keypair, String label) throws P11TokenException {
    byte[] id = generateId();
    savePkcs11PrivateKey(id, label, keypair.getPrivate());
    savePkcs11PublicKey(id, label, keypair.getPublic());
    P11EntityIdentifier identityId = new P11EntityIdentifier(slotId, new P11ObjectIdentifier(id, label));
    try {
        return new EmulatorP11Identity(this, identityId, keypair.getPrivate(), keypair.getPublic(), null, maxSessions, random);
    } catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchProviderException ex) {
        throw new P11TokenException("could not construct KeyStoreP11Identity: " + ex.getMessage(), ex);
    }
}
Also used : P11TokenException(org.xipki.security.exception.P11TokenException) P11EntityIdentifier(org.xipki.security.pkcs11.P11EntityIdentifier) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) NoSuchProviderException(java.security.NoSuchProviderException) P11ObjectIdentifier(org.xipki.security.pkcs11.P11ObjectIdentifier)

Example 22 with P11TokenException

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

the class EmulatorP11Slot method saveP11Entity.

private P11Identity saveP11Entity(SecretKey key, String label) throws P11TokenException {
    byte[] id = generateId();
    savePkcs11SecretKey(id, label, key);
    P11EntityIdentifier identityId = new P11EntityIdentifier(slotId, new P11ObjectIdentifier(id, label));
    return new EmulatorP11Identity(this, identityId, key, maxSessions, random);
}
Also used : P11EntityIdentifier(org.xipki.security.pkcs11.P11EntityIdentifier) P11ObjectIdentifier(org.xipki.security.pkcs11.P11ObjectIdentifier)

Example 23 with P11TokenException

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

the class P11SecurityAction method getObjectIdentifier.

public P11ObjectIdentifier getObjectIdentifier() throws IllegalCmdParamException, XiSecurityException, P11TokenException {
    P11Slot slot = getSlot();
    P11ObjectIdentifier objIdentifier;
    if (id != null && label == null) {
        objIdentifier = slot.getObjectIdForId(Hex.decode(id));
    } else if (id == null && label != null) {
        objIdentifier = slot.getObjectIdForLabel(label);
    } else {
        throw new IllegalCmdParamException("exactly one of keyId or keyLabel should be specified");
    }
    return objIdentifier;
}
Also used : P11Slot(org.xipki.security.pkcs11.P11Slot) IllegalCmdParamException(org.xipki.console.karaf.IllegalCmdParamException) P11ObjectIdentifier(org.xipki.security.pkcs11.P11ObjectIdentifier)

Example 24 with P11TokenException

use of org.xipki.security.pkcs11.P11TokenException 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)

Example 25 with P11TokenException

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

the class IaikP11Module method getInstance.

public static P11Module getInstance(P11ModuleConf moduleConf) throws P11TokenException {
    ParamUtil.requireNonNull("moduleConf", moduleConf);
    Module module;
    try {
        module = Module.getInstance(moduleConf.getNativeLibrary());
    } catch (IOException ex) {
        final String msg = "could not load the PKCS#11 module " + moduleConf.getName();
        LogUtil.error(LOG, ex, msg);
        throw new P11TokenException(msg, ex);
    }
    try {
        module.initialize(new DefaultInitializeArgs());
    } catch (PKCS11Exception ex) {
        if (ex.getErrorCode() != PKCS11Constants.CKR_CRYPTOKI_ALREADY_INITIALIZED) {
            LogUtil.error(LOG, ex);
            close(moduleConf.getName(), module);
            throw new P11TokenException(ex.getMessage(), ex);
        } else {
            LOG.info("PKCS#11 module already initialized");
            if (LOG.isInfoEnabled()) {
                try {
                    LOG.info("pkcs11.getInfo():\n{}", module.getInfo());
                } catch (TokenException e2) {
                    LOG.debug("module.getInfo()", e2);
                }
            }
        }
    } catch (Throwable th) {
        LOG.error("unexpected Exception", th);
        close(moduleConf.getName(), module);
        throw new P11TokenException(th.getMessage());
    }
    return new IaikP11Module(module, moduleConf);
}
Also used : DefaultInitializeArgs(iaik.pkcs.pkcs11.DefaultInitializeArgs) PKCS11Exception(iaik.pkcs.pkcs11.wrapper.PKCS11Exception) P11TokenException(org.xipki.security.exception.P11TokenException) P11TokenException(org.xipki.security.exception.P11TokenException) TokenException(iaik.pkcs.pkcs11.TokenException) IOException(java.io.IOException) P11Module(org.xipki.security.pkcs11.P11Module) AbstractP11Module(org.xipki.security.pkcs11.AbstractP11Module) Module(iaik.pkcs.pkcs11.Module)

Aggregations

P11TokenException (org.xipki.security.exception.P11TokenException)15 P11EntityIdentifier (org.xipki.security.pkcs11.P11EntityIdentifier)11 P11TokenException (org.xipki.security.pkcs11.P11TokenException)11 P11ObjectIdentifier (org.xipki.security.pkcs11.P11ObjectIdentifier)9 XiSecurityException (org.xipki.security.exception.XiSecurityException)8 P11CryptService (org.xipki.security.pkcs11.P11CryptService)7 P11Module (org.xipki.security.pkcs11.P11Module)6 P11SlotIdentifier (org.xipki.security.pkcs11.P11SlotIdentifier)6 TokenException (iaik.pkcs.pkcs11.TokenException)4 PublicKey (java.security.PublicKey)4 DEROctetString (org.bouncycastle.asn1.DEROctetString)4 Asn1P11EntityIdentifier (org.xipki.p11proxy.msg.Asn1P11EntityIdentifier)4 P11Params (org.xipki.security.pkcs11.P11Params)4 P11Slot (org.xipki.security.pkcs11.P11Slot)4 Mechanism (iaik.pkcs.pkcs11.Mechanism)3 Session (iaik.pkcs.pkcs11.Session)3 PKCS11Exception (iaik.pkcs.pkcs11.wrapper.PKCS11Exception)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 BadAsn1ObjectException (org.xipki.security.exception.BadAsn1ObjectException)3