use of iaik.pkcs.pkcs11.Session in project wildfly-swarm by wildfly-swarm.
the class StatefulTestBean method transactionEnlistmentReadAfterCallingTransactionClose.
public String transactionEnlistmentReadAfterCallingTransactionClose() {
// JTA transaction is started by CMT, the following obtains a Session that is enlisted into the JTA transaction.
Session session = injectedDriver.session();
// Calls to Session.beginTransaction() in a JTA transaction are expected to throw a RuntimeException
try {
Transaction transaction = session.beginTransaction();
fail("Calling Session.beginTransaction in a JTA transaction should throw a RuntimeException.");
} catch (RuntimeException expectedException) {
// success
}
try {
session.run("CREATE (a:Person {name:'TRANSACTION', title:'King'})");
return nestedBean.getPerson("TRANSACTION");
} finally {
if (session.isOpen()) {
// this will be true
session.run("MATCH (a:Person) delete a");
// ignored, session is auto closed when the transaction ends.
session.close();
}
}
}
use of iaik.pkcs.pkcs11.Session in project wildfly-swarm by wildfly-swarm.
the class StatefulTestBean method addPersonClassInstanceInjection.
public String addPersonClassInstanceInjection() {
Session session = injectedDriver.session();
try {
session.run("CREATE (a:Person {name:'CDI', title:'King'})");
StatementResult result = session.run("MATCH (a:Person) WHERE a.name = 'CDI' RETURN a.name AS name, a.title AS title");
Record record = result.next();
return record.toString();
} finally {
session.run("MATCH (a:Person) delete a");
session.close();
}
}
use of iaik.pkcs.pkcs11.Session in project wildfly-swarm by wildfly-swarm.
the class StatefulTestBean method addPerson.
public String addPerson() {
Session session = driver.session();
try {
session.run("CREATE (a:Person {name:'Arthur', title:'King'})");
StatementResult result = session.run("MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title");
Record record = result.next();
return record.toString();
} finally {
session.run("MATCH (a:Person) delete a");
session.close();
}
}
use of iaik.pkcs.pkcs11.Session in project xipki by xipki.
the class IaikP11Slot method getAllSecretKeyObjects.
private List<SecretKey> getAllSecretKeyObjects(Session session) throws P11TokenException {
SecretKey template = new SecretKey();
List<Storage> tmpObjects = getObjects(session, template);
if (CollectionUtil.isEmpty(tmpObjects)) {
return Collections.emptyList();
}
final int n = tmpObjects.size();
LOG.info("found {} private keys", n);
List<SecretKey> keys = new ArrayList<>(n);
for (Storage tmpObject : tmpObjects) {
SecretKey key = (SecretKey) tmpObject;
keys.add(key);
}
return keys;
}
use of iaik.pkcs.pkcs11.Session in project xipki by xipki.
the class IaikP11Slot method generateKeyPair.
private P11Identity generateKeyPair(long mech, PrivateKey privateKey, PublicKey publicKey) throws P11TokenException {
final String label = toString(privateKey.getLabel());
byte[] id = null;
try {
KeyPair keypair;
Session session = borrowWritableSession();
try {
if (labelExists(session, label)) {
throw new IllegalArgumentException("label " + label + " exists, please specify another one");
}
id = generateKeyId(session);
privateKey.getId().setByteArrayValue(id);
publicKey.getId().setByteArrayValue(id);
try {
keypair = session.generateKeyPair(Mechanism.get(mech), publicKey, privateKey);
} catch (TokenException ex) {
throw new P11TokenException("could not generate keypair " + Pkcs11Functions.mechanismCodeToString(mech), ex);
}
P11ObjectIdentifier objId = new P11ObjectIdentifier(id, label);
P11EntityIdentifier entityId = new P11EntityIdentifier(slotId, objId);
java.security.PublicKey jcePublicKey;
try {
jcePublicKey = generatePublicKey(keypair.getPublicKey());
} catch (XiSecurityException ex) {
throw new P11TokenException("could not generate public key " + objId, ex);
}
PrivateKey privateKey2 = getPrivateKeyObject(session, id, label.toCharArray());
if (privateKey2 == null) {
throw new P11TokenException("could not read the generated private key");
}
return new IaikP11Identity(this, entityId, privateKey2, jcePublicKey, null);
} finally {
returnWritableSession(session);
}
} catch (P11TokenException | RuntimeException ex) {
try {
removeObjects(id, label);
} catch (Throwable th) {
LogUtil.error(LOG, th, "could not remove objects");
}
throw ex;
}
}
Aggregations