From 69b218bf24d1374876fa900dc75c14532ec1c040 Mon Sep 17 00:00:00 2001 From: Egor Duda Date: Fri, 4 May 2001 16:30:18 +0000 Subject: [PATCH] * fhandler_socket.cc (set_connect_secret): Use /dev/urandom to generate secret cookie. --- winsup/cygwin/ChangeLog | 5 +++++ winsup/cygwin/fhandler_socket.cc | 22 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index b8b70558e..f1f92afb4 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2001-05-04 Egor Duda + + * fhandler_socket.cc (set_connect_secret): Use /dev/urandom to + generate secret cookie. + Thu May 3 16:37:55 2001 Christopher Faylor * include/pthread.h (pthread_cleanup_push): Eliminate space preceding diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index f4428639a..eb6f36a2e 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -28,6 +28,10 @@ #include "sigproc.h" #define SECRET_EVENT_NAME "cygwin.local_socket.secret.%d.%08x-%08x-%08x-%08x" +#define ENTROPY_SOURCE_NAME "/dev/urandom" +#define ENTROPY_SOURCE_DEV_UNIT 9 + +fhandler_dev_random* entropy_source = NULL; /**********************************************************************/ /* fhandler_socket */ @@ -50,8 +54,22 @@ fhandler_socket::~fhandler_socket () void fhandler_socket::set_connect_secret () { - for (int i = 0; i < 4; i++) - connect_secret [i] = random (); + if (!entropy_source) + { + void *buf = malloc (sizeof (fhandler_dev_random)); + entropy_source = new (buf) fhandler_dev_random (ENTROPY_SOURCE_NAME, + ENTROPY_SOURCE_DEV_UNIT); + } + if (entropy_source && + !entropy_source->open (ENTROPY_SOURCE_NAME, O_RDONLY)) + { + delete entropy_source; + entropy_source = NULL; + } + if (!entropy_source || + (entropy_source->read (connect_secret, sizeof (connect_secret)) != + sizeof (connect_secret))) + bzero ((char*) connect_secret, sizeof (connect_secret)); } void