From 8f4eab23456d1b038d8d0d2a3b56f9524c2030ad Mon Sep 17 00:00:00 2001 From: Moshe Zadka Date: Sun, 18 Mar 2001 17:11:56 +0000 Subject: Committing patch 405101 --- Modules/socketmodule.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index ce572ff..c92dc95 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -194,6 +194,7 @@ Socket methods: #include "openssl/pem.h" #include "openssl/ssl.h" #include "openssl/err.h" +#include "openssl/rand.h" #endif /* USE_SSL */ #if defined(MS_WINDOWS) || defined(__BEOS__) @@ -2544,6 +2545,32 @@ init_socket(void) if (PyDict_SetItemString(d, "SSLType", (PyObject *)&SSL_Type) != 0) return; + if (RAND_status() == 0) { +#ifdef USE_EGD + char random_device[MAXPATHLEN+1]; + if (!RAND_file_name (random_device, MAXPATHLEN + 1)) { + PyErr_SetObject(SSLErrorObject, + PyString_FromString("RAND_file_name error")); + return; + } + if (RAND_egd (random_device) == -1) { + PyErr_SetObject(SSLErrorObject, + PyString_FromString("RAND_egd error")); + return; + } +#else /* USE_EGD not defined */ + char random_string[32]; + int i; + + PyErr_Warn(PyExc_RuntimeWarning, + "using insecure method to generate random numbers"); + srand(time(NULL)); + for(i=0; i