当前位置: 首页>>代码示例>>Java>>正文


Java DOMValidateContext.setBaseURI方法代码示例

本文整理汇总了Java中javax.xml.crypto.dsig.dom.DOMValidateContext.setBaseURI方法的典型用法代码示例。如果您正苦于以下问题:Java DOMValidateContext.setBaseURI方法的具体用法?Java DOMValidateContext.setBaseURI怎么用?Java DOMValidateContext.setBaseURI使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.crypto.dsig.dom.DOMValidateContext的用法示例。


在下文中一共展示了DOMValidateContext.setBaseURI方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validate

import javax.xml.crypto.dsig.dom.DOMValidateContext; //导入方法依赖的package包/类
boolean validate(String fn, KeySelector ks, URIDereferencer ud,
    boolean cache) throws Exception {

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    dbf.setValidating(false);
    Document doc = dbf.newDocumentBuilder().parse(new File(dir, fn));
    NodeList nl =
        doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
    if (nl.getLength() == 0) {
        throw new Exception("Couldn't find signature Element");
    }
    Element sigElement = (Element) nl.item(0);
    DOMValidateContext vc = new DOMValidateContext(ks, sigElement);
    vc.setBaseURI(dir.toURI().toString());
    if (cache) {
        vc.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE);
    }
    XMLSignatureFactory factory = XMLSignatureFactory.getInstance();
    XMLSignature signature = factory.unmarshalXMLSignature(vc);
    if (ud != null) {
        vc.setURIDereferencer(ud);
    }
    boolean coreValidity = signature.validate(vc);

    // Check reference cache
    if (cache) {
        Iterator i = signature.getSignedInfo().getReferences().iterator();
        for (int j=0; i.hasNext(); j++) {
            Reference ref = (Reference) i.next();
            if (!digestInputEqual(ref)) {
                throw new Exception
                    ("cached data for Reference[" + j + "] is not correct");
            }
            // check that dereferenced data does not contain comment nodes
            if (ref.getURI() == "") {
                System.out.println("checking deref data");
                NodeSetData data = (NodeSetData) ref.getDereferencedData();
                Iterator ni = data.iterator();
                while (ni.hasNext()) {
                    Node n = (Node) ni.next();
                    if (n.getNodeType() == Node.COMMENT_NODE) {
                        throw new Exception("dereferenced data for " +
                            " Reference[" + j + " contains comment node");
                    }
                }
            }
        }
    }
    return coreValidity;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:52,代码来源:SignatureValidator.java

示例2: getValidateContext

import javax.xml.crypto.dsig.dom.DOMValidateContext; //导入方法依赖的package包/类
public DOMValidateContext getValidateContext(String fn, KeySelector ks)
    throws Exception {
    Document doc = XMLUtils.createDocumentBuilder(false, false).parse(new File(dir, fn));
    Element sigElement = getSignatureElement(doc);
    if (sigElement == null) {
        throw new Exception("Couldn't find signature Element");
    }
    DOMValidateContext vc = new DOMValidateContext(ks, sigElement);
    vc.setBaseURI(dir.toURI().toString());
    return vc;
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:12,代码来源:SignatureValidator.java

示例3: testWrappingAttack

import javax.xml.crypto.dsig.dom.DOMValidateContext; //导入方法依赖的package包/类
@org.junit.Test
public void testWrappingAttack() throws Exception {
    String file = "manifestSignatureWrapping.xml";

    Document doc = XMLUtils.createDocumentBuilder(false, false).parse(new File(dir, file));
    Element sigElement = SignatureValidator.getSignatureElement(doc);
    if (sigElement == null) {
        throw new Exception("Couldn't find signature Element");
    }
    DOMValidateContext vc =
        new DOMValidateContext(new KeySelectors.KeyValueKeySelector(), sigElement);
    vc.setBaseURI(dir.toURI().toString());

    vc.setProperty("org.apache.jcp.xml.dsig.secureValidation", Boolean.FALSE);
    boolean coreValidity = validator.validate(vc);
    assertTrue("Signature failed core validation", coreValidity);

    vc.setProperty("org.apache.jcp.xml.dsig.secureValidation", Boolean.TRUE);

    Element manifestElement =
        (Element) doc.getElementsByTagName("Manifest").item(0);
    vc.setIdAttributeNS(manifestElement, null, "Id");

    try {
        boolean valid = validator.validate(vc);
        System.out.println("Valid: " + valid);
        fail("Failure expected when secure validation is enabled");
    } catch (XMLSignatureException ex) {
        assertTrue(ex.getMessage().contains("URIReferenceException"));
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:32,代码来源:JSRWrappingAttackTest.java

示例4: if

import javax.xml.crypto.dsig.dom.DOMValidateContext; //导入方法依赖的package包/类
private static void test_create_signature_external
    (SignatureMethod sm, KeyInfo ki, Key signingKey, KeySelector ks,
    boolean b64) throws Exception {

    // create reference
    Reference ref;
    if (b64) {
        ref = fac.newReference
            (STYLESHEET_B64,
            sha1, Collections.singletonList
            (fac.newTransform(Transform.BASE64,
             (TransformParameterSpec) null)), null, null);
    } else {
        ref = fac.newReference(STYLESHEET, sha1);
    }

    // create SignedInfo
    SignedInfo si = fac.newSignedInfo(withoutComments, sm,
        Collections.singletonList(ref));

    Document doc = db.newDocument();

    // create XMLSignature
    XMLSignature sig = fac.newXMLSignature(si, ki);

    DOMSignContext dsc = new DOMSignContext(signingKey, doc);
    dsc.setURIDereferencer(httpUd);

    sig.sign(dsc);

    DOMValidateContext dvc = new DOMValidateContext
        (ks, doc.getDocumentElement());
    File f = new File(DATA_DIR);
    dvc.setBaseURI(f.toURI().toString());
    dvc.setURIDereferencer(httpUd);

    XMLSignature sig2 = fac.unmarshalXMLSignature(dvc);

    if (sig.equals(sig2) == false) {
        throw new Exception
            ("Unmarshalled signature is not equal to generated signature");
    }
    if (sig2.validate(dvc) == false) {
        throw new Exception("Validation of generated signature failed");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:47,代码来源:GenerationTests.java

示例5: validate

import javax.xml.crypto.dsig.dom.DOMValidateContext; //导入方法依赖的package包/类
boolean validate(String fn, KeySelector ks, URIDereferencer ud,
    boolean cache) throws Exception {

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    dbf.setValidating(false);
    Document doc = dbf.newDocumentBuilder().parse(new File(dir, fn));
    NodeList nl =
        doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
    if (nl.getLength() == 0) {
        throw new Exception("Couldn't find signature Element");
    }
    Element sigElement = (Element) nl.item(0);
    DOMValidateContext vc = new DOMValidateContext(ks, sigElement);
    vc.setBaseURI(dir.toURI().toString());
    if (cache) {
        vc.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE);
    }
    XMLSignatureFactory factory = XMLSignatureFactory.getInstance();
    XMLSignature signature = factory.unmarshalXMLSignature(vc);
    if (ud != null) {
        vc.setURIDereferencer(ud);
    }
    boolean coreValidity = signature.validate(vc);

    // Check reference cache
    if (cache) {
        Iterator<Reference> i =
            signature.getSignedInfo().getReferences().iterator();
        for (int j = 0; i.hasNext(); j++) {
            Reference ref = i.next();
            if (!digestInputEqual(ref)) {
                throw new Exception
                    ("cached data for Reference[" + j + "] is not correct");
            }
            // check that dereferenced data does not contain comment nodes
            if (ref.getURI() == "") {
                System.out.println("checking deref data");
                @SuppressWarnings("unchecked")
                NodeSetData<Node> data =
                    (NodeSetData<Node>)ref.getDereferencedData();
                for (Node n : data) {
                    if (n.getNodeType() == Node.COMMENT_NODE) {
                        throw new Exception("dereferenced data for " +
                            " Reference[" + j + " contains comment node");
                    }
                }
            }
        }
    }
    return coreValidity;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:53,代码来源:SignatureValidator.java

示例6: if

import javax.xml.crypto.dsig.dom.DOMValidateContext; //导入方法依赖的package包/类
private void test_create_signature_external
    (SignatureMethod sm, KeyInfo ki, Key signingKey, KeySelector ks,
    boolean b64) throws Exception {

    // create reference
    Reference ref;
    if (b64) {
        ref = fac.newReference
            ("http://www.w3.org/Signature/2002/04/xml-stylesheet.b64",
            sha1, Collections.singletonList
            (fac.newTransform(Transform.BASE64,
             (TransformParameterSpec) null)), null, null);
    } else {
        ref = fac.newReference
            ("http://www.w3.org/Signature/2002/04/xml-stylesheet.b64",sha1);
    }

    // create SignedInfo
    SignedInfo si = fac.newSignedInfo(withoutComments, sm,
        Collections.singletonList(ref));

    Document doc = db.newDocument();

    // create XMLSignature
    XMLSignature sig = fac.newXMLSignature(si, ki);

    DOMSignContext dsc = new DOMSignContext(signingKey, doc);
    dsc.setURIDereferencer(ud);

    sig.sign(dsc);
    TestUtils.validateSecurityOrEncryptionElement(doc.getDocumentElement());

    /*
    System.out.println("doc is:");
    StringWriter sw = new StringWriter();
    dumpDocument(doc, sw);
    System.out.println(sw.toString());
    */

    DOMValidateContext dvc = new DOMValidateContext
        (ks, doc.getDocumentElement());
    String base = System.getProperty("basedir") == null ? "./": System.getProperty("basedir");
    String fs = System.getProperty("file.separator");
    File f = new File(
        base + fs + "src/test/resources" + fs + "ie" + fs +
        "baltimore" + fs + "merlin-examples" + fs +
        "merlin-xmldsig-twenty-three" + fs);
    dvc.setBaseURI(f.toURI().toString());
    dvc.setURIDereferencer(ud);

    XMLSignature sig2 = fac.unmarshalXMLSignature(dvc);

    assertTrue(sig.equals(sig2));
    assertTrue(sig2.validate(dvc));
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:56,代码来源:CreateBaltimore23Test.java


注:本文中的javax.xml.crypto.dsig.dom.DOMValidateContext.setBaseURI方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。