use of com.sun.org.apache.xml.internal.security.transforms.TransformationException in project jdk8u_jdk by JetBrains.
the class Reference method getContentsAfterTransformation.
private XMLSignatureInput getContentsAfterTransformation(XMLSignatureInput input, OutputStream os) throws XMLSignatureException {
try {
Transforms transforms = this.getTransforms();
XMLSignatureInput output = null;
if (transforms != null) {
output = transforms.performTransforms(input, os);
//new XMLSignatureInput(output.getBytes());
this.transformsOutput = output;
//this.transformsOutput.setSourceURI(output.getSourceURI());
} else {
output = input;
}
return output;
} catch (ResourceResolverException ex) {
throw new XMLSignatureException("empty", ex);
} catch (CanonicalizationException ex) {
throw new XMLSignatureException("empty", ex);
} catch (InvalidCanonicalizerException ex) {
throw new XMLSignatureException("empty", ex);
} catch (TransformationException ex) {
throw new XMLSignatureException("empty", ex);
} catch (XMLSecurityException ex) {
throw new XMLSignatureException("empty", ex);
}
}
use of com.sun.org.apache.xml.internal.security.transforms.TransformationException in project jdk8u_jdk by JetBrains.
the class Reference method getHTMLRepresentation.
/**
* Method getHTMLRepresentation
* @return The HTML of the transformation
* @throws XMLSignatureException
*/
public String getHTMLRepresentation() throws XMLSignatureException {
try {
XMLSignatureInput nodes = this.getNodesetBeforeFirstCanonicalization();
Transforms transforms = this.getTransforms();
Transform c14nTransform = null;
if (transforms != null) {
doTransforms: for (int i = 0; i < transforms.getLength(); i++) {
Transform t = transforms.item(i);
String uri = t.getURI();
if (uri.equals(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS) || uri.equals(Transforms.TRANSFORM_C14N_EXCL_WITH_COMMENTS)) {
c14nTransform = t;
break doTransforms;
}
}
}
Set<String> inclusiveNamespaces = new HashSet<String>();
if (c14nTransform != null && (c14nTransform.length(InclusiveNamespaces.ExclusiveCanonicalizationNamespace, InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES) == 1)) {
// there is one InclusiveNamespaces element
InclusiveNamespaces in = new InclusiveNamespaces(XMLUtils.selectNode(c14nTransform.getElement().getFirstChild(), InclusiveNamespaces.ExclusiveCanonicalizationNamespace, InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES, 0), this.getBaseURI());
inclusiveNamespaces = InclusiveNamespaces.prefixStr2Set(in.getInclusiveNamespaces());
}
return nodes.getHTMLRepresentation(inclusiveNamespaces);
} catch (TransformationException ex) {
throw new XMLSignatureException("empty", ex);
} catch (InvalidTransformException ex) {
throw new XMLSignatureException("empty", ex);
} catch (XMLSecurityException ex) {
throw new XMLSignatureException("empty", ex);
}
}
use of com.sun.org.apache.xml.internal.security.transforms.TransformationException in project jdk8u_jdk by JetBrains.
the class TransformEnvelopedSignature method searchSignatureElement.
/**
* @param signatureElement
* @return the node that is the signature
* @throws TransformationException
*/
private static Node searchSignatureElement(Node signatureElement) throws TransformationException {
boolean found = false;
while (true) {
if (signatureElement == null || signatureElement.getNodeType() == Node.DOCUMENT_NODE) {
break;
}
Element el = (Element) signatureElement;
if (el.getNamespaceURI().equals(Constants.SignatureSpecNS) && el.getLocalName().equals(Constants._TAG_SIGNATURE)) {
found = true;
break;
}
signatureElement = signatureElement.getParentNode();
}
if (!found) {
throw new TransformationException("transform.envelopedSignatureTransformNotInSignatureElement");
}
return signatureElement;
}
use of com.sun.org.apache.xml.internal.security.transforms.TransformationException in project jdk8u_jdk by JetBrains.
the class TransformXPath method enginePerformTransform.
/**
* Method enginePerformTransform
* @inheritDoc
* @param input
*
* @throws TransformationException
*/
protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input, OutputStream os, Transform transformObject) throws TransformationException {
try {
/**
* If the actual input is an octet stream, then the application MUST
* convert the octet stream to an XPath node-set suitable for use by
* Canonical XML with Comments. (A subsequent application of the
* REQUIRED Canonical XML algorithm would strip away these comments.)
*
* ...
*
* The evaluation of this expression includes all of the document's nodes
* (including comments) in the node-set representing the octet stream.
*/
Element xpathElement = XMLUtils.selectDsNode(transformObject.getElement().getFirstChild(), Constants._TAG_XPATH, 0);
if (xpathElement == null) {
Object[] exArgs = { "ds:XPath", "Transform" };
throw new TransformationException("xml.WrongContent", exArgs);
}
Node xpathnode = xpathElement.getChildNodes().item(0);
String str = XMLUtils.getStrFromNode(xpathnode);
input.setNeedsToBeExpanded(needsCircumvent(str));
if (xpathnode == null) {
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "Text must be in ds:Xpath");
}
XPathFactory xpathFactory = XPathFactory.newInstance();
XPathAPI xpathAPIInstance = xpathFactory.newXPathAPI();
input.addNodeFilter(new XPathNodeFilter(xpathElement, xpathnode, str, xpathAPIInstance));
input.setNodeSet(true);
return input;
} catch (DOMException ex) {
throw new TransformationException("empty", ex);
}
}
use of com.sun.org.apache.xml.internal.security.transforms.TransformationException in project jdk8u_jdk by JetBrains.
the class XMLCipherInput method getDecryptBytes.
/**
* Internal method to get bytes in decryption mode
* @return the decrypted bytes
* @throws XMLEncryptionException
*/
private byte[] getDecryptBytes() throws XMLEncryptionException {
String base64EncodedEncryptedOctets = null;
if (cipherData.getDataType() == CipherData.REFERENCE_TYPE) {
// Fun time!
if (logger.isLoggable(java.util.logging.Level.FINE)) {
logger.log(java.util.logging.Level.FINE, "Found a reference type CipherData");
}
CipherReference cr = cipherData.getCipherReference();
// Need to wrap the uri in an Attribute node so that we can
// Pass to the resource resolvers
Attr uriAttr = cr.getURIAsAttr();
XMLSignatureInput input = null;
try {
ResourceResolver resolver = ResourceResolver.getInstance(uriAttr, null, secureValidation);
input = resolver.resolve(uriAttr, null, secureValidation);
} catch (ResourceResolverException ex) {
throw new XMLEncryptionException("empty", ex);
}
if (input != null) {
if (logger.isLoggable(java.util.logging.Level.FINE)) {
logger.log(java.util.logging.Level.FINE, "Managed to resolve URI \"" + cr.getURI() + "\"");
}
} else {
if (logger.isLoggable(java.util.logging.Level.FINE)) {
logger.log(java.util.logging.Level.FINE, "Failed to resolve URI \"" + cr.getURI() + "\"");
}
}
// Lets see if there are any transforms
Transforms transforms = cr.getTransforms();
if (transforms != null) {
if (logger.isLoggable(java.util.logging.Level.FINE)) {
logger.log(java.util.logging.Level.FINE, "Have transforms in cipher reference");
}
try {
com.sun.org.apache.xml.internal.security.transforms.Transforms dsTransforms = transforms.getDSTransforms();
dsTransforms.setSecureValidation(secureValidation);
input = dsTransforms.performTransforms(input);
} catch (TransformationException ex) {
throw new XMLEncryptionException("empty", ex);
}
}
try {
return input.getBytes();
} catch (IOException ex) {
throw new XMLEncryptionException("empty", ex);
} catch (CanonicalizationException ex) {
throw new XMLEncryptionException("empty", ex);
}
// retrieve the cipher text
} else if (cipherData.getDataType() == CipherData.VALUE_TYPE) {
base64EncodedEncryptedOctets = cipherData.getCipherValue().getValue();
} else {
throw new XMLEncryptionException("CipherData.getDataType() returned unexpected value");
}
if (logger.isLoggable(java.util.logging.Level.FINE)) {
logger.log(java.util.logging.Level.FINE, "Encrypted octets:\n" + base64EncodedEncryptedOctets);
}
try {
return Base64.decode(base64EncodedEncryptedOctets);
} catch (Base64DecodingException bde) {
throw new XMLEncryptionException("empty", bde);
}
}
Aggregations