| 1 | package Log::Saftpresse::Plugin::Postfix::Tls; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # ABSTRACT: plugin to gather TLS statistics | ||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '1.5'; # VERSION | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | sub process_tls { | ||||||||||||||||||||||||||||
| 9 | 0 | ▶ | my ( $self, $stash, $notes ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
process_tls: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 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 | ▶ | if( $service ne 'smtp' && $service ne 'smtpd' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$service ne "smtp" and $service ne "smtpd"
MC/DC0%0/2
$service ne "smtp" and $service ne "smtpd"
$service ne "smtp"
$service ne "smtpd"
Truth table0%0/3
A and B
A= $service ne "smtp"B= $service ne "smtpd"
| |||||||||||||||||||||||||||||
| 16 | 0 | return; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | if( my ($tlsLevel,$tlsHost, $tlsAddr, $tlsProto, $tlsCipher, $tlsKeylen) = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | if( defined $tls_params ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if( $service eq 'smtpd' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if( $message =~ /^connect from/ ) { # we missed the disconnect? | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 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' && | |||||||||||||||||||||||||||
|
Condition0%0/3
$service eq "smtp" and $message =~ /status=(sent|bounced|deferred)/
MC/DC0%0/2
$service eq "smtp" and $message =~ /status=(sent|bounced|deferred)/
$service eq "smtp"
$message =~ /status=(sent|bounced|deferred)/
Truth table0%0/3
A and B
A= $service eq "smtp"B= $message =~ /status=(sent|bounced|deferred)/
| |||||||||||||||||||||||||||||
| 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 | ▶ | if( defined $queue_id ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | $notes->set($service.'-tls-'.$queue_id, $tls_params); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | ▶ | } elsif( defined $queue_id && | |||||||||||||||||||||||||||
|
Condition0%0/3
defined $queue_id and defined($tls_params = $notes->get($service . '-tls-' . $queue_id))
MC/DC0%0/2
defined $queue_id and defined($tls_params = $notes->get($service . '-tls-' . $queue_id))
defined $queue_id
defined($tls_params = $notes->get($service . '-tls-' . $queue_id))
Truth table0%0/3
A and B
A= defined $queue_idB= defined($tls_params = $notes->get($service . '-tls-' . $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 | ▶ | my ( $self, $stash, $tls_params, @path ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
incr_tls_stats: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 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 | 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 | ||||||||||||||||||||||||||||