=================================================================== RCS file: /cvs/palm/Palm-Keyring/lib/Palm/Keyring.pm,v retrieving revision 1.56 retrieving revision 1.61 diff -u -r1.56 -r1.61 --- palm/Palm-Keyring/lib/Palm/Keyring.pm 2008/09/18 07:04:55 1.56 +++ palm/Palm-Keyring/lib/Palm/Keyring.pm 2008/09/19 06:55:35 1.61 @@ -1,5 +1,5 @@ package Palm::Keyring; -# $RedRiver: Keyring.pm,v 1.55 2008/09/17 14:47:47 andrew Exp $ +# $RedRiver: Keyring.pm,v 1.60 2008/09/19 05:53:08 andrew Exp $ ######################################################################## # Keyring.pm *** Perl class for Keyring for Palm OS databases. # @@ -292,9 +292,6 @@ my $self = shift; my $rec = shift; - # XXX This probably shouldn't croak, just make something up - croak "No encrypted content to pack" if !defined $rec->{encrypted}; - if ($self->{version} == 4) { if ($rec->{encrypted}) { my $name = $rec->{plaintext}->{0}->{data} || $EMPTY; @@ -302,8 +299,8 @@ } } elsif ($self->{version} == 5) { - # XXX This probably shouldn't croak, just make something up - croak "No ivec" if !$rec->{ivec}; + croak 'No encrypted data in record' if !defined $rec->{encrypted}; + croak 'No ivec!' if !$rec->{ivec}; my $field; if ($rec->{plaintext}->{0}) { @@ -327,6 +324,8 @@ delete $rec->{plaintext}; delete $rec->{encrypted}; + croak 'No data in record to pack' if !$rec->{data}; + return $self->SUPER::PackRecord($rec, @_); } @@ -353,7 +352,7 @@ # Nothing extra for version 4 } elsif ($self->{version} == 5) { - _parse_appinfo_v5($appinfo) || return; + _parse_appinfo_v5($appinfo); } else { croak "Unsupported Version $self->{version}"; @@ -366,10 +365,7 @@ { my $appinfo = shift; - if (! exists $appinfo->{other}) { - # XXX Corrupt appinfo? - return; - } + croak 'Corrupt appinfo? no {other}' if ! $appinfo->{other}; my $unpackstr = ("C1" x 8) # 8 uint8s in an array for the salt @@ -438,23 +434,25 @@ my $self = shift; my $rec = shift; my $pass = shift || $self->{password}; + + if ( !$rec ) { + croak('Needed parameter [record] not passed!'); + } + my $data = shift || $rec->{plaintext}; my $ivec = shift; + if ( ! $pass && ! $self->{appinfo}->{key}) { - croak("password not set!\n"); + croak('password not set!'); } - if ( ! $rec) { - croak("Needed parameter 'record' not passed!\n"); - } - if ( ! $data) { - croak("Needed 'plaintext' not passed!\n"); + croak('Needed parameter [plaintext] not passed!'); } if ( $pass && ! $self->Password($pass)) { - croak("Incorrect Password!\n"); + croak('Incorrect Password!'); } my $acct; @@ -482,18 +480,15 @@ $encrypted = _encrypt_v4($datav4, $acctv4, $self->{digest}); } elsif ($self->{version} == 5) { - ($encrypted, $ivec) = _encrypt_v5( + ($encrypted, $rec->{ivec}) = _encrypt_v5( $data, $acct, $self->{appinfo}->{key}, $self->{appinfo}->{cipher}, $ivec, ); - if (defined $ivec) { - $rec->{ivec} = $ivec; - } } else { - croak "Unsupported Version $self->{version}"; + croak "Unsupported version $self->{version}"; } $rec->{plaintext}->{0} = $data->{0}; @@ -593,7 +588,9 @@ my $c = crypts($cipher) or croak('Unknown cipher ' . $cipher); if (! defined $ivec) { - $ivec = pack("C*",map {rand(256)} 1..$c->{blocksize}); + while (! $ivec) { + $ivec = pack("C*",map {rand(256)} 1..$c->{blocksize}); + } } my $changed = 0; @@ -623,7 +620,7 @@ } } - return 1, 0 if $changed == 0; + return (1, $ivec) if $changed == 0; if ($need_newdate) { my ($day, $month, $year) = (localtime)[3,4,5];