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);
}
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);
}
}
Aggregations