Search in sources :

Example 6 with URIDereferencer

use of javax.xml.crypto.URIDereferencer in project santuario-java by apache.

the class CreatePhaosXMLDSig3Test method test_create_hmac_sha1_exclusive_c14n_comments_detached.

private void test_create_hmac_sha1_exclusive_c14n_comments_detached(boolean fortyBit) throws Exception {
    // create reference
    Reference ref = fac.newReference("http://www.ietf.org/rfc/rfc3161.txt", fac.newDigestMethod(DigestMethod.SHA1, null));
    // create SignedInfo
    HMACParameterSpec spec = null;
    if (fortyBit) {
        spec = new HMACParameterSpec(40);
    }
    SignedInfo si = fac.newSignedInfo(fac.newCanonicalizationMethod(CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS, (C14NMethodParameterSpec) null), fac.newSignatureMethod(SignatureMethod.HMAC_SHA1, spec), Collections.singletonList(ref));
    // create XMLSignature
    XMLSignature sig = fac.newXMLSignature(si, null);
    Document doc = db.newDocument();
    DOMSignContext dsc = new DOMSignContext(new KeySelectors.SecretKeySelector("test".getBytes(StandardCharsets.US_ASCII)), doc);
    dsc.putNamespacePrefix(XMLSignature.XMLNS, "dsig");
    URIDereferencer ud = new LocalHttpCacheURIDereferencer();
    dsc.setURIDereferencer(ud);
    sig.sign(dsc);
    TestUtils.validateSecurityOrEncryptionElement(doc.getDocumentElement());
    DOMValidateContext dvc = new DOMValidateContext(new KeySelectors.SecretKeySelector("test".getBytes(StandardCharsets.US_ASCII)), doc);
    dvc.setURIDereferencer(ud);
    XMLSignature sig2 = fac.unmarshalXMLSignature(dvc);
    assertTrue(sig.equals(sig2));
    assertTrue(sig2.validate(dvc));
}
Also used : KeySelectors(javax.xml.crypto.test.KeySelectors) URIDereferencer(javax.xml.crypto.URIDereferencer)

Aggregations

URIDereferencer (javax.xml.crypto.URIDereferencer)6 DOMSignContext (javax.xml.crypto.dsig.dom.DOMSignContext)3 DOMValidateContext (javax.xml.crypto.dsig.dom.DOMValidateContext)2 Document (org.w3c.dom.Document)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 URISyntaxException (java.net.URISyntaxException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 MessageDigest (java.security.MessageDigest)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Data (javax.xml.crypto.Data)1 MarshalException (javax.xml.crypto.MarshalException)1 NodeSetData (javax.xml.crypto.NodeSetData)1 URIReferenceException (javax.xml.crypto.URIReferenceException)1 XMLStructure (javax.xml.crypto.XMLStructure)1 javax.xml.crypto.dsig (javax.xml.crypto.dsig)1 CanonicalizationMethod (javax.xml.crypto.dsig.CanonicalizationMethod)1 Manifest (javax.xml.crypto.dsig.Manifest)1