From 96614ad6830ae849e84a4e37efbae0728352e3a9 Mon Sep 17 00:00:00 2001 From: IKEDA Soji Date: Wed, 12 Feb 2020 15:31:34 +0900 Subject: [PATCH] Unreasonable error message to notify broken signature in the message, if the messages signed with PGP/MIME was posted. --- src/lib/Sympa/Message.pm | 58 ++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/src/lib/Sympa/Message.pm b/src/lib/Sympa/Message.pm index 6e932a03c..306a42b34 100644 --- a/src/lib/Sympa/Message.pm +++ b/src/lib/Sympa/Message.pm @@ -1286,20 +1286,7 @@ sub check_smime_signature { my $self = shift; return 0 unless $Crypt::SMIME::VERSION; - my $content_type = lc($self->{_head}->mime_attr('Content-Type') || ''); - unless ( - $content_type eq 'multipart/signed' - or (( $content_type eq 'application/pkcs7-mime' - or $content_type eq 'application/x-pkcs7-mime' - ) - and Sympa::Tools::Data::smart_eq( - $self->{_head}->mime_attr('Content-Type.smime-type'), - qr/signed-data/i - ) - ) - ) { - return 0; - } + return 0 unless $self->is_signed; ## Messages that should not be altered (no footer) $self->{'protected'} = 1; @@ -1380,6 +1367,24 @@ sub check_smime_signature { return 1; } +sub is_signed { + my $self = shift; + + my $content_type = lc($self->head->mime_attr('Content-Type') // ''); + my $protocol = lc($self->head->mime_attr('Content-Type.protocol') // ''); + my $smime_type = + lc($self->head->mime_attr('Content-Type.smime-type') // ''); + return 1 + if $content_type eq 'multipart/signed' + and ($protocol eq 'application/pkcs7-signature' + or $protocol eq 'application/x-pkcs7-signature'); + return 1 + if ($content_type eq 'application/pkcs7-mime' + or $content_type eq 'application/x-pkcs7-mime') + and $smime_type eq 'signed-data'; + return 0; +} + # Old name: Bulk::merge_msg() sub personalize { my $self = shift; @@ -3874,6 +3879,31 @@ Returns: 0 otherwise. C if something went wrong. +=item is_signed ( ) + +I. +Checks if the message is signed. + +B: +This checks if the message has appropriate content type and +header parameters. Use check_smime_signature() to check if the message has +properly signed content. + +Currently, S/MIME-signed messages with content type +"multipart/signed" or "application/pkcs7-mime" (with smime-type="signed-data" +parameter) are recognized. +Enveloped-only messages are not supported. +The other signature mechanisms such as PGP/MIME have not been supported yet. + +Parameters: + +None. + +Returns: + +C<1> if the message is considered signed. +C<0> otherwise. + =item personalize ( $list, [ $rcpt ], [ $data ] ) I.