Author: markt
Date: Fri Mar 25 12:20:39 2011
New Revision: 1085346

URL: http://svn.apache.org/viewvc?rev=1085346&view=rev
Log:
Securely seed the SecureRandom instance used for UUID generation and report 
excessive creation time (greater than 100ms) at INFO level.
Added:
    tomcat/trunk/java/org/apache/catalina/tribes/util/LocalStrings.properties   
(with props)
Modified:
    tomcat/trunk/java/org/apache/catalina/tribes/util/UUIDGenerator.java
    tomcat/trunk/webapps/docs/changelog.xml

Added: tomcat/trunk/java/org/apache/catalina/tribes/util/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/util/LocalStrings.properties?rev=1085346&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/util/LocalStrings.properties 
(added)
+++ tomcat/trunk/java/org/apache/catalina/tribes/util/LocalStrings.properties 
Fri Mar 25 12:20:39 2011
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+uuidGenerator.createRandom=Creation of SecureRandom instance for UUID 
generation using [{0}] took [{1}] milliseconds.

Propchange: 
tomcat/trunk/java/org/apache/catalina/tribes/util/LocalStrings.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/java/org/apache/catalina/tribes/util/UUIDGenerator.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/util/UUIDGenerator.java?rev=1085346&r1=1085345&r2=1085346&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/util/UUIDGenerator.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/tribes/util/UUIDGenerator.java Fri 
Mar 25 12:20:39 2011
@@ -19,12 +19,19 @@ package org.apache.catalina.tribes.util;
 import java.security.SecureRandom;
 import java.util.Random;
 
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
 /**
  * simple generation of a UUID 
  * @author Filip Hanik
  * @version 1.0
  */
 public class UUIDGenerator {
+    private static final Log log = LogFactory.getLog(UUIDGenerator.class);
+    protected static final StringManager sm =
+        StringManager.getManager("org.apache.catalina.tribes.util");
+
     public static final int UUID_LENGTH = 16;
     public static final int UUID_VERSION = 4;
     public static final int BYTES_PER_INT = 4;
@@ -32,9 +39,17 @@ public class UUIDGenerator {
     
     protected static SecureRandom secrand = null;
     protected static Random rand = new Random();
+    
     static {
+        long start = System.currentTimeMillis();
         secrand = new SecureRandom();
-        secrand.setSeed(rand.nextLong());
+        // seed the generator
+        secrand.nextInt();
+        long time = System.currentTimeMillis() - start;
+        if (time > 100) {
+            log.info(sm.getString("uuidGenerator.createRandom",
+                    secrand.getAlgorithm(), Long.valueOf(time)));
+        }
     }
     
     public static byte[] randomUUID(boolean secure) {

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1085346&r1=1085345&r2=1085346&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Fri Mar 25 12:20:39 2011
@@ -116,6 +116,15 @@
       </fix>
     </changelog>
   </subsection>
+  <subsection name="Cluster">
+    <changelog>
+      <fix>
+        Securely seed the SecureRandom instance used for UUID generation and
+        report excessive creation time (greater than 100ms) at INFO level.
+        (markt)
+      </fix>
+    </changelog>
+  </subsection>
   <subsection name="Web applications">
     <changelog>
       <fix>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to