From 5236e631bb3c6f3a31c920709e3fe6c5cd579c14 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Wed, 26 Dec 2018 20:32:56 +0100 Subject: autoconf check for srandom()/random() or fallback to less secure srand()/rand() Signed-off-by: Toni Uhlig --- src/Makefile.am | 4 ++++ src/ptunnel.c | 4 ---- src/utils.c | 8 ++++++++ 3 files changed, 12 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 3abddda..da23fd8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,6 +18,10 @@ if HAVE_ICMPFILTER ptunnel_ng_CFLAGS += -DHAVE_ICMPFILTER=1 endif +if HAVE_RANDOM +ptunnel_ng_CFLAGS += -DHAVE_RANDOM=1 +endif + ptunnel_ng_SOURCES = \ md5.c \ challenge.c \ diff --git a/src/ptunnel.c b/src/ptunnel.c index 1944041..52661ae 100644 --- a/src/ptunnel.c +++ b/src/ptunnel.c @@ -126,10 +126,6 @@ int main(int argc, char *argv[]) { } #endif /* WIN32 */ - /* Seed random generator; it'll be used in combination with a timestamp - * when generating authentication challenges. - */ - srand(time(0)); memset(opts.password_digest, 0, kMD5_digest_size); /* The seq_expiry_tbl is used to prevent the remote ends from prematurely diff --git a/src/utils.c b/src/utils.c index 12e7992..6233753 100644 --- a/src/utils.c +++ b/src/utils.c @@ -148,9 +148,17 @@ void print_hexstr(unsigned char *buf, size_t siz) { #endif int pt_random(void) { +#ifdef HAVE_RANDOM +#ifndef TIME_UTC +#define TIME_UTC 1 +#endif struct timespec ts; assert(timespec_get(&ts, TIME_UTC)); srandom(ts.tv_nsec ^ ts.tv_sec); return random(); +#else + srand(time(0)); + return rand(); +#endif } -- cgit v1.2.3