Search in sources :

Example 1 with PKCS11Exception

use of iaik.pkcs.pkcs11.wrapper.PKCS11Exception 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)

Example 2 with PKCS11Exception

use of iaik.pkcs.pkcs11.wrapper.PKCS11Exception in project xipki by xipki.

the class IaikP11Slot method firstLogin.

private void firstLogin(Session session, List<char[]> password) throws P11TokenException {
    try {
        boolean isProtectedAuthenticationPath = session.getToken().getTokenInfo().isProtectedAuthenticationPath();
        if (isProtectedAuthenticationPath || CollectionUtil.isEmpty(password)) {
            LOG.info("verify on PKCS11Module with PROTECTED_AUTHENTICATION_PATH");
            singleLogin(session, null);
        } else {
            LOG.info("verify on PKCS11Module with PIN");
            for (char[] singlePwd : password) {
                singleLogin(session, singlePwd);
            }
            this.password = password;
        }
    } catch (PKCS11Exception ex) {
        // 0x100: user already logged in
        if (ex.getErrorCode() != 0x100) {
            throw new P11TokenException(ex.getMessage(), ex);
        }
    } catch (TokenException ex) {
        throw new P11TokenException(ex.getMessage(), ex);
    }
}
Also used : PKCS11Exception(iaik.pkcs.pkcs11.wrapper.PKCS11Exception) P11TokenException(org.xipki.security.exception.P11TokenException) P11TokenException(org.xipki.security.exception.P11TokenException) TokenException(iaik.pkcs.pkcs11.TokenException)

Aggregations

TokenException (iaik.pkcs.pkcs11.TokenException)2 PKCS11Exception (iaik.pkcs.pkcs11.wrapper.PKCS11Exception)2 P11TokenException (org.xipki.security.exception.P11TokenException)2 DefaultInitializeArgs (iaik.pkcs.pkcs11.DefaultInitializeArgs)1 Module (iaik.pkcs.pkcs11.Module)1 IOException (java.io.IOException)1 AbstractP11Module (org.xipki.security.pkcs11.AbstractP11Module)1 P11Module (org.xipki.security.pkcs11.P11Module)1