| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Log::Saftpresse::Plugin::Postfix::Tls; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
720
|
use Moose::Role; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: plugin to gather TLS statistics |
|
6
|
|
|
|
|
|
|
our $VERSION = '1.5'; # VERSION |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub process_tls { |
|
9
|
0
|
|
|
0
|
0
|
|
my ( $self, $stash, $notes ) = @_; |
|
10
|
0
|
|
|
|
|
|
my $service = $stash->{'service'}; |
|
11
|
0
|
|
|
|
|
|
my $pid = $stash->{'pid'}; |
|
12
|
0
|
|
|
|
|
|
my $message = $stash->{'message'}; |
|
13
|
0
|
|
|
|
|
|
my $queue_id = $stash->{'queue_id'}; |
|
14
|
|
|
|
|
|
|
|
|
15
|
0
|
0
|
0
|
|
|
|
if( $service ne 'smtp' && $service ne 'smtpd' ) { |
|
16
|
0
|
|
|
|
|
|
return; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
|
if( my ($tlsLevel,$tlsHost, $tlsAddr, $tlsProto, $tlsCipher, $tlsKeylen) = |
|
20
|
|
|
|
|
|
|
$message =~ /^(\S+) TLS connection established (?:from|to) ([^\[]+)\[([^\]]+)\]:(?:\d+:)? (\S+) with cipher (\S+) \((\d+)\/(\d+) bits\)/ ) { |
|
21
|
0
|
|
|
|
|
|
my $tls_params = { |
|
22
|
|
|
|
|
|
|
'tls_level' => $tlsLevel, |
|
23
|
|
|
|
|
|
|
'tls_proto' => $tlsProto, |
|
24
|
|
|
|
|
|
|
'tls_chipher' => $tlsCipher, |
|
25
|
|
|
|
|
|
|
'tls_keylen' => $tlsKeylen, |
|
26
|
|
|
|
|
|
|
}; |
|
27
|
0
|
|
|
|
|
|
$self->incr_tls_stats( $stash, $tls_params, 'tls_conn', $service); |
|
28
|
0
|
|
|
|
|
|
@$stash{keys %$tls_params} = values %$tls_params; |
|
29
|
0
|
|
|
|
|
|
$notes->set($service.'-tls-'.$pid, $tls_params); |
|
30
|
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
return; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $tls_params = $notes->get($service.'-tls-'.$pid); |
|
35
|
0
|
0
|
0
|
|
|
|
if( defined $tls_params ) { |
|
|
|
0
|
|
|
|
|
|
|
36
|
0
|
0
|
0
|
|
|
|
if( $service eq 'smtpd' ) { |
|
|
|
0
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
if( $message =~ /^connect from/ ) { # we missed the disconnect? |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
$notes->remove($service.'-tls-'.$pid); |
|
39
|
0
|
|
|
|
|
|
return; |
|
40
|
|
|
|
|
|
|
} elsif( $message =~ /^disconnect/ ) { |
|
41
|
0
|
|
|
|
|
|
$notes->remove($service.'-tls-'.$pid); |
|
42
|
|
|
|
|
|
|
} elsif( $message =~ /^client=/ ) { |
|
43
|
0
|
|
|
|
|
|
$self->incr_tls_stats( $stash, $tls_params, 'tls_msg', $service); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
0
|
|
|
|
|
|
@$stash{keys %$tls_params} = values %$tls_params; |
|
46
|
|
|
|
|
|
|
} elsif( $service eq 'smtp' && |
|
47
|
|
|
|
|
|
|
$message =~ /status=(sent|bounced|deferred)/ ) { |
|
48
|
0
|
|
|
|
|
|
$self->incr_tls_stats( $stash, $tls_params, 'tls_msg', $service); |
|
49
|
0
|
|
|
|
|
|
$notes->remove($service.'-tls-'.$pid); |
|
50
|
|
|
|
|
|
|
# postfix/smtp closes the TLS connection after each delivery |
|
51
|
|
|
|
|
|
|
# see postfix-users maillist (2015-02-05) |
|
52
|
|
|
|
|
|
|
# but there may be more than one recipients so remember |
|
53
|
|
|
|
|
|
|
# TLS parameters for this queue_id |
|
54
|
0
|
0
|
|
|
|
|
if( defined $queue_id ) { |
|
55
|
0
|
|
|
|
|
|
$notes->set($service.'-tls-'.$queue_id, $tls_params); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
} elsif( defined $queue_id && |
|
59
|
|
|
|
|
|
|
defined($tls_params = $notes->get($service.'-tls-'.$queue_id)) |
|
60
|
|
|
|
|
|
|
) { |
|
61
|
0
|
|
|
|
|
|
@$stash{keys %$tls_params} = values %$tls_params; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub incr_tls_stats { |
|
68
|
0
|
|
|
0
|
0
|
|
my ( $self, $stash, $tls_params, @path ) = @_; |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$self->incr_host_one( $stash, @path, 'total'); |
|
71
|
0
|
|
|
|
|
|
$self->incr_host_one( $stash, @path, 'level', $tls_params->{'tls_level'}); |
|
72
|
0
|
|
|
|
|
|
$self->incr_host_one( $stash, @path, 'proto', $tls_params->{'tls_proto'}); |
|
73
|
0
|
|
|
|
|
|
$self->incr_host_one( $stash, @path, 'cipher', $tls_params->{'tls_chipher'}); |
|
74
|
0
|
|
|
|
|
|
$self->incr_host_one( $stash, @path, 'keylen', $tls_params->{'tls_keylen'}); |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=pod |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=encoding UTF-8 |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 NAME |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Log::Saftpresse::Plugin::Postfix::Tls - plugin to gather TLS statistics |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 VERSION |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
version 1.5 |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 AUTHOR |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This is free software, licensed under: |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |