當前位置: 首頁>>代碼示例>>Java>>正文


Java DOMValidateContext類代碼示例

本文整理匯總了Java中javax.xml.crypto.dsig.dom.DOMValidateContext的典型用法代碼示例。如果您正苦於以下問題:Java DOMValidateContext類的具體用法?Java DOMValidateContext怎麽用?Java DOMValidateContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DOMValidateContext類屬於javax.xml.crypto.dsig.dom包,在下文中一共展示了DOMValidateContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: validate

import javax.xml.crypto.dsig.dom.DOMValidateContext; //導入依賴的package包/類
public Result validate ( final Document doc ) throws Exception
{
    final NodeList nl = doc.getElementsByTagNameNS ( XMLSignature.XMLNS, "Signature" ); //$NON-NLS-1$

    if ( nl.getLength () == 0 )
    {
        return new Result ( StatusCodes.VALIDATE_NO_SIGNATURE_DATA, "No signature data found" );
    }

    final DOMValidateContext dvc = new DOMValidateContext ( this.keySelector, nl.item ( 0 ) );

    final XMLSignature signature = this.factory.unmarshalXMLSignature ( dvc );

    try
    {
        final boolean result = signature.validate ( dvc );

        return new Result ( result, signature );
    }
    catch ( final XMLSignatureException e )
    {
        logger.debug ( "Failed to perform validation", e );
        return Result.INVALID;
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:26,代碼來源:RequestValidator.java

示例2: testCreateDSA2048Signature

import javax.xml.crypto.dsig.dom.DOMValidateContext; //導入依賴的package包/類
@org.junit.Test
public void testCreateDSA2048Signature() throws Exception {

    // check if SHA256withDSA is supported
    boolean gotSHA256withDSA = false;
    try {
        Signature.getInstance("SHA256withDSA");
        gotSHA256withDSA = true;
    } catch (NoSuchAlgorithmException e) {}
    org.junit.Assume.assumeTrue(gotSHA256withDSA);

    SignatureMethod sm = fac.newSignatureMethod(DSA_SHA256, null);
    SignedInfo si = createSignedInfo(sm);
    KeyInfo ki = kifac.newKeyInfo(Collections.singletonList
        (kifac.newKeyValue((PublicKey)TestUtils.getPublicKey("DSA", 2048))));
    XMLSignature sig = fac.newXMLSignature(si, ki, objs, id, sigValueId);
    Document doc = TestUtils.newDocument();
    XMLSignContext signContext =
        new DOMSignContext(TestUtils.getPrivateKey("DSA", 2048), doc);
    signContext.setURIDereferencer(ud);
    sig.sign(signContext);
    XMLValidateContext validateContext = new DOMValidateContext
        (TestUtils.getPublicKey("DSA", 2048), doc.getDocumentElement());
    validateContext.setURIDereferencer(ud);
    assertTrue(sig.validate(validateContext));
}
 
開發者ID:Legostaev,項目名稱:xmlsec-gost,代碼行數:27,代碼來源:XMLSignatureTest.java

示例3: validate

import javax.xml.crypto.dsig.dom.DOMValidateContext; //導入依賴的package包/類
public boolean validate(DOMValidateContext vc) throws Exception {

        XMLSignatureFactory factory = XMLSignatureFactory.getInstance
            ("DOM", new org.apache.jcp.xml.dsig.internal.dom.XMLDSigRI());
        XMLSignature signature = factory.unmarshalXMLSignature(vc);
        boolean coreValidity = signature.validate(vc);

        // Check core validation status
        if (coreValidity == false) {
            // check the validation status of each Reference
            @SuppressWarnings("unchecked")
            Iterator<Reference> i = signature.getSignedInfo().getReferences().iterator();
            while (i.hasNext()) {
                Reference reference = i.next();
                reference.validate(vc);
            }
        }
        return coreValidity;
    }
 
開發者ID:Legostaev,項目名稱:xmlsec-gost,代碼行數:20,代碼來源:SignatureValidator.java

示例4: getXMLValidateContext

import javax.xml.crypto.dsig.dom.DOMValidateContext; //導入依賴的package包/類
public static XMLValidateContext getXMLValidateContext(String type,
                                                   File input,
                                                   String tag)
    throws Exception {
    if (type.equalsIgnoreCase("dom")) {
        DocumentBuilder docBuilder = XMLUtils.createDocumentBuilder(false, false);
        Document doc = docBuilder.parse(input);
        if (tag == null) {
            return new DOMValidateContext
                (TestUtils.getPublicKey("RSA", 512),
                 doc.getDocumentElement());
        } else {
            NodeList list = doc.getElementsByTagName(tag);
            return new DOMValidateContext
                (TestUtils.getPublicKey("RSA", 512), list.item(0));
        }
    } else {
        throw new Exception("Unsupported XMLValidateContext type: " + type);
    }
}
 
開發者ID:Legostaev,項目名稱:xmlsec-gost,代碼行數:21,代碼來源:TestUtils.java

示例5: testLocalFilesystem

import javax.xml.crypto.dsig.dom.DOMValidateContext; //導入依賴的package包/類
@org.junit.Test
public void testLocalFilesystem() throws Exception {
    String file = "signature-external-c14n-xmlatrs.xml";

    DOMValidateContext vc =
        validator.getValidateContext(
            file, new KeySelectors.SecretKeySelector("secret".getBytes("ASCII"))
        );

    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);

    try {
        validator.validate(vc);
        fail("Failure expected when secure validation is enabled");
    } catch (XMLSignatureException ex) {
        assertTrue(ex.getMessage().contains("URIReferenceException"));
    }
}
 
開發者ID:Legostaev,項目名稱:xmlsec-gost,代碼行數:23,代碼來源:JSRForbiddenReferenceTest.java

示例6: explainValidationProblem

import javax.xml.crypto.dsig.dom.DOMValidateContext; //導入依賴的package包/類
private static String explainValidationProblem(
    DOMValidateContext context, XMLSignature signature)
        throws XMLSignatureException {
  @SuppressWarnings("unchecked")  // Safe by specification.
  List<Reference> references = signature.getSignedInfo().getReferences();
  StringBuilder builder = new StringBuilder();
  builder.append("Signature failed core validation\n");
  boolean sv = signature.getSignatureValue().validate(context);
  builder.append("Signature validation status: " + sv + "\n");
  for (Reference ref : references) {
    builder.append("references[");
    builder.append(ref.getURI());
    builder.append("] validity status: ");
    builder.append(ref.validate(context));
    builder.append("\n");
  }
  return builder.toString();
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:19,代碼來源:TmchXmlSignature.java

示例7: verifySignature

import javax.xml.crypto.dsig.dom.DOMValidateContext; //導入依賴的package包/類
/**
 * Verification via the default JSR105 implementation triggers some
 * canonicalization errors.
 * 
 * @param odfUrl
 * @param signatureNode
 * @throws MarshalException
 * @throws XMLSignatureException
 */
private boolean verifySignature(URL odfUrl, Node signatureNode) throws MarshalException, XMLSignatureException {

	// work-around for Java 7
	Element signedPropertiesElement = (Element) ((Element) signatureNode)
			.getElementsByTagNameNS(XAdESXLSignatureFacet.XADES_NAMESPACE, "SignedProperties").item(0);
	if (null != signedPropertiesElement) {
		signedPropertiesElement.setIdAttribute("Id", true);
	}

	DOMValidateContext domValidateContext = new DOMValidateContext(new KeyInfoKeySelector(), signatureNode);
	ODFURIDereferencer dereferencer = new ODFURIDereferencer(odfUrl);
	domValidateContext.setURIDereferencer(dereferencer);
	XMLSignatureFactory xmlSignatureFactory = XMLSignatureFactory.getInstance();
	LOG.debug("java version: " + System.getProperty("java.version"));
	/*
	 * Requires Java 6u10 because of a bug. See also:
	 * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6696582
	 */
	XMLSignature xmlSignature = xmlSignatureFactory.unmarshalXMLSignature(domValidateContext);
	boolean validity = xmlSignature.validate(domValidateContext);
	return validity;
}
 
開發者ID:e-Contract,項目名稱:eid-applet,代碼行數:32,代碼來源:AbstractODFSignatureServiceTest.java

示例8: validate_error

import javax.xml.crypto.dsig.dom.DOMValidateContext; //導入依賴的package包/類
@Test(expected = DigitalSignatureValidationException.class)
public void validate_error() throws Exception {
    // given
    FileInputStream in = null;
    Document document = null;
    try {
        in = new FileInputStream(FILE_OPENAM_RESPONSE);
        document = XMLConverter.convertToDocument(in);
    } finally {
        if (in != null) {
            in.close();
        }
    }
    NodeList nl = document.getElementsByTagNameNS(XMLSignature.XMLNS,
            "Signature");
    doThrow(new XMLSignatureException("")).when(validator)
            .workaroundOpenamBug(any(XMLSignature.class),
                    any(DOMValidateContext.class), anyBoolean());

    // when
    validator.validate(nl.item(0));

    // then exception expected
}
 
開發者ID:servicecatalog,項目名稱:development,代碼行數:25,代碼來源:DigitalSignatureValidatorTest.java

示例9: validSignature

import javax.xml.crypto.dsig.dom.DOMValidateContext; //導入依賴的package包/類
/**
 * Check the xmldsig signature of the XML document.
 *
 * @param document  the document to test
 * @param publicKey the public key corresponding to the key pair the document was signed with
 * @return true if a correct signature is present, false otherwise
 */
public static boolean validSignature(Document document, Key publicKey) {
    Node signatureNode = document.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature").item(0);
    KeySelector keySelector = KeySelector.singletonKeySelector(publicKey);

    try {
        String providerName =
                System.getProperty("jsr105Provider", "org.jcp.xml.dsig.internal.dom.XMLDSigRI");
        XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM",
                (Provider) Class.forName(providerName).newInstance());
        DOMValidateContext valContext = new DOMValidateContext(keySelector, signatureNode);

        XMLSignature signature = fac.unmarshalXMLSignature(valContext);
        return signature.validate(valContext);
    } catch (Exception e) {
        logger.warn("Error validating an XML signature.", e);
        return false;
    }
}
 
開發者ID:GojaFramework,項目名稱:goja,代碼行數:26,代碼來源:XML.java

示例10: isValid

import javax.xml.crypto.dsig.dom.DOMValidateContext; //導入依賴的package包/類
public boolean isValid() throws Exception {
	NodeList nodes = xmlDoc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");

	if (nodes == null || nodes.getLength() == 0) {
		throw new Exception("Can't find signature in document.");
	}

	if (setIdAttributeExists()) {
		tagIdAttributes(xmlDoc);
	}

	X509Certificate cert = samlSettings.getCertificate();
	DOMValidateContext ctx = new DOMValidateContext(cert.getPublicKey(), nodes.item(0));
	XMLSignatureFactory sigF = XMLSignatureFactory.getInstance("DOM");
	XMLSignature xmlSignature = sigF.unmarshalXMLSignature(ctx);

	return xmlSignature.validate(ctx);
}
 
開發者ID:GluuFederation,項目名稱:oxCore,代碼行數:19,代碼來源:Response.java

示例11: isValida

import javax.xml.crypto.dsig.dom.DOMValidateContext; //導入依賴的package包/類
public boolean isValida(final InputStream xmlStream) throws Exception {
    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);

    final Document document = dbf.newDocumentBuilder().parse(xmlStream);
    final NodeList nodeList = document.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
    if (nodeList.getLength() == 0) {
        throw new IllegalStateException("Nao foi encontrada a assinatura do XML.");
    }

    final String providerName = System.getProperty("jsr105Provider", "org.jcp.xml.dsig.internal.dom.XMLDSigRI");
    final XMLSignatureFactory signatureFactory = XMLSignatureFactory.getInstance("DOM", (Provider) Class.forName(providerName).newInstance());
    final DOMValidateContext validateContext = new DOMValidateContext(new X509KeySelector(), nodeList.item(0));

    for (final String tag : AssinaturaDigital.ELEMENTOS_ASSINAVEIS) {
        final NodeList elements = document.getElementsByTagName(tag);
        if (elements.getLength() > 0) {
            validateContext.setIdAttributeNS((Element) elements.item(0), null, "Id");
        }
    }

    return signatureFactory.unmarshalXMLSignature(validateContext).validate(validateContext);
}
 
開發者ID:wmixvideo,項目名稱:nfe,代碼行數:24,代碼來源:AssinaturaDigital.java

示例12: validate

import javax.xml.crypto.dsig.dom.DOMValidateContext; //導入依賴的package包/類
public synchronized boolean validate()
		throws MarshalException,
		XMLSignatureException {

	// Find Signature element.
	NodeList list = document.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
	if (list.getLength() == 0) {
		throw new RuntimeException("Cannot find Signature element");
	}

	// Create a DOMValidateContext and specify a KeySelector
	// and document context.
	DOMValidateContext validateContext = new DOMValidateContext(new X509CertificateKeySelector(), list.item(0));

	// Unmarshal the XMLSignature.
	XMLSignature signature = this.signatureFactory.unmarshalXMLSignature(validateContext);

	// Validate the XMLSignature.
	if (signature.validate(validateContext)) {
		return true;
	} else {
		Iterator<?> i = signature.getSignedInfo().getReferences().iterator();
		for (int j = 0; i.hasNext(); j++) {
			System.out.print("ref[" + j + "] -> ");
			Reference ref = (Reference) i.next();
			System.out.print(ref.getURI());
			System.out.print(", ");
			System.out.print(ref.getDigestMethod().toString());
			System.out.print(", ");
			System.out.print(ref.getId());
			boolean refValid = ref.validate(validateContext);
			System.out.print(", validity status: " + refValid + "\r\n");
		}
		return false;
	}
}
 
開發者ID:EixoX,項目名稱:jetfuel,代碼行數:37,代碼來源:XmlSignatureHandler.java

示例13: verifySignature

import javax.xml.crypto.dsig.dom.DOMValidateContext; //導入依賴的package包/類
public static boolean verifySignature(Document doc , X509Certificate cert) {
    try{
        if (doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature").getLength() == 0)
            throw new Exception("Cannot find Signature element");

        DOMValidateContext valContext = new DOMValidateContext(cert.getPublicKey(), doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature").item(0));

        XMLSignature signature = XMLSignatureFactory.getInstance("DOM").unmarshalXMLSignature(valContext);

        return signature.validate(valContext); 
    }catch(Exception e){e.printStackTrace();}
    return false;
}
 
開發者ID:damianofalcioni,項目名稱:Websocket-Smart-Card-Signer,代碼行數:14,代碼來源:XMLUtils.java

示例14: validate

import javax.xml.crypto.dsig.dom.DOMValidateContext; //導入依賴的package包/類
private boolean validate(final DOMValidateContext validationContext)
        throws DigitalSignatureValidationException {

    try {
        // if (getLogger().isDebugLoggingEnabled()) {
        // enableReferenceCaching(validationContext);
        // }

        XMLSignatureFactory factory = XMLSignatureFactory
                .getInstance(XML_MECHANISM_TYPE);
        XMLSignature signature = factory
                .unmarshalXMLSignature(validationContext);
        boolean validationResult = signature.validate(validationContext);

        validationResult = workaroundOpenamBug(signature,
                validationContext, validationResult);

        // if (getLogger().isDebugLoggingEnabled()) {
        // debugLogReferences(signature, validationContext);
        // }
        return validationResult;
    } catch (XMLSignatureException | MarshalException exception) {
        throw new DigitalSignatureValidationException(
                "Error occurred during digital signature validation process",
                DigitalSignatureValidationException.ReasonEnum.EXCEPTION_OCCURRED,
                exception);
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:29,代碼來源:DigitalSignatureValidator.java

示例15: workaroundOpenamBug

import javax.xml.crypto.dsig.dom.DOMValidateContext; //導入依賴的package包/類
/**
 * The overall signature validation consists of two steps, one is the
 * validation of the signature itself and the other the validation of the
 * references digest values. Because of a canonicalization bug in openam,
 * which is not yet registered, the second verification cannot be done.
 * 
 * @return true if the signature validation has not failed, even if the
 *         reference validation failed.
 */
boolean workaroundOpenamBug(XMLSignature signature,
        DOMValidateContext validationContext, boolean validationResult)
        throws XMLSignatureException {
    if (!validationResult) {
        if (signature.getSignatureValue().validate(validationContext)) {
            return true;
        }
    }
    return validationResult;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:20,代碼來源:DigitalSignatureValidator.java


注:本文中的javax.xml.crypto.dsig.dom.DOMValidateContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。