@Test @Ignore public void testSignCreatedAtom() throws Exception { Dataset testDataset = TestSigningUtils.prepareTestDatasetFromNamedGraphs(RESOURCE_FILE, new String[] { ATOM_CORE_DATA_URI }); WonSigner signer = new WonSigner(testDataset); signer.signNamedGraphsSeparately(keys.getPrivateKey(TestSigningUtils.atomCertUri), TestSigningUtils.atomCertUri, keys.getPublicKey(TestSigningUtils.atomCertUri), ATOM_CORE_DATA_URI); List<String> namesList = RdfUtils.getModelNames(testDataset); Assert.assertEquals(2, namesList.size()); Assert.assertTrue(namesList.contains(ATOM_CORE_DATA_URI)); Assert.assertTrue(namesList.contains(ATOM_CORE_DATA_SIG_URI)); int triplesCounter = TestSigningUtils .countTriples(testDataset.getNamedModel(ATOM_CORE_DATA_SIG_URI).listStatements()); Assert.assertEquals(11, triplesCounter); String sigValue = TestSigningUtils.getObjectOfPredAsString(testDataset.getNamedModel(ATOM_CORE_DATA_SIG_URI), WONMSG.signatureValue.getURI()); Assert.assertTrue(sigValue.length() > 75); }
public List<WonSignatureData> signNamedGraphsSeparately(PrivateKey privateKey, String cert, PublicKey publicKey, String... graphsToSign) throws Exception { List<WonSignatureData> sigRefs = new ArrayList<>(graphsToSign.length); String fingerprint = WonHasher.hashToString(publicKey.getEncoded()); for (String signedGraphUri : graphsToSign) { if (logger.isDebugEnabled()) { StringWriter sw = new StringWriter(); RDFDataMgr.write(sw, dataset.getNamedModel(signedGraphUri), Lang.TRIG); logger.debug("signing graph {} with content: {}", graphsToSign, sw.toString()); } String signatureUri = signedGraphUri + "-sig"; GraphCollection inputGraph = ModelConverter.modelToGraphCollection(signedGraphUri, dataset); SignatureData sigValue = signNamedGraph(inputGraph, privateKey, cert); String hash = WonHasher.hashToString(sigValue.getHash()); WonSignatureData sigRef = new WonSignatureData(Arrays.asList(signedGraphUri), signatureUri, sigValue.getSignature(), hash, fingerprint, cert); sigRefs.add(sigRef); } return sigRefs; }
WonSigner { public List<WonSignatureData> signNamedGraphsSeparately(PrivateKey privateKey, String cert, PublicKey publicKey, String... graphsToSign) throws Exception { List<WonSignatureData> sigRefs = new ArrayList<>(graphsToSign.length); String fingerprint = WonHasher.hashToString(publicKey.getEncoded()); for (String signedGraphUri : graphsToSign) { if (logger.isDebugEnabled()) { StringWriter sw = new StringWriter(); RDFDataMgr.write(sw, dataset.getNamedModel(signedGraphUri), Lang.TRIG); logger.debug("signing graph {} with content: {}", graphsToSign, sw.toString()); } String signatureUri = signedGraphUri + "-sig"; GraphCollection inputGraph = ModelConverter.modelToGraphCollection(signedGraphUri, dataset); SignatureData sigValue = signNamedGraph(inputGraph, privateKey, cert); String hash = WonHasher.hashToString(sigValue.getHash()); WonSignatureData sigRef = new WonSignatureData(Arrays.asList(signedGraphUri), signatureUri, sigValue.getSignature(), hash, fingerprint, cert); sigRefs.add(sigRef); } return sigRefs; } }
WonSigner { public List<WonSignatureData> signNamedGraphsSeparately(PrivateKey privateKey, String cert, PublicKey publicKey, String... graphsToSign) throws Exception { List<WonSignatureData> sigRefs = new ArrayList<>(graphsToSign.length); String fingerprint = WonHasher.hashToString(publicKey.getEncoded()); for (String signedGraphUri : graphsToSign) { if (logger.isDebugEnabled()) { StringWriter sw = new StringWriter(); RDFDataMgr.write(sw, dataset.getNamedModel(signedGraphUri), Lang.TRIG); logger.debug("signing graph {} with content: {}", graphsToSign, sw.toString()); } String signatureUri = signedGraphUri + "-sig"; GraphCollection inputGraph = ModelConverter.modelToGraphCollection(signedGraphUri, dataset); SignatureData sigValue = signNamedGraph(inputGraph, privateKey, cert); String hash = WonHasher.hashToString(sigValue.getHash()); WonSignatureData sigRef = new WonSignatureData(Arrays.asList(signedGraphUri), signatureUri, sigValue.getSignature(), hash, fingerprint, cert); sigRefs.add(sigRef); } return sigRefs; } WonSigner(Dataset dataset); }
WonSigner { public List<WonSignatureData> signNamedGraphsSeparately(PrivateKey privateKey, String cert, PublicKey publicKey, String... graphsToSign) throws Exception { List<WonSignatureData> sigRefs = new ArrayList<>(graphsToSign.length); String fingerprint = WonHasher.hashToString(publicKey.getEncoded()); for (String signedGraphUri : graphsToSign) { if (logger.isDebugEnabled()) { StringWriter sw = new StringWriter(); RDFDataMgr.write(sw, dataset.getNamedModel(signedGraphUri), Lang.TRIG); logger.debug("signing graph {} with content: {}", graphsToSign, sw.toString()); } String signatureUri = signedGraphUri + "-sig"; GraphCollection inputGraph = ModelConverter.modelToGraphCollection(signedGraphUri, dataset); SignatureData sigValue = signNamedGraph(inputGraph, privateKey, cert); String hash = WonHasher.hashToString(sigValue.getHash()); WonSignatureData sigRef = new WonSignatureData(Arrays.asList(signedGraphUri), signatureUri, sigValue.getSignature(), hash, fingerprint, cert); sigRefs.add(sigRef); } return sigRefs; } WonSigner(Dataset dataset); List<WonSignatureData> signNamedGraphsSeparately(PrivateKey privateKey, String cert, PublicKey publicKey,
                    String... graphsToSign); WonSignatureData signWholeDataset(PrivateKey privateKey, String cert, PublicKey publicKey,
                    String signatureUri); List<WonSignatureData> sign(PrivateKey privateKey, String cert, PublicKey publicKey,
                    Collection<String> graphsToSign); }
WonSigner { public List<WonSignatureData> signNamedGraphsSeparately(PrivateKey privateKey, String cert, PublicKey publicKey, String... graphsToSign) throws Exception { List<WonSignatureData> sigRefs = new ArrayList<>(graphsToSign.length); String fingerprint = WonHasher.hashToString(publicKey.getEncoded()); for (String signedGraphUri : graphsToSign) { if (logger.isDebugEnabled()) { StringWriter sw = new StringWriter(); RDFDataMgr.write(sw, dataset.getNamedModel(signedGraphUri), Lang.TRIG); logger.debug("signing graph {} with content: {}", graphsToSign, sw.toString()); } String signatureUri = signedGraphUri + "-sig"; GraphCollection inputGraph = ModelConverter.modelToGraphCollection(signedGraphUri, dataset); SignatureData sigValue = signNamedGraph(inputGraph, privateKey, cert); String hash = WonHasher.hashToString(sigValue.getHash()); WonSignatureData sigRef = new WonSignatureData(Arrays.asList(signedGraphUri), signatureUri, sigValue.getSignature(), hash, fingerprint, cert); sigRefs.add(sigRef); } return sigRefs; } WonSigner(Dataset dataset); List<WonSignatureData> signNamedGraphsSeparately(PrivateKey privateKey, String cert, PublicKey publicKey,
                    String... graphsToSign); WonSignatureData signWholeDataset(PrivateKey privateKey, String cert, PublicKey publicKey,
                    String signatureUri); List<WonSignatureData> sign(PrivateKey privateKey, String cert, PublicKey publicKey,
                    Collection<String> graphsToSign); static final String SIGNING_ALGORITHM_NAME; static final String SIGNING_ALGORITHM_PROVIDER; static final String ENV_HASH_ALGORITHM; static final Type HASH_ALGORITHM_FOR_MULTIHASH; }