line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Authen::Passphrase::NetscapeMail - passphrases using Netscape Mail |
4
|
|
|
|
|
|
|
Server's method |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 SYNOPSIS |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Authen::Passphrase::NetscapeMail; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$ppr = Authen::Passphrase::NetscapeMail->new( |
11
|
|
|
|
|
|
|
salt => "8fd9d0a03491ce8f99cfbc9ab39f0dd5", |
12
|
|
|
|
|
|
|
hash_hex => "983757d7b519e86d9b5d472aca4eea3a"); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$ppr = Authen::Passphrase::NetscapeMail->new( |
15
|
|
|
|
|
|
|
salt_random => 1, |
16
|
|
|
|
|
|
|
passphrase => "passphrase"); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$ppr = Authen::Passphrase::NetscapeMail->from_rfc2307( |
19
|
|
|
|
|
|
|
"{NS-MTA-MD5}8fd9d0a03491ce8f99cfbc9ab39f0dd5". |
20
|
|
|
|
|
|
|
"983757d7b519e86d9b5d472aca4eea3a"); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$salt = $ppr->salt; |
23
|
|
|
|
|
|
|
$hash = $ppr->hash; |
24
|
|
|
|
|
|
|
$hash_hex = $ppr->hash_hex; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
if($ppr->match($passphrase)) { ... |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$userPassword = $ppr->as_rfc2307; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
An object of this class encapsulates a passphrase hashed using |
33
|
|
|
|
|
|
|
the algorithm used by Netscape Mail Server. This is a subclass of |
34
|
|
|
|
|
|
|
L, and this document assumes that the reader is |
35
|
|
|
|
|
|
|
familiar with the documentation for that class. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
The Netscape Mail Server scheme is based on the MD5 digest algorithm. |
38
|
|
|
|
|
|
|
The passphrase and a salt are concatenated, along with some fixed |
39
|
|
|
|
|
|
|
bytes, and this record is hashed through MD5. The output of MD5 is the |
40
|
|
|
|
|
|
|
password hash. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
This algorithm is deprecated, and is supported for compatibility only. |
43
|
|
|
|
|
|
|
Prefer the mechanism of L. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
package Authen::Passphrase::NetscapeMail; |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
1
|
|
34188
|
{ use 5.006; } |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
81
|
|
50
|
1
|
|
|
1
|
|
9
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
159
|
|
51
|
1
|
|
|
1
|
|
9
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
59
|
|
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
1
|
|
1119
|
use Authen::Passphrase 0.003; |
|
1
|
|
|
|
|
24
|
|
|
1
|
|
|
|
|
33
|
|
54
|
1
|
|
|
1
|
|
9
|
use Carp qw(croak); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
70
|
|
55
|
1
|
|
|
1
|
|
1120
|
use Data::Entropy::Algorithms 0.000 qw(rand_bits); |
|
1
|
|
|
|
|
19808
|
|
|
1
|
|
|
|
|
94
|
|
56
|
1
|
|
|
1
|
|
11
|
use Digest::MD5 1.99_53 (); |
|
1
|
|
|
|
|
21
|
|
|
1
|
|
|
|
|
42
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
our $VERSION = "0.008"; |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
1
|
|
6
|
use parent "Authen::Passphrase"; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 CONSTRUCTORS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=over |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item Authen::Passphrase::NetscapeMail->new(ATTR => VALUE, ...) |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Generates a new passphrase recogniser object using the Netscape Mail |
69
|
|
|
|
|
|
|
Server algorithm. The following attributes may be given: |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=over |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item B |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
The salt, as a raw 32-byte string. It may be any 32-byte string, but |
76
|
|
|
|
|
|
|
it is conventionally limited to lowercase hexadecimal digits. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item B |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Causes salt to be generated randomly. The value given for this attribute |
81
|
|
|
|
|
|
|
is ignored. The salt will be a string of 32 lowercase hexadecimal digits. |
82
|
|
|
|
|
|
|
The source of randomness may be controlled by the facility described |
83
|
|
|
|
|
|
|
in L. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item B |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
The hash, as a string of 16 bytes. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item B |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
The hash, as a string of 32 hexadecimal digits. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item B |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
A passphrase that will be accepted. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=back |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
The salt must be given, and either the hash or the passphrase. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub new { |
104
|
8
|
|
|
8
|
1
|
25
|
my $class = shift; |
105
|
8
|
|
|
|
|
25
|
my $self = bless({}, $class); |
106
|
8
|
|
|
|
|
13
|
my $passphrase; |
107
|
8
|
|
|
|
|
21
|
while(@_) { |
108
|
16
|
|
|
|
|
8748
|
my $attr = shift; |
109
|
16
|
|
|
|
|
21
|
my $value = shift; |
110
|
16
|
100
|
|
|
|
63
|
if($attr eq "salt") { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
111
|
7
|
50
|
|
|
|
21
|
croak "salt specified redundantly" |
112
|
|
|
|
|
|
|
if exists $self->{salt}; |
113
|
7
|
50
|
|
|
|
57
|
$value =~ m#\A[\x00-\xff]{32}\z# |
114
|
|
|
|
|
|
|
or croak "not a valid salt"; |
115
|
7
|
|
|
|
|
29
|
$self->{salt} = "$value"; |
116
|
|
|
|
|
|
|
} elsif($attr eq "salt_random") { |
117
|
1
|
50
|
|
|
|
4
|
croak "salt specified redundantly" |
118
|
|
|
|
|
|
|
if exists $self->{salt}; |
119
|
1
|
|
|
|
|
9
|
$self->{salt} = unpack("H*", rand_bits(128)); |
120
|
|
|
|
|
|
|
} elsif($attr eq "hash") { |
121
|
3
|
50
|
33
|
|
|
21
|
croak "hash specified redundantly" |
122
|
|
|
|
|
|
|
if exists($self->{hash}) || |
123
|
|
|
|
|
|
|
defined($passphrase); |
124
|
3
|
50
|
|
|
|
11
|
$value =~ m#\A[\x00-\xff]{16}\z# |
125
|
|
|
|
|
|
|
or croak "not a valid MD5 hash"; |
126
|
3
|
|
|
|
|
12
|
$self->{hash} = "$value"; |
127
|
|
|
|
|
|
|
} elsif($attr eq "hash_hex") { |
128
|
3
|
50
|
33
|
|
|
25
|
croak "hash specified redundantly" |
129
|
|
|
|
|
|
|
if exists($self->{hash}) || |
130
|
|
|
|
|
|
|
defined($passphrase); |
131
|
3
|
50
|
|
|
|
13
|
$value =~ m#\A[0-9A-Fa-f]{32}\z# |
132
|
|
|
|
|
|
|
or croak "\"$value\" is not a valid ". |
133
|
|
|
|
|
|
|
"hex MD5 hash"; |
134
|
3
|
|
|
|
|
22
|
$self->{hash} = pack("H*", $value); |
135
|
|
|
|
|
|
|
} elsif($attr eq "passphrase") { |
136
|
2
|
50
|
33
|
|
|
17
|
croak "passphrase specified redundantly" |
137
|
|
|
|
|
|
|
if exists($self->{hash}) || |
138
|
|
|
|
|
|
|
defined($passphrase); |
139
|
2
|
|
|
|
|
8
|
$passphrase = $value; |
140
|
|
|
|
|
|
|
} else { |
141
|
0
|
|
|
|
|
0
|
croak "unrecognised attribute `$attr'"; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
} |
144
|
8
|
50
|
|
|
|
23
|
croak "salt not specified" unless exists $self->{salt}; |
145
|
8
|
100
|
|
|
|
23
|
$self->{hash} = $self->_hash_of($passphrase) if defined $passphrase; |
146
|
8
|
50
|
|
|
|
26
|
croak "hash not specified" unless exists $self->{hash}; |
147
|
8
|
|
|
|
|
23
|
return $self; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item Authen::Passphrase::NetscapeMail->from_rfc2307(USERPASSWORD) |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Generates a new Netscape Mail Server passphrase recogniser object from |
153
|
|
|
|
|
|
|
an RFC 2307 string. The string must consist of "B<{NS-MTA-MD5}>" (case |
154
|
|
|
|
|
|
|
insensitive) followed by the hash in case-insensitive hexadecimal and |
155
|
|
|
|
|
|
|
then the salt. The salt must be exactly 32 characters long, and cannot |
156
|
|
|
|
|
|
|
contain any character that cannot appear in an RFC 2307 string. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub from_rfc2307 { |
161
|
1
|
|
|
1
|
1
|
3
|
my($class, $userpassword) = @_; |
162
|
1
|
50
|
|
|
|
8
|
if($userpassword =~ /\A\{(?i:ns-mta-md5)\}/) { |
163
|
1
|
50
|
|
|
|
8
|
$userpassword =~ /\A\{.*?\}([0-9a-fA-F]{32})([!-~]{32})\z/ |
164
|
|
|
|
|
|
|
or croak "malformed {NS-MTA-MD5} data"; |
165
|
1
|
|
|
|
|
5
|
my($hash, $salt) = ($1, $2); |
166
|
1
|
|
|
|
|
6
|
return $class->new(salt => $salt, hash_hex => $hash); |
167
|
|
|
|
|
|
|
} |
168
|
0
|
|
|
|
|
0
|
return $class->SUPER::from_rfc2307($userpassword); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=back |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 METHODS |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=over |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item $ppr->salt |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Returns the salt value, as a string of 32 bytes. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub salt { |
184
|
8
|
|
|
8
|
1
|
3667
|
my($self) = @_; |
185
|
8
|
|
|
|
|
44
|
return $self->{salt}; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item $ppr->hash |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Returns the hash value, as a string of 16 bytes. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=cut |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub hash { |
195
|
7
|
|
|
7
|
1
|
13
|
my($self) = @_; |
196
|
7
|
|
|
|
|
42
|
return $self->{hash}; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item $ppr->hash_hex |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Returns the hash value, as a string of 32 hexadecimal digits. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub hash_hex { |
206
|
12
|
|
|
12
|
1
|
19
|
my($self) = @_; |
207
|
12
|
|
|
|
|
87
|
return unpack("H*", $self->{hash}); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item $ppr->match(PASSPHRASE) |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=item $ppr->as_rfc2307 |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
These methods are part of the standard L interface. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub _hash_of { |
219
|
28
|
|
|
28
|
|
45
|
my($self, $passphrase) = @_; |
220
|
28
|
|
|
|
|
232
|
my $ctx = Digest::MD5->new; |
221
|
28
|
|
|
|
|
105
|
$ctx->add($self->{salt}); |
222
|
28
|
|
|
|
|
62
|
$ctx->add("\x59"); |
223
|
28
|
|
|
|
|
62
|
$ctx->add($passphrase); |
224
|
28
|
|
|
|
|
57
|
$ctx->add("\xf7"); |
225
|
28
|
|
|
|
|
72
|
$ctx->add($self->{salt}); |
226
|
28
|
|
|
|
|
232
|
return $ctx->digest; |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub match { |
230
|
26
|
|
|
26
|
1
|
10342
|
my($self, $passphrase) = @_; |
231
|
26
|
|
|
|
|
58
|
return $self->_hash_of($passphrase) eq $self->{hash}; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub as_rfc2307 { |
235
|
5
|
|
|
5
|
1
|
9
|
my($self) = @_; |
236
|
5
|
50
|
|
|
|
84
|
croak "can't put this salt into an RFC 2307 string" |
237
|
|
|
|
|
|
|
if $self->{salt} =~ /[^!-~]/; |
238
|
5
|
|
|
|
|
15
|
return "{NS-MTA-MD5}".$self->hash_hex.$self->{salt}; |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=back |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head1 SEE ALSO |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
L, |
246
|
|
|
|
|
|
|
L |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head1 AUTHOR |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
Andrew Main (Zefram) |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head1 COPYRIGHT |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
Copyright (C) 2006, 2007, 2009, 2010, 2012 |
255
|
|
|
|
|
|
|
Andrew Main (Zefram) |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head1 LICENSE |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it |
260
|
|
|
|
|
|
|
under the same terms as Perl itself. |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=cut |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
1; |