From a8f8158d403d78e6cf919f442ad58c6797f5e49b Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Tue, 7 May 2013 09:30:56 -0700 Subject: [PATCH] Prefer /dev/urandom over /dev/random if it exists --- CACreateCert | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CACreateCert b/CACreateCert index 1379b9e..85d4bc0 100755 --- a/CACreateCert +++ b/CACreateCert @@ -35,7 +35,7 @@ my $USAGE; my $hasSha2; BEGIN { - *VERSION = \'1.2.6'; + *VERSION = \'1.2.7'; $VERSIONMSG = "CACreateCert version $VERSION\n" . "Copyright (c) 2011-2013 Kyle J. McKay. All rights reserved.\n" . "License AGPLv3+: GNU Affero GPL version 3 or later.\n" . @@ -574,13 +574,15 @@ sub RandomID(;$) # return 20 random bytes except that the first byte has its high bit clear my $suppress = shift || 0; print STDERR "Generating serial number, please wait...\n" unless $suppress; - open(RANDIN, "<", "/dev/random") - or die "Cannot open /dev/random for input\n"; + my $randfile = "/dev/random"; + $randfile = "/dev/urandom" if -e "/dev/urandom"; + open(RANDIN, "<", $randfile) + or die "Cannot open $randfile for input\n"; my $result = ''; for (my $cnt = 0; $cnt < 20; ++$cnt) { my $byte; sysread(RANDIN, $byte, 1) - or die "Cannot read from /dev/random\n"; + or die "Cannot read from $randfile\n"; if (!$cnt) { my $val = unpack('C', $byte); $val &= 0x7F; -- 2.11.4.GIT