org.apache.xml.security.transforms.Transforms Java Examples

The following examples show how to use org.apache.xml.security.transforms.Transforms. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlSigOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private XMLSignature prepareEnvelopedSignature(Document doc,
        String id,
        String referenceURI,
        String sigAlgo,
        String digestAlgo) throws Exception {
    doc.getDocumentElement().setAttributeNS(null, "Id", id);
    doc.getDocumentElement().setIdAttributeNS(null, "Id", true);

    XMLSignature sig = new XMLSignature(doc, "", sigAlgo);
    doc.getDocumentElement().appendChild(sig.getElement());
    Transforms transforms = new Transforms(doc);
    transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
    transforms.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);

    sig.addDocument(referenceURI, transforms, digestAlgo);
    return sig;
}
 
Example #2
Source File: XadesHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public void before() throws TechnicalConnectorException, XMLSecurityException {
   if (!ArrayUtils.isEmpty(this.specs)) {
      ObjectContainer container = new ObjectContainer(this.sig.getDocument());
      this.sig.appendObject(container);
      QualifyingPropertiesBuilder qualProperties = new QualifyingPropertiesBuilder();
      String xadesSignedId = IdGeneratorFactory.getIdGenerator("uuid").generateId();
      XadesSpecification[] arr$ = this.specs;
      int len$ = arr$.length;

      for(int i$ = 0; i$ < len$; ++i$) {
         XadesSpecification spec = arr$[i$];
         spec.addOptionalBeforeSignatureParts(qualProperties.getSignedProps(), this.sig, this.signatureCredential, xadesSignedId, this.options);
      }

      Document xadesQualPropertiesDocument = qualProperties.buildBeforeSigningAsDocument();
      this.xadesQualProperties = (Element)this.sig.getDocument().importNode(xadesQualPropertiesDocument.getDocumentElement(), true);
      container.appendChild(this.xadesQualProperties);
      this.sig.addResourceResolver(new DocumentResolver(xadesQualPropertiesDocument));
      Transforms xadesTransform = new Transforms(this.sig.getDocument());
      xadesTransform.addTransform("http://www.w3.org/2001/10/xml-exc-c14n#");
      this.sig.addDocument(ref(qualProperties.getSignedProps().getId()), xadesTransform, (String)SignatureUtils.getOption("digestURI", this.options, "http://www.w3.org/2001/04/xmlenc#sha256"), (String)null, "http://uri.etsi.org/01903#SignedProperties");
   }
}
 
Example #3
Source File: XmlSigOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private XMLSignature prepareDetachedSignature(Document doc,
        String id,
        String referenceId,
        String sigAlgo,
        String digestAlgo) throws Exception {
    Element docEl = doc.getDocumentElement();
    Document newDoc = DOMUtils.createDocument();
    doc.removeChild(docEl);
    newDoc.adoptNode(docEl);
    docEl.setAttributeNS(null, "Id", id);
    docEl.setIdAttributeNS(null, "Id", true);

    Element root = newDoc.createElementNS(envelopeQName.getNamespaceURI(),
            envelopeQName.getPrefix() + ":" + envelopeQName.getLocalPart());
    root.appendChild(docEl);
    newDoc.appendChild(root);

    XMLSignature sig = new XMLSignature(newDoc, "", sigAlgo);
    root.appendChild(sig.getElement());

    Transforms transforms = new Transforms(newDoc);
    transforms.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);

    sig.addDocument(referenceId, transforms, digestAlgo);
    return sig;
}
 
Example #4
Source File: XadesHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public void before() throws TechnicalConnectorException, XMLSecurityException {
   if (!ArrayUtils.isEmpty(this.specs)) {
      ObjectContainer container = new ObjectContainer(this.sig.getDocument());
      this.sig.appendObject(container);
      QualifyingPropertiesBuilder qualProperties = new QualifyingPropertiesBuilder();
      String xadesSignedId = IdGeneratorFactory.getIdGenerator("uuid").generateId();
      XadesSpecification[] arr$ = this.specs;
      int len$ = arr$.length;

      for(int i$ = 0; i$ < len$; ++i$) {
         XadesSpecification spec = arr$[i$];
         spec.addOptionalBeforeSignatureParts(qualProperties.getSignedProps(), this.sig, this.signatureCredential, xadesSignedId, this.options);
      }

      Document xadesQualPropertiesDocument = qualProperties.buildBeforeSigningAsDocument();
      this.xadesQualProperties = (Element)this.sig.getDocument().importNode(xadesQualPropertiesDocument.getDocumentElement(), true);
      container.appendChild(this.xadesQualProperties);
      this.sig.addResourceResolver(new DocumentResolver(xadesQualPropertiesDocument));
      Transforms xadesTransform = new Transforms(this.sig.getDocument());
      xadesTransform.addTransform("http://www.w3.org/2001/10/xml-exc-c14n#");
      this.sig.addDocument(ref(qualProperties.getSignedProps().getId()), xadesTransform, (String)SignatureUtils.getOption("digestURI", this.options, "http://www.w3.org/2001/04/xmlenc#sha256"), (String)null, "http://uri.etsi.org/01903#SignedProperties");
   }
}
 
Example #5
Source File: XmlSigOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private XMLSignature prepareEnvelopingSignature(Document doc,
                                                String id,
                                                String referenceId,
                                                String sigAlgo,
                                                String digestAlgo) throws Exception {
    Element docEl = doc.getDocumentElement();
    Document newDoc = DOMUtils.createDocument();
    doc.removeChild(docEl);
    newDoc.adoptNode(docEl);
    Element object = newDoc.createElementNS(Constants.SignatureSpecNS, "ds:Object");
    object.appendChild(docEl);
    docEl.setAttributeNS(null, "Id", id);
    docEl.setIdAttributeNS(null, "Id", true);

    XMLSignature sig = new XMLSignature(newDoc, "", sigAlgo);
    newDoc.appendChild(sig.getElement());
    sig.getElement().appendChild(object);

    Transforms transforms = new Transforms(newDoc);
    transforms.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);

    sig.addDocument(referenceId, transforms, digestAlgo);
    return sig;
}
 
Example #6
Source File: XadesHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public void before() throws TechnicalConnectorException, XMLSecurityException {
   if (!ArrayUtils.isEmpty(this.specs)) {
      ObjectContainer container = new ObjectContainer(this.sig.getDocument());
      this.sig.appendObject(container);
      QualifyingPropertiesBuilder qualProperties = new QualifyingPropertiesBuilder();
      String xadesSignedId = IdGeneratorFactory.getIdGenerator("uuid").generateId();
      XadesSpecification[] arr$ = this.specs;
      int len$ = arr$.length;

      for(int i$ = 0; i$ < len$; ++i$) {
         XadesSpecification spec = arr$[i$];
         spec.addOptionalBeforeSignatureParts(qualProperties.getSignedProps(), this.sig, this.signatureCredential, xadesSignedId, this.options);
      }

      Document xadesQualPropertiesDocument = qualProperties.buildBeforeSigningAsDocument();
      this.xadesQualProperties = (Element)this.sig.getDocument().importNode(xadesQualPropertiesDocument.getDocumentElement(), true);
      container.appendChild(this.xadesQualProperties);
      this.sig.addResourceResolver(new DocumentResolver(xadesQualPropertiesDocument));
      Transforms xadesTransform = new Transforms(this.sig.getDocument());
      xadesTransform.addTransform("http://www.w3.org/2001/10/xml-exc-c14n#");
      this.sig.addDocument(ref(qualProperties.getSignedProps().getId()), xadesTransform, (String)SignatureUtils.getOption("digestURI", this.options, "http://www.w3.org/2001/04/xmlenc#sha256"), (String)null, "http://uri.etsi.org/01903#SignedProperties");
   }
}
 
Example #7
Source File: XadesHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public void before() throws TechnicalConnectorException, XMLSecurityException {
   if (!ArrayUtils.isEmpty(this.specs)) {
      ObjectContainer container = new ObjectContainer(this.sig.getDocument());
      this.sig.appendObject(container);
      QualifyingPropertiesBuilder qualProperties = new QualifyingPropertiesBuilder();
      String xadesSignedId = IdGeneratorFactory.getIdGenerator("uuid").generateId();
      XadesSpecification[] arr$ = this.specs;
      int len$ = arr$.length;

      for(int i$ = 0; i$ < len$; ++i$) {
         XadesSpecification spec = arr$[i$];
         spec.addOptionalBeforeSignatureParts(qualProperties.getSignedProps(), this.sig, this.signatureCredential, xadesSignedId, this.options);
      }

      Document xadesQualPropertiesDocument = qualProperties.buildBeforeSigningAsDocument();
      this.xadesQualProperties = (Element)this.sig.getDocument().importNode(xadesQualPropertiesDocument.getDocumentElement(), true);
      container.appendChild(this.xadesQualProperties);
      this.sig.addResourceResolver(new DocumentResolver(xadesQualPropertiesDocument));
      Transforms xadesTransform = new Transforms(this.sig.getDocument());
      xadesTransform.addTransform("http://www.w3.org/2001/10/xml-exc-c14n#");
      this.sig.addDocument(ref(qualProperties.getSignedProps().getId()), xadesTransform, (String)SignatureUtils.getOption("digestURI", this.options, "http://www.w3.org/2001/04/xmlenc#sha256"), (String)null, "http://uri.etsi.org/01903#SignedProperties");
   }
}
 
Example #8
Source File: XAdESReferenceValidation.java    From dss with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public List<String> getTransformationNames() {
	if (transforms == null) {
		transforms = new ArrayList<>();
		try {
			Transforms referenceTransforms = reference.getTransforms();
			if (referenceTransforms != null) {
				Element transformsElement = referenceTransforms.getElement();
				NodeList transfromChildNodes = transformsElement.getChildNodes();
				if (transfromChildNodes != null && transfromChildNodes.getLength() > 0) {
					for (int i = 0; i < transfromChildNodes.getLength(); i++) {
						Node transformation = transfromChildNodes.item(i);
						if (Node.ELEMENT_NODE == transformation.getNodeType()) {
							transforms.add(buildTransformationName(transformation));
						}
					}
				}
			}
		} catch (XMLSecurityException e) {
			LOG.warn("Unable to analyze trasnformations", e);
		}
	}
	return transforms;
}
 
Example #9
Source File: DSSXMLUtils.java    From dss with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static boolean isEnvelopedTransform(Node transformation) {
	final String algorithm = DomUtils.getValue(transformation, "@Algorithm");
	if (Transforms.TRANSFORM_ENVELOPED_SIGNATURE.equals(algorithm)) {
		return true;
	} else if (Transforms.TRANSFORM_XPATH.equals(algorithm) || 
			Transforms.TRANSFORM_XPATH2FILTER.equals(algorithm)) {
		NodeList childNodes = transformation.getChildNodes();
		for (int j = 0; j < childNodes.getLength(); j++) {
			Node item = childNodes.item(j);
			if (Node.ELEMENT_NODE == item.getNodeType() && TRANSFORMATION_XPATH_NODE_NAME.equals(item.getLocalName()) &&
					TRANSFORMATION_EXCLUDE_SIGNATURE.equals(item.getTextContent())) {
				return true;
			}
		}
	}
	return false;
}
 
Example #10
Source File: XadesHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public void before() throws TechnicalConnectorException, XMLSecurityException {
   if (!ArrayUtils.isEmpty(this.specs)) {
      ObjectContainer container = new ObjectContainer(this.sig.getDocument());
      this.sig.appendObject(container);
      QualifyingPropertiesBuilder qualProperties = new QualifyingPropertiesBuilder();
      String xadesSignedId = IdGeneratorFactory.getIdGenerator("uuid").generateId();
      XadesSpecification[] arr$ = this.specs;
      int len$ = arr$.length;

      for(int i$ = 0; i$ < len$; ++i$) {
         XadesSpecification spec = arr$[i$];
         spec.addOptionalBeforeSignatureParts(qualProperties.getSignedProps(), this.sig, this.signatureCredential, xadesSignedId, this.options);
      }

      Document xadesQualPropertiesDocument = qualProperties.buildBeforeSigningAsDocument();
      this.xadesQualProperties = (Element)this.sig.getDocument().importNode(xadesQualPropertiesDocument.getDocumentElement(), true);
      container.appendChild(this.xadesQualProperties);
      this.sig.addResourceResolver(new DocumentResolver(xadesQualPropertiesDocument));
      Transforms xadesTransform = new Transforms(this.sig.getDocument());
      xadesTransform.addTransform("http://www.w3.org/2001/10/xml-exc-c14n#");
      this.sig.addDocument(ref(qualProperties.getSignedProps().getId()), xadesTransform, (String)SignatureUtils.getOption("digestURI", this.options, "http://www.w3.org/2001/04/xmlenc#sha256"), (String)null, "http://uri.etsi.org/01903#SignedProperties");
   }
}
 
Example #11
Source File: CanonicalizerUtils.java    From xades4j with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Checks if all the transforms in a ds:Reference are canonicalization transforms.
 * @param r the reference
 * @return true if all transforms are c14n, false otherwise.
 * @throws XMLSecurityException
 */
public static boolean allTransformsAreC14N(Reference r) throws XMLSecurityException
{
    Transforms transforms = r.getTransforms();
    try
    {
        for (int i = 0; i < transforms.getLength(); ++i)
        {
            Canonicalizer.getInstance(transforms.item(i).getURI());
        }
        return true;
    }
    catch (InvalidCanonicalizerException ex)
    {
        return false;
    }
}
 
Example #12
Source File: DSSXMLUtils.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method registers the default transforms.
 */
private static void registerDefaultTransforms() {

	registerTransform(Transforms.TRANSFORM_BASE64_DECODE);
	registerTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
	registerTransform(Transforms.TRANSFORM_XPATH);
	registerTransform(Transforms.TRANSFORM_XPATH2FILTER);
	registerTransform(Transforms.TRANSFORM_XPOINTER);
	registerTransform(Transforms.TRANSFORM_XSLT);
}
 
Example #13
Source File: AlgorithmSuitePolicyValidator.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Check the individual signature references
 */
private boolean checkDataRefs(
    List<WSDataRef> dataRefs,
    AlgorithmSuite algorithmPolicy,
    AssertionInfo ai
) {
    AlgorithmSuiteType algorithmSuiteType = algorithmPolicy.getAlgorithmSuiteType();
    for (WSDataRef dataRef : dataRefs) {
        String digestMethod = dataRef.getDigestAlgorithm();
        if (!algorithmSuiteType.getDigest().equals(digestMethod)) {
            ai.setNotAsserted(
                "The digest method does not match the requirement"
            );
            return false;
        }

        List<String> transformAlgorithms = dataRef.getTransformAlgorithms();
        // Only a max of 2 transforms per reference is allowed
        if (transformAlgorithms == null || transformAlgorithms.size() > 2) {
            ai.setNotAsserted("The transform algorithms do not match the requirement");
            return false;
        }
        for (String transformAlgorithm : transformAlgorithms) {
            if (!(algorithmPolicy.getC14n().getValue().equals(transformAlgorithm)
                || WSS4JConstants.C14N_EXCL_OMIT_COMMENTS.equals(transformAlgorithm)
                || STRTransform.TRANSFORM_URI.equals(transformAlgorithm)
                || Transforms.TRANSFORM_ENVELOPED_SIGNATURE.equals(transformAlgorithm)
                || WSS4JConstants.SWA_ATTACHMENT_CONTENT_SIG_TRANS.equals(transformAlgorithm)
                || WSS4JConstants.SWA_ATTACHMENT_COMPLETE_SIG_TRANS.equals(transformAlgorithm))) {
                ai.setNotAsserted("The transform algorithms do not match the requirement");
                return false;
            }
        }
    }
    return true;
}
 
Example #14
Source File: DSSXMLUtils.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns bytes of the original referenced data
 * @param reference {@link Reference} to get bytes from
 * @return byte array containing original data
 */
public static byte[] getReferenceOriginalContentBytes(Reference reference) {
	
	try {
		// returns bytes after transformation in case of enveloped signature
		Transforms transforms = reference.getTransforms();
		if (transforms != null) {
			Element transformsElement = transforms.getElement();
			NodeList transformChildNodes = transformsElement.getChildNodes();
			if (transformChildNodes != null && transformChildNodes.getLength() > 0) {
				for (int i = 0; i < transformChildNodes.getLength(); i++) {
					Node transformation = transformChildNodes.item(i);
					if (isEnvelopedTransform(transformation)) {
						return reference.getReferencedBytes();
					}
				    // if enveloped transformations are not applied to the signature go further and 
					// return bytes before transformation
				}
			}
		}
		
	} catch (XMLSecurityException | XMLSecurityRuntimeException e) {
		// if exception occurs during the transformations
		LOG.warn("Signature reference with id [{}] is corrupted or has an invalid format. "
				+ "Original data cannot be obtained. Reason: [{}]", reference.getId(), e.getMessage());
		
	}
	// otherwise bytes before transformation
	return getBytesBeforeTransformation(reference);
}
 
Example #15
Source File: XPathTransform.java    From xades4j with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new instance of the transform
 * @param xpath the XPath filtering expression
 */
public XPathTransform(String xpath)
{
    super(Transforms.TRANSFORM_XPATH);
    if (null == xpath)
    {
        throw new NullPointerException("XPath expression cannot be null");
    }
    this.xpath = xpath;
}
 
Example #16
Source File: XmlSignatureBuilder.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Transforms transforms(List<String> tranformerList, Document doc) throws TransformationException {
   Transforms baseDocTransform = new Transforms(doc);
   Iterator i$ = tranformerList.iterator();

   while(i$.hasNext()) {
      String transform = (String)i$.next();
      baseDocTransform.addTransform(transform);
   }

   return baseDocTransform;
}
 
Example #17
Source File: SignedDataObjectsProcessor.java    From xades4j with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Transforms processTransforms(
        DataObjectDesc dataObjDesc,
        Document document) throws UnsupportedAlgorithmException
{
    Collection<Algorithm> dObjTransfs = dataObjDesc.getTransforms();
    if (dObjTransfs.isEmpty())
    {
        return null;
    }

    return TransformUtils.createTransforms(document, this.algorithmsParametersMarshaller, dObjTransfs);
}
 
Example #18
Source File: XmlSignatureBuilder.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Transforms transforms(List<String> tranformerList, Document doc) throws TransformationException {
   Transforms baseDocTransform = new Transforms(doc);
   Iterator i$ = tranformerList.iterator();

   while(i$.hasNext()) {
      String transform = (String)i$.next();
      baseDocTransform.addTransform(transform);
   }

   return baseDocTransform;
}
 
Example #19
Source File: TransformUtils.java    From xades4j with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a Transforms element for a given set of algorithms
 * @param document the target XML document
 * @param algorithmsParametersMarshaller algorithm parameters marshaller
 * @param algorithms algorithms
 * @return the Transforms
 * @throws UnsupportedAlgorithmException if an algorithm is not supported
 */
public static Transforms createTransforms(
        Document document,
        AlgorithmsParametersMarshallingProvider algorithmsParametersMarshaller,
        Iterable<Algorithm> algorithms) throws UnsupportedAlgorithmException
{
    Transforms transforms = new Transforms(document);

    for (Algorithm t : algorithms)
    {
        try
        {
            List<Node> params = algorithmsParametersMarshaller.marshalParameters(t, document);
            if (null == params)
            {
                transforms.addTransform(t.getUri());
            }
            else
            {
                transforms.addTransform(t.getUri(), DOMHelper.nodeList(params));
            }
        }
        catch (TransformationException ex)
        {
            throw new UnsupportedAlgorithmException(
                    "Unsupported transform on XML Signature provider",
                    t.getUri(), ex);
        }
    }
    return transforms;
}
 
Example #20
Source File: URIContentReference.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void createReference(XMLSignature signature) {
    try {
        Transforms dsigTransforms = new Transforms(signature.getDocument());
        for (String transform : transforms) {
            dsigTransforms.addTransform(transform);
        }

        signature.addDocument(referenceID, dsigTransforms, digestAlgorithm);
    } catch (Exception e) {
        log.error("Error while adding content reference", e);
    }
}
 
Example #21
Source File: XmlSignatureBuilder.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Transforms transforms(List<String> tranformerList, Document doc) throws TransformationException {
   Transforms baseDocTransform = new Transforms(doc);
   Iterator i$ = tranformerList.iterator();

   while(i$.hasNext()) {
      String transform = (String)i$.next();
      baseDocTransform.addTransform(transform);
   }

   return baseDocTransform;
}
 
Example #22
Source File: XmlSignatureBuilder.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Transforms transforms(List<String> tranformerList, Document doc) throws TransformationException {
   Transforms baseDocTransform = new Transforms(doc);
   Iterator i$ = tranformerList.iterator();

   while(i$.hasNext()) {
      String transform = (String)i$.next();
      baseDocTransform.addTransform(transform);
   }

   return baseDocTransform;
}
 
Example #23
Source File: XmlSignatureBuilder.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Transforms transforms(List<String> tranformerList, Document doc) throws TransformationException {
   Transforms baseDocTransform = new Transforms(doc);
   Iterator i$ = tranformerList.iterator();

   while(i$.hasNext()) {
      String transform = (String)i$.next();
      baseDocTransform.addTransform(transform);
   }

   return baseDocTransform;
}
 
Example #24
Source File: XPath2FilterTransform.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
public XPath2FilterTransform(DSSNamespace xmlDSigNamespace, String xPathExpression, String filter) {
	super(xmlDSigNamespace, Transforms.TRANSFORM_XPATH2FILTER, xPathExpression);
	Objects.requireNonNull(filter, "filter cannot be null!");
	this.filter = filter;
}
 
Example #25
Source File: XAdESLevelBEnvelopedWithReferenceTest.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
@BeforeEach
public void init() throws Exception {
	SantuarioInitializer.init();

	documentToSign = new FileDocument(new File("src/test/resources/sampleWithPlaceOfSignature.xml"));

	signatureParameters = new XAdESSignatureParameters();
	signatureParameters.bLevel().setSigningDate(new Date());
	signatureParameters.setSigningCertificate(getSigningCert());
	signatureParameters.setCertificateChain(getCertificateChain());
	signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPED);
	signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B);
	signatureParameters.setXPathLocationString("//placeOfSignature");

	List<DSSReference> dssReferences = new ArrayList<>();
	DSSReference reference1 = new DSSReference();
	reference1.setContents(documentToSign);
	reference1.setId("REF-ID1");
	reference1.setDigestMethodAlgorithm(DigestAlgorithm.SHA256);
	reference1.setUri("#data1");
	List<DSSTransform> transforms1 = new ArrayList<>();
	CanonicalizationTransform transform1 = new CanonicalizationTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
	transforms1.add(transform1);
	reference1.setTransforms(transforms1);
	dssReferences.add(reference1);

	DSSReference reference2 = new DSSReference();
	reference2.setContents(documentToSign);
	reference2.setId("REF-ID2");
	reference2.setDigestMethodAlgorithm(DigestAlgorithm.SHA256);
	reference2.setUri("#data2");
	List<DSSTransform> transforms2 = new ArrayList<>();
	CanonicalizationTransform transform2 = new CanonicalizationTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
	transforms2.add(transform2);
	reference2.setTransforms(transforms2);
	dssReferences.add(reference2);

	signatureParameters.setReferences(dssReferences);

	service = new XAdESService(getOfflineCertificateVerifier());
}
 
Example #26
Source File: XsltTransform.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
public XsltTransform(DSSNamespace xmlDSigNamespace, Document content) {
	super(xmlDSigNamespace, Transforms.TRANSFORM_XSLT);
	Objects.requireNonNull(content, "The content cannot be null!");
	this.content = content;
}
 
Example #27
Source File: Base64Transform.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Base64Transform(DSSNamespace xmlDSigNamespace) {
	super(xmlDSigNamespace, Transforms.TRANSFORM_BASE64_DECODE);
}
 
Example #28
Source File: Base64Transform.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Base64Transform() {
	super(Transforms.TRANSFORM_BASE64_DECODE);
}
 
Example #29
Source File: XPathTransform.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
public XPathTransform(DSSNamespace xmlDSigNamespace, String xPathExpression) {
	this(xmlDSigNamespace, Transforms.TRANSFORM_XPATH, xPathExpression);
}
 
Example #30
Source File: XPathTransform.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
public XPathTransform( String xPathExpression) {
	this(XAdESNamespaces.XMLDSIG, Transforms.TRANSFORM_XPATH, xPathExpression);
}