use of won.cryptography.rdfsign.WonKeysReaderWriter in project webofneeds by researchstudio-sat.
the class TestingDataSource method getDataForResource.
@Override
public Dataset getDataForResource(final URI resourceURI) {
Dataset dataset = DatasetFactory.createGeneral();
DefaultPrefixUtils.setDefaultPrefixes(dataset.getDefaultModel());
WonKeysReaderWriter keyWriter = new WonKeysReaderWriter();
Model model = dataset.getDefaultModel();
Resource subj = model.createResource(resourceURI.toString());
try {
keyWriter.writeToModel(model, subj, pubKeysMap.get(resourceURI.toString()));
} catch (Exception e) {
e.printStackTrace();
return null;
}
return dataset;
}
use of won.cryptography.rdfsign.WonKeysReaderWriter in project webofneeds by researchstudio-sat.
the class KeyForNewAtomAddingProcessor method process.
@Override
public WonMessage process(final WonMessage message) throws WonMessageProcessingException {
try {
if (message.getMessageType() == WonMessageType.CREATE_ATOM) {
String atomUri = message.getAtomURIRequired().toString();
// generate and add atom's public key to the atom content
String alias = keyPairAliasDerivationStrategy.getAliasForAtomUri(atomUri);
if (cryptographyService.getPrivateKey(alias) == null) {
cryptographyService.createNewKeyPair(alias, alias);
}
PublicKey pubKey = cryptographyService.getPublicKey(alias);
WonKeysReaderWriter keyWriter = new WonKeysReaderWriter();
Model keyGraph = ModelFactory.createDefaultModel();
keyWriter.writeToModel(keyGraph, keyGraph.createResource(atomUri), pubKey);
message.addOrReplaceContentGraph(WonMessage.KEY_URI_SUFFIX, keyGraph);
}
} catch (Exception e) {
logger.error("Failed to add key", e);
throw new WonMessageProcessingException("Failed to add key for atom in message " + message.getMessageURI().toString(), e);
}
return message;
}
use of won.cryptography.rdfsign.WonKeysReaderWriter in project webofneeds by researchstudio-sat.
the class TestingDataSource method getDataForPublicResource.
@Override
public Dataset getDataForPublicResource(final URI resourceURI) {
Dataset dataset = DatasetFactory.createGeneral();
DefaultPrefixUtils.setDefaultPrefixes(dataset.getDefaultModel());
WonKeysReaderWriter keyWriter = new WonKeysReaderWriter();
Model model = dataset.getDefaultModel();
Resource subj = model.createResource(resourceURI.toString());
try {
keyWriter.writeToModel(model, subj, pubKeysMap.get(resourceURI.toString()));
} catch (Exception e) {
e.printStackTrace();
return null;
}
return dataset;
}
use of won.cryptography.rdfsign.WonKeysReaderWriter in project webofneeds by researchstudio-sat.
the class KeyForNewNeedAddingProcessor method process.
@Override
public WonMessage process(final WonMessage message) throws WonMessageProcessingException {
try {
if (message.getMessageType() == WonMessageType.CREATE_NEED) {
String needUri = message.getSenderNeedURI().toString();
Dataset msgDataset = WonMessageEncoder.encodeAsDataset(message);
// generate and add need's public key to the need content
String alias = keyPairAliasDerivationStrategy.getAliasForNeedUri(needUri);
if (cryptographyService.getPrivateKey(alias) == null) {
cryptographyService.createNewKeyPair(alias, alias);
}
PublicKey pubKey = cryptographyService.getPublicKey(alias);
WonKeysReaderWriter keyWriter = new WonKeysReaderWriter();
String contentName = message.getContentGraphURIs().get(0);
Model contentModel = msgDataset.getNamedModel(contentName);
keyWriter.writeToModel(contentModel, contentModel.createResource(needUri), pubKey);
return new WonMessage(msgDataset);
}
} catch (Exception e) {
logger.error("Failed to add key", e);
throw new WonMessageProcessingException("Failed to add key for need in message " + message.getMessageURI().toString());
}
return message;
}
Aggregations