diff options
author | Paul Querna <pquerna@apache.org> | 2008-02-19 18:05:26 +0100 |
---|---|---|
committer | Paul Querna <pquerna@apache.org> | 2008-02-19 18:05:26 +0100 |
commit | 9aa0687d9c4c728d248cea275b132779c39730e7 (patch) | |
tree | 35ad75c3f6348eccf454c94d56a3d11c8f4ebbcd /support | |
parent | Improve salt string generation. (diff) | |
download | apache2-9aa0687d9c4c728d248cea275b132779c39730e7.tar.xz apache2-9aa0687d9c4c728d248cea275b132779c39730e7.zip |
Improve generation of the seed to rand, by using apr_generate_random_bytes,
rather than the current time as a seed.
PR: 31440
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@629164 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'support')
-rw-r--r-- | support/htpasswd.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/support/htpasswd.c b/support/htpasswd.c index ac259809c9..129d8f0dba 100644 --- a/support/htpasswd.c +++ b/support/htpasswd.c @@ -126,6 +126,18 @@ static void generate_salt(char *s, size_t size) } } +static apr_status_t seed_rand() +{ + 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) { @@ -174,7 +186,9 @@ static int mkrecord(char *user, char *record, apr_size_t rlen, char *passwd, break; case ALG_APMD5: - (void) srand((int) time((time_t *) NULL)); + if (seed_rand()) { + break; + } generate_salt(&salt[0], 8); salt[8] = '\0'; @@ -190,7 +204,9 @@ static int mkrecord(char *user, char *record, apr_size_t rlen, char *passwd, #if (!(defined(WIN32) || defined(TPF) || 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'; |