You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by ge...@apache.org on 2002/09/02 16:34:46 UTC

cvs commit: xml-security/src/org/apache/xml/security/signature Manifest.java Reference.java

geuerp      2002/09/02 07:34:46

  Modified:    src/org/apache/xml/security/signature Manifest.java
                        Reference.java
  Log:
  Changed caching strategy for signed contents
  
  Revision  Changes    Path
  1.23      +2 -2      xml-security/src/org/apache/xml/security/signature/Manifest.java
  
  Index: Manifest.java
  ===================================================================
  RCS file: /home/cvs/xml-security/src/org/apache/xml/security/signature/Manifest.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Manifest.java	30 Aug 2002 15:53:56 -0000	1.22
  +++ Manifest.java	2 Sep 2002 14:34:46 -0000	1.23
  @@ -589,7 +589,7 @@
       */
      public XMLSignatureInput getReferencedContentBeforeTransformsItem(int i)
              throws XMLSecurityException {
  -      return this.item(i).getTransformsInput();
  +      return this.item(i).getContentsBeforeTransformation();
      }
   
      /**
  @@ -601,7 +601,7 @@
       */
      public XMLSignatureInput getReferencedContentAfterTransformsItem(int i)
              throws XMLSecurityException {
  -      return this.item(i).getTransformsOutput();
  +      return this.item(i).getContentsAfterTransformation();
      }
   
      /**
  
  
  
  1.25      +97 -32    xml-security/src/org/apache/xml/security/signature/Reference.java
  
  Index: Reference.java
  ===================================================================
  RCS file: /home/cvs/xml-security/src/org/apache/xml/security/signature/Reference.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- Reference.java	30 Aug 2002 15:53:56 -0000	1.24
  +++ Reference.java	2 Sep 2002 14:34:46 -0000	1.25
  @@ -142,6 +142,8 @@
    */
   public class Reference extends SignatureElementProxy {
   
  +   public static boolean CacheSignedNodes = false;
  +
      /** {@link org.apache.log4j} logging facility */
      static org.apache.log4j.Category cat =
         org.apache.log4j.Category.getInstance(Reference.class.getName());
  @@ -445,16 +447,9 @@
      }
   
      /**
  -    * This method returns the {@link XMLSignatureInput} which is referenced by the
  -    * <CODE>URI</CODE> Attribute.
  -    *
  -    * @throws ReferenceNotInitializedException
  -    * @throws XMLSignatureException
  -    * @see Manifest#verifyReferences
  +    * Returns the XMLSignatureInput which is created by de-referencing the URI attribute.
       */
  -   protected void dereferenceURIandPerformTransforms()
  -           throws ReferenceNotInitializedException, XMLSignatureException {
  -
  +   public XMLSignatureInput getContentsBeforeTransformation () throws ReferenceNotInitializedException {
         try {
            Attr URIAttr =
               this._constructionElement.getAttributeNodeNS(null, Constants._ATT_URI);
  @@ -479,24 +474,112 @@
   
            resolver.addProperties(this._manifest._resolverProperties);
   
  -         this._transformsInput = resolver.resolve(URIAttr, this._baseURI);
  +         XMLSignatureInput input = resolver.resolve(URIAttr, this._baseURI);
   
  +         this._transformsInput = new XMLSignatureInput(input.getBytes());
  +         this._transformsInput.setSourceURI(input.getSourceURI());
  +
  +         return input;
  +      } catch (IOException ex) {
  +         throw new ReferenceNotInitializedException("empty", ex);
  +      } catch (ResourceResolverException ex) {
  +         throw new ReferenceNotInitializedException("empty", ex);
  +      } catch (XMLSecurityException ex) {
  +         throw new ReferenceNotInitializedException("empty", ex);
  +      }
  +   }
  +
  +   /**
  +    * Returns the data which is referenced by the URI attribute. This method
  +    * only works works after a call to verify.
  +    *
  +    * @deprecated use
  +    */
  +   public XMLSignatureInput getTransformsInput() {
  +      return this._transformsInput;
  +   }
  +
  +   private XMLSignatureInput getContentsAfterTransformation (XMLSignatureInput input) throws XMLSignatureException {
  +      try {
            Transforms transforms = this.getTransforms();
   
  +         XMLSignatureInput output = null;
            if (transforms != null) {
  -            this._transformsOutput =
  -               transforms.performTransforms(this._transformsInput);
  +            output = transforms.performTransforms(input);
  +
  +            this._transformsOutput = new XMLSignatureInput(output.getBytes());
  +            this._transformsOutput.setSourceURI(output.getSourceURI());
            } else {
  +            output = input;
  +
               this._transformsOutput = this._transformsInput;
            }
  +
  +         return output;
  +      } catch (IOException ex) {
  +         throw new XMLSignatureException("empty", ex);
         } 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);
  +      }
  +   }
  +
  +   /**
  +    * Returns the XMLSignatureInput which is the result of the Transforms.
  +    */
  +   public XMLSignatureInput getContentsAfterTransformation () throws XMLSignatureException {
  +      XMLSignatureInput input = this.getContentsBeforeTransformation();
  +
  +      return this.getContentsAfterTransformation(input);
  +   }
  +
  +   /**
  +    * This method only works works after a call to verify.
  +    *
  +    */
  +   public XMLSignatureInput getTransformsOutput() {
  +      return this._transformsOutput;
  +   }
  +
  +   /**
  +    * This method returns the {@link XMLSignatureInput} which is referenced by the
  +    * <CODE>URI</CODE> Attribute.
  +    *
  +    * @throws XMLSignatureException
  +    * @see Manifest#verifyReferences
  +    */
  +   protected void dereferenceURIandPerformTransforms() throws XMLSignatureException {
  +
  +      try {
  +
  +         XMLSignatureInput input = this.getContentsBeforeTransformation();
  +         XMLSignatureInput output = this.getContentsAfterTransformation(input);
  +
  +         /* at this stage, this._transformsInput and this._transformsOutput
  +          * contain a huge amount of nodes. When we do not cache these nodes
  +          * but only preserve the octets, the memory footprint is dramatically
  +          * reduced.
  +          */
  +         if (!Reference.CacheSignedNodes) {
  +            this._transformsInput = new XMLSignatureInput(input.getBytes());
  +            this._transformsInput.setSourceURI(input.getSourceURI());
  +
  +            this._transformsOutput = new XMLSignatureInput(output.getBytes());
  +            this._transformsOutput.setSourceURI(output.getSourceURI());
  +         }
  +      } catch (IOException ex) {
            throw new ReferenceNotInitializedException("empty", ex);
         } catch (CanonicalizationException ex) {
            throw new ReferenceNotInitializedException("empty", ex);
         } catch (InvalidCanonicalizerException ex) {
            throw new ReferenceNotInitializedException("empty", ex);
  -      } catch (TransformationException ex) {
  -         throw new ReferenceNotInitializedException("empty", ex);
         } catch (XMLSecurityException ex) {
            throw new ReferenceNotInitializedException("empty", ex);
         }
  @@ -625,24 +708,6 @@
         }
   
         return equal;
  -   }
  -
  -   /**
  -    * Method getTransformsInput
  -    *
  -    *
  -    */
  -   public XMLSignatureInput getTransformsInput() {
  -      return this._transformsInput;
  -   }
  -
  -   /**
  -    * Method getTransformsOutput
  -    *
  -    *
  -    */
  -   public XMLSignatureInput getTransformsOutput() {
  -      return this._transformsOutput;
      }
   
      /**