From 3d80bb1608eeb4c9f972452f80f93db37a8d7c1b Mon Sep 17 00:00:00 2001 From: "git@daemon.de" Date: Mon, 19 Nov 2012 11:57:15 +0100 Subject: [PATCH] made Bytes::Random::Secure optional, version++ --- CHANGELOG | 9 ++++++- Makefile.PL | 13 +++++++++- README | 2 +- lib/Crypt/PWSafe3.pm | 51 +++++++++++++++++++++++++------------ lib/Crypt/PWSafe3/Record.pm | 2 +- 5 files changed, 57 insertions(+), 20 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 6d4066d..6869f64 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,9 +1,16 @@ +1.06 + applied patch by https://github.com/Mekk: + https://github.com/TLINDEN/Crypt--PWSafe3/pull/2, + adds new function "deleterecord()", improves performance + when using Bytes::Random::Secure[now optional] and fixes + an error in ::Record::addfield(). + 1.05 applied patch by https://github.com/Mekk: https://github.com/TLINDEN/Crypt--PWSafe3/pull/1, which replaces use of cp and mv commands with File::Copy. this makes it portable. - + 1.04 fixed rt.cpan.org#75145. uninitialized fields lead to diff --git a/Makefile.PL b/Makefile.PL index f7f557b..ff2a31d 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,6 +1,18 @@ require 5.004; use ExtUtils::MakeMaker; +my %optional = ( + 'Bytes::Random::Secure' => 0.09, + ); + +foreach my $module (sort keys %optional) { + eval "require $module"; + if ($@) { + warn("Optional module $module not installed, $optional{$module}\n"); + } +} + + WriteMakefile( 'NAME' => 'Crypt::PWSafe3', 'VERSION_FROM' => 'lib/Crypt/PWSafe3.pm', @@ -12,7 +24,6 @@ WriteMakefile( 'Crypt::Random' => 1.25, 'Data::UUID' => 1.217, 'Shell' => 0.5, - 'Bytes::Random::Secure' => 0.09, }, 'AUTHOR' => 'Thomas Linden ', 'clean' => { diff --git a/README b/README index 321e481..8007b8b 100644 --- a/README +++ b/README @@ -49,5 +49,5 @@ AUTHOR VERSION - 1.05 + 1.06 diff --git a/lib/Crypt/PWSafe3.pm b/lib/Crypt/PWSafe3.pm index 62ef3d5..5e60c83 100644 --- a/lib/Crypt/PWSafe3.pm +++ b/lib/Crypt/PWSafe3.pm @@ -22,13 +22,42 @@ use Data::Dumper; use Exporter (); use vars qw(@ISA @EXPORT); -$Crypt::PWSafe3::VERSION = '1.05'; +$Crypt::PWSafe3::VERSION = '1.06'; use Crypt::PWSafe3::Field; use Crypt::PWSafe3::HeaderField; use Crypt::PWSafe3::Record; use Crypt::PWSafe3::SHA256; +# +# check, which random source to use. +# install a wrapper closure around the +# one we found. +BEGIN { + eval { require Bytes::Random::Secure }; + if ($@) { + # well, didn' work, use slow function + eval { require Crypt::Random; };# qw( makerandom ); }; + if ($@) { + croak "Could not find either Crypt::Random or Bytes::Random::Secure. Install one of them and retry!"; + } + else { + *Crypt::PWSafe3::random = sub { + my($this, $len) = @_; + my $bits = makerandom(Size => 256, Strength => 1); + return substr($bits, 0, $len); + }; + } + } + else { + # good. use the faster one + *Crypt::PWSafe3::random = sub { + my($this, $len) = @_; + return random_bytes($len); + }; + } +} + my @fields = qw(tag salt iter shaps b1 b2 b3 b4 keyk file program keyl iv hmac header strechedpw password whoami); foreach my $field (@fields) { @@ -641,20 +670,6 @@ sub writebytes { } } -# This is original, very slow random -#sub random { -# # -# # helper, return some secure random bytes -# my($this, $len) = @_; -# my $bits = makerandom(Size => 256, Strength => 1); -# return substr($bits, 0, $len); -#} - -use Bytes::Random::Secure qw(random_bytes random_bytes_hex); -sub random { - my($this, $len) = @_; - return random_bytes($len); -} sub getheader { # @@ -845,6 +860,10 @@ type with according values. Refer to L for details about available fields. +=head2 B + +Delete the record identified by the given UUID. + =head2 B Save the current password safe vault back to disk. @@ -928,7 +947,7 @@ and/or modify it under the same terms as Perl itself. =head1 VERSION -Crypt::PWSafe3 Version 1.05. +Crypt::PWSafe3 Version 1.06. =cut diff --git a/lib/Crypt/PWSafe3/Record.pm b/lib/Crypt/PWSafe3/Record.pm index b4f7a0d..0120f31 100644 --- a/lib/Crypt/PWSafe3/Record.pm +++ b/lib/Crypt/PWSafe3/Record.pm @@ -9,7 +9,7 @@ my %map2type = %Crypt::PWSafe3::Field::map2type; my %map2name = %Crypt::PWSafe3::Field::map2name; -$Crypt::PWSafe3::Record::VERSION = '1.03'; +$Crypt::PWSafe3::Record::VERSION = '1.04'; foreach my $field (keys %map2type ) { eval qq(