PennMUSH Community

Changeset 999

Show
Ignore:
Timestamp:
07/07/07 13:06:35 (1 year ago)
Author:
shawnw
Message:

Fix OpenSSL random number issue for systems without /dev/urandom or EGD

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.2/branches/devel/CHANGES.182

    r993 r999  
    2828  * Fixed assorted small memory leaks. [SW] 
    2929  * Fixed handling of telnet NOPs sent by clients. [SW] 
     30  * The OpenSSL random number pool wasn't getting adequately 
     31    initialized on systems without /dev/urandom 
    3032 
    3133Version 1.8.2 patchlevel 5                      June 13, 2007 
  • 1.8.2/branches/devel/src/myssl.c

    r932 r999  
    7474#include <openssl/dh.h> 
    7575#include <openssl/evp.h> 
     76#include <openssl/rand.h> 
    7677 
    7778#include "conf.h" 
     
    106107static SSL_CTX *ctx = NULL; 
    107108 
     109unsigned int genrand_int32(void); 
     110 
    108111/** Initialize the SSL context. 
    109112 * \return pointer to SSL context object. 
     
    115118  unsigned char context[128]; 
    116119  DH *dh; 
     120  unsigned int reps = 1; 
    117121 
    118122  if (!bio_err) { 
     
    123127    bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); 
    124128  } 
    125 #ifndef HAS_DEV_URANDOM 
    126   /* We need to seed the RNG with RAND_seed() or RAND_egd() here. 
    127    * Where are we going to get an unpredictable seed? 
    128    */ 
    129 #endif 
     129 
     130  do_rawlog(LT_ERR, "Seeding OpenSSL random number pool."); 
     131  while (!RAND_status()) { 
     132    /* At this point, a system with /dev/urandom or a EGD file in the usual 
     133       places will have enough entropy. Otherwise, be lazy and use random numbers 
     134       until it's satisfied. */ 
     135    unsigned int gibberish[4]; 
     136    int n; 
     137     
     138    for (n = 0; n < 4; n++) 
     139      gibberish[n] = genrand_int32(); 
     140 
     141    RAND_seed(gibberish, sizeof gibberish); 
     142     
     143    reps += 1; 
     144  }     
     145  do_rawlog(LT_ERR, "Seeded after %u %s.", reps, reps > 1 ? "cycles" : "cycle"); 
    130146 
    131147  /* Set up SIGPIPE handler here? */ 
  • 1.8.2/branches/devel/src/utils.c

    r951 r999  
    4949dbref find_entrance(dbref door); 
    5050void initialize_mt(void); 
    51 static unsigned long genrand_int32(void); 
     51unsigned int genrand_int32(void); 
    5252static void init_genrand(unsigned long); 
    5353static void init_by_array(unsigned long *, int); 
     
    589589 
    590590/* generates a random number on [0,0xffffffff]-interval */ 
    591 static unsigned long 
     591unsigned int 
    592592genrand_int32(void) 
    593593{