Search in sources :

Example 1 with WonSignatureData

use of won.protocol.message.WonSignatureData in project webofneeds by researchstudio-sat.

the class SigningStage method extractSignatureData.

private void extractSignatureData(final String uri, final Model model) {
    WonSignatureData wonSignatureData = WonRdfUtils.SignatureUtils.extractWonSignatureData(uri, model);
    if (wonSignatureData != null && wonSignatureData.getSignatureValue() != null) {
        graphUriToSigUri.put(wonSignatureData.getSignedGraphUri(), uri);
        sigUriToSigReference.put(uri, wonSignatureData);
    }
}
Also used : WonSignatureData(won.protocol.message.WonSignatureData)

Example 2 with WonSignatureData

use of won.protocol.message.WonSignatureData in project webofneeds by researchstudio-sat.

the class WonVerifier method addSignatureReferenceToResult.

private void addSignatureReferenceToResult(final String graphURI, final Model model) {
    RDFNode tempNode = null;
    StmtIterator si = model.listStatements(null, WONMSG.CONTAINS_SIGNATURE_PROPERTY, tempNode);
    while (si.hasNext()) {
        WonSignatureData sigRef = WonRdfUtils.SignatureUtils.extractWonSignatureData(si.nextStatement().getObject().asResource());
        verificationState.addSignatureData(sigRef);
    }
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) WonSignatureData(won.protocol.message.WonSignatureData) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 3 with WonSignatureData

use of won.protocol.message.WonSignatureData in project webofneeds by researchstudio-sat.

the class WonMessageSignerVerifier method signEnvelopes.

/**
 * If the provided signing stage has unsigned content graphs, sign them, add signature graphs
 * to the dataset, and add signatures to the envelope graph
 * that has contains envelope property referencing signed by that signature envelope graph
 * @param msgDataset
 * @param sigStage
 * @param signer
 * @param privateKey
 * @param privateKeyUri
 */
private static void signEnvelopes(final Dataset msgDataset, final SigningStage sigStage, final WonSigner signer, final PrivateKey privateKey, final String privateKeyUri, final PublicKey publicKey) throws Exception {
    List<String> envUris = sigStage.getUnsignedEnvUrisOrderedByContainment();
    WonSignatureData wonSignatureData = null;
    String outerEnvUri = null;
    for (String envUri : sigStage.getUnsignedEnvUrisOrderedByContainment()) {
        if (wonSignatureData != null) {
            // this is the signature of the envelope we signed in the last iteration.
            // add it to the current one:
            addSignature(wonSignatureData, envUri, msgDataset, true);
        }
        wonSignatureData = signer.sign(privateKey, privateKeyUri, publicKey, envUri).get(0);
        outerEnvUri = envUri;
    }
    // this is the signature of the outermost envelopoe. put it in a new graph.
    msgDataset.addNamedModel(wonSignatureData.getSignatureUri(), ModelFactory.createDefaultModel());
    addSignature(wonSignatureData, wonSignatureData.getSignatureUri(), msgDataset, false);
}
Also used : WonSignatureData(won.protocol.message.WonSignatureData)

Example 4 with WonSignatureData

use of won.protocol.message.WonSignatureData in project webofneeds by researchstudio-sat.

the class WonMessageSignerVerifier method signContents.

/**
 * If the provided signing stage has unsigned content graphs, sign them.
 * This adds the signature triples to the graph, add signature graphs
 * to the dataset, and add signature references of those signatures into the envelope graph
 * that has has content property referencing signed by that signature content graph
 * @param msgDataset
 * @param sigStage
 * @param signer
 * @param privateKey
 * @param privateKeyUri
 */
private static void signContents(final Dataset msgDataset, final SigningStage sigStage, final WonSigner signer, final PrivateKey privateKey, final String privateKeyUri, final PublicKey publicKey) throws Exception {
    List<WonSignatureData> sigRefs = signer.sign(privateKey, privateKeyUri, publicKey, sigStage.getUnsignedContentUris());
    for (WonSignatureData sigRef : sigRefs) {
        String envUri = sigStage.getEnvelopeUriContainingContent(sigRef.getSignedGraphUri());
        addSignature(sigRef, envUri, msgDataset, true);
    }
}
Also used : WonSignatureData(won.protocol.message.WonSignatureData)

Example 5 with WonSignatureData

use of won.protocol.message.WonSignatureData in project webofneeds by researchstudio-sat.

the class WonMessageSignerVerifier method addUnreferencedSigReferences.

/**
 * If the provided signing stage has signature graphs that are not referenced from any envelope graphs, they
 * should be moved to the innermost not-signed envelope graph. The signature graph is to be deleted.
 * @param msgDataset
 * @param sigStage
 */
private static void addUnreferencedSigReferences(final Dataset msgDataset, final SigningStage sigStage) {
    String innemostUnsignedEnvUri = null;
    List<String> envUris = sigStage.getUnsignedEnvUrisOrderedByContainment();
    if (envUris.isEmpty()) {
        return;
    } else {
        innemostUnsignedEnvUri = envUris.get(0);
    }
    WonSignatureData sigRef = sigStage.getOutermostSignature();
    if (sigRef != null) {
        addSignature(sigRef, innemostUnsignedEnvUri, msgDataset, true);
        msgDataset.removeNamedModel(sigRef.getSignatureUri());
    }
}
Also used : WonSignatureData(won.protocol.message.WonSignatureData)

Aggregations

WonSignatureData (won.protocol.message.WonSignatureData)7 GraphCollection (de.uni_koblenz.aggrimm.icp.crypto.sign.graph.GraphCollection)2 StringWriter (java.io.StringWriter)2 SignatureAlgorithmInterface (de.uni_koblenz.aggrimm.icp.crypto.sign.algorithm.SignatureAlgorithmInterface)1 SignatureAlgorithmFisteus2010 (de.uni_koblenz.aggrimm.icp.crypto.sign.algorithm.algorithm.SignatureAlgorithmFisteus2010)1 SignatureData (de.uni_koblenz.aggrimm.icp.crypto.sign.graph.SignatureData)1 BigInteger (java.math.BigInteger)1 MessageDigest (java.security.MessageDigest)1 PublicKey (java.security.PublicKey)1 Signature (java.security.Signature)1 ArrayList (java.util.ArrayList)1 RDFNode (org.apache.jena.rdf.model.RDFNode)1 StmtIterator (org.apache.jena.rdf.model.StmtIterator)1