You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by ra...@apache.org on 2005/04/02 20:52:39 UTC

cvs commit: xml-security/src/org/apache/xml/security/keys/content/x509 XMLX509SKI.java XMLX509Certificate.java

raul        2005/04/02 10:52:39

  Modified:    src/org/apache/xml/security/keys/content/keyvalues
                        RSAKeyValue.java DSAKeyValue.java
               src/org/apache/xml/security/utils JavaUtils.java
               src/org/apache/xml/security/keys/content/x509
                        XMLX509SKI.java XMLX509Certificate.java
  Log:
  move binaryCompare funcionality to the class where this funcionality is needed.
  Use instanceOf instead of implementsInterface
  
  Revision  Changes    Path
  1.13      +2 -4      xml-security/src/org/apache/xml/security/keys/content/keyvalues/RSAKeyValue.java
  
  Index: RSAKeyValue.java
  ===================================================================
  RCS file: /home/cvs/xml-security/src/org/apache/xml/security/keys/content/keyvalues/RSAKeyValue.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- RSAKeyValue.java	6 Oct 2004 14:42:22 -0000	1.12
  +++ RSAKeyValue.java	2 Apr 2005 18:52:39 -0000	1.13
  @@ -30,7 +30,6 @@
   import org.apache.xml.security.exceptions.XMLSecurityException;
   import org.apache.xml.security.utils.Constants;
   import org.apache.xml.security.utils.I18n;
  -import org.apache.xml.security.utils.JavaUtils;
   import org.apache.xml.security.utils.SignatureElementProxy;
   import org.apache.xml.security.utils.XMLUtils;
   import org.w3c.dom.Document;
  @@ -90,8 +89,7 @@
   
         XMLUtils.addReturnToElement(this._constructionElement);
   
  -      if (JavaUtils.implementsInterface(
  -              key, "java.security.interfaces.RSAPublicKey")) {
  +      if (key instanceof java.security.interfaces.RSAPublicKey ) {
            this.addBigIntegerElement(((RSAPublicKey) key).getModulus(),
                                      Constants._TAG_MODULUS);
            this.addBigIntegerElement(((RSAPublicKey) key).getPublicExponent(),
  
  
  
  1.12      +2 -4      xml-security/src/org/apache/xml/security/keys/content/keyvalues/DSAKeyValue.java
  
  Index: DSAKeyValue.java
  ===================================================================
  RCS file: /home/cvs/xml-security/src/org/apache/xml/security/keys/content/keyvalues/DSAKeyValue.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DSAKeyValue.java	24 Sep 2004 20:54:29 -0000	1.11
  +++ DSAKeyValue.java	2 Apr 2005 18:52:39 -0000	1.12
  @@ -30,7 +30,6 @@
   import org.apache.xml.security.exceptions.XMLSecurityException;
   import org.apache.xml.security.utils.Constants;
   import org.apache.xml.security.utils.I18n;
  -import org.apache.xml.security.utils.JavaUtils;
   import org.apache.xml.security.utils.SignatureElementProxy;
   import org.apache.xml.security.utils.XMLUtils;
   import org.w3c.dom.Document;
  @@ -94,8 +93,7 @@
   
         XMLUtils.addReturnToElement(this._constructionElement);
   
  -      if (JavaUtils.implementsInterface(
  -              key, "java.security.interfaces.DSAPublicKey")) {
  +      if (key instanceof java.security.interfaces.DSAPublicKey) {
            this.addBigIntegerElement(((DSAPublicKey) key).getParams().getP(),
                                      Constants._TAG_P);
            this.addBigIntegerElement(((DSAPublicKey) key).getParams().getQ(),
  
  
  
  1.11      +2 -177    xml-security/src/org/apache/xml/security/utils/JavaUtils.java
  
  Index: JavaUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-security/src/org/apache/xml/security/utils/JavaUtils.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- JavaUtils.java	25 Sep 2004 19:42:23 -0000	1.10
  +++ JavaUtils.java	2 Apr 2005 18:52:39 -0000	1.11
  @@ -25,7 +25,6 @@
   import java.io.FileOutputStream;
   import java.io.IOException;
   import java.io.InputStream;
  -import java.util.Vector;
   
   
   /**
  @@ -42,148 +41,11 @@
      private JavaUtils() {
        // we don't allow instantiation
      }
  -
  -   /**
  -    * Checks whether an object implements a specific interface.
  -    *
  -    * <pre>
  -    * org.w3c.dom.Document doc = ...; // some init
  -    *
  -    * boolean this_is_true =
  -    *    JavaUtils.implementsInterface(doc.getDocumentElement(),
  -    *                                  "org.w3c.dom.Element");
  -    *
  -    * boolean this_is_true_too =
  -    *    JavaUtils.implementsInterface(doc.getDocumentElement(),
  -    *                                  "org.w3c.dom.Node");
  -    *
  -    * </pre>
  -    *
  -    * @param object which is to be checked
  -    * @param interfaceName is the String of the Interface
  -    * @return <code>true</code> if the object implements the specified interface
  -    */
  -   public static boolean implementsInterface(Object object,
  -                                             String interfaceName) {
  -
  -      Vector allClasses = new Vector();
  -      Vector allInterfaces = new Vector();
  -      Class c = object.getClass();
  -
  -      while (!c.getName().equals("java.lang.Object")) {
  -         Class interfaces[] = c.getInterfaces();
  -         String className = c.getName();
  -
  -         allClasses.add(className);
  -
  -         for (int i = 0; i < interfaces.length; i++) {
  -            String ifName = interfaces[i].getName();
  -
  -            allInterfaces.add(ifName);
  -         }
  -
  -         c = c.getSuperclass();
  -      }
  -
  -      for (int i = 0; i < allInterfaces.size(); i++) {
  -         if (((String) allInterfaces.get(i)).equals(interfaceName)) {
  -            return true;
  -         }
  -      }
  -
  -      return false;
  -   }
  -
  -   /**
  -    *
  -    * @param object
  -    * @param className
  -    * @return
  -    */
  -   public static boolean instanceOf(Object object, String className) {
  -
  -      if (object.getClass().getName().equals(className)) {
  -         return true;
  -      }
  -
  -      return implementsInterface(object, className);
  -   }
  -
  -   /**
  -    * Returns true if both byte arrays are bytewise equal, false if the differ.
  -    *
  -    * @param refBytes
  -    * @param c14nBytes
  -    * @return true if both byte arrays are bytewise equal, false if the differ.
  -    * @see java.security.MessageDigest#isEqual
  -    */
  -   public static boolean binaryCompare(byte refBytes[], byte c14nBytes[]) {
  -
  -      /*
  -      {
  -         if (refBytes.length != c14nBytes.length) {
  -            return false;
  -         }
  -
  -         for (int i = 0; i < refBytes.length; i++) {
  -            if (refBytes[i] != c14nBytes[i]) {
  -               return false;
  -            }
  -         }
  -      }
  -      return true;
  -      */
  -      return java.security.MessageDigest.isEqual(refBytes, c14nBytes);
  -   }
  -
  -   /*
  -    * Checks whether an object extends a specific class.
  -    *
  -    * @param object which is to be checked
  -    * @param className is the String of the Class
  -    * @return <code>true</code> if the object extends the specified class
  -    * public static boolean extendsClass(Object object,
  -    *                                  String className) {
  -    *
  -    *  String cn = object.getClass().getName();
  -    *  while (!cn.equals("java.lang.object")) {
  -    *     Object o = null;
  -    *     try {
  -    *     o = Class.forName(cn);
  -    *     Class superC = o.getClass().getSuperclass();
  -    *     cn = superC.getName();
  -    *     } catch (Exception e) {}
  -    *  }
  -    *
  -    *  Class ancestors[] = object.getClass().getDeclaredClasses();
  -    *
  -    *  for (int i=0; i<ancestors.length; i++) {
  -    *     System.out.println(i + " " + ancestors[i].getName());
  -    *  }
  -    *
  -    *  for (int i = 0; i < ancestors.length; i++) {
  -    *     if (ancestors[i].getName().equals(className)) {
  -    *        return true;
  -    *     }
  -    *  }
  -    *
  -    *  return false;
  -    * }
  -    */
  -
  -   /*
  -   public static boolean extendsClassOrImplementsInterface(Object object,
  -                                             String name) {
  -       return (extendsClass(object, name) ||
  -               implementsInterface(object, name));
  -   }
  -   */
  -
      /**
       * Method getBytesFromFile
       *
       * @param fileName
  -    * @return
  +    * @return the bytes readed from the file
       *
       * @throws FileNotFoundException
       * @throws IOException
  @@ -236,7 +98,7 @@
       * them as a byte array.
       *
       * @param inputStream
  -    * @return
  +    * @return the bytes readed from the stream
       *
       * @throws FileNotFoundException
       * @throws IOException
  @@ -259,41 +121,4 @@
   
         return refBytes;
      }
  -
  -   /**
  -    * Method runGC
  -    *
  -    */
  -   public static void runGC() {
  -
  -      log.debug("<METHOD name=runGC()>");
  -
  -      Runtime runtime = Runtime.getRuntime();
  -      long lFreeMemBefore = runtime.freeMemory();
  -      long lTotalMemBefore = runtime.totalMemory();
  -      long lStart = System.currentTimeMillis();
  -
  -      runtime.gc();
  -      runtime.runFinalization();
  -
  -      long lEnd = System.currentTimeMillis();
  -      double time = (lEnd - lStart) / 1000.0;
  -      long lFreeMemAfter = runtime.freeMemory();
  -      long lTotalMemAfter = runtime.totalMemory();
  -
  -      if (log.isDebugEnabled()) {
  -      	log.debug("* Garbage collection took " + time + " seconds.");
  -      	log.debug("* Memory before gc()... free:" + lFreeMemBefore + "= "
  -                + lFreeMemBefore / 1024 + "KB,...total:" + lTotalMemBefore
  -                + "= " + lTotalMemBefore / 1024 + "KB,...  used:"
  -                + (lTotalMemBefore - lFreeMemBefore) + "= "
  -                + (lTotalMemBefore - lFreeMemBefore) / 1024 + "KB");
  -      	log.debug("* Memory after: gc()... free:" + lFreeMemAfter + "= "
  -                + lFreeMemAfter / 1024 + "KB,...total:" + lTotalMemAfter + "= "
  -                + lTotalMemAfter / 1024 + "KB,...  used:"
  -                + (lTotalMemAfter - lFreeMemAfter) + "= "
  -                + (lTotalMemAfter - lFreeMemAfter) / 1024 + "KB");
  -      	log.debug("</METHOD>");
  -      }
  -   }
   }
  
  
  
  1.13      +3 -4      xml-security/src/org/apache/xml/security/keys/content/x509/XMLX509SKI.java
  
  Index: XMLX509SKI.java
  ===================================================================
  RCS file: /home/cvs/xml-security/src/org/apache/xml/security/keys/content/x509/XMLX509SKI.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- XMLX509SKI.java	25 Sep 2004 19:42:23 -0000	1.12
  +++ XMLX509SKI.java	2 Apr 2005 18:52:39 -0000	1.13
  @@ -28,7 +28,6 @@
   import org.apache.xml.security.exceptions.XMLSecurityException;
   import org.apache.xml.security.utils.Base64;
   import org.apache.xml.security.utils.Constants;
  -import org.apache.xml.security.utils.JavaUtils;
   import org.apache.xml.security.utils.SignatureElementProxy;
   import org.apache.xml.security.utils.XMLUtils;
   import org.w3c.dom.Document;
  @@ -104,7 +103,7 @@
      /**
       * Method getSKIBytes
       *
  -    * @return
  +    * @return the skibytes
       * @throws XMLSecurityException
       */
      public byte[] getSKIBytes() throws XMLSecurityException {
  @@ -115,7 +114,7 @@
       * Method getSKIBytesFromCert
       *
       * @param cert
  -    * @return
  +    * @return sky bytes from the given certificate
       *
       * @throws XMLSecurityException
       * @see java.security.cert.X509Extension#getExtensionValue(java.lang.String)
  @@ -214,7 +213,7 @@
         XMLX509SKI other = (XMLX509SKI) obj;
   
         try {
  -         return JavaUtils.binaryCompare(other.getSKIBytes(),
  +         return java.security.MessageDigest.isEqual(other.getSKIBytes(),
                                           this.getSKIBytes());
         } catch (XMLSecurityException ex) {
            return false;
  
  
  
  1.11      +5 -6      xml-security/src/org/apache/xml/security/keys/content/x509/XMLX509Certificate.java
  
  Index: XMLX509Certificate.java
  ===================================================================
  RCS file: /home/cvs/xml-security/src/org/apache/xml/security/keys/content/x509/XMLX509Certificate.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- XMLX509Certificate.java	24 Sep 2004 20:54:29 -0000	1.10
  +++ XMLX509Certificate.java	2 Apr 2005 18:52:39 -0000	1.11
  @@ -26,7 +26,6 @@
   
   import org.apache.xml.security.exceptions.XMLSecurityException;
   import org.apache.xml.security.utils.Constants;
  -import org.apache.xml.security.utils.JavaUtils;
   import org.apache.xml.security.utils.SignatureElementProxy;
   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
  @@ -93,7 +92,7 @@
      /**
       * Method getCertificateBytes
       *
  -    * @return
  +    * @return the certificate bytes
       * @throws XMLSecurityException
       */
      public byte[] getCertificateBytes() throws XMLSecurityException {
  @@ -103,7 +102,7 @@
      /**
       * Method getX509Certificate
       *
  -    * @return
  +    * @return the x509 certificate
       * @throws XMLSecurityException
       */
      public X509Certificate getX509Certificate() throws XMLSecurityException {
  @@ -129,7 +128,7 @@
      /**
       * Method getPublicKey
       *
  -    * @return
  +    * @return teh publickey
       * @throws XMLSecurityException
       */
      public PublicKey getPublicKey() throws XMLSecurityException {
  @@ -154,7 +153,7 @@
            XMLX509Certificate other = (XMLX509Certificate) obj;
   
            /** $todo$ or should be create X509Certificates and use the equals() from the Certs */
  -         return JavaUtils.binaryCompare(other.getCertificateBytes(),
  +         return java.security.MessageDigest.isEqual(other.getCertificateBytes(),
                                           this.getCertificateBytes());
         } catch (XMLSecurityException ex) {
            return false;