]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Merge r629159, r629164, r629218, r630139 from trunk:
authorRuediger Pluem <rpluem@apache.org>
Mon, 2 Jun 2008 21:24:12 +0000 (21:24 +0000)
committerRuediger Pluem <rpluem@apache.org>
Mon, 2 Jun 2008 21:24:12 +0000 (21:24 +0000)
Improve salt string generation.

Submited by: Andreas Krennmair <ak synflood.at>

Improve generation of the seed to rand, by using apr_generate_random_bytes,
rather than the current time as a seed.

Fix printing of error message.

* support/htpasswd.c (seed_rand): Fix compiler warning.

PR: 31440
Reviewed by: rpluem, jim, pquerna

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@662572 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
support/htpasswd.c

diff --git a/CHANGES b/CHANGES
index d778816d12454228c1832cee2f7fdcec4e12f9c4..820a75d0d08df0cef5546faca844c39378df6059 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,10 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.2.9
 
+  *) htpasswd: Fix salt generation weakness. PR 31440
+     [Andreas Krennmair <ak synflood.at>, Peter Watkins <peterw tux.org>,
+     Paul Querna]
+
   *) core: Add the filename of the configuration file to the warning message
      about the useless use of AllowOverride. PR 39992.
      [Darryl Miles <darryl darrylmiles.org>]
diff --git a/STATUS b/STATUS
index 43d4563f0006c88d00fda7676f62fc4eb66e4bb9..a2a65eff143699e004479491a521ef25d63634da 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -90,17 +90,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
- * htpasswd: Fix salt generation weakness. PR 31440
-   [Andreas Krennmair <ak synflood.at>, Peter Watkins <peterw tux.org>, Paul Querna]
-    Trunk version of patch:
-       http://svn.apache.org/viewvc?rev=629159&view=rev
-       http://svn.apache.org/viewvc?rev=629164&view=rev
-       http://svn.apache.org/viewvc?rev=629218&view=rev
-       http://svn.apache.org/viewvc?rev=630139&view=rev
-    Backport version for 2.2.x of patch:
-       Trunk version of patch works
-    +1: rpluem, jim, pquerna
-
  * mod_unique_id: Convert request time to seconds before before storing it in
    unique_id_rec struct. PR 37064
     Trunk version of patch:
index 6bce702d944ba57cfe35b38e0108dbab20cd16e0..2eadc78e29e394b910f11906beb9dbbee8aa89c3 100644 (file)
@@ -115,6 +115,30 @@ static void to64(char *s, unsigned long v, int n)
     }
 }
 
+static void generate_salt(char *s, size_t size)
+{
+    static unsigned char tbl[] = 
+        "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+    size_t i;
+    for (i = 0; i < size; ++i) {
+        int idx = (int) (64.0 * rand() / (RAND_MAX + 1.0));
+        s[i] = tbl[idx];
+    }
+}
+
+static apr_status_t seed_rand(void)
+{
+    int seed = 0;
+    apr_status_t rv;
+    rv = apr_generate_random_bytes((unsigned char*) &seed, sizeof(seed));
+    if (rv) {
+        apr_file_printf(errfile, "Unable to generate random bytes: %pm" NL, &rv);
+        return rv;
+    }
+    srand(seed);
+    return rv;
+}
+
 static void putline(apr_file_t *f, const char *l)
 {
     apr_file_puts(l, f);
@@ -162,8 +186,10 @@ static int mkrecord(char *user, char *record, apr_size_t rlen, char *passwd,
         break;
 
     case ALG_APMD5:
-        (void) srand((int) time((time_t *) NULL));
-        to64(&salt[0], rand(), 8);
+        if (seed_rand()) {
+            break;
+        }
+        generate_salt(&salt[0], 8);
         salt[8] = '\0';
 
         apr_md5_encode((const char *)pw, (const char *)salt,
@@ -178,7 +204,9 @@ static int mkrecord(char *user, char *record, apr_size_t rlen, char *passwd,
 #if !(defined(WIN32) || defined(NETWARE))
     case ALG_CRYPT:
     default:
-        (void) srand((int) time((time_t *) NULL));
+        if (seed_rand()) {
+            break;
+        }
         to64(&salt[0], rand(), 8);
         salt[8] = '\0';