Search in sources :

Example 1 with DefaultInitializeArgs

use of iaik.pkcs.pkcs11.DefaultInitializeArgs 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

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 P11TokenException (org.xipki.security.exception.P11TokenException)1 AbstractP11Module (org.xipki.security.pkcs11.AbstractP11Module)1 P11Module (org.xipki.security.pkcs11.P11Module)1