use of iaik.pkcs.pkcs11.Session in project xipki by xipki.
the class IaikP11Slot method removeIdentity0.
@Override
protected void removeIdentity0(P11ObjectIdentifier objectId) throws P11TokenException {
Session session = borrowWritableSession();
try {
byte[] id = objectId.getId();
char[] label = objectId.getLabelChars();
SecretKey secretKey = getSecretKeyObject(session, id, label);
if (secretKey != null) {
try {
session.destroyObject(secretKey);
} catch (TokenException ex) {
String msg = "could not delete secret key " + objectId;
LogUtil.error(LOG, ex, msg);
throw new P11TokenException(msg);
}
}
PrivateKey privKey = getPrivateKeyObject(session, id, label);
if (privKey != null) {
try {
session.destroyObject(privKey);
} catch (TokenException ex) {
String msg = "could not delete private key " + objectId;
LogUtil.error(LOG, ex, msg);
throw new P11TokenException(msg);
}
}
PublicKey pubKey = getPublicKeyObject(session, id, label);
if (pubKey != null) {
try {
session.destroyObject(pubKey);
} catch (TokenException ex) {
String msg = "could not delete public key " + objectId;
LogUtil.error(LOG, ex, msg);
throw new P11TokenException(msg);
}
}
X509PublicKeyCertificate[] certs = getCertificateObjects(session, id, label);
if (certs != null && certs.length > 0) {
for (int i = 0; i < certs.length; i++) {
try {
session.destroyObject(certs[i]);
} catch (TokenException ex) {
String msg = "could not delete certificate " + objectId;
LogUtil.error(LOG, ex, msg);
throw new P11TokenException(msg);
}
}
}
} finally {
returnWritableSession(session);
}
}
use of iaik.pkcs.pkcs11.Session in project xipki by xipki.
the class IaikP11Slot method addCert0.
@Override
protected void addCert0(P11ObjectIdentifier objectId, X509Certificate cert) throws P11TokenException {
X509PublicKeyCertificate newCaCertTemp = createPkcs11Template(new X509Cert(cert), objectId.getId(), objectId.getLabelChars());
Session session = borrowWritableSession();
try {
session.createObject(newCaCertTemp);
} catch (TokenException ex) {
throw new P11TokenException(ex.getMessage(), ex);
} finally {
returnWritableSession(session);
}
}
use of iaik.pkcs.pkcs11.Session in project xipki by xipki.
the class IaikP11Slot method importSecretKey0.
@Override
protected P11Identity importSecretKey0(long keyType, byte[] keyValue, String label, P11NewKeyControl control) throws P11TokenException {
ValuedSecretKey template = new ValuedSecretKey(keyType);
template.getToken().setBooleanValue(true);
template.getLabel().setCharArrayValue(label.toCharArray());
template.getSign().setBooleanValue(true);
template.getSensitive().setBooleanValue(true);
template.getExtractable().setBooleanValue(control.isExtractable());
template.getValue().setByteArrayValue(keyValue);
SecretKey key;
Session session = borrowWritableSession();
try {
if (labelExists(session, label)) {
throw new IllegalArgumentException("label " + label + " exists, please specify another one");
}
byte[] id = generateKeyId(session);
template.getId().setByteArrayValue(id);
try {
key = (SecretKey) session.createObject(template);
} catch (TokenException ex) {
throw new P11TokenException("could not create secret key", ex);
}
P11ObjectIdentifier objId = new P11ObjectIdentifier(id, label);
P11EntityIdentifier entityId = new P11EntityIdentifier(slotId, objId);
return new IaikP11Identity(this, entityId, key);
} finally {
returnWritableSession(session);
}
}
use of iaik.pkcs.pkcs11.Session in project xipki by xipki.
the class IaikP11Slot method checkSessionLoggedIn.
private static boolean checkSessionLoggedIn(Session session) throws P11TokenException {
SessionInfo info;
try {
info = session.getSessionInfo();
} catch (TokenException ex) {
throw new P11TokenException(ex.getMessage(), ex);
}
if (LOG.isTraceEnabled()) {
LOG.debug("SessionInfo: {}", info);
}
State state = info.getState();
long deviceError = info.getDeviceError();
LOG.debug("to be verified PKCS11Module: state = {}, deviceError: {}", state, deviceError);
boolean isRwSessionLoggedIn = state.equals(State.RW_USER_FUNCTIONS);
boolean isRoSessionLoggedIn = state.equals(State.RO_USER_FUNCTIONS);
boolean sessionLoggedIn = ((isRoSessionLoggedIn || isRwSessionLoggedIn) && deviceError == 0);
LOG.debug("sessionLoggedIn: {}", sessionLoggedIn);
return sessionLoggedIn;
}
use of iaik.pkcs.pkcs11.Session in project rdf2neo by Rothamsted.
the class Neo4jDataManager method processCypherMatches.
public void processCypherMatches(Consumer<Record> action, String cypher, Object... keyVals) {
if (log.isTraceEnabled())
log.trace("Cypher: {} params: {}", cypher, ArrayUtils.toString(keyVals));
// Re-attempt a couple of times, in case of exceptions due to deadlocks over locking nodes.
MultipleAttemptsExecutor attempter = new MultipleAttemptsExecutor(TransientException.class, DatabaseException.class, ServiceUnavailableException.class);
attempter.setMaxAttempts(10);
attempter.setMinPauseTime(30 * 1000);
attempter.setMaxPauseTime(3 * 60 * 1000);
attempter.execute(() -> {
try (Session session = this.neo4jDriver.session()) {
StatementResult cursor = session.run(cypher, parameters(keyVals));
cursor.forEachRemaining(action);
}
});
}
Aggregations