You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2009/07/08 16:13:06 UTC
svn commit: r792148 - in /xml/security/trunk/src/org/apache/xml/security:
algorithms/SignatureAlgorithm.java signature/XMLSignature.java
Author: coheigea
Date: Wed Jul 8 14:13:06 2009
New Revision: 792148
URL: http://svn.apache.org/viewvc?rev=792148&view=rev
Log:
[44335] - Can't validate after initial validation
Modified:
xml/security/trunk/src/org/apache/xml/security/algorithms/SignatureAlgorithm.java
xml/security/trunk/src/org/apache/xml/security/signature/XMLSignature.java
Modified: xml/security/trunk/src/org/apache/xml/security/algorithms/SignatureAlgorithm.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/algorithms/SignatureAlgorithm.java?rev=792148&r1=792147&r2=792148&view=diff
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/algorithms/SignatureAlgorithm.java (original)
+++ xml/security/trunk/src/org/apache/xml/security/algorithms/SignatureAlgorithm.java Wed Jul 8 14:13:06 2009
@@ -334,6 +334,26 @@
map.put(this.algorithmURI,verificationKey);
this._signatureAlgorithm.engineInitVerify(verificationKey);
}
+
+ /**
+ * Clear the verification caches keysVerify and instancesVerify.
+ */
+ public void clearVerificationCache() {
+ Map keysMap = (Map)keysVerify.get();
+ keysMap.clear();
+ Map instancesMap = (Map)instancesVerify.get();
+ instancesMap.clear();
+ }
+
+ /**
+ * Clear the signature caches keysSigning and instancesSigning.
+ */
+ public void clearSignatureCache() {
+ Map keysMap = (Map)keysSigning.get();
+ keysMap.clear();
+ Map instancesMap = (Map)instancesSigning.get();
+ instancesMap.clear();
+ }
/**
* Proxy method for {@link java.security.Signature#verify(byte[])}
Modified: xml/security/trunk/src/org/apache/xml/security/signature/XMLSignature.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/signature/XMLSignature.java?rev=792148&r1=792147&r2=792148&view=diff
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/signature/XMLSignature.java (original)
+++ xml/security/trunk/src/org/apache/xml/security/signature/XMLSignature.java Wed Jul 8 14:13:06 2009
@@ -493,20 +493,24 @@
//Create a SignatureAlgorithm object
SignedInfo si = this.getSignedInfo();
SignatureAlgorithm sa = si.getSignatureAlgorithm();
- // initialize SignatureAlgorithm for signing
- sa.initSign(signingKey);
-
- // generate digest values for all References in this SignedInfo
- si.generateDigestValues();
- OutputStream so =
- new UnsyncBufferedOutputStream(new SignerOutputStream(sa));
try {
+ // initialize SignatureAlgorithm for signing
+ sa.initSign(signingKey);
+
+ // generate digest values for all References in this SignedInfo
+ si.generateDigestValues();
+ OutputStream so = new UnsyncBufferedOutputStream(new SignerOutputStream(sa));
+ // get the canonicalized bytes from SignedInfo
+ si.signInOctectStream(so);
+
so.close();
- } catch (IOException e) {
- //Imposible
+ } catch (IOException ex) {
+ // Impossible...but clear the signature cache anyway
+ sa.clearSignatureCache();
+ } catch (XMLSecurityException ex) {
+ sa.clearSignatureCache();
+ throw ex;
}
- // get the canonicalized bytes from SignedInfo
- si.signInOctectStream(so);
// set them on the SignatureValue element
this.setSignatureValueElement(sa.sign());
@@ -590,32 +594,37 @@
//SignedInfo. This is used to validate the signature.
SignatureAlgorithm sa = si.getSignatureAlgorithm();
if (log.isDebugEnabled()) {
- log.debug("SignatureMethodURI = " + sa.getAlgorithmURI());
- log.debug("jceSigAlgorithm = " + sa.getJCEAlgorithmString());
- log.debug("jceSigProvider = " + sa.getJCEProviderName());
- log.debug("PublicKey = " + pk);
+ log.debug("SignatureMethodURI = " + sa.getAlgorithmURI());
+ log.debug("jceSigAlgorithm = " + sa.getJCEAlgorithmString());
+ log.debug("jceSigProvider = " + sa.getJCEProviderName());
+ log.debug("PublicKey = " + pk);
}
- sa.initVerify(pk);
-
- // Get the canonicalized (normalized) SignedInfo
- SignerOutputStream so = new SignerOutputStream(sa);
- OutputStream bos = new UnsyncBufferedOutputStream(so);
- si.signInOctectStream(bos);
+ byte sigBytes[] = null;
try {
- bos.close();
- } catch (IOException e) {
- //Imposible
- }
+ sa.initVerify(pk);
- //retrieve the byte[] from the stored signature
- byte sigBytes[] = this.getSignatureValue();
+ // Get the canonicalized (normalized) SignedInfo
+ SignerOutputStream so = new SignerOutputStream(sa);
+ OutputStream bos = new UnsyncBufferedOutputStream(so);
+
+ si.signInOctectStream(bos);
+ bos.close();
+ // retrieve the byte[] from the stored signature
+ sigBytes = this.getSignatureValue();
+ } catch (IOException ex) {
+ // Impossible...but clear the verification cache anyway
+ sa.clearVerificationCache();
+ } catch (XMLSecurityException ex) {
+ sa.clearVerificationCache();
+ throw ex;
+ }
// have SignatureAlgorithm sign the input bytes and compare them to
// the bytes that were stored in the signature.
if (!sa.verify(sigBytes)) {
log.warn("Signature verification failed.");
- return false;
- }
+ return false;
+ }
return si.verify(this._followManifestsDuringValidation);
} catch (XMLSecurityException ex) {