return new ApacheNodeSetData(new XMLSignatureInput(root));
public ApacheOctetStreamData(XMLSignatureInput xi) throws CanonicalizationException, IOException { super(xi.getOctetStream(), xi.getSourceURI(), xi.getMIMEType()); this.xi = xi; }
/** * Returns the node set from input which was specified as the parameter of * {@link XMLSignatureInput} constructor * * @return the node set * @throws SAXException * @throws IOException * @throws ParserConfigurationException * @throws CanonicalizationException */ public Set<Node> getNodeSet() throws CanonicalizationException, ParserConfigurationException, IOException, SAXException { return getNodeSet(false); }
/** {@inheritDoc} */ @Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) { XMLSignatureInput input = new XMLSignatureInput(inStream); input.setSecureValidation(context.secureValidation); return input; }
@Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { XMLSignatureInput xmlSignatureInput = new XMLSignatureInput(EMPTY_BYTE_ARRAY); xmlSignatureInput.setSourceURI(context.uriToResolve); return xmlSignatureInput; }
XMLSignatureInput result = new XMLSignatureInput(selectedElem); result.setSecureValidation(context.secureValidation); result.setExcludeComments(true); result.setMIMEType("text/xml"); if (context.baseUri != null && context.baseUri.length() > 0) { result.setSourceURI(context.baseUri.concat(context.uriToResolve)); } else { result.setSourceURI(context.uriToResolve);
protected XMLSignatureInput enginePerformTransform( XMLSignatureInput input, OutputStream os, Transform transformObject ) throws IOException, CanonicalizationException, TransformationException { if (input.isElement()) { Node el = input.getSubNode(); if (input.getSubNode().getNodeType() == Node.TEXT_NODE) { el = el.getParentNode(); if (os == null) { byte[] decodedBytes = XMLUtils.decode(sb.toString()); XMLSignatureInput output = new XMLSignatureInput(decodedBytes); output.setSecureValidation(secureValidation); return output; XMLSignatureInput output = new XMLSignatureInput((byte[])null); output.setSecureValidation(secureValidation); output.setOutputStream(os); return output; if (input.isOctetStream() || input.isNodeSet()) { if (os == null) { byte[] base64Bytes = input.getBytes(); byte[] decodedBytes = XMLUtils.decode(base64Bytes); XMLSignatureInput output = new XMLSignatureInput(decodedBytes); output.setSecureValidation(secureValidation); return output; if (input.isByteArray() || input.isNodeSet()) { byte[] bytes = XMLUtils.decode(input.getBytes()); os.write(bytes);
if (input.isNodeSet()) { try { final Set<Node> s = input.getNodeSet(); referenceData = new ReferenceNodeSetData() { public Iterator<Node> iterator() { } else if (input.isElement()) { referenceData = new ReferenceSubTreeData (input.getSubNode(), input.isExcludeComments()); } else if (input.isOctetStream() || input.isByteArray()) { try { referenceData = new ReferenceOctetStreamData (input.getOctetStream(), input.getSourceURI(), input.getMIMEType()); } catch (IOException ioe) {
try { XMLSignatureInput xmlSignatureInput = new XMLSignatureInput(((OctetStreamData)data).getOctetStream()); str = (Element)xmlSignatureInput.getSubNode(); } catch (Exception ex) { throw new TransformException(ex); log.debug(bf1); XMLSignatureInput output = new XMLSignatureInput(bf1.getBytes()); if (os != null) { output.updateOutputStream(os); return null; return new OctetStreamData(output.getOctetStream()); } catch (Exception ex) { throw new TransformException(ex);
if (input.isExcludeComments()) { includeComments = false; if (input.isOctetStream()) { return engineCanonicalize(input.getBytes()); if (input.isElement()) { return engineCanonicalizeSubTree(input.getSubNode(), input.getExcludeNode()); } else if (input.isNodeSet()) { nodeFilter = input.getNodeFilters(); if (input.getSubNode() != null) { return engineCanonicalizeXPathNodeSetInternal(input.getSubNode()); } else { return engineCanonicalizeXPathNodeSet(input.getNodeSet());
if (data instanceof DOMSubTreeData) { DOMSubTreeData subTree = (DOMSubTreeData)data; in = new XMLSignatureInput(subTree.getRoot()); in.setExcludeComments(subTree.excludeComments()); } else { @SuppressWarnings("unchecked") Set<Node> nodeSet = Utils.toNodeSet(((NodeSetData)data).iterator()); in = new XMLSignatureInput(nodeSet); in = new XMLSignatureInput (((OctetStreamData)data).getOctetStream()); } catch (Exception ex) { in.setSecureValidation(secVal); if (!in.isNodeSet() && !in.isElement()) { return null; if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else {
protected XMLSignatureInput enginePerformTransform( XMLSignatureInput input, OutputStream os, Transform transform ) throws CanonicalizationException { Canonicalizer11_OmitComments c14n = new Canonicalizer11_OmitComments(); c14n.setSecureValidation(secureValidation); if (os != null) { c14n.setWriter(os); } byte[] result = null; result = c14n.engineCanonicalize(input); XMLSignatureInput output = new XMLSignatureInput(result); output.setSecureValidation(secureValidation); if (os != null) { output.setOutputStream(os); } return output; } }
private static Element obtainReferenceElement(XMLSignatureInput resource, boolean secureValidation) throws CanonicalizationException, ParserConfigurationException, IOException, SAXException, KeyResolverException { Element e; if (resource.isElement()){ e = (Element) resource.getSubNode(); } else if (resource.isNodeSet()) { // Retrieved resource is a nodeSet e = getDocumentElement(resource.getNodeSet()); } else { // Retrieved resource is an inputStream byte inputBytes[] = resource.getBytes(); e = getDocFromBytes(inputBytes, secureValidation); // otherwise, we parse the resource, create an Element and delegate LOG.debug("we have to parse {} bytes", inputBytes.length); } return e; }
private void addToDigestInput(XMLSignatureInput refData, Document doc) throws CannotAddDataToDigestInputException { try { if (refData.isNodeSet() || refData.isElement()) { Transform c14nTransform = TransformUtils.createTransform(this.c14n, this.parametersMarshallingProvider, doc); refData = c14nTransform.performTransform(refData); // Fall through to add the bytes resulting from the canonicalization. } if (refData.isByteArray()) { digestInput.write(refData.getBytes()); } else if (refData.isOctetStream()) { StreamUtils.readWrite(refData.getOctetStream(), digestInput); } } catch (Exception ex) { throw new CannotAddDataToDigestInputException(ex); } }
XMLSignatureInput in = ((ApacheData)data).getXMLSignatureInput(); if (in.isElement()) { if (inclusiveNamespaces != null) { return new OctetStreamData(new ByteArrayInputStream (apacheCanonicalizer.canonicalizeSubtree (in.getSubNode(), inclusiveNamespaces))); } else { return new OctetStreamData(new ByteArrayInputStream (apacheCanonicalizer.canonicalizeSubtree (in.getSubNode()))); } else if (in.isNodeSet()) { nodeSet = in.getNodeSet(); } else { return new OctetStreamData(new ByteArrayInputStream( apacheCanonicalizer.canonicalize( Utils.readBytesFromStream(in.getOctetStream()))));
xi = ((ApacheData)data).getXMLSignatureInput(); } else if (data instanceof OctetStreamData) { xi = new XMLSignatureInput (((OctetStreamData)data).getOctetStream()); } else if (data instanceof NodeSetData) { xi = new XMLSignatureInput (((OctetStreamData)data).getOctetStream()); } else { xi.setSecureValidation(secVal); if (context instanceof XMLSignContext && c14n11 && !xi.isOctetStream() && !xi.isOutputStreamSet()) { TransformService spi = null; if (provider == null) { t.marshal(xwriter, dsPrefix, context); allTransforms.add(t); xi.updateOutputStream(os, true); } else { xi.updateOutputStream(os);
public byte[] transform(final Node input) throws DSSException { try { final String dssTransformAlgorithm = dssTransform.getAlgorithm(); final NodeList childNodes = document.getFirstChild().getChildNodes(); final Transform transformObject = new Transform(document, dssTransformAlgorithm, childNodes); final XMLSignatureInput xmlSignatureInput = new XMLSignatureInput(input); final XMLSignatureInput xmlSignatureInputOut = transformObject.performTransform(xmlSignatureInput); return xmlSignatureInputOut.getBytes(); } catch (TransformationException e) { throw new DSSException(e); } catch (InvalidTransformException e) { throw new DSSException(e); } catch (InvalidCanonicalizerException e) { throw new DSSException(e); } catch (CanonicalizationException e) { throw new DSSException(e); } catch (IOException e) { throw new DSSException(e); } } }
try (InputStream is = new ByteArrayInputStream(input.getBytes())) { Source xmlSource = new StreamSource(is); if (baos == null) { StreamResult outputTarget = new StreamResult(baos1); transformer.transform(xmlSource, outputTarget); XMLSignatureInput output = new XMLSignatureInput(baos1.toByteArray()); output.setSecureValidation(secureValidation); return output; XMLSignatureInput output = new XMLSignatureInput((byte[])null); output.setSecureValidation(secureValidation); output.setOutputStream(baos); return output; } catch (XMLSecurityException ex) {
@Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { final Attr uriAttr = context.attr; final String baseUriString = context.baseUri; String documentUri = uriAttr.getNodeValue(); documentUri = decodeUrl(documentUri); final DSSDocument document = getDocument(documentUri); if (document != null) { // The input stream is closed automatically by XMLSignatureInput class // TODO-Bob (05/09/2014): There is an error concerning the input streams base64 encoded. Some extra bytes are added within the santuario which breaks the HASH. // TODO-Vin (05/09/2014): Can you create an isolated test-case JIRA DSS-? InputStream inputStream = document.openStream(); // final byte[] bytes = DSSUtils.toByteArray(inputStream); // final String string = new String(bytes); // inputStream = DSSUtils.toInputStream(bytes); final XMLSignatureInput result = new XMLSignatureInput(inputStream); result.setSourceURI(documentUri); final MimeType mimeType = document.getMimeType(); if (mimeType != null) { result.setMIMEType(mimeType.getMimeTypeString()); } return result; } else { Object exArgs[] = {"The uriNodeValue " + documentUri + " is not configured for offline work"}; throw new ResourceResolverException("generic.EmptyMessage", exArgs, documentUri, baseUriString); } }
try { XMLSignatureInput xmlSignatureInput = new XMLSignatureInput(((OctetStreamData)data).getOctetStream()); str = (Element)xmlSignatureInput.getSubNode(); } catch (Exception ex) { throw new TransformException(ex);