use of iaik.pkcs.pkcs11.Session in project xipki by xipki.
the class IaikP11Slot method singleSign.
private byte[] singleSign(Session session, long mechanism, P11Params parameters, byte[] content, IaikP11Identity identity) throws P11TokenException {
Key signingKey = identity.getSigningKey();
Mechanism mechanismObj = getMechanism(mechanism, parameters);
if (LOG.isTraceEnabled()) {
LOG.debug("sign with signing key:\n{}", signingKey);
}
byte[] signature;
try {
session.signInit(mechanismObj, signingKey);
signature = session.sign(content);
} catch (TokenException ex) {
throw new P11TokenException(ex.getMessage(), ex);
}
if (LOG.isDebugEnabled()) {
LOG.debug("signature:\n{}", hex(signature));
}
return signature;
}
use of iaik.pkcs.pkcs11.Session in project xipki by xipki.
the class IaikP11Slot method idExists.
private static boolean idExists(Session session, byte[] keyId) throws P11TokenException {
Key key = new Key();
key.getId().setByteArrayValue(keyId);
Object[] objects;
try {
session.findObjectsInit(key);
objects = session.findObjects(1);
if (objects.length > 0) {
return true;
}
} catch (TokenException ex) {
throw new P11TokenException(ex.getMessage(), ex);
} finally {
try {
session.findObjectsFinal();
} catch (TokenException ex) {
LogUtil.error(LOG, ex, "session.findObjectsFinal() failed");
}
}
X509PublicKeyCertificate cert = new X509PublicKeyCertificate();
cert.getId().setByteArrayValue(keyId);
try {
session.findObjectsInit(cert);
objects = session.findObjects(1);
} catch (TokenException ex) {
throw new P11TokenException(ex.getMessage(), ex);
} finally {
try {
session.findObjectsFinal();
} catch (TokenException ex) {
LogUtil.error(LOG, ex, "session.findObjectsFinal() failed");
}
}
return objects.length > 0;
}
use of iaik.pkcs.pkcs11.Session 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);
}
}
use of iaik.pkcs.pkcs11.Session in project xipki by xipki.
the class IaikP11Slot method getAllCertificateObjects.
private List<X509PublicKeyCertificate> getAllCertificateObjects(Session session) throws P11TokenException {
X509PublicKeyCertificate template = new X509PublicKeyCertificate();
List<Storage> tmpObjects = getObjects(session, template);
List<X509PublicKeyCertificate> certs = new ArrayList<>(tmpObjects.size());
for (PKCS11Object tmpObject : tmpObjects) {
X509PublicKeyCertificate cert = (X509PublicKeyCertificate) tmpObject;
certs.add(cert);
}
return certs;
}
use of iaik.pkcs.pkcs11.Session in project rdf2neo by Rothamsted.
the class CypherHandlersIT method testRelations.
/**
* Tests {@link CyRelationLoadingHandler} to see if relations are mapped from RDF and loaded into Neo4J.
*/
@Test
public void testRelations() throws Exception {
try (Driver neoDriver = GraphDatabase.driver("bolt://127.0.0.1:7687", AuthTokens.basic("neo4j", "test"));
CyRelationLoadingHandler handler = new CyRelationLoadingHandler();
RdfDataManager rdfMgr = new RdfDataManager(RdfDataManagerTest.TDB_PATH);
Neo4jDataManager neoMgr = new Neo4jDataManager(neoDriver)) {
handler.setRdfDataManager(rdfMgr);
handler.setNeo4jDataManager(neoMgr);
handler.setRelationTypesSparql(RdfDataManagerTest.SPARQL_REL_TYPES);
handler.setRelationPropsSparql(RdfDataManagerTest.SPARQL_REL_PROPS);
Set<QuerySolution> relSparqlRows = new HashSet<>();
Dataset dataSet = rdfMgr.getDataSet();
Txn.executeRead(dataSet, () -> SparqlUtils.select(RdfDataManagerTest.SPARQL_REL_TYPES, rdfMgr.getDataSet().getDefaultModel()).forEachRemaining(row -> relSparqlRows.add(row)));
handler.accept(relSparqlRows);
Session session = neoDriver.session(AccessMode.READ);
StatementResult cursor = session.run("MATCH ()-[r]->() RETURN COUNT ( r ) AS ct");
Assert.assertEquals("Wrong count for relations", 3, cursor.next().get("ct").asLong());
cursor = session.run("MATCH p = (:TestNode{ iri:$iri1 })-[:relatedTo]->(:TestNode{ iri:$iri2 }) RETURN COUNT ( p ) AS ct", parameters("iri1", iri("ex:1"), "iri2", iri("ex:2")));
Assert.assertEquals("Wrong count for {1 relatedTo 2}!", 1, cursor.next().get("ct").asLong());
cursor = session.run("MATCH p = (:SuperTestNode{ iri:$iri1 })-[:derivedFrom]->(:TestNode{ iri:$iri2 }) RETURN COUNT ( p ) AS ct", parameters("iri1", iri("ex:3"), "iri2", iri("ex:1")));
Assert.assertEquals("Wrong count for {3 derivedFrom 1}!", 1, cursor.next().get("ct").asLong());
cursor = session.run("MATCH (:TestNode{ iri:$iri1 })-[r:relatedTo]->(:AdditionalLabel{ iri:$iri2 }) RETURN r.note AS note", parameters("iri1", iri("ex:2"), "iri2", iri("ex:3")));
assertTrue("{2 relatedTo 3} not found!", cursor.hasNext());
Set<String> values = cursor.next().get("note").asList().stream().map(v -> (String) v).collect(Collectors.toSet());
Set<String> refValues = new HashSet<>(Arrays.asList(new String[] { "Reified Relation", "Another Note" }));
assertTrue("reified relation, wrong property value for 'note'!", Sets.difference(values, refValues).isEmpty());
}
}
Aggregations