fixed pack/unpack formats to use strictly little-endian values as required

by database format
This commit is contained in:
git@daemon.de
2012-11-27 17:41:49 +01:00
parent 37b3bf567d
commit fca71efd62
3 changed files with 21 additions and 19 deletions

View File

@@ -22,13 +22,15 @@ use Data::Dumper;
use Exporter (); use Exporter ();
use vars qw(@ISA @EXPORT); use vars qw(@ISA @EXPORT);
$Crypt::PWSafe3::VERSION = '1.07'; $Crypt::PWSafe3::VERSION = '1.08';
use Crypt::PWSafe3::Field; use Crypt::PWSafe3::Field;
use Crypt::PWSafe3::HeaderField; use Crypt::PWSafe3::HeaderField;
use Crypt::PWSafe3::Record; use Crypt::PWSafe3::Record;
use Crypt::PWSafe3::SHA256; use Crypt::PWSafe3::SHA256;
require 5.10.0;
# #
# check, which random source to use. # check, which random source to use.
# install a wrapper closure around the # install a wrapper closure around the
@@ -204,7 +206,7 @@ sub read {
} }
$this->salt( $this->readbytes(32) ); $this->salt( $this->readbytes(32) );
$this->iter( unpack("V", $this->readbytes(4) ) ); $this->iter( unpack("L<", $this->readbytes(4) ) );
$this->strechedpw($this->stretchpw($this->password())); $this->strechedpw($this->stretchpw($this->password()));
@@ -324,7 +326,7 @@ sub save {
$this->addheader($whosaved); $this->addheader($whosaved);
my $tmpfile = File::Spec->catfile(File::Spec->tmpdir(), my $tmpfile = File::Spec->catfile(File::Spec->tmpdir(),
".vault-" . unpack("H*", $this->random(16))); ".vault-" . unpack("L<4", $this->random(16)));
unlink $tmpfile; unlink $tmpfile;
my $fd = new FileHandle($tmpfile, 'w') or croak "Could not open tmpfile $tmpfile: $!\n"; my $fd = new FileHandle($tmpfile, 'w') or croak "Could not open tmpfile $tmpfile: $!\n";
$fd->binmode(); $fd->binmode();
@@ -332,7 +334,7 @@ sub save {
$this->writebytes($this->tag); $this->writebytes($this->tag);
$this->writebytes($this->salt); $this->writebytes($this->salt);
$this->writebytes(pack("V", $this->iter)); $this->writebytes(pack("L<", $this->iter));
$this->strechedpw($this->stretchpw($passwd)); $this->strechedpw($this->stretchpw($passwd));
@@ -423,7 +425,7 @@ sub writefield {
return; return;
} }
my $len = pack("V", $field->len); my $len = pack("L<", $field->len);
my $type = pack("C", $field->type); my $type = pack("C", $field->type);
my $raw = $field->raw; my $raw = $field->raw;
@@ -585,7 +587,7 @@ sub readfield {
#print "clear: <" . unpack('H*', $data) . ">\n"; #print "clear: <" . unpack('H*', $data) . ">\n";
my $len = unpack("V", substr($data, 0, 4)); my $len = unpack("L<", substr($data, 0, 4));
my $type = unpack("C", substr($data, 4, 1)); my $type = unpack("C", substr($data, 4, 1));
my $raw = substr($data, 5); my $raw = substr($data, 5);
@@ -950,7 +952,7 @@ and/or modify it under the same terms as Perl itself.
=head1 VERSION =head1 VERSION
Crypt::PWSafe3 Version 1.07. Crypt::PWSafe3 Version 1.08.
=cut =cut

View File

@@ -70,13 +70,13 @@ sub new {
if (exists $param{raw}) { if (exists $param{raw}) {
if (grep { $_ eq $param{type} } @convtime) { if (grep { $_ eq $param{type} } @convtime) {
$self->{value} = unpack("V", $param{raw}); $self->{value} = unpack("L<", $param{raw});
} }
elsif (grep { $_ eq $param{type} } @convhex) { elsif (grep { $_ eq $param{type} } @convhex) {
$self->{value} = unpack('H*', $param{raw}); $self->{value} = unpack('L<4', $param{raw});
} }
elsif (grep { $_ eq $param{type} } @convbyte) { elsif (grep { $_ eq $param{type} } @convbyte) {
$self->{value} = unpack('W*', $param{raw}); $self->{value} = unpack('W<*', $param{raw});
} }
else { else {
$self->{value} = $param{raw}; $self->{value} = $param{raw};
@@ -87,13 +87,13 @@ sub new {
else { else {
if (exists $param{value}) { if (exists $param{value}) {
if (grep { $_ eq $param{type} } @convtime) { if (grep { $_ eq $param{type} } @convtime) {
$self->{raw} = pack("V", $param{value}); $self->{raw} = pack("L<", $param{value});
} }
elsif (grep { $_ eq $param{type} } @convhex) { elsif (grep { $_ eq $param{type} } @convhex) {
$self->{raw} = pack('H*', $param{value}); $self->{raw} = pack('L<4', $param{value});
} }
elsif (grep { $_ eq $param{type} } @convbyte) { elsif (grep { $_ eq $param{type} } @convbyte) {
$self->{raw} = pack('W*', $param{value}); $self->{raw} = pack('W<*', $param{value});
} }
else { else {
$self->{raw} = $param{value}; $self->{raw} = $param{value};

View File

@@ -65,13 +65,13 @@ sub new {
if (exists $param{raw}) { if (exists $param{raw}) {
if ($param{type} == 0x00) { if ($param{type} == 0x00) {
$self->{value} = unpack('H*', $param{raw});# maybe WW or CC ? $self->{value} = unpack('L<2', $param{raw});# maybe WW or CC ?
} }
elsif ($param{type} == 0x01) { elsif ($param{type} == 0x01) {
$self->{value} = unpack('H*', $param{raw}); $self->{value} = unpack('L<4', $param{raw});
} }
elsif ($param{type} == 0x04) { elsif ($param{type} == 0x04) {
$self->{value} = unpack('V', $param{raw}); $self->{value} = unpack('L<', $param{raw});
} }
else { else {
$self->{value} = $param{raw}; $self->{value} = $param{raw};
@@ -81,13 +81,13 @@ sub new {
else { else {
if (exists $param{value}) { if (exists $param{value}) {
if ($param{type} == 0x00) { if ($param{type} == 0x00) {
$self->{raw} = pack("H*", $param{value}); $self->{raw} = pack("L<2", $param{value});
} }
elsif ($param{type} == 0x01) { elsif ($param{type} == 0x01) {
$self->{raw} = pack('H*', $param{value}); $self->{raw} = pack('L<4', $param{value});
} }
elsif ($param{type} == 0x04) { elsif ($param{type} == 0x04) {
$self->{raw} = pack('V', $param{value}); $self->{raw} = pack('L<', $param{value});
} }
else { else {
$self->{raw} = $param{value}; $self->{raw} = $param{value};