]> git.proxmox.com Git - pmg-api.git/commitdiff
Don't add DKIM signature without domain
authorStoiko Ivanov <s.ivanov@proxmox.com>
Fri, 22 Nov 2019 09:40:57 +0000 (10:40 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 22 Nov 2019 11:32:47 +0000 (12:32 +0100)
When the DKIMSign module fails to determine the domain for signing
(the one added to the header and used for retrieving the publickey record)
the code logs that no signing will take place, but only does not set the
domain - resulting in a generated and added signature with domain 'example.com'

Fixed by returning the success-status from signing_domain and only signing if
it was successful.

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
src/PMG/DKIMSign.pm

index 11079593f54c19bd08b27c048b69f9be9a5e1a8d..5810cea339cec7052ff36a2eefa0720c66b56bd7 100644 (file)
@@ -61,7 +61,7 @@ sub signing_domain {
 
     if ($self->{sign_all}) {
            $self->domain($input_domain) if $self->{sign_all};
-           return;
+           return 1;
     }
 
     # check that input_domain is in/a subdomain of in the
@@ -72,13 +72,13 @@ sub signing_domain {
     foreach my $domain (sort keys %$dkimdomains) {
        if ( $input_domain =~ /\Q$domain\E$/i ) {
            $self->domain($domain);
-           return;
+           return 1;
        }
     }
 
     syslog('info', "not DKIM signing mail from $sender_email");
 
-    return;
+    return 0;
 }
 
 
@@ -107,11 +107,12 @@ sub sign_entity {
     my $signer = __PACKAGE__->new($selector, $sign_all);
 
     $signer->extended_headers($extended_headers);
-    $signer->signing_domain($sender);
 
-    $entity->print($signer);
-    my $signature = $signer->create_signature();
-    $entity->head->add('DKIM-Signature', $signature, 0);
+    if ($signer->signing_domain($sender)) {
+       $entity->print($signer);
+       my $signature = $signer->create_signature();
+       $entity->head->add('DKIM-Signature', $signature, 0);
+    }
 
     return $entity;