| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Server::Mail::ESMTP::STARTTLS; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
43989
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
39
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
41
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
7
|
use base qw(Net::Server::Mail::ESMTP::Extension); |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
3923
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3431
|
use IO::Socket::SSL; |
|
|
1
|
|
|
|
|
129794
|
|
|
|
1
|
|
|
|
|
9
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Net::Server::Mail::ESMTP::STARTTLS - Simple implementation of STARTTLS (RFC3207) for Net::Server::Mail::ESMTP |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Version 0.02 |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Simple implementation of STARTTLS (RFC3207) for Net::Server::Mail::ESMTP. |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use Net::Server::Mail::ESMTP; |
|
27
|
|
|
|
|
|
|
my $server = new IO::Socket::INET Listen => 1, LocalPort => 25; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $conn; |
|
30
|
|
|
|
|
|
|
while($conn = $server->accept) |
|
31
|
|
|
|
|
|
|
{ |
|
32
|
|
|
|
|
|
|
my $esmtp = new Net::Server::Mail::ESMTP socket => $conn; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# activate STARTTLS extension |
|
35
|
|
|
|
|
|
|
$esmtp->register('Net::Server::Mail::ESMTP::STARTTLS'); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# adding STARTTLS handler |
|
38
|
|
|
|
|
|
|
$esmtp->set_callback(STARTTLS => \&tls_started); |
|
39
|
|
|
|
|
|
|
$esmtp->process; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub tls_started |
|
43
|
|
|
|
|
|
|
{ |
|
44
|
|
|
|
|
|
|
my ($session) = @_; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# now allow authentication |
|
47
|
|
|
|
|
|
|
$session->register('Net::Server::Mail::ESMTP::AUTH'); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 verb |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub verb { |
|
60
|
0
|
|
|
0
|
1
|
|
return [ 'STARTTLS' => 'starttls' ]; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 keyword |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub keyword { |
|
68
|
0
|
|
|
0
|
1
|
|
return 'STARTTLS'; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 reply |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub reply { |
|
76
|
0
|
|
|
0
|
1
|
|
return ( [ 'STARTTLS', ] ); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 starttls |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub starttls { |
|
84
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
85
|
0
|
|
|
|
|
|
my ($args) = @_; |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
0
|
0
|
|
|
|
if ( defined($args) && $args ne '' ) { |
|
88
|
0
|
|
|
|
|
|
$self->reply( 501, 'Syntax error (no parameters allowed)' ); |
|
89
|
0
|
|
|
|
|
|
return; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$self->reply( 220, 'Ready to start TLS' ); |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $sslret = IO::Socket::SSL->start_SSL( |
|
95
|
|
|
|
|
|
|
$self->{out}, |
|
96
|
|
|
|
|
|
|
SSL_server => 1, |
|
97
|
|
|
|
|
|
|
Timeout => 30, |
|
98
|
|
|
|
|
|
|
SSL_startHandshake => 1 |
|
99
|
|
|
|
|
|
|
); |
|
100
|
|
|
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
|
unless ($sslret) { |
|
102
|
0
|
|
|
|
|
|
$self->reply( 454, |
|
103
|
|
|
|
|
|
|
'TLS not available due to temporary reason' . ' [' |
|
104
|
|
|
|
|
|
|
. IO::Socket::SSL::errstr() |
|
105
|
|
|
|
|
|
|
. ']' ); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
my $ref = $self->{callback}->{STARTTLS}; |
|
109
|
0
|
0
|
0
|
|
|
|
if ( ref $ref eq 'ARRAY' && ref $ref->[0] eq 'CODE' ) { |
|
110
|
0
|
|
|
|
|
|
my $code = $ref->[0]; |
|
111
|
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my $ok = &$code($self); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
return (); |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
*Net::Server::Mail::ESMTP::starttls = \&starttls; |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 AUTHOR |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Dan Moore, C<< >> |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 TODO |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 RFC Compliance Issues |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=over |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item Reset state after success |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Quoth RFC2487: "Upon completion of the TLS handshake, the SMTP protocol is reset to |
|
133
|
|
|
|
|
|
|
the initial state (the state in SMTP after a server issues a 220 |
|
134
|
|
|
|
|
|
|
service ready greeting). The server MUST discard any knowledge |
|
135
|
|
|
|
|
|
|
obtained from the client, such as the argument to the EHLO command, |
|
136
|
|
|
|
|
|
|
which was not obtained from the TLS negotiation itself." |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item Remove STARTTLS from list of commands after success |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Quoth RFC2487: "A server MUST NOT return the TLS extension |
|
141
|
|
|
|
|
|
|
in response to an EHLO command received after a TLS handshake has |
|
142
|
|
|
|
|
|
|
completed." |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=back |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Note, though, that both of the above can be done outside the library. |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 BUGS |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=over |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item Failed handshaking might break things badly |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
When the start_SSL call fails, I'm not sure that things will work out so well. |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=back |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
159
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
160
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 SUPPORT |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
perldoc Net::Server::Mail::ESMTP::STARTTLS |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
You can also look for information at: |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=over 4 |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item * Net::Server::Mail::ESMTP::STARTTLS's GitHub page |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
L |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
L |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
L |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
L |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item * Search CPAN |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
L |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=back |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Net::Server::Mail rules, but I had to rely on Net::Server::Mail::ESMTP::AUTH as an example for how to write an ESMTP::Extension. Thanks to the authors of both! |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Copyright 2009 Dan Moore, all rights reserved. |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
208
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=cut |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
1; # End of Net::Server::Mail::ESMTP::STARTTLS |