marcsaeg    00/12/22 09:35:06

  Modified:    src/share/org/apache/tomcat/util Tag: tomcat_32
                        SessionIdGenerator.java
  Log:
  The PRNG is now initialized with a seed value to prevent the multi-second
  delay seen on many platforms.
  
  This code is based on Craig's changes to Catalina that address the same
  issue there.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.3.2.3   +51 -7     
jakarta-tomcat/src/share/org/apache/tomcat/util/SessionIdGenerator.java
  
  Index: SessionIdGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/SessionIdGenerator.java,v
  retrieving revision 1.3.2.2
  retrieving revision 1.3.2.3
  diff -u -r1.3.2.2 -r1.3.2.3
  --- SessionIdGenerator.java   2000/11/18 01:33:59     1.3.2.2
  +++ SessionIdGenerator.java   2000/12/22 17:35:05     1.3.2.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/SessionIdGenerator.java,v 
1.3.2.2 2000/11/18 01:33:59 craigmcc Exp $
  - * $Revision: 1.3.2.2 $
  - * $Date: 2000/11/18 01:33:59 $
  + * $Header: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/SessionIdGenerator.java,v 
1.3.2.3 2000/12/22 17:35:05 marcsaeg Exp $
  + * $Revision: 1.3.2.3 $
  + * $Date: 2000/12/22 17:35:05 $
    *
    * ====================================================================
    *
  @@ -114,7 +114,41 @@
        */
       public final static long ticDifference = 2000;
   
  -    // ** NOTE that this must work together with get_jserv_session_balance()
  +    /**
  +     * A String initialization parameter used to increase the entropy of
  +     * the initialization of our random number generator.
  +     */
  +    private static String entropy = null;
  +
  +
  +    /**
  +     * Return the entropy increaser value, or compute a semi-useful value
  +     * if this String has not yet been set.
  +     */
  +    public static String getEntropy() {
  +
  +     // Calculate a semi-useful value if this has not been set
  +     if (entropy == null)
  +         setEntropy((new Object()).toString());
  +
  +     return (entropy);
  +
  +    }
  +
  +
  +    /**
  +     * Set the entropy increaser value.
  +     *
  +     * @param entropy The new entropy increaser value
  +     */
  +    public static void setEntropy(String newEntropy) {
  +
  +     entropy = newEntropy;
  +
  +    }
  +
  +
  +      // ** NOTE that this must work together with get_jserv_session_balance()
       // ** in jserv_balance.c
       static synchronized public String getIdentifier (String jsIdent)
       {
  @@ -133,10 +167,20 @@
               }
               if (randomSource == null)
                   randomSource = new java.security.SecureRandom();
  -        }
  +
  +                             // Set the seed PRNG's seed value
  +                             long seed = System.currentTimeMillis();
  +                             char entropy[] = getEntropy().toCharArray();
  +                             for (int i = 0; i < entropy.length; i++) {
  +                                      long update = ((byte) entropy[i]) << ((i % 8) 
* 8);
  +                                      seed ^= update;                    
  +                             }
  +                             randomSource.setSeed(seed);
  +               }
  +
   
  -        // random value ..
  -        long n = randomSource.nextLong();
  +               // random value ..
  +               long n = randomSource.nextLong();
           if (n < 0) n = -n;
           n %= maxRandomLen;
           // add maxLen to pad the leading characters with '0'; remove
  
  
  

Reply via email to