Strip/PDB/PasswordV05i.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 63 CC 2 SCAR 10.0
CC
2
Cov
0%
verify_password
6.0
new
2.0
load
2.0
CRAP 2.7
1 package Palm::Zetetic::Strip::PDB::PasswordV05i;
2  
3 use strict;
4 use Palm::PDB;
5 use Palm::Raw;
6 use Palm::Zetetic::Strip::CryptV05i;
7  
8 use vars qw(@ISA $VERSION);
9  
10 require Exporter;
11  
12 @ISA = qw(Exporter);
13 $VERSION = "1.02";
14  
15 sub new
16 {
17 my $class = shift;
18 my $self = {};
19  
20 bless $self, $class;
21 $self->{pdb} = undef;
22 return $self;
23 }
24  
25 sub load
26 {
27 my ($self, $file) = @_;
28 my $pdb;
29  
30 $pdb = new Palm::PDB;
31 $pdb->Load($file);
32 $self->{pdb} = $pdb;
33 }
34  
35 sub get_encrypted_password
36 {
37 my ($self) = @_;
38 my $records;
39  
40 $records = $self->{pdb}->{records};
41 return $records->[0]->{data};
42 }
43  
44 sub verify_password
45 {
46 my ($self, $plaintext_password) = @_;
47 my $encrypted_password;
48 my $decrypted_password;
49 my $hashed_password;
50 my $crypt;
51  
52 # The encrypted password is the MD5 hash of the plaintext
53 # password, encrypted. The MD5 hash is only 16 bytes long, so
54 # only look at the first 16 bytes after decrypting. To verify a
55 # password, decrypt the current password using the supplied
56 # password as the key.
57  
58 $crypt = new Palm::Zetetic::Strip::CryptV05i($plaintext_password);
59  
60 $hashed_password = $crypt->get_hashed_key();
61 $encrypted_password = $self->get_encrypted_password();
62 $decrypted_password = $crypt->decrypt($encrypted_password);
63 $decrypted_password = substr($decrypted_password,0,16);
64  
65 if ($decrypted_password eq $hashed_password)
66 {
67 return 1;
68 }
69 else
70 {
71 return 0;
72 }
73 }
74  
75 1;