version 1.50, 2007/09/13 01:02:52 |
version 1.55, 2008/09/17 15:47:47 |
|
|
package Palm::Keyring; |
package Palm::Keyring; |
# $RedRiver: Keyring.pm,v 1.49 2007/09/12 03:39:22 andrew Exp $ |
# $RedRiver: Keyring.pm,v 1.54 2007/12/05 05:42:29 andrew Exp $ |
######################################################################## |
######################################################################## |
# Keyring.pm *** Perl class for Keyring for Palm OS databases. |
# Keyring.pm *** Perl class for Keyring for Palm OS databases. |
# |
# |
|
|
use strict; |
use strict; |
use warnings; |
use warnings; |
|
|
|
require 5.006_001; |
|
|
use Carp; |
use Carp; |
|
|
use base qw/ Palm::StdAppInfo /; |
use base qw/ Palm::StdAppInfo /; |
|
|
); |
); |
|
|
|
|
our $VERSION = '0.96_04'; |
our $VERSION = '0.96_07'; |
|
|
sub new |
sub new |
{ |
{ |
|
|
|
|
my $plaintext; |
my $plaintext; |
foreach my $k (keys %{ $new }) { |
foreach my $k (keys %{ $new }) { |
|
next if $new->{$k}->{label_id} == 0; |
$plaintext .= _pack_field($new->{$k}); |
$plaintext .= _pack_field($new->{$k}); |
} |
} |
|
$plaintext .= chr(0xff) x 2; |
|
|
my $encrypted; |
my $encrypted; |
if ($c->{name} eq 'None') { |
if ($c->{name} eq 'None') { |
|
|
|
|
my ($len) = unpack "n", $field; |
my ($len) = unpack "n", $field; |
if ($len + 4 > length $field) { |
if ($len + 4 > length $field) { |
return undef, $field; |
return (undef, $field); |
} |
} |
my $unpackstr = "x2 C1 C1 A$len"; |
my $unpackstr = "x2 C1 C1 A$len"; |
my $offset = 2 +1 +1 +$len; |
my $offset = 2 +1 +1 +$len; |
|
|
my $maxlines = shift; # Max # of lines to dump |
my $maxlines = shift; # Max # of lines to dump |
my $offset; # Offset of current chunk |
my $offset; # Offset of current chunk |
|
|
|
my @lines; |
|
|
for ($offset = 0; $offset < length($data); $offset += 16) |
for ($offset = 0; $offset < length($data); $offset += 16) |
{ |
{ |
my $hex; # Hex values of the data |
my $hex; # Hex values of the data |
|
|
|
|
($ascii = $chunk) =~ y/\040-\176/./c; |
($ascii = $chunk) =~ y/\040-\176/./c; |
|
|
printf "%s %-48s|%-16s|\n", $prefix, $hex, $ascii; |
push @lines, sprintf "%s %-48s|%-16s|\n", $prefix, $hex, $ascii; |
} |
} |
|
return wantarray ? @lines : \@lines; |
} |
} |
|
|
sub _bindump |
sub _bindump |
|
|
my $maxlines = shift; # Max # of lines to dump |
my $maxlines = shift; # Max # of lines to dump |
my $offset; # Offset of current chunk |
my $offset; # Offset of current chunk |
|
|
|
my @lines; |
|
|
for ($offset = 0; $offset < length($data); $offset += 8) |
for ($offset = 0; $offset < length($data); $offset += 8) |
{ |
{ |
my $bin; # binary values of the data |
my $bin; # binary values of the data |
|
|
|
|
($ascii = $chunk) =~ y/\040-\176/./c; |
($ascii = $chunk) =~ y/\040-\176/./c; |
|
|
printf "%s %-72s|%-8s|\n", $prefix, $bin, $ascii; |
push @lines, sprintf "%s %-72s|%-8s|\n", $prefix, $bin, $ascii; |
} |
} |
|
return wantarray ? @lines : \@lines; |
} |
} |
|
|
# Thanks to Jochen Hoenicke <hoenicke@gmail.com> |
# Thanks to Jochen Hoenicke <hoenicke@gmail.com> |
|
|
# keylen is length of generated key in bytes |
# keylen is length of generated key in bytes |
# prf is the pseudo random function (e.g. hmac_sha1) |
# prf is the pseudo random function (e.g. hmac_sha1) |
# returns the key. |
# returns the key. |
sub _pbkdf2($$$$$) |
sub _pbkdf2 |
{ |
{ |
my ($password, $salt, $iter, $keylen, $prf) = @_; |
my ($password, $salt, $iter, $keylen, $prf) = @_; |
my ($k, $t, $u, $ui, $i); |
my ($k, $t, $u, $ui, $i); |
|
|
return substr($t, 0, $keylen); |
return substr($t, 0, $keylen); |
} |
} |
|
|
sub _DES_odd_parity($) { |
sub _DES_odd_parity { |
my $key = $_[0]; |
my $key = $_[0]; |
my ($r, $i); |
my ($r, $i); |
my @odd_parity = ( |
my @odd_parity = ( |