Skip to content

Commit 5f06293

Browse files
authored
Merge pull request #1869 from ikedas/issue-1851_ikedas-02 by ikedas
Several fixes/improvements on ARC seal & DKIM signature
2 parents 9ddb11e + c9903ac commit 5f06293

File tree

8 files changed

+212
-270
lines changed

8 files changed

+212
-270
lines changed

Diff for: src/lib/Sympa/Internals/Workflow.pod

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ workflow of Sympa. For more details see documentation on each class.
4141
/ v
4242
Incoming => [ProcessIncoming] *2
4343
\ +-> (reject)
44-
+-> [DoForward] => (Mailer) /
44+
+-> [DoForward] => Outgoing /
4545
\ +-> [ToEditor] => Outgoing
4646
+-> [DoMessage] /
4747
\ /---> [ToHeld] => Held

Diff for: src/lib/Sympa/Message.pm

+8-2
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,14 @@ sub arc_seal {
544544
$log->syslog('err', 'Can\'t create Mail::DKIM::ARC::Signer');
545545
return undef;
546546
}
547-
# For One-Click Unsubscribe.
548-
$arc->extended_headers({'List-Unsubscribe-Post' => '*'});
547+
$arc->extended_headers(
548+
{
549+
# For any DKIM signature(s). See RFC 8617, 4.1.2.
550+
'DKIM-Signature' => '*',
551+
# For One-Click Unsubscribe.
552+
'List-Unsubscribe-Post' => '*',
553+
}
554+
);
549555

550556
# $new_body will store the body as fed to Mail::DKIM to reuse it
551557
# when returning the message as string. Line terminators must be

Diff for: src/lib/Sympa/Spindle/AuthorizeMessage.pm

+10-21
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
88
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
99
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
10-
# Copyright 2018, 2019, 2021, 2022 The Sympa Community. See the
10+
# Copyright 2018, 2019, 2021, 2022, 2024 The Sympa Community. See the
1111
# AUTHORS.md file at the top-level directory of this distribution and at
1212
# <https://github.com/sympa-community/sympa.git>.
1313
#
@@ -34,7 +34,6 @@ use Sympa::List;
3434
use Sympa::Log;
3535
use Sympa::Scenario;
3636
use Sympa::Spool::Topic;
37-
use Sympa::Tools::Data;
3837

3938
use base qw(Sympa::Spindle);
4039

@@ -163,31 +162,21 @@ sub _twist {
163162
if ($action =~ /^do_it\b/) {
164163
$self->{quiet} ||= ($action =~ /,\s*quiet\b/); # Overwrite.
165164

165+
my @apply_on =
166+
@{$list->{'admin'}{'dkim_signature_apply_on'} || []};
166167
unless ($self->{confirmed_by}) { # Not in ProcessHeld spindle.
167168
$message->{shelved}{dkim_sign} = 1
168-
if Sympa::Tools::Data::is_in_array(
169-
$list->{'admin'}{'dkim_signature_apply_on'}, 'any')
170-
or (
171-
Sympa::Tools::Data::is_in_array(
172-
$list->{'admin'}{'dkim_signature_apply_on'},
173-
'smime_authenticated_messages')
174-
and $message->{'smime_signed'}
175-
)
176-
or (
177-
Sympa::Tools::Data::is_in_array(
178-
$list->{'admin'}{'dkim_signature_apply_on'},
179-
'dkim_authenticated_messages')
180-
and $message->{'dkim_pass'}
181-
);
169+
if grep { 'any' eq $_ } @apply_on
170+
or (grep { 'smime_authenticated_messages' eq $_ } @apply_on
171+
and $message->{'smime_signed'})
172+
or (grep { 'dkim_authenticated_messages' eq $_ } @apply_on
173+
and $message->{'dkim_pass'});
182174
} else {
183175
$message->add_header('X-Validation-by', $self->{confirmed_by});
184176

185177
$message->{shelved}{dkim_sign} = 1
186-
if Sympa::Tools::Data::is_in_array(
187-
$list->{'admin'}{'dkim_signature_apply_on'}, 'any')
188-
or Sympa::Tools::Data::is_in_array(
189-
$list->{'admin'}{'dkim_signature_apply_on'},
190-
'md5_authenticated_messages');
178+
if grep { 'any' eq $_ } @apply_on
179+
or grep { 'md5_authenticated_messages' eq $_ } @apply_on;
191180
}
192181

193182
# Keep track of known message IDs...if any.

Diff for: src/lib/Sympa/Spindle/DoForward.pm

+27-18
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,16 @@ sub _twist {
4747
# Fail-safe: Skip messages with unwanted types.
4848
return 0 unless $self->_splicing_to($message) eq __PACKAGE__;
4949

50-
my ($list, $robot, $arc_enabled);
50+
my ($list, $robot);
5151
if (ref $message->{context} eq 'Sympa::List') {
52-
$list = $message->{context};
53-
$robot = $list->{'domain'};
54-
$arc_enabled = 'on' eq $list->{'admin'}{'arc_feature'};
52+
$list = $message->{context};
53+
$robot = $message->{context}->{'domain'};
5554
} elsif ($message->{context} and $message->{context} ne '*') {
5655
$robot = $message->{context};
57-
$arc_enabled = 'on' eq Conf::get_robot_conf($robot, 'arc_feature');
5856
} else {
59-
$robot = $Conf::Conf{'domain'};
60-
$arc_enabled = 'on' eq $Conf::Conf{'arc_feature'};
57+
$robot = '*';
6158
}
59+
6260
my $function = $message->{listtype};
6361
my $recipient = Sympa::get_address($message->{context}, $function);
6462

@@ -153,30 +151,41 @@ sub _twist {
153151
return undef;
154152
}
155153

154+
my (@apply_on, @protection);
155+
if (ref $list eq 'Sympa::List') {
156+
@apply_on =
157+
@{$list->{'admin'}{'dkim_signature_apply_on'} || []};
158+
@protection = @{$list->{'admin'}{'dmarc_protection'}{'mode'} || []};
159+
} else {
160+
@apply_on =
161+
@{Conf::get_robot_conf($robot, 'dkim_signature_apply_on') || []};
162+
@protection =
163+
@{Conf::get_robot_conf($robot, 'dmarc_protection.mode') || []};
164+
}
165+
$message->{shelved}{dkim_sign} = 1
166+
if grep { 'any' eq $_ } @apply_on
167+
or (grep { 'smime_authenticated_messages' eq $_ } @apply_on
168+
and $message->{'smime_signed'})
169+
or (grep { 'dkim_authenticated_messages' eq $_ } @apply_on
170+
and $message->{'dkim_pass'});
171+
172+
$message->{shelved}{dmarc_protect} = 1
173+
if grep { $_ and 'none' ne $_ } @protection;
174+
156175
# Add or remove several headers to forward message safely.
157176
# - Add X-Loop: field to mitigate mail looping.
158177
# - The Sender: field should be added (overwritten) at least for Sender ID
159178
# (a.k.a. SPF 2.0) compatibility. Note that Resent-Sender: field will
160179
# be removed.
161180
# - Add ARC seal if enabled, or try applying DMARC protection.
162-
#FIXME: Existing DKIM signature depends on these headers will be broken.
163-
#FIXME: Currently messages via -request and -editor addresses will be
164-
# protected against DMARC if neccessary. The listmaster address
165-
# would be protected, too.
166181
$message->add_header('X-Loop', $recipient);
167182
$message->replace_header('Sender', Sympa::get_address($robot, 'owner'));
168183
$message->delete_header('Resent-Sender');
169-
my %arc =
170-
Sympa::Tools::DKIM::get_arc_parameters($message->{context},
171-
$message->{shelved}{arc_cv})
172-
if $arc_enabled and $message->{shelved}{arc_cv};
173-
my $arc_sealed = $message->arc_seal(%arc) if %arc;
174-
$message->dmarc_protect unless $arc_sealed;
175184

176185
# Overwrite envelope sender. It is REQUIRED for delivery.
177186
$message->{envelope_sender} = Sympa::get_address($robot, 'owner');
178187

179-
unless (defined Sympa::Mailer->instance->store($message, \@rcpt)) {
188+
unless (defined Sympa::Spool::Outgoing->new->store($message, [@rcpt])) {
180189
$log->syslog('err', 'Impossible to forward mail for %s', $recipient);
181190
Sympa::send_notify_to_listmaster(
182191
$message->{context} || '*',

Diff for: src/lib/Sympa/Spindle/ProcessModeration.pm

+9-8
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
99
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
1010
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
11-
# Copyright 2017 The Sympa Community. See the AUTHORS.md file at the top-level
12-
# directory of this distribution and at
11+
# Copyright 2017, 2024 The Sympa Community. See the
12+
# AUTHORS.md file at the top-level directory of this distribution and at
1313
# <https://github.com/sympa-community/sympa.git>.
1414
#
1515
# This program is free software; you can redistribute it and/or modify
@@ -34,7 +34,6 @@ use Sympa;
3434
use Conf;
3535
use Sympa::Language;
3636
use Sympa::Log;
37-
use Sympa::Tools::Data;
3837

3938
use base qw(Sympa::Spindle);
4039

@@ -191,12 +190,14 @@ sub _distribute {
191190

192191
$message->add_header('X-Validation-by', $self->{distributed_by});
193192

193+
my @apply_on = @{$list->{'admin'}{'dkim_signature_apply_on'} || []};
194194
$message->{shelved}{dkim_sign} = 1
195-
if Sympa::Tools::Data::is_in_array(
196-
$list->{'admin'}{'dkim_signature_apply_on'}, 'any')
197-
or Sympa::Tools::Data::is_in_array(
198-
$list->{'admin'}{'dkim_signature_apply_on'},
199-
'editor_validated_messages');
195+
if grep { 'any' eq $_ } @apply_on
196+
or (grep { 'smime_authenticated_messages' eq $_ } @apply_on
197+
and $message->{'smime_signed'})
198+
or (grep { 'dkim_authenticated_messages' eq $_ } @apply_on
199+
and $message->{'dkim_pass'})
200+
or grep { 'editor_validated_messages' eq $_ } @apply_on;
200201

201202
# Notify author of message.
202203
$message->{envelope_sender} = $message->{sender};

0 commit comments

Comments
 (0)