use of won.cryptography.rdfsign.SignatureVerificationState in project webofneeds by researchstudio-sat.
the class WonMessageSignerVerifierTest method signAndVerifySignedMessageNode.
@Test
public void signAndVerifySignedMessageNode() throws Exception {
// create signed dataset
Dataset testDataset = TestSigningUtils.prepareTestDataset(RESOURCE_NODE_FILE_NOSIG);
WonMessage testMsg = new WonMessage(testDataset);
// sign
testMsg = WonMessageSignerVerifier.sign(nodeKey, pubKeysMap.get(TestSigningUtils.nodeCertUri), TestSigningUtils.nodeCertUri, testMsg);
// pretend msg was serialized and deserialized in between
// pretend it was serialized and deserialized
String datasetString = RdfUtils.writeDatasetToString(testMsg.getCompleteDataset(), Lang.TRIG);
testMsg = new WonMessage(RdfUtils.readDatasetFromString(datasetString, Lang.TRIG));
// verify
SignatureVerificationState result = WonMessageSignerVerifier.verify(pubKeysMap, testMsg);
Assert.assertTrue(result.getMessage(), result.isVerificationPassed());
Assert.assertEquals(3, result.getSignatureGraphNames().size());
Assert.assertEquals(NEED_CORE_DATA_URI, result.getSignedGraphName(NEED_CORE_DATA_SIG_URI));
Assert.assertEquals(EVENT_ENV1_URI, result.getSignedGraphName(EVENT_ENV1_SIG_URI));
Assert.assertEquals(EVENT_ENV2_URI, result.getSignedGraphName(EVENT_ENV2_SIG_URI));
// write for debugging
TestSigningUtils.writeToTempFile(testMsg.getCompleteDataset());
}
use of won.cryptography.rdfsign.SignatureVerificationState in project webofneeds by researchstudio-sat.
the class SignatureCheckingWonMessageProcessor method process.
@Override
public WonMessage process(final WonMessage message) throws WonMessageProcessingException {
SignatureVerificationState result = null;
try {
// obtain public keys
Map<String, PublicKey> keys = getRequiredPublicKeys(message.getCompleteDataset());
// verify with those public keys
result = WonMessageSignerVerifier.verify(keys, message);
logger.debug("VERIFIED=" + result.isVerificationPassed() + " with keys: " + keys.values() + " for\n" + RdfUtils.writeDatasetToString(message.getCompleteDataset(), Lang.TRIG));
} catch (Exception e) {
// TODO SignatureProcessingException?
throw new WonMessageProcessingException("Could not verify message " + message.getMessageURI(), e);
}
// throw exception if the verification fails:
if (!result.isVerificationPassed()) {
// TODO SignatureProcessingException?
throw new WonMessageProcessingException(new SignatureException("Could not verify message " + message.getMessageURI() + ": " + result.getMessage()));
}
return message;
}
use of won.cryptography.rdfsign.SignatureVerificationState in project webofneeds by researchstudio-sat.
the class WonMessageSignerVerifierTest method signAndVerifyUnsignedMessage.
@Test
@Ignore
public void signAndVerifyUnsignedMessage() throws Exception {
// create signed dataset
Dataset testDataset = TestSigningUtils.prepareTestDataset(RESOURCE_OWNER_FILE_NOSIG);
WonMessage testMsg = new WonMessage(testDataset);
// sign
testMsg = WonMessageSignerVerifier.sign(needKey, pubKeysMap.get(TestSigningUtils.nodeCertUri), TestSigningUtils.needCertUri, testMsg);
// pretend msg was serialized and deserialized in between
// pretend it was serialized and deserialized
String datasetString = RdfUtils.writeDatasetToString(testMsg.getCompleteDataset(), Lang.TRIG);
testMsg = new WonMessage(RdfUtils.readDatasetFromString(datasetString, Lang.TRIG));
// verify
SignatureVerificationState result = WonMessageSignerVerifier.verify(pubKeysMap, testMsg);
Assert.assertTrue(result.isVerificationPassed());
Assert.assertEquals(2, result.getSignatureGraphNames().size());
Assert.assertEquals(NEED_CORE_DATA_URI, result.getSignedGraphName(NEED_CORE_DATA_SIG_URI));
Assert.assertEquals(EVENT_ENV1_URI, result.getSignedGraphName(EVENT_ENV1_SIG_URI));
// write for debugging
TestSigningUtils.writeToTempFile(testMsg.getCompleteDataset());
}
use of won.cryptography.rdfsign.SignatureVerificationState in project webofneeds by researchstudio-sat.
the class WonMessageSignerVerifierTest method testVerify.
@Test
public void testVerify() throws Exception {
// create signed dataset
Dataset testDataset = TestSigningUtils.prepareTestDataset(RESOURCE_FILE_SIG);
WonMessage testMsg = new WonMessage(testDataset);
// verify
SignatureVerificationState result = WonMessageSignerVerifier.verify(pubKeysMap, testMsg);
Assert.assertTrue(result.getMessage(), result.isVerificationPassed());
Assert.assertEquals(3, result.getSignatureGraphNames().size());
Assert.assertEquals(NEED_CORE_DATA_URI, result.getSignedGraphName(NEED_CORE_DATA_SIG_URI));
Assert.assertEquals(EVENT_ENV1_URI, result.getSignedGraphName(EVENT_ENV1_SIG_URI));
Assert.assertEquals(EVENT_ENV2_URI, result.getSignedGraphName(EVENT_ENV2_SIG_URI));
}
Aggregations