avoid blocking /dev/random on cpantesters systems

This commit is contained in:
git@daemon.de
2015-02-17 10:27:55 +01:00
parent 1672943fcc
commit e7471e1f6f
4 changed files with 22 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
NEXT:
1.17:
added license to META
open tmpfiles with O_EXLOCK disabled (cpantesters)
@@ -16,6 +16,10 @@ NEXT:
replaced "new $perl::$object" with $perl::$object->new()
everywhere.
using weak random source for unit tests to avoid blocking
/dev/random on cpantesters systems with heavy entropy
load.
1.16
re-licensed from artistic1 to artistic2 in order to be
compatible to fedora packaging. no code changes otherwise

2
README
View File

@@ -52,5 +52,5 @@ AUTHOR
VERSION
1.16
1.17

View File

@@ -22,7 +22,6 @@ use Digest::SHA;
use Crypt::Random qw( makerandom );
use Data::UUID;
use File::Copy qw(copy move);
#use File::Spec;
use File::Temp;
use FileHandle;
use Data::Dumper;
@@ -176,7 +175,6 @@ sub create {
# encrypt b1 .. b4
my $crypt = Crypt::ECB->new;
#$crypt->padding(PADDING_AUTO);
$crypt->cipher('Twofish');
$crypt->key( $this->strechedpw() );
$this->b1( $crypt->encrypt( $this->random(16) ) );

17
t/run.t
View File

@@ -15,6 +15,7 @@ use Data::Dumper;
use Test::More tests => 11;
#use Test::More qw(no_plan);
my %params = (create => 0, password => 'tom');
my %record = (
@@ -25,6 +26,8 @@ my %record = (
notes => 'n3'
);
sub rdpw {
my $file = shift;
my $vault = Crypt::PWSafe3->new(file => $file, %params) or die "$!";
@@ -36,6 +39,18 @@ sub rdpw {
BEGIN { use_ok "Crypt::PWSafe3"};
require_ok( 'Crypt::PWSafe3' );
# I'm going to replace the secure random number generator
# backends with this very primitive and insecure one, because
# these are only unit tests and because we use external modules
# for the purpose anyway (which are not to be tested with these
# unit tests).
# This has to be done, so that unit tests running on cpantesters
# don't block if we use a real random source, which has reportedly
# happened in the past.
# ***** CAUTION: DO NOT USE THIS CODE IN PRODUCTION. EVER. ****
*Crypt::PWSafe3::random = sub { return join'',map{chr(int(rand(255)))}(1..$_[1]); };
### 2
# open vault and read in all records
eval {
@@ -62,7 +77,7 @@ my $tmpfile = "$fd";
close($fd);
eval {
my $vault = Crypt::PWSafe3->new(file => $tmpfile, password => 'tom') or die "$!";
my $vault = Crypt::PWSafe3->new(file => $tmpfile, password => 'tom', random => $trand) or die "$!";
$vault->newrecord(%record);
$vault->save();
};