Package javax.xml.crypto.dsig.dom

Examples of javax.xml.crypto.dsig.dom.DOMValidateContext


  DOMSignContext dsc = new DOMSignContext(signingKey, doc);

  sig.sign(dsc);

  DOMValidateContext dvc = new DOMValidateContext
      (ks, doc.getDocumentElement());
  XMLSignature sig2 = fac.unmarshalXMLSignature(dvc);

  assertTrue(sig.equals(sig2));
  assertTrue(sig2.validate(dvc));
View Full Code Here


    public void tearDown() {}

    public void testConstructor() throws Exception {
  assertNotNull(domVC);
  DOMValidateContext vc;
  try {
      vc = new DOMValidateContext(TestUtils.getPublicKey("RSA"), null);
      fail("Should throw a NPE for null node");
  } catch (NullPointerException npe) {
  } catch (Exception ex) {
      fail("Should throw a NPE instead of " + ex + " for null node");
  }
View Full Code Here

     * The element's ID needs to be registered so that it can be found.
     */
    public void test_signature_with_ID() throws Exception {
        String file = "envelopingSignature.xml";

  DOMValidateContext vc = validator.getValidateContext
      (file, new KeySelectors.KeyValueKeySelector());
  Document doc = vc.getNode().getOwnerDocument();
  NodeList nl = doc.getElementsByTagName("Assertion");
  vc.setIdAttributeNS((Element) nl.item(0), null, "AssertionID");
  boolean coreValidity = validator.validate(vc);
  assertTrue("Signature failed core validation", coreValidity);
    }
View Full Code Here

      }
      sig = fac.newXMLSignature(si, ki, objs, id, sigValueId);
      Document doc = TestUtils.newDocument();
      signContext = new DOMSignContext(SIGN_KEYS[i], doc);
      sig.sign(signContext);
      validateContext = new DOMValidateContext
    (VALIDATE_KEYS[i], doc.getDocumentElement());
      if (sig.validate(validateContext) == false) {
    status = false;
    TestUtils.dumpDocument(doc, "signatureTest_out"+i+".xml");
      }
View Full Code Here

    public void tearDown() {}

    public void testConstructor() throws Exception {
  assertNotNull(domVC);
  try {
      new DOMValidateContext(TestUtils.getPublicKey("RSA"), null);
      fail("Should throw a NPE for null node");
  } catch (NullPointerException npe) {
  } catch (Exception ex) {
      fail("Should throw a NPE instead of " + ex + " for null node");
  }
View Full Code Here

            key = publicKey;
        } else {
            key = WSSecurityUtil.prepareSecretKey(signatureMethod, secretKey);
        }
       
        XMLValidateContext context = new DOMValidateContext(key, elem);
        context.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE);
        context.setProperty("org.apache.jcp.xml.dsig.secureValidation", Boolean.TRUE);
        context.setProperty(STRTransform.TRANSFORM_WS_DOC_INFO, wsDocInfo);
       
        try {
            XMLSignature xmlSignature = signatureFactory.unmarshalXMLSignature(context);
           
            // Test for replay attacks
View Full Code Here

        NodeList nodeList = document.getElementsByTagNameNS(XMLSignature.XMLNS, XMLSigner.SIGNATURE_ELEMENT);
        if ((nodeList != null) && (nodeList.getLength() > 0)) {
          Node node = nodeList.item(0);
          if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element element = (Element) node;
            DOMValidateContext domValidateContext = new DOMValidateContext(KeySelector.singletonKeySelector(publicKey), element);
            XMLSignature xmlSignature = this.xmlSignatureFactory.unmarshalXMLSignature(domValidateContext);
            valid = xmlSignature.getSignatureValue().validate(domValidateContext);
            if (!valid) {
              break;
            }
View Full Code Here

    NodeList nl = doc.getElementsByTagNameNS( XMLSignature.XMLNS, "Signature" );
    if ( nl.getLength() == 0 ) {
      throw new IllegalStateException( "Cannot find Signature element!" );
    }

    DOMValidateContext valContext = new DOMValidateContext( x509Support.getCertificate().getPublicKey(), nl.item( 0 ) );
    XMLSignature signature = SIGNATURE_FACTORY.unmarshalXMLSignature( valContext );
    return signature.validate( valContext );

    //    if ( signature.validate( valContext ) ) {
    //      System.out.println( "Signature passed core validation!" );
View Full Code Here

        XMLSignatureFactory fac = initXMLSigFactory();
        NodeList nl = element.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
        if (nl.getLength() == 0) {
            throw new RuntimeException("Cannot find Signature element");
        }
        DOMValidateContext valContext = new DOMValidateContext(validatingKey, nl.item(0));
        try {
            valContext.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE);
            XMLSignature signature = fac.unmarshalXMLSignature(valContext);
            boolean coreValidity = signature.validate(valContext);
            // Check core validation status.
            if (coreValidity == false) {
                System.err.println("Signature failed core validation");
View Full Code Here

            key = publicKey;
        } else {
            key = WSSecurityUtil.prepareSecretKey(signatureMethod, secretKey);
        }
       
        XMLValidateContext context = new DOMValidateContext(key, elem);
        context.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE);
        context.setProperty(STRTransform.TRANSFORM_WS_DOC_INFO, wsDocInfo);
       
        try {
            XMLSignature xmlSignature = signatureFactory.unmarshalXMLSignature(context);
            setElementsOnContext(xmlSignature, (DOMValidateContext)context, wsDocInfo, elem.getOwnerDocument());
            boolean signatureOk = xmlSignature.validate(context);
View Full Code Here

TOP

Related Classes of javax.xml.crypto.dsig.dom.DOMValidateContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.