当前位置: 首页>>代码示例>>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;未经允许,请勿转载。