Java Code Examples for com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput#isOctetStream()
The following examples show how to use
com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput#isOctetStream() .
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: DOMReference.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private static Data copyDerefData(Data dereferencedData) { if (dereferencedData instanceof ApacheData) { // need to make a copy of the Data ApacheData ad = (ApacheData)dereferencedData; XMLSignatureInput xsi = ad.getXMLSignatureInput(); if (xsi.isNodeSet()) { try { final Set<Node> s = xsi.getNodeSet(); return new NodeSetData() { public Iterator<Node> iterator() { return s.iterator(); } }; } catch (Exception e) { // log a warning log.log(java.util.logging.Level.WARNING, "cannot cache dereferenced data: " + e); return null; } } else if (xsi.isElement()) { return new DOMSubTreeData (xsi.getSubNode(), xsi.isExcludeComments()); } else if (xsi.isOctetStream() || xsi.isByteArray()) { try { return new OctetStreamData (xsi.getOctetStream(), xsi.getSourceURI(), xsi.getMIMEType()); } catch (IOException ioe) { // log a warning log.log(java.util.logging.Level.WARNING, "cannot cache dereferenced data: " + ioe); return null; } } } return dereferencedData; }
Example 2
Source File: DOMReference.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static Data copyDerefData(Data dereferencedData) { if (dereferencedData instanceof ApacheData) { // need to make a copy of the Data ApacheData ad = (ApacheData)dereferencedData; XMLSignatureInput xsi = ad.getXMLSignatureInput(); if (xsi.isNodeSet()) { try { final Set<Node> s = xsi.getNodeSet(); return new NodeSetData() { public Iterator iterator() { return s.iterator(); } }; } catch (Exception e) { // log a warning log.log(java.util.logging.Level.WARNING, "cannot cache dereferenced data: " + e); return null; } } else if (xsi.isElement()) { return new DOMSubTreeData (xsi.getSubNode(), xsi.isExcludeComments()); } else if (xsi.isOctetStream() || xsi.isByteArray()) { try { return new OctetStreamData (xsi.getOctetStream(), xsi.getSourceURI(), xsi.getMIMEType()); } catch (IOException ioe) { // log a warning log.log(java.util.logging.Level.WARNING, "cannot cache dereferenced data: " + ioe); return null; } } } return dereferencedData; }
Example 3
Source File: DOMReference.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private static Data copyDerefData(Data dereferencedData) { if (dereferencedData instanceof ApacheData) { // need to make a copy of the Data ApacheData ad = (ApacheData)dereferencedData; XMLSignatureInput xsi = ad.getXMLSignatureInput(); if (xsi.isNodeSet()) { try { final Set<Node> s = xsi.getNodeSet(); return new NodeSetData() { public Iterator iterator() { return s.iterator(); } }; } catch (Exception e) { // log a warning log.log(java.util.logging.Level.WARNING, "cannot cache dereferenced data: " + e); return null; } } else if (xsi.isElement()) { return new DOMSubTreeData (xsi.getSubNode(), xsi.isExcludeComments()); } else if (xsi.isOctetStream() || xsi.isByteArray()) { try { return new OctetStreamData (xsi.getOctetStream(), xsi.getSourceURI(), xsi.getMIMEType()); } catch (IOException ioe) { // log a warning log.log(java.util.logging.Level.WARNING, "cannot cache dereferenced data: " + ioe); return null; } } } return dereferencedData; }
Example 4
Source File: DOMReference.java From hottub with GNU General Public License v2.0 | 5 votes |
private static Data copyDerefData(Data dereferencedData) { if (dereferencedData instanceof ApacheData) { // need to make a copy of the Data ApacheData ad = (ApacheData)dereferencedData; XMLSignatureInput xsi = ad.getXMLSignatureInput(); if (xsi.isNodeSet()) { try { final Set<Node> s = xsi.getNodeSet(); return new NodeSetData() { public Iterator iterator() { return s.iterator(); } }; } catch (Exception e) { // log a warning log.log(java.util.logging.Level.WARNING, "cannot cache dereferenced data: " + e); return null; } } else if (xsi.isElement()) { return new DOMSubTreeData (xsi.getSubNode(), xsi.isExcludeComments()); } else if (xsi.isOctetStream() || xsi.isByteArray()) { try { return new OctetStreamData (xsi.getOctetStream(), xsi.getSourceURI(), xsi.getMIMEType()); } catch (IOException ioe) { // log a warning log.log(java.util.logging.Level.WARNING, "cannot cache dereferenced data: " + ioe); return null; } } } return dereferencedData; }
Example 5
Source File: DOMReference.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static Data copyDerefData(Data dereferencedData) { if (dereferencedData instanceof ApacheData) { // need to make a copy of the Data ApacheData ad = (ApacheData)dereferencedData; XMLSignatureInput xsi = ad.getXMLSignatureInput(); if (xsi.isNodeSet()) { try { final Set<Node> s = xsi.getNodeSet(); return new NodeSetData() { public Iterator<Node> iterator() { return s.iterator(); } }; } catch (Exception e) { // log a warning log.log(java.util.logging.Level.WARNING, "cannot cache dereferenced data: " + e); return null; } } else if (xsi.isElement()) { return new DOMSubTreeData (xsi.getSubNode(), xsi.isExcludeComments()); } else if (xsi.isOctetStream() || xsi.isByteArray()) { try { return new OctetStreamData (xsi.getOctetStream(), xsi.getSourceURI(), xsi.getMIMEType()); } catch (IOException ioe) { // log a warning log.log(java.util.logging.Level.WARNING, "cannot cache dereferenced data: " + ioe); return null; } } } return dereferencedData; }
Example 6
Source File: DOMReference.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static Data copyDerefData(Data dereferencedData) { if (dereferencedData instanceof ApacheData) { // need to make a copy of the Data ApacheData ad = (ApacheData)dereferencedData; XMLSignatureInput xsi = ad.getXMLSignatureInput(); if (xsi.isNodeSet()) { try { final Set<Node> s = xsi.getNodeSet(); return new NodeSetData() { public Iterator iterator() { return s.iterator(); } }; } catch (Exception e) { // log a warning log.log(java.util.logging.Level.WARNING, "cannot cache dereferenced data: " + e); return null; } } else if (xsi.isElement()) { return new DOMSubTreeData (xsi.getSubNode(), xsi.isExcludeComments()); } else if (xsi.isOctetStream() || xsi.isByteArray()) { try { return new OctetStreamData (xsi.getOctetStream(), xsi.getSourceURI(), xsi.getMIMEType()); } catch (IOException ioe) { // log a warning log.log(java.util.logging.Level.WARNING, "cannot cache dereferenced data: " + ioe); return null; } } } return dereferencedData; }
Example 7
Source File: DOMReference.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static Data copyDerefData(Data dereferencedData) { if (dereferencedData instanceof ApacheData) { // need to make a copy of the Data ApacheData ad = (ApacheData)dereferencedData; XMLSignatureInput xsi = ad.getXMLSignatureInput(); if (xsi.isNodeSet()) { try { final Set<Node> s = xsi.getNodeSet(); return new NodeSetData() { public Iterator iterator() { return s.iterator(); } }; } catch (Exception e) { // log a warning log.log(java.util.logging.Level.WARNING, "cannot cache dereferenced data: " + e); return null; } } else if (xsi.isElement()) { return new DOMSubTreeData (xsi.getSubNode(), xsi.isExcludeComments()); } else if (xsi.isOctetStream() || xsi.isByteArray()) { try { return new OctetStreamData (xsi.getOctetStream(), xsi.getSourceURI(), xsi.getMIMEType()); } catch (IOException ioe) { // log a warning log.log(java.util.logging.Level.WARNING, "cannot cache dereferenced data: " + ioe); return null; } } } return dereferencedData; }
Example 8
Source File: DOMReference.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static Data copyDerefData(Data dereferencedData) { if (dereferencedData instanceof ApacheData) { // need to make a copy of the Data ApacheData ad = (ApacheData)dereferencedData; XMLSignatureInput xsi = ad.getXMLSignatureInput(); if (xsi.isNodeSet()) { try { final Set<Node> s = xsi.getNodeSet(); return new NodeSetData<Node>() { public Iterator<Node> iterator() { return s.iterator(); } }; } catch (Exception e) { // log a warning log.log(java.util.logging.Level.WARNING, "cannot cache dereferenced data: " + e); return null; } } else if (xsi.isElement()) { return new DOMSubTreeData (xsi.getSubNode(), xsi.isExcludeComments()); } else if (xsi.isOctetStream() || xsi.isByteArray()) { try { return new OctetStreamData (xsi.getOctetStream(), xsi.getSourceURI(), xsi.getMIMEType()); } catch (IOException ioe) { // log a warning log.log(java.util.logging.Level.WARNING, "cannot cache dereferenced data: " + ioe); return null; } } } return dereferencedData; }
Example 9
Source File: DOMReference.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static Data copyDerefData(Data dereferencedData) { if (dereferencedData instanceof ApacheData) { // need to make a copy of the Data ApacheData ad = (ApacheData)dereferencedData; XMLSignatureInput xsi = ad.getXMLSignatureInput(); if (xsi.isNodeSet()) { try { final Set<Node> s = xsi.getNodeSet(); return new NodeSetData() { public Iterator iterator() { return s.iterator(); } }; } catch (Exception e) { // log a warning log.log(java.util.logging.Level.WARNING, "cannot cache dereferenced data: " + e); return null; } } else if (xsi.isElement()) { return new DOMSubTreeData (xsi.getSubNode(), xsi.isExcludeComments()); } else if (xsi.isOctetStream() || xsi.isByteArray()) { try { return new OctetStreamData (xsi.getOctetStream(), xsi.getSourceURI(), xsi.getMIMEType()); } catch (IOException ioe) { // log a warning log.log(java.util.logging.Level.WARNING, "cannot cache dereferenced data: " + ioe); return null; } } } return dereferencedData; }
Example 10
Source File: DOMURIDereferencer.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); if (secVal && Policy.restrictReferenceUriScheme(uri)) { throw new URIReferenceException( "Uri " + uri + " is forbidden when secure validation is enabled"); } // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } // check if element is registered by Id Node referencedElem = uriAttr.getOwnerDocument().getElementById(id); if (referencedElem == null) { // see if element is registered in DOMCryptoContext referencedElem = dcc.getElementById(id); } if (referencedElem != null) { if (secVal && Policy.restrictDuplicateIds()) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " detected when secure validation" + " is enabled"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, false); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI, false); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }
Example 11
Source File: DOMURIDereferencer.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } Node referencedElem = dcc.getElementById(id); if (referencedElem != null) { if (secVal) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " were detected"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, secVal); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }
Example 12
Source File: DOMURIDereferencer.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } Node referencedElem = dcc.getElementById(id); if (referencedElem != null) { if (secVal) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " were detected"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, secVal); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }
Example 13
Source File: DOMURIDereferencer.java From hottub with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } Node referencedElem = dcc.getElementById(id); if (referencedElem != null) { if (secVal) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " were detected"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, secVal); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI, secVal); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }
Example 14
Source File: DOMURIDereferencer.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); if (secVal && Policy.restrictReferenceUriScheme(uri)) { throw new URIReferenceException( "Uri " + uri + " is forbidden when secure validation is enabled"); } // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } // check if element is registered by Id Node referencedElem = uriAttr.getOwnerDocument().getElementById(id); if (referencedElem == null) { // see if element is registered in DOMCryptoContext referencedElem = dcc.getElementById(id); } if (referencedElem != null) { if (secVal && Policy.restrictDuplicateIds()) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " detected when secure validation" + " is enabled"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, false); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI, false); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }
Example 15
Source File: DOMURIDereferencer.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } Node referencedElem = dcc.getElementById(id); if (referencedElem != null) { if (secVal) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " were detected"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, secVal); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }
Example 16
Source File: DOMURIDereferencer.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); if (secVal && Policy.restrictReferenceUriScheme(uri)) { throw new URIReferenceException( "Uri " + uri + " is forbidden when secure validation is enabled"); } // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } // check if element is registered by Id Node referencedElem = uriAttr.getOwnerDocument().getElementById(id); if (referencedElem == null) { // see if element is registered in DOMCryptoContext referencedElem = dcc.getElementById(id); } if (referencedElem != null) { if (secVal && Policy.restrictDuplicateIds()) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " detected when secure validation" + " is enabled"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, false); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI, false); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }
Example 17
Source File: DOMURIDereferencer.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); if (secVal && Policy.restrictReferenceUriScheme(uri)) { throw new URIReferenceException( "Uri " + uri + " is forbidden when secure validation is enabled"); } // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } // check if element is registered by Id Node referencedElem = uriAttr.getOwnerDocument().getElementById(id); if (referencedElem == null) { // see if element is registered in DOMCryptoContext referencedElem = dcc.getElementById(id); } if (referencedElem != null) { if (secVal && Policy.restrictDuplicateIds()) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " detected when secure validation" + " is enabled"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, false); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI, false); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }
Example 18
Source File: DOMURIDereferencer.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } Node referencedElem = dcc.getElementById(id); if (referencedElem != null) { if (secVal) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " were detected"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, secVal); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }
Example 19
Source File: DOMURIDereferencer.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); if (secVal && Policy.restrictReferenceUriScheme(uri)) { throw new URIReferenceException( "Uri " + uri + " is forbidden when secure validation is enabled"); } // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } // check if element is registered by Id Node referencedElem = uriAttr.getOwnerDocument().getElementById(id); if (referencedElem == null) { // see if element is registered in DOMCryptoContext referencedElem = dcc.getElementById(id); } if (referencedElem != null) { if (secVal && Policy.restrictDuplicateIds()) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " detected when secure validation" + " is enabled"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, false); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI, false); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }
Example 20
Source File: DOMURIDereferencer.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } Node referencedElem = dcc.getElementById(id); if (referencedElem != null) { if (secVal) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " were detected"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, secVal); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }