You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by gi...@apache.org on 2012/10/07 12:02:50 UTC
svn commit: r1395267 [2/3] - in /santuario/xml-security-java/trunk/src:
main/java/org/apache/xml/security/exceptions/
main/java/org/apache/xml/security/resource/
main/java/org/apache/xml/security/stax/config/
main/java/org/apache/xml/security/stax/ext/...
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java?rev=1395267&r1=1395266&r2=1395267&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java Sun Oct 7 10:02:46 2012
@@ -26,6 +26,7 @@ import org.apache.xml.security.binding.e
import org.apache.xml.security.binding.xmldsig.ReferenceType;
import org.apache.xml.security.binding.xmldsig.SignatureType;
import org.apache.xml.security.binding.xmldsig.TransformType;
+import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.stax.config.ConfigurationProperties;
import org.apache.xml.security.stax.config.JCEAlgorithmMapper;
import org.apache.xml.security.stax.config.ResourceResolverMapper;
@@ -44,7 +45,6 @@ import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import java.io.*;
-import java.lang.reflect.InvocationTargetException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
@@ -84,7 +84,6 @@ public abstract class AbstractSignatureR
List<ReferenceType> referencesTypeList = signatureType.getSignedInfo().getReference();
if (referencesTypeList.size() > maximumAllowedReferencesPerManifest) {
throw new XMLSecurityException(
- XMLSecurityException.ErrorCode.INVALID_SECURITY,
"secureProcessing.MaximumAllowedReferencesPerManifest",
referencesTypeList.size(),
maximumAllowedReferencesPerManifest);
@@ -98,12 +97,11 @@ public abstract class AbstractSignatureR
ReferenceType referenceType = referenceTypeIterator.next();
if (!doNotThrowExceptionForManifests && XMLSecurityConstants.NS_XMLDSIG_MANIFEST.equals(referenceType.getType())) {
throw new XMLSecurityException(
- XMLSecurityException.ErrorCode.INVALID_SECURITY,
"secureProcessing.DoNotThrowExceptionForManifests"
);
}
if (referenceType.getURI() == null) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK);
+ throw new XMLSecurityException("stax.emptyReferenceURI");
}
if (referenceType.getId() == null) {
referenceType.setId(IDGenerator.generateID(null));
@@ -117,7 +115,6 @@ public abstract class AbstractSignatureR
} else {
if (!allowNotSameDocumentReferences) {
throw new XMLSecurityException(
- XMLSecurityException.ErrorCode.INVALID_SECURITY,
"secureProcessing.AllowNotSameDocumentReferences"
);
}
@@ -158,7 +155,7 @@ public abstract class AbstractSignatureR
ReferenceType referenceType = referenceTypes.get(i);
if (processedReferences.contains(referenceType)) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, "duplicateId");
+ throw new XMLSecurityException("signature.Verification.MultipleIDs", referenceType.getURI());
}
InternalSignatureReferenceVerifier internalSignatureReferenceVerifier =
getSignatureReferenceVerifier(getSecurityProperties(), inputProcessorChain,
@@ -219,7 +216,7 @@ public abstract class AbstractSignatureR
while (externalReferenceIterator.hasNext()) {
Map.Entry<ResourceResolver, ReferenceType> referenceTypeEntry = externalReferenceIterator.next();
if (!processedReferences.contains(referenceTypeEntry.getValue())) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, "unprocessedSignatureReferences");
+ throw new XMLSecurityException("stax.signature.unprocessedReferences");
}
}
}
@@ -228,7 +225,7 @@ public abstract class AbstractSignatureR
while (sameDocumentReferenceIterator.hasNext()) {
Map.Entry<ResourceResolver, ReferenceType> referenceTypeEntry = sameDocumentReferenceIterator.next();
if (!processedReferences.contains(referenceTypeEntry.getValue())) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, "unprocessedSignatureReferences");
+ throw new XMLSecurityException("stax.signature.unprocessedReferences");
}
}
inputProcessorChain.doFinal();
@@ -261,19 +258,7 @@ public abstract class AbstractSignatureR
bufferedDigestOutputStream.close();
}
} catch (IOException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
- } catch (NoSuchMethodException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
- } catch (IllegalAccessException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
- } catch (NoSuchAlgorithmException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
- } catch (InstantiationException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
- } catch (NoSuchProviderException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
- } catch (InvocationTargetException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
+ throw new XMLSecurityException(e);
} finally {
try {
inputStream.close();
@@ -285,15 +270,26 @@ public abstract class AbstractSignatureR
}
protected DigestOutputStream createMessageDigestOutputStream(ReferenceType referenceType, SecurityContext securityContext)
- throws XMLSecurityException, NoSuchAlgorithmException, NoSuchProviderException {
+ throws XMLSecurityException {
+
+ String digestMethodAlgorithm = referenceType.getDigestMethod().getAlgorithm();
AlgorithmType digestAlgorithm =
- JCEAlgorithmMapper.getAlgorithmMapping(referenceType.getDigestMethod().getAlgorithm());
+ JCEAlgorithmMapper.getAlgorithmMapping(digestMethodAlgorithm);
+ if (digestAlgorithm == null) {
+ throw new XMLSecurityException("algorithms.NoSuchMap", digestMethodAlgorithm);
+ }
MessageDigest messageDigest;
- if (digestAlgorithm.getJCEProvider() != null) {
- messageDigest = MessageDigest.getInstance(digestAlgorithm.getJCEName(), digestAlgorithm.getJCEProvider());
- } else {
- messageDigest = MessageDigest.getInstance(digestAlgorithm.getJCEName());
+ try {
+ if (digestAlgorithm.getJCEProvider() != null) {
+ messageDigest = MessageDigest.getInstance(digestAlgorithm.getJCEName(), digestAlgorithm.getJCEProvider());
+ } else {
+ messageDigest = MessageDigest.getInstance(digestAlgorithm.getJCEName());
+ }
+ } catch (NoSuchAlgorithmException e) {
+ throw new XMLSecurityException(e);
+ } catch (NoSuchProviderException e) {
+ throw new XMLSecurityException(e);
}
AlgorithmSuiteSecurityEvent algorithmSuiteSecurityEvent = new AlgorithmSuiteSecurityEvent();
@@ -308,8 +304,7 @@ public abstract class AbstractSignatureR
protected Transformer buildTransformerChain(ReferenceType referenceType, OutputStream outputStream,
InputProcessorChain inputProcessorChain,
InternalSignatureReferenceVerifier internalSignatureReferenceVerifier)
- throws XMLSecurityException, XMLStreamException, NoSuchMethodException, InstantiationException,
- IllegalAccessException, InvocationTargetException {
+ throws XMLSecurityException {
if (referenceType.getTransforms() == null || referenceType.getTransforms().getTransform().isEmpty()) {
// If no Transforms then just default to an Inclusive without comments transform
@@ -330,7 +325,6 @@ public abstract class AbstractSignatureR
if (transformTypeList.size() > maximumAllowedTransformsPerReference) {
throw new XMLSecurityException(
- XMLSecurityException.ErrorCode.INVALID_SECURITY,
"secureProcessing.MaximumAllowedTransformsPerReference",
transformTypeList.size(),
maximumAllowedTransformsPerReference);
@@ -355,10 +349,12 @@ public abstract class AbstractSignatureR
inputProcessorChain.getSecurityContext().registerSecurityEvent(algorithmSuiteSecurityEvent);
if (parentTransformer != null) {
- parentTransformer = XMLSecurityUtils.getTransformer(parentTransformer, inclusiveNamespaces, algorithm, XMLSecurityConstants.DIRECTION.IN);
+ parentTransformer = XMLSecurityUtils.getTransformer(
+ parentTransformer, inclusiveNamespaces, algorithm, XMLSecurityConstants.DIRECTION.IN);
} else {
parentTransformer =
- XMLSecurityUtils.getTransformer(inclusiveNamespaces, outputStream, algorithm, XMLSecurityConstants.DIRECTION.IN);
+ XMLSecurityUtils.getTransformer(
+ inclusiveNamespaces, outputStream, algorithm, XMLSecurityConstants.DIRECTION.IN);
}
}
return parentTransformer;
@@ -372,8 +368,7 @@ public abstract class AbstractSignatureR
if (!MessageDigest.isEqual(referenceType.getDigestValue(), calculatedDigest)) {
throw new XMLSecurityException(
- XMLSecurityException.ErrorCode.FAILED_CHECK,
- "digestVerificationFailed", referenceType.getURI());
+ "signature.Verification.InvalidDigestOrReference", referenceType.getURI());
}
}
@@ -393,30 +388,13 @@ public abstract class AbstractSignatureR
super(securityProperties);
this.setStartElement(startElement);
this.setReferenceType(referenceType);
- try {
- this.digestOutputStream = createMessageDigestOutputStream(referenceType, inputProcessorChain.getSecurityContext());
- this.bufferedDigestOutputStream = new UnsynchronizedBufferedOutputStream(this.getDigestOutputStream());
- this.transformer = buildTransformerChain(referenceType, bufferedDigestOutputStream, inputProcessorChain);
- } catch (NoSuchMethodException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
- } catch (IllegalAccessException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
- } catch (NoSuchAlgorithmException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
- } catch (InstantiationException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
- } catch (XMLStreamException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
- } catch (NoSuchProviderException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
- } catch (InvocationTargetException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
- }
+ this.digestOutputStream = createMessageDigestOutputStream(referenceType, inputProcessorChain.getSecurityContext());
+ this.bufferedDigestOutputStream = new UnsynchronizedBufferedOutputStream(this.getDigestOutputStream());
+ this.transformer = buildTransformerChain(referenceType, bufferedDigestOutputStream, inputProcessorChain);
}
public Transformer buildTransformerChain(ReferenceType referenceType, OutputStream outputStream, InputProcessorChain inputProcessorChain)
- throws XMLSecurityException, XMLStreamException, NoSuchMethodException, InstantiationException,
- IllegalAccessException, InvocationTargetException {
+ throws XMLSecurityException {
return AbstractSignatureReferenceVerifyInputProcessor.this.buildTransformerChain(
referenceType, outputStream, inputProcessorChain, this);
}
@@ -452,7 +430,7 @@ public abstract class AbstractSignatureR
try {
getBufferedDigestOutputStream().close();
} catch (IOException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
+ throw new XMLSecurityException(e);
}
compareDigest(this.getDigestOutputStream().getDigestValue(), getReferenceType());
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/LogInputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/LogInputProcessor.java?rev=1395267&r1=1395266&r2=1395267&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/LogInputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/LogInputProcessor.java Sun Oct 7 10:02:46 2012
@@ -20,6 +20,7 @@ package org.apache.xml.security.stax.imp
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.stax.ext.*;
import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLDecryptInputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLDecryptInputProcessor.java?rev=1395267&r1=1395266&r2=1395267&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLDecryptInputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLDecryptInputProcessor.java Sun Oct 7 10:02:46 2012
@@ -23,13 +23,13 @@ import java.util.List;
import javax.xml.namespace.QName;
import org.apache.xml.security.binding.xmlenc.EncryptedDataType;
+import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.stax.ext.DocumentContext;
import org.apache.xml.security.stax.ext.InputProcessorChain;
import org.apache.xml.security.stax.ext.SecurePart;
import org.apache.xml.security.stax.ext.SecurityContext;
import org.apache.xml.security.stax.ext.SecurityToken;
import org.apache.xml.security.stax.ext.XMLSecurityConstants;
-import org.apache.xml.security.stax.ext.XMLSecurityException;
import org.apache.xml.security.stax.ext.XMLSecurityProperties;
import org.apache.xml.security.stax.ext.stax.XMLSecStartElement;
import org.apache.xml.security.stax.securityEvent.ContentEncryptedElementSecurityEvent;
@@ -85,7 +85,7 @@ public class XMLDecryptInputProcessor ex
} else if (tokenType == XMLSecurityConstants.EncryptedKeyToken) {
tokenSecurityEvent = new EncryptedKeyTokenSecurityEvent();
} else {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.UNSUPPORTED_SECURITY_TOKEN);
+ throw new XMLSecurityException("stax.unsupportedToken", tokenType);
}
tokenSecurityEvent.setSecurityToken(securityToken);
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLEncryptedKeyInputHandler.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLEncryptedKeyInputHandler.java?rev=1395267&r1=1395266&r2=1395267&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLEncryptedKeyInputHandler.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLEncryptedKeyInputHandler.java Sun Oct 7 10:02:46 2012
@@ -22,6 +22,7 @@ import org.apache.xml.security.binding.x
import org.apache.xml.security.binding.xmldsig.KeyInfoType;
import org.apache.xml.security.binding.xmlenc.EncryptedKeyType;
import org.apache.xml.security.binding.xmlenc11.MGFType;
+import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.stax.config.JCEAlgorithmMapper;
import org.apache.xml.security.stax.ext.*;
import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
@@ -68,7 +69,7 @@ public class XMLEncryptedKeyInputHandler
final XMLSecurityProperties securityProperties) throws XMLSecurityException {
if (encryptedKeyType.getEncryptionMethod() == null) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, "noEncAlgo");
+ throw new XMLSecurityException("stax.encryption.noEncAlgo");
}
checkBSPCompliance(inputProcessorChain, encryptedKeyType);
@@ -145,11 +146,11 @@ public class XMLEncryptedKeyInputHandler
String algorithmURI = encryptedKeyType.getEncryptionMethod().getAlgorithm();
if (algorithmURI == null) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, "noEncAlgo");
+ throw new XMLSecurityException("stax.encryption.noEncAlgo");
}
AlgorithmType encAlgo = JCEAlgorithmMapper.getAlgorithmMapping(algorithmURI);
if (encAlgo == null) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, "noEncAlgo");
+ throw new XMLSecurityException("algorithms.NoSuchMap", algorithmURI);
}
final SecurityToken wrappingSecurityToken = getWrappingSecurityToken(wrappedSecurityToken);
@@ -198,7 +199,7 @@ public class XMLEncryptedKeyInputHandler
}
if (encryptedKeyType.getCipherData() == null
|| encryptedKeyType.getCipherData().getCipherValue() == null) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.INVALID_SECURITY, "noCipher");
+ throw new XMLSecurityException("stax.encryption.noCipherValue");
}
Key key = cipher.unwrap(encryptedKeyType.getCipherData().getCipherValue(),
encAlgo.getJCEName(),
@@ -206,24 +207,15 @@ public class XMLEncryptedKeyInputHandler
return this.decryptedKey = key.getEncoded();
} catch (NoSuchPaddingException e) {
- throw new XMLSecurityException(
- XMLSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, "unsupportedKeyTransp",
- e, "No such padding: " + algorithmURI
- );
+ throw new XMLSecurityException(e);
} catch (NoSuchAlgorithmException e) {
- throw new XMLSecurityException(
- XMLSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, "unsupportedKeyTransp",
- e, "No such algorithm: " + algorithmURI
- );
+ throw new XMLSecurityException(e);
} catch (InvalidAlgorithmParameterException e) {
- throw new XMLSecurityException(
- XMLSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, "unsupportedKeyTransp",
- e, "No such algorithm: " + algorithmURI
- );
+ throw new XMLSecurityException(e);
} catch (InvalidKeyException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
+ throw new XMLSecurityException(e);
} catch (NoSuchProviderException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILURE, "noSecProvider", e);
+ throw new XMLSecurityException(e);
}
}
};
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLEventReaderInputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLEventReaderInputProcessor.java?rev=1395267&r1=1395266&r2=1395267&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLEventReaderInputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLEventReaderInputProcessor.java Sun Oct 7 10:02:46 2012
@@ -18,6 +18,7 @@
*/
package org.apache.xml.security.stax.impl.processor.input;
+import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.stax.config.ConfigurationProperties;
import org.apache.xml.security.stax.ext.*;
import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
@@ -70,7 +71,6 @@ public class XMLEventReaderInputProcesso
currentXMLStructureDepth++;
if (currentXMLStructureDepth > maximumAllowedXMLStructureDepth) {
XMLSecurityException xmlSecurityException = new XMLSecurityException(
- XMLSecurityException.ErrorCode.INVALID_SECURITY,
"secureProcessing.MaximumAllowedXMLStructureDepth",
maximumAllowedXMLStructureDepth
);
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSecurityInputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSecurityInputProcessor.java?rev=1395267&r1=1395266&r2=1395267&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSecurityInputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSecurityInputProcessor.java Sun Oct 7 10:02:46 2012
@@ -25,10 +25,10 @@ import javax.xml.stream.XMLStreamExcepti
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.stax.ext.AbstractInputProcessor;
import org.apache.xml.security.stax.ext.InputProcessorChain;
import org.apache.xml.security.stax.ext.XMLSecurityConstants;
-import org.apache.xml.security.stax.ext.XMLSecurityException;
import org.apache.xml.security.stax.ext.XMLSecurityProperties;
import org.apache.xml.security.stax.ext.stax.XMLSecEndElement;
import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
@@ -126,9 +126,8 @@ public class XMLSecurityInputProcessor e
}
} while (!xmlSecEvent.isEndDocument());
- //if we reach this state we didn't find a signature
- //todo exception is wrong. We don't miss a signature when we are decrypting but we miss EncryptedData
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILURE, "missingSignature");
+ //if we reach this state we didn't find a signature nor a encryptedData Element
+ throw new XMLSecurityException("stax.unsecuredMessage");
}
/**
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSignatureInputHandler.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSignatureInputHandler.java?rev=1395267&r1=1395266&r2=1395267&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSignatureInputHandler.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSignatureInputHandler.java Sun Oct 7 10:02:46 2012
@@ -20,11 +20,11 @@ package org.apache.xml.security.stax.imp
import org.apache.xml.security.binding.xmldsig.KeyInfoType;
import org.apache.xml.security.binding.xmldsig.SignatureType;
+import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.stax.ext.InputProcessorChain;
import org.apache.xml.security.stax.ext.SecurityContext;
import org.apache.xml.security.stax.ext.SecurityToken;
import org.apache.xml.security.stax.ext.XMLSecurityConstants;
-import org.apache.xml.security.stax.ext.XMLSecurityException;
import org.apache.xml.security.stax.ext.XMLSecurityProperties;
import org.apache.xml.security.stax.impl.securityToken.SecurityTokenFactory;
import org.apache.xml.security.stax.securityEvent.AlgorithmSuiteSecurityEvent;
@@ -46,16 +46,16 @@ public class XMLSignatureInputHandler ex
final SignatureType signatureType) throws XMLSecurityException {
if (signatureType.getSignedInfo() == null) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.INVALID_SECURITY);
+ throw new XMLSecurityException("stax.signature.signedInfoMissing");
}
if (signatureType.getSignedInfo().getSignatureMethod() == null) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.INVALID_SECURITY);
+ throw new XMLSecurityException("stax.signature.signatureMethodMissing");
}
if (signatureType.getSignedInfo().getCanonicalizationMethod() == null) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.INVALID_SECURITY);
+ throw new XMLSecurityException("stax.signature.canonicalizationMethodMissing");
}
if (signatureType.getSignatureValue() == null) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.INVALID_SECURITY);
+ throw new XMLSecurityException("stax.signature.signatureValueMissing");
}
final SecurityContext securityContext = inputProcessorChain.getSecurityContext();
final SignatureVerifier signatureVerifier =
@@ -78,7 +78,7 @@ public class XMLSignatureInputHandler ex
} else if (tokenType == XMLSecurityConstants.DefaultToken) {
tokenSecurityEvent = new DefaultTokenSecurityEvent();
} else {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.UNSUPPORTED_SECURITY_TOKEN);
+ throw new XMLSecurityException("stax.unsupportedToken", tokenType);
}
tokenSecurityEvent.setSecurityToken(securityToken);
tokenSecurityEvent.setCorrelationID(signatureType.getId());
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSignatureReferenceVerifyInputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSignatureReferenceVerifyInputProcessor.java?rev=1395267&r1=1395266&r2=1395267&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSignatureReferenceVerifyInputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSignatureReferenceVerifyInputProcessor.java Sun Oct 7 10:02:46 2012
@@ -24,10 +24,10 @@ import javax.xml.namespace.QName;
import org.apache.xml.security.binding.xmldsig.ReferenceType;
import org.apache.xml.security.binding.xmldsig.SignatureType;
+import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.stax.ext.DocumentContext;
import org.apache.xml.security.stax.ext.InputProcessorChain;
import org.apache.xml.security.stax.ext.SecurityToken;
-import org.apache.xml.security.stax.ext.XMLSecurityException;
import org.apache.xml.security.stax.ext.XMLSecurityProperties;
import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
import org.apache.xml.security.stax.securityEvent.SignedElementSecurityEvent;
@@ -37,7 +37,10 @@ import org.apache.xml.security.stax.secu
*/
public class XMLSignatureReferenceVerifyInputProcessor extends AbstractSignatureReferenceVerifyInputProcessor {
- public XMLSignatureReferenceVerifyInputProcessor(InputProcessorChain inputProcessorChain, SignatureType signatureType, SecurityToken securityToken, XMLSecurityProperties securityProperties) throws XMLSecurityException {
+ public XMLSignatureReferenceVerifyInputProcessor(
+ InputProcessorChain inputProcessorChain, SignatureType signatureType, SecurityToken securityToken,
+ XMLSecurityProperties securityProperties) throws XMLSecurityException {
+
super(inputProcessorChain, signatureType, securityToken, securityProperties);
this.addAfterProcessor(XMLSignatureReferenceVerifyInputProcessor.class.getName());
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptEndingOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptEndingOutputProcessor.java?rev=1395267&r1=1395266&r2=1395267&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptEndingOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptEndingOutputProcessor.java Sun Oct 7 10:02:46 2012
@@ -18,8 +18,8 @@
*/
package org.apache.xml.security.stax.impl.processor.output;
+import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.stax.ext.AbstractBufferingOutputProcessor;
-import org.apache.xml.security.stax.ext.XMLSecurityException;
/**
* Processor buffers encrypted XMLEvents and forwards them when final is called
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java?rev=1395267&r1=1395266&r2=1395267&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java Sun Oct 7 10:02:46 2012
@@ -19,12 +19,12 @@
package org.apache.xml.security.stax.impl.processor.output;
import org.apache.commons.codec.binary.Base64OutputStream;
+import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.stax.config.JCEAlgorithmMapper;
import org.apache.xml.security.stax.config.TransformerAlgorithmMapper;
import org.apache.xml.security.stax.ext.AbstractOutputProcessor;
import org.apache.xml.security.stax.ext.OutputProcessorChain;
import org.apache.xml.security.stax.ext.XMLSecurityConstants;
-import org.apache.xml.security.stax.ext.XMLSecurityException;
import org.apache.xml.security.stax.ext.stax.*;
import org.apache.xml.security.stax.impl.EncryptionPartDef;
import org.apache.xml.security.stax.impl.util.TrimmerOutputStream;
@@ -97,7 +97,7 @@ public abstract class AbstractEncryptOut
public AbstractInternalEncryptionOutputProcessor(EncryptionPartDef encryptionPartDef,
XMLSecStartElement xmlSecStartElement, String encoding)
- throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IOException, XMLStreamException {
+ throws XMLSecurityException {
super();
this.addBeforeProcessor(AbstractEncryptEndingOutputProcessor.class.getName());
@@ -110,9 +110,14 @@ public abstract class AbstractEncryptOut
@Override
public void init(OutputProcessorChain outputProcessorChain) throws XMLSecurityException {
+
+ String encryptionSymAlgorithm = securityProperties.getEncryptionSymAlgorithm();
try {
//initialize the cipher
- String jceAlgorithm = JCEAlgorithmMapper.translateURItoJCEID(securityProperties.getEncryptionSymAlgorithm());
+ String jceAlgorithm = JCEAlgorithmMapper.translateURItoJCEID(encryptionSymAlgorithm);
+ if (jceAlgorithm == null) {
+ throw new XMLSecurityException("algorithms.NoSuchMap", encryptionSymAlgorithm);
+ }
Cipher symmetricCipher = Cipher.getInstance(jceAlgorithm);
// The Spec mandates a 96-bit IV for GCM algorithms
@@ -152,25 +157,25 @@ public abstract class AbstractEncryptOut
//we have to output a fake element to workaround text-only encryption:
xmlEventWriter.add(wrapperStartElement);
} catch (NoSuchPaddingException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_ENCRYPTION, e);
+ throw new XMLSecurityException(e);
} catch (NoSuchAlgorithmException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_ENCRYPTION, e);
+ throw new XMLSecurityException(e);
} catch (IOException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_ENCRYPTION, e);
+ throw new XMLSecurityException(e);
} catch (XMLStreamException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_ENCRYPTION, e);
+ throw new XMLSecurityException(e);
} catch (InvalidKeyException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_ENCRYPTION, e);
+ throw new XMLSecurityException(e);
} catch (InvalidAlgorithmParameterException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_ENCRYPTION, e);
+ throw new XMLSecurityException(e);
} catch (InvocationTargetException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILURE, e);
+ throw new XMLSecurityException(e);
} catch (NoSuchMethodException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILURE, e);
+ throw new XMLSecurityException(e);
} catch (InstantiationException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILURE, e);
+ throw new XMLSecurityException(e);
} catch (IllegalAccessException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILURE, e);
+ throw new XMLSecurityException(e);
}
super.init(outputProcessorChain);
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureEndingOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureEndingOutputProcessor.java?rev=1395267&r1=1395266&r2=1395267&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureEndingOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureEndingOutputProcessor.java Sun Oct 7 10:02:46 2012
@@ -19,6 +19,7 @@
package org.apache.xml.security.stax.impl.processor.output;
import org.apache.commons.codec.binary.Base64;
+import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.stax.ext.*;
import org.apache.xml.security.stax.ext.stax.XMLSecAttribute;
import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
@@ -34,7 +35,6 @@ import org.apache.xml.security.stax.impl
import javax.xml.stream.XMLStreamException;
import java.io.IOException;
import java.io.OutputStream;
-import java.lang.reflect.InvocationTargetException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.util.ArrayList;
@@ -100,26 +100,25 @@ public abstract class AbstractSignatureE
XMLSecStartElement signatureElement = createStartElementAndOutputAsEvent(subOutputProcessorChain, XMLSecurityConstants.TAG_dsig_Signature, true, attributes);
SignatureAlgorithm signatureAlgorithm;
-
try {
signatureAlgorithm = SignatureAlgorithmFactory.getInstance().getSignatureAlgorithm(getSecurityProperties().getSignatureAlgorithm());
} catch (NoSuchAlgorithmException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
+ throw new XMLSecurityException(e);
} catch (NoSuchProviderException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILURE, "noSecProvider", e);
+ throw new XMLSecurityException(e);
}
String tokenId = outputProcessorChain.getSecurityContext().get(XMLSecurityConstants.PROP_USE_THIS_TOKEN_ID_FOR_SIGNATURE);
if (tokenId == null) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE);
+ throw new XMLSecurityException("stax.keyNotFound");
}
SecurityTokenProvider wrappingSecurityTokenProvider = outputProcessorChain.getSecurityContext().getSecurityTokenProvider(tokenId);
if (wrappingSecurityTokenProvider == null) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE);
+ throw new XMLSecurityException("stax.keyNotFound");
}
final OutboundSecurityToken wrappingSecurityToken = wrappingSecurityTokenProvider.getSecurityToken();
if (wrappingSecurityToken == null) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE);
+ throw new XMLSecurityException("stax.keyNotFound");
}
signatureAlgorithm.engineInitSign(wrappingSecurityToken.getSecretKey(getSecurityProperties().getSignatureAlgorithm()));
@@ -244,18 +243,8 @@ public abstract class AbstractSignatureE
this.inclusiveNamespacePrefixes = prefixes.toString();
}
- try {
- this.transformer = XMLSecurityUtils.getTransformer(inclusiveNamespacePrefixes, this.bufferedSignerOutputStream,
- canonicalizationAlgorithm, XMLSecurityConstants.DIRECTION.OUT);
- } catch (NoSuchMethodException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
- } catch (InstantiationException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
- } catch (IllegalAccessException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
- } catch (InvocationTargetException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
- }
+ this.transformer = XMLSecurityUtils.getTransformer(inclusiveNamespacePrefixes, this.bufferedSignerOutputStream,
+ canonicalizationAlgorithm, XMLSecurityConstants.DIRECTION.OUT);
super.init(outputProcessorChain);
}
@@ -270,9 +259,9 @@ public abstract class AbstractSignatureE
signatureValue = signerOutputStream.sign();
return signatureValue;
} catch (IOException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
+ throw new XMLSecurityException(e);
} catch (XMLStreamException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
+ throw new XMLSecurityException(e);
}
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java?rev=1395267&r1=1395266&r2=1395267&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java Sun Oct 7 10:02:46 2012
@@ -22,6 +22,7 @@ import org.apache.commons.codec.binary.B
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.stax.config.JCEAlgorithmMapper;
import org.apache.xml.security.stax.config.ResourceResolverMapper;
import org.apache.xml.security.stax.ext.*;
@@ -38,7 +39,6 @@ import javax.xml.stream.XMLStreamExcepti
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.lang.reflect.InvocationTargetException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
@@ -78,15 +78,7 @@ public abstract class AbstractSignatureO
if (externalReference != null) {
ResourceResolver resourceResolver = ResourceResolverMapper.getResourceResolver(externalReference, outputProcessorChain.getDocumentContext().getBaseURI());
- DigestOutputStream digestOutputStream = null;
- try {
- digestOutputStream = createMessageDigestOutputStream(securePart.getDigestMethod());
- } catch (NoSuchAlgorithmException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
- } catch (NoSuchProviderException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
- }
-
+ DigestOutputStream digestOutputStream = createMessageDigestOutputStream(securePart.getDigestMethod());
InputStream inputStream = resourceResolver.getInputStreamFromExternalReference();
SignaturePartDef signaturePartDef = new SignaturePartDef();
@@ -110,16 +102,8 @@ public abstract class AbstractSignatureO
IOUtils.copy(inputStream, digestOutputStream);
}
digestOutputStream.close();
- } catch (NoSuchMethodException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
- } catch (InstantiationException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
- } catch (IllegalAccessException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
- } catch (InvocationTargetException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
} catch (IOException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
+ throw new XMLSecurityException(e);
}
String calculatedDigest = new String(Base64.encodeBase64(digestOutputStream.getDigestValue()));
@@ -144,17 +128,23 @@ public abstract class AbstractSignatureO
}
private DigestOutputStream createMessageDigestOutputStream(String digestAlgorithm)
- throws XMLSecurityException, NoSuchAlgorithmException, NoSuchProviderException {
+ throws XMLSecurityException {
AlgorithmType algorithmType = JCEAlgorithmMapper.getAlgorithmMapping(digestAlgorithm);
if (algorithmType == null) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, "unknownSignatureAlgorithm", digestAlgorithm);
+ throw new XMLSecurityException("algorithms.NoSuchMap", digestAlgorithm);
}
MessageDigest messageDigest;
- if (algorithmType.getJCEProvider() != null) {
- messageDigest = MessageDigest.getInstance(algorithmType.getJCEName(), algorithmType.getJCEProvider());
- } else {
- messageDigest = MessageDigest.getInstance(algorithmType.getJCEName());
+ try {
+ if (algorithmType.getJCEProvider() != null) {
+ messageDigest = MessageDigest.getInstance(algorithmType.getJCEName(), algorithmType.getJCEProvider());
+ } else {
+ messageDigest = MessageDigest.getInstance(algorithmType.getJCEName());
+ }
+ } catch (NoSuchAlgorithmException e) {
+ throw new XMLSecurityException(e);
+ } catch (NoSuchProviderException e) {
+ throw new XMLSecurityException(e);
}
return new DigestOutputStream(messageDigest);
}
@@ -162,8 +152,7 @@ public abstract class AbstractSignatureO
protected Transformer buildTransformerChain(OutputStream outputStream,
SignaturePartDef signaturePartDef,
XMLSecStartElement xmlSecStartElement)
- throws XMLSecurityException, NoSuchMethodException, InstantiationException,
- IllegalAccessException, InvocationTargetException {
+ throws XMLSecurityException {
String[] transforms = signaturePartDef.getTransforms();
@@ -218,7 +207,7 @@ public abstract class AbstractSignatureO
private Transformer transformer;
public InternalSignatureOutputProcessor(SignaturePartDef signaturePartDef, XMLSecStartElement xmlSecStartElement)
- throws XMLSecurityException, NoSuchProviderException, NoSuchAlgorithmException {
+ throws XMLSecurityException {
super();
this.addBeforeProcessor(InternalSignatureOutputProcessor.class.getName());
this.signaturePartDef = signaturePartDef;
@@ -227,23 +216,9 @@ public abstract class AbstractSignatureO
@Override
public void init(OutputProcessorChain outputProcessorChain) throws XMLSecurityException {
- try {
- this.digestOutputStream = createMessageDigestOutputStream(signaturePartDef.getDigestAlgo());
- this.bufferedDigestOutputStream = new UnsynchronizedBufferedOutputStream(digestOutputStream);
- this.transformer = buildTransformerChain(this.bufferedDigestOutputStream, signaturePartDef, xmlSecStartElement);
- } catch (NoSuchMethodException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
- } catch (InstantiationException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
- } catch (IllegalAccessException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
- } catch (InvocationTargetException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
- } catch (NoSuchAlgorithmException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
- } catch (NoSuchProviderException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
- }
+ this.digestOutputStream = createMessageDigestOutputStream(signaturePartDef.getDigestAlgo());
+ this.bufferedDigestOutputStream = new UnsynchronizedBufferedOutputStream(digestOutputStream);
+ this.transformer = buildTransformerChain(this.bufferedDigestOutputStream, signaturePartDef, xmlSecStartElement);
super.init(outputProcessorChain);
}
@@ -267,7 +242,7 @@ public abstract class AbstractSignatureO
try {
bufferedDigestOutputStream.close();
} catch (IOException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, e);
+ throw new XMLSecurityException(e);
}
String calculatedDigest = new String(Base64.encodeBase64(this.digestOutputStream.getDigestValue()));
if (logger.isDebugEnabled()) {
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/FinalOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/FinalOutputProcessor.java?rev=1395267&r1=1395266&r2=1395267&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/FinalOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/FinalOutputProcessor.java Sun Oct 7 10:02:46 2012
@@ -18,10 +18,10 @@
*/
package org.apache.xml.security.stax.impl.processor.output;
+import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.stax.ext.AbstractOutputProcessor;
import org.apache.xml.security.stax.ext.OutputProcessorChain;
import org.apache.xml.security.stax.ext.XMLSecurityConstants;
-import org.apache.xml.security.stax.ext.XMLSecurityException;
import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
import org.apache.xml.security.stax.impl.XMLSecurityEventWriter;
@@ -47,7 +47,7 @@ public class FinalOutputProcessor extend
try {
xmlEventWriter = XMLSecurityConstants.xmlOutputFactory.createXMLEventWriter(outputStream, encoding);
} catch (XMLStreamException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILURE, e);
+ throw new XMLSecurityException(e);
}
}
@@ -68,7 +68,7 @@ public class FinalOutputProcessor extend
xmlEventWriter.flush();
xmlEventWriter.close();
} catch (XMLStreamException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILURE, e);
+ throw new XMLSecurityException(e);
}
}
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/XMLEncryptOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/XMLEncryptOutputProcessor.java?rev=1395267&r1=1395266&r2=1395267&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/XMLEncryptOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/XMLEncryptOutputProcessor.java Sun Oct 7 10:02:46 2012
@@ -21,6 +21,7 @@ package org.apache.xml.security.stax.imp
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.stax.config.JCEAlgorithmMapper;
import org.apache.xml.security.stax.ext.*;
import org.apache.xml.security.stax.ext.stax.XMLSecAttribute;
@@ -37,7 +38,6 @@ import javax.crypto.spec.OAEPParameterSp
import javax.crypto.spec.PSource;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
-import java.io.IOException;
import java.security.*;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.MGF1ParameterSpec;
@@ -68,32 +68,26 @@ public class XMLEncryptOutputProcessor e
SecurePart securePart = securePartMatches(xmlSecStartElement, outputProcessorChain, XMLSecurityConstants.ENCRYPTION_PARTS);
if (securePart != null) {
logger.debug("Matched encryptionPart for encryption");
- AbstractInternalEncryptionOutputProcessor internalEncryptionOutputProcessor;
- try {
- String tokenId = outputProcessorChain.getSecurityContext().get(XMLSecurityConstants.PROP_USE_THIS_TOKEN_ID_FOR_ENCRYPTION);
- SecurityTokenProvider securityTokenProvider = outputProcessorChain.getSecurityContext().getSecurityTokenProvider(tokenId);
- final OutboundSecurityToken securityToken = securityTokenProvider.getSecurityToken();
-
- EncryptionPartDef encryptionPartDef = new EncryptionPartDef();
- encryptionPartDef.setModifier(securePart.getModifier());
- encryptionPartDef.setEncRefId(IDGenerator.generateID(null));
- encryptionPartDef.setKeyId(securityTokenProvider.getId());
- encryptionPartDef.setSymmetricKey(securityToken.getSecretKey(getSecurityProperties().getEncryptionSymAlgorithm()));
- outputProcessorChain.getSecurityContext().putAsList(EncryptionPartDef.class, encryptionPartDef);
-
- internalEncryptionOutputProcessor =
- createInternalEncryptionOutputProcessor(
- encryptionPartDef, xmlSecStartElement,
- outputProcessorChain.getDocumentContext().getEncoding(),
- securityToken.getKeyWrappingToken()
- );
- internalEncryptionOutputProcessor.setXMLSecurityProperties(getSecurityProperties());
- internalEncryptionOutputProcessor.setAction(getAction());
- internalEncryptionOutputProcessor.init(outputProcessorChain);
-
- } catch (IOException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_ENCRYPTION, e);
- }
+ String tokenId = outputProcessorChain.getSecurityContext().get(XMLSecurityConstants.PROP_USE_THIS_TOKEN_ID_FOR_ENCRYPTION);
+ SecurityTokenProvider securityTokenProvider = outputProcessorChain.getSecurityContext().getSecurityTokenProvider(tokenId);
+ final OutboundSecurityToken securityToken = securityTokenProvider.getSecurityToken();
+
+ EncryptionPartDef encryptionPartDef = new EncryptionPartDef();
+ encryptionPartDef.setModifier(securePart.getModifier());
+ encryptionPartDef.setEncRefId(IDGenerator.generateID(null));
+ encryptionPartDef.setKeyId(securityTokenProvider.getId());
+ encryptionPartDef.setSymmetricKey(securityToken.getSecretKey(getSecurityProperties().getEncryptionSymAlgorithm()));
+ outputProcessorChain.getSecurityContext().putAsList(EncryptionPartDef.class, encryptionPartDef);
+
+ AbstractInternalEncryptionOutputProcessor internalEncryptionOutputProcessor =
+ createInternalEncryptionOutputProcessor(
+ encryptionPartDef, xmlSecStartElement,
+ outputProcessorChain.getDocumentContext().getEncoding(),
+ securityToken.getKeyWrappingToken()
+ );
+ internalEncryptionOutputProcessor.setXMLSecurityProperties(getSecurityProperties());
+ internalEncryptionOutputProcessor.setAction(getAction());
+ internalEncryptionOutputProcessor.init(outputProcessorChain);
setActiveInternalEncryptionOutputProcessor(internalEncryptionOutputProcessor);
}
@@ -113,158 +107,151 @@ public class XMLEncryptOutputProcessor e
String encoding,
final OutboundSecurityToken keyWrappingToken
) throws XMLStreamException, XMLSecurityException {
- try {
- final AbstractInternalEncryptionOutputProcessor processor =
- new AbstractInternalEncryptionOutputProcessor(encryptionPartDef,
- startElement,
- encoding) {
- @Override
- protected void createKeyInfoStructure(OutputProcessorChain outputProcessorChain)
- throws XMLStreamException, XMLSecurityException {
- if (keyWrappingToken == null) {
- // Do not write out a KeyInfo element
- return;
- }
+ final AbstractInternalEncryptionOutputProcessor processor =
+ new AbstractInternalEncryptionOutputProcessor(encryptionPartDef,
+ startElement,
+ encoding) {
+
+ @Override
+ protected void createKeyInfoStructure(OutputProcessorChain outputProcessorChain)
+ throws XMLStreamException, XMLSecurityException {
+ if (keyWrappingToken == null) {
+ // Do not write out a KeyInfo element
+ return;
+ }
+
+ final String encryptionKeyTransportAlgorithm = getSecurityProperties().getEncryptionKeyTransportAlgorithm();
+
+ PublicKey pubKey = keyWrappingToken.getPublicKey();
+ Key secretKey = keyWrappingToken.getSecretKey(encryptionKeyTransportAlgorithm);
+ if (pubKey == null && secretKey == null) {
+ // Do not write out a KeyInfo element
+ return;
+ }
- final String encryptionKeyTransportAlgorithm = getSecurityProperties().getEncryptionKeyTransportAlgorithm();
+ createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_KeyInfo, true, null);
- PublicKey pubKey = keyWrappingToken.getPublicKey();
- Key secretKey = keyWrappingToken.getSecretKey(encryptionKeyTransportAlgorithm);
- if (pubKey == null && secretKey == null) {
- // Do not write out a KeyInfo element
- return;
+ List<XMLSecAttribute> attributes = new ArrayList<XMLSecAttribute>(1);
+ String keyId = getEncryptionPartDef().getKeyId();
+ if (keyId == null) {
+ keyId = IDGenerator.generateID("EK");
+ }
+ attributes.add(createAttribute(XMLSecurityConstants.ATT_NULL_Id, keyId));
+ createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_EncryptedKey, true, attributes);
+
+ attributes = new ArrayList<XMLSecAttribute>(1);
+ attributes.add(createAttribute(XMLSecurityConstants.ATT_NULL_Algorithm, encryptionKeyTransportAlgorithm));
+ createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_EncryptionMethod, false, attributes);
+
+ final String encryptionKeyTransportDigestAlgorithm = getSecurityProperties().getEncryptionKeyTransportDigestAlgorithm();
+ final String encryptionKeyTransportMGFAlgorithm = getSecurityProperties().getEncryptionKeyTransportMGFAlgorithm();
+
+ if (XMLSecurityConstants.NS_XENC11_RSAOAEP.equals(encryptionKeyTransportAlgorithm) ||
+ XMLSecurityConstants.NS_XENC_RSAOAEPMGF1P.equals(encryptionKeyTransportAlgorithm)) {
+
+ byte[] oaepParams = getSecurityProperties().getEncryptionKeyTransportOAEPParams();
+ if (oaepParams != null) {
+ createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_OAEPparams, false, null);
+ createCharactersAndOutputAsEvent(outputProcessorChain, Base64.encodeBase64String(oaepParams));
+ createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_OAEPparams);
}
- createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_KeyInfo, true, null);
+ if (encryptionKeyTransportDigestAlgorithm != null) {
+ attributes = new ArrayList<XMLSecAttribute>(1);
+ attributes.add(createAttribute(XMLSecurityConstants.ATT_NULL_Algorithm, encryptionKeyTransportDigestAlgorithm));
+ createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_DigestMethod, true, attributes);
+ createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_DigestMethod);
+ }
- List<XMLSecAttribute> attributes = new ArrayList<XMLSecAttribute>(1);
- String keyId = getEncryptionPartDef().getKeyId();
- if (keyId == null) {
- keyId = IDGenerator.generateID("EK");
+ if (encryptionKeyTransportMGFAlgorithm != null) {
+ attributes = new ArrayList<XMLSecAttribute>(1);
+ attributes.add(createAttribute(XMLSecurityConstants.ATT_NULL_Algorithm, encryptionKeyTransportMGFAlgorithm));
+ createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc11_MGF, true, attributes);
+ createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc11_MGF);
}
- attributes.add(createAttribute(XMLSecurityConstants.ATT_NULL_Id, keyId));
- createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_EncryptedKey, true, attributes);
+ }
- attributes = new ArrayList<XMLSecAttribute>(1);
- attributes.add(createAttribute(XMLSecurityConstants.ATT_NULL_Algorithm, encryptionKeyTransportAlgorithm));
- createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_EncryptionMethod, false, attributes);
+ createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_EncryptionMethod);
+ createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_CipherData, false, null);
+ createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_CipherValue, false, null);
+
+ //encrypt the symmetric session key with the public key from the receiver:
+ String jceid = JCEAlgorithmMapper.translateURItoJCEID(encryptionKeyTransportAlgorithm);
+ if (jceid == null) {
+ throw new XMLSecurityException("algorithms.NoSuchMap", encryptionKeyTransportAlgorithm);
+ }
- final String encryptionKeyTransportDigestAlgorithm = getSecurityProperties().getEncryptionKeyTransportDigestAlgorithm();
- final String encryptionKeyTransportMGFAlgorithm = getSecurityProperties().getEncryptionKeyTransportMGFAlgorithm();
+ try {
+ Cipher cipher = Cipher.getInstance(jceid);
+ AlgorithmParameterSpec algorithmParameterSpec = null;
if (XMLSecurityConstants.NS_XENC11_RSAOAEP.equals(encryptionKeyTransportAlgorithm) ||
XMLSecurityConstants.NS_XENC_RSAOAEPMGF1P.equals(encryptionKeyTransportAlgorithm)) {
- byte[] oaepParams = getSecurityProperties().getEncryptionKeyTransportOAEPParams();
- if (oaepParams != null) {
- createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_OAEPparams, false, null);
- createCharactersAndOutputAsEvent(outputProcessorChain, Base64.encodeBase64String(oaepParams));
- createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_OAEPparams);
+ String jceDigestAlgorithm = "SHA-1";
+ if (encryptionKeyTransportDigestAlgorithm != null) {
+ jceDigestAlgorithm = JCEAlgorithmMapper.translateURItoJCEID(encryptionKeyTransportDigestAlgorithm);
}
- if (encryptionKeyTransportDigestAlgorithm != null) {
- attributes = new ArrayList<XMLSecAttribute>(1);
- attributes.add(createAttribute(XMLSecurityConstants.ATT_NULL_Algorithm, encryptionKeyTransportDigestAlgorithm));
- createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_DigestMethod, true, attributes);
- createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_DigestMethod);
+ PSource.PSpecified pSource = PSource.PSpecified.DEFAULT;
+ byte[] oaepParams = getSecurityProperties().getEncryptionKeyTransportOAEPParams();
+ if (oaepParams != null) {
+ pSource = new PSource.PSpecified(oaepParams);
}
+ MGF1ParameterSpec mgfParameterSpec = new MGF1ParameterSpec("SHA-1");
if (encryptionKeyTransportMGFAlgorithm != null) {
- attributes = new ArrayList<XMLSecAttribute>(1);
- attributes.add(createAttribute(XMLSecurityConstants.ATT_NULL_Algorithm, encryptionKeyTransportMGFAlgorithm));
- createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc11_MGF, true, attributes);
- createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc11_MGF);
+ String jceMGFAlgorithm = JCEAlgorithmMapper.translateURItoJCEID(encryptionKeyTransportMGFAlgorithm);
+ mgfParameterSpec = new MGF1ParameterSpec(jceMGFAlgorithm);
}
+ algorithmParameterSpec = new OAEPParameterSpec(jceDigestAlgorithm, "MGF1", mgfParameterSpec, pSource);
}
- createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_EncryptionMethod);
- createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_CipherData, false, null);
- createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_CipherValue, false, null);
-
- try {
- //encrypt the symmetric session key with the public key from the receiver:
- String jceid = JCEAlgorithmMapper.translateURItoJCEID(encryptionKeyTransportAlgorithm);
- Cipher cipher = Cipher.getInstance(jceid);
-
- AlgorithmParameterSpec algorithmParameterSpec = null;
- if (XMLSecurityConstants.NS_XENC11_RSAOAEP.equals(encryptionKeyTransportAlgorithm) ||
- XMLSecurityConstants.NS_XENC_RSAOAEPMGF1P.equals(encryptionKeyTransportAlgorithm)) {
-
- String jceDigestAlgorithm = "SHA-1";
- if (encryptionKeyTransportDigestAlgorithm != null) {
- jceDigestAlgorithm = JCEAlgorithmMapper.translateURItoJCEID(encryptionKeyTransportDigestAlgorithm);
- }
-
- PSource.PSpecified pSource = PSource.PSpecified.DEFAULT;
- byte[] oaepParams = getSecurityProperties().getEncryptionKeyTransportOAEPParams();
- if (oaepParams != null) {
- pSource = new PSource.PSpecified(oaepParams);
- }
-
- MGF1ParameterSpec mgfParameterSpec = new MGF1ParameterSpec("SHA-1");
- if (encryptionKeyTransportMGFAlgorithm != null) {
- String jceMGFAlgorithm = JCEAlgorithmMapper.translateURItoJCEID(encryptionKeyTransportMGFAlgorithm);
- mgfParameterSpec = new MGF1ParameterSpec(jceMGFAlgorithm);
- }
- algorithmParameterSpec = new OAEPParameterSpec(jceDigestAlgorithm, "MGF1", mgfParameterSpec, pSource);
- }
+ if (pubKey != null) {
+ cipher.init(Cipher.WRAP_MODE, pubKey, algorithmParameterSpec);
+ } else {
+ cipher.init(Cipher.WRAP_MODE, secretKey, algorithmParameterSpec);
+ }
+
+ String tokenId = outputProcessorChain.getSecurityContext().get(XMLSecurityConstants.PROP_USE_THIS_TOKEN_ID_FOR_ENCRYPTION);
+ SecurityTokenProvider securityTokenProvider = outputProcessorChain.getSecurityContext().getSecurityTokenProvider(tokenId);
- if (pubKey != null) {
- cipher.init(Cipher.WRAP_MODE, pubKey, algorithmParameterSpec);
- } else {
- cipher.init(Cipher.WRAP_MODE, secretKey, algorithmParameterSpec);
+ final OutboundSecurityToken securityToken = securityTokenProvider.getSecurityToken();
+ Key sessionKey =
+ securityToken.getSecretKey(getSecurityProperties().getEncryptionSymAlgorithm());
+ if (pubKey != null) {
+ int blockSize = cipher.getBlockSize();
+ if (blockSize > 0 && blockSize < sessionKey.getEncoded().length) {
+ throw new XMLSecurityException(
+ "stax.unsupportedKeyTransp"
+ );
}
+ }
+ byte[] encryptedEphemeralKey = cipher.wrap(sessionKey);
- String tokenId = outputProcessorChain.getSecurityContext().get(XMLSecurityConstants.PROP_USE_THIS_TOKEN_ID_FOR_ENCRYPTION);
- SecurityTokenProvider securityTokenProvider = outputProcessorChain.getSecurityContext().getSecurityTokenProvider(tokenId);
+ createCharactersAndOutputAsEvent(outputProcessorChain, new Base64(76, new byte[]{'\n'}).encodeToString(encryptedEphemeralKey));
- final OutboundSecurityToken securityToken = securityTokenProvider.getSecurityToken();
- Key sessionKey =
- securityToken.getSecretKey(getSecurityProperties().getEncryptionSymAlgorithm());
- if (pubKey != null) {
- int blockSize = cipher.getBlockSize();
- if (blockSize > 0 && blockSize < sessionKey.getEncoded().length) {
- throw new XMLSecurityException(
- XMLSecurityException.ErrorCode.FAILURE,
- "unsupportedKeyTransp",
- "public key algorithm too weak to encrypt symmetric key"
- );
- }
- }
- byte[] encryptedEphemeralKey = cipher.wrap(sessionKey);
+ } catch (NoSuchPaddingException e) {
+ throw new XMLSecurityException(e);
+ } catch (NoSuchAlgorithmException e) {
+ throw new XMLSecurityException(e);
+ } catch (InvalidKeyException e) {
+ throw new XMLSecurityException(e);
+ } catch (IllegalBlockSizeException e) {
+ throw new XMLSecurityException(e);
+ } catch (InvalidAlgorithmParameterException e) {
+ throw new XMLSecurityException(e);
+ }
- createCharactersAndOutputAsEvent(outputProcessorChain, new Base64(76, new byte[]{'\n'}).encodeToString(encryptedEphemeralKey));
+ createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_CipherValue);
+ createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_CipherData);
- } catch (NoSuchPaddingException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_ENCRYPTION, e);
- } catch (NoSuchAlgorithmException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_ENCRYPTION, e);
- } catch (InvalidKeyException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_ENCRYPTION, e);
- } catch (IllegalBlockSizeException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_ENCRYPTION, e);
- } catch (InvalidAlgorithmParameterException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_ENCRYPTION, e);
- }
-
- createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_CipherValue);
- createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_CipherData);
-
- createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_EncryptedKey);
-
- createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_KeyInfo);
- }
- };
- return processor;
- } catch (NoSuchAlgorithmException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_ENCRYPTION, e);
- } catch (NoSuchPaddingException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_ENCRYPTION, e);
- } catch (InvalidKeyException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_ENCRYPTION, e);
- } catch (IOException e) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_ENCRYPTION, e);
- }
+ createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_EncryptedKey);
+
+ createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_KeyInfo);
+ }
+ };
+ return processor;
}
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/XMLSignatureEndingOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/XMLSignatureEndingOutputProcessor.java?rev=1395267&r1=1395266&r2=1395267&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/XMLSignatureEndingOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/XMLSignatureEndingOutputProcessor.java Sun Oct 7 10:02:46 2012
@@ -25,9 +25,9 @@ import java.util.List;
import javax.xml.stream.XMLStreamException;
+import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.stax.ext.OutputProcessorChain;
import org.apache.xml.security.stax.ext.XMLSecurityConstants;
-import org.apache.xml.security.stax.ext.XMLSecurityException;
import org.apache.xml.security.stax.ext.XMLSecurityUtils;
import org.apache.xml.security.stax.ext.stax.XMLSecAttribute;
import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
@@ -108,7 +108,7 @@ public class XMLSignatureEndingOutputPro
} else if (keyIdentifierType == XMLSecurityConstants.XMLKeyIdentifierType.X509_SUBJECT_NAME) {
XMLSecurityUtils.createX509SubjectNameStructure(this, outputProcessorChain, x509Certificates);
} else {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_SIGNATURE, "unsupportedSecurityToken");
+ throw new XMLSecurityException("stax.unsupportedToken", keyIdentifierType);
}
}