@@ -194,6 +194,7 @@ Socket methods:
194194#include "openssl/pem.h"
195195#include "openssl/ssl.h"
196196#include "openssl/err.h"
197+ #include "openssl/rand.h"
197198#endif /* USE_SSL */
198199
199200#if defined(MS_WINDOWS ) || defined(__BEOS__ )
@@ -2544,6 +2545,32 @@ init_socket(void)
25442545 if (PyDict_SetItemString (d , "SSLType" ,
25452546 (PyObject * )& SSL_Type ) != 0 )
25462547 return ;
2548+ if (RAND_status () == 0 ) {
2549+ #ifdef USE_EGD
2550+ char random_device [MAXPATHLEN + 1 ];
2551+ if (!RAND_file_name (random_device , MAXPATHLEN + 1 )) {
2552+ PyErr_SetObject (SSLErrorObject ,
2553+ PyString_FromString ("RAND_file_name error" ));
2554+ return ;
2555+ }
2556+ if (RAND_egd (random_device ) == -1 ) {
2557+ PyErr_SetObject (SSLErrorObject ,
2558+ PyString_FromString ("RAND_egd error" ));
2559+ return ;
2560+ }
2561+ #else /* USE_EGD not defined */
2562+ char random_string [32 ];
2563+ int i ;
2564+
2565+ PyErr_Warn (PyExc_RuntimeWarning ,
2566+ "using insecure method to generate random numbers" );
2567+ srand (time (NULL ));
2568+ for (i = 0 ; i < sizeof (random_string ); i ++ ) {
2569+ random_string [i ] = rand ();
2570+ }
2571+ RAND_seed (random_string , sizeof (random_string ));
2572+ #endif /* USE_EGD */
2573+ }
25472574#endif /* USE_SSL */
25482575 PyDict_SetItemString (d , "error" , PySocket_Error );
25492576 PySocketSock_Type .ob_type = & PyType_Type ;
0 commit comments