From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id iPjDKawju14sdwAA0tVLHw (envelope-from ) for ; Tue, 12 May 2020 22:31:08 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id YLAbC7sju17OawAA1q6Kng (envelope-from ) for ; Tue, 12 May 2020 22:31:23 +0000 Received: from arlo.cworth.org (unknown [50.126.95.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id CB673940F82 for ; Tue, 12 May 2020 22:31:20 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id DF7986DE14D4; Tue, 12 May 2020 15:30:33 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6LtqkeiNmHxf; Tue, 12 May 2020 15:30:33 -0700 (PDT) Received: from arlo.cworth.org (localhost [IPv6:::1]) by arlo.cworth.org (Postfix) with ESMTP id 8A84E6DE145F; Tue, 12 May 2020 15:30:08 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id A2AEC6DE13FF for ; Tue, 12 May 2020 15:30:03 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LTaDiU0I6Q0U for ; Tue, 12 May 2020 15:30:01 -0700 (PDT) Received: from che.mayfirst.org (unknown [162.247.75.117]) by arlo.cworth.org (Postfix) with ESMTPS id 44A136DE13EC for ; Tue, 12 May 2020 15:29:57 -0700 (PDT) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/simple; d=fifthhorseman.net; i=@fifthhorseman.net; q=dns/txt; s=2019; t=1589322596; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=6rsrf8+OopwUqDHjy0tGypw0QLrqVOdjeCUa0FvqGB4=; b=LdiOpHc6itJdaFxiXf1hznwp8U34dd3V1xc0jriIC8NIJnMQ6yqiYOEiXCBAVZgdCTjKN lax9+lqqBtZXvgKBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fifthhorseman.net; i=@fifthhorseman.net; q=dns/txt; s=2019rsa; t=1589322596; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=6rsrf8+OopwUqDHjy0tGypw0QLrqVOdjeCUa0FvqGB4=; b=I89qsnKnmlQQw9cmT/RbnmNUkXZOOSkBz5Sla3A8TRoBQk5c1ielxMLcDqxYlaxaLoUyj xu8/kdObKQb3V3B5a0EwEDHT9q5LF95N9YtT/suP4mTQP3za6zGgi5k3De0a7dGDRN9MF6u 59lvBbBP6Nh0MgPTLlMCpIcqHgmoTo52zIATLS2uQoD60JR+gyeAbIlUkK04Li0wUCTn9dT 1AyuFtXLpX7uMdq6rrsSCdx+A2QLxT7ZK+lAmwuTInND/X0gTpR4cOsxcJNBldq3ScQMNnA 9OpkpNYosJB3hkhTx8GLybIvGQhrJ4Ydj6NMS5rGNL1sU7R4tJ/CCyzCcfKA== Received: from fifthhorseman.net (unknown [108.58.6.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by che.mayfirst.org (Postfix) with ESMTPSA id E5F70F9AD for ; Tue, 12 May 2020 18:29:55 -0400 (EDT) Received: by fifthhorseman.net (Postfix, from userid 1000) id DCA6A209F9; Tue, 12 May 2020 18:29:51 -0400 (EDT) From: Daniel Kahn Gillmor To: Notmuch Mail Subject: [PATCH v2 3/9] cli: include wrapped part of PKCS#7 SignedData in the MIME tree Date: Tue, 12 May 2020 18:29:33 -0400 Message-Id: <20200512222939.372093-4-dkg@fifthhorseman.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200512222939.372093-1-dkg@fifthhorseman.net> References: <20200512222939.372093-1-dkg@fifthhorseman.net> MIME-Version: 1.0 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: notmuch-bounces@notmuchmail.org Sender: "notmuch" X-Scanner: scn0 X-Spam-Score: 4.59 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=fifthhorseman.net header.s=2019 header.b=LdiOpHc6; dkim=fail (body hash did not verify) header.d=fifthhorseman.net header.s=2019rsa header.b=I89qsnKn; dmarc=fail reason="SPF not aligned (relaxed)" header.from=fifthhorseman.net (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 50.126.95.6 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Scan-Result: default: False [4.59 / 13.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; RDNS_NONE(1.00)[]; GENERIC_REPUTATION(0.00)[-0.44776842672803]; FORGED_SENDER_MAILLIST(0.00)[]; DWL_DNSWL_BLOCKED(0.00)[50.126.95.6:from]; R_DKIM_REJECT(1.00)[fifthhorseman.net:s=2019,fifthhorseman.net:s=2019rsa]; IP_REPUTATION_HAM(0.00)[asn: 27017(-0.18), country: US(-0.00), ip: 50.126.95.6(-0.45)]; R_SPF_ALLOW(-0.20)[+a]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[fifthhorseman.net:-]; MX_GOOD(-0.50)[cached: notmuchmail.org]; MAILLIST(-0.20)[mailman]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:27017, ipnet:50.126.64.0/18, country:US]; FROM_NEQ_ENVFROM(0.00)[dkg@fifthhorseman.net,notmuch-bounces@notmuchmail.org]; RDNS_DNSFAIL(0.00)[]; ARC_NA(0.00)[]; URIBL_BLOCKED(0.00)[fifthhorseman.net:email,notmuchmail.org:email]; FROM_HAS_DN(0.00)[]; SPF_REPUTATION_HAM(0.00)[-0.4128827033031]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[notmuch@notmuchmail.org]; HAS_LIST_UNSUB(-0.01)[]; RCPT_COUNT_ONE(0.00)[1]; DNSWL_BLOCKED(0.00)[50.126.95.6:from]; MID_CONTAINS_FROM(1.00)[]; HFILTER_HOSTNAME_UNKNOWN(2.50)[]; RCVD_COUNT_SEVEN(0.00)[8]; DMARC_POLICY_SOFTFAIL(0.10)[fifthhorseman.net : SPF not aligned (relaxed),none] X-TUID: IqU+BYcqzima Unwrap a PKCS#7 SignedData part unconditionally when the cli is traversing the MIME tree, and return it as a "child" of what would otherwise be a leaf in the tree. Unfortunately, this also breaks the JSON output. We will fix that next. Signed-off-by: Daniel Kahn Gillmor --- mime-node.c | 23 +++++++++++++++++++++-- test/T355-smime.sh | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/mime-node.c b/mime-node.c index ff6805bf..b6431e3b 100644 --- a/mime-node.c +++ b/mime-node.c @@ -220,8 +220,17 @@ node_verify (mime_node_t *node, GMimeObject *part) notmuch_status_t status; node->verify_attempted = true; - node->sig_list = g_mime_multipart_signed_verify ( - GMIME_MULTIPART_SIGNED (part), GMIME_VERIFY_NONE, &err); + if (GMIME_IS_APPLICATION_PKCS7_MIME (part)) + node->sig_list = g_mime_application_pkcs7_mime_verify ( + GMIME_APPLICATION_PKCS7_MIME (part), GMIME_VERIFY_NONE, &node->unwrapped_child, &err); + else + node->sig_list = g_mime_multipart_signed_verify ( + GMIME_MULTIPART_SIGNED (part), GMIME_VERIFY_NONE, &err); + + if (node->unwrapped_child) { + node->nchildren = 1; + set_unwrapped_child_destructor (node); + } if (node->sig_list) set_signature_list_destructor (node); @@ -376,6 +385,12 @@ _mime_node_set_up_part (mime_node_t *node, GMimeObject *part, int numchild) } else { node_verify (node, part); } + } else if (GMIME_IS_APPLICATION_PKCS7_MIME (part) && + GMIME_SECURE_MIME_TYPE_SIGNED_DATA == g_mime_application_pkcs7_mime_get_smime_type (GMIME_APPLICATION_PKCS7_MIME (part))) { + /* If node->ctx->crypto->verify is false, it would be better + * to just unwrap (instead of verifying), but + * https://github.com/jstedfast/gmime/issues/67 */ + node_verify (node, part); } else { if (_notmuch_message_crypto_potential_payload (node->ctx->msg_crypto, part, node->parent ? node->parent->part : NULL, numchild) && node->ctx->msg_crypto->decryption_status == NOTMUCH_MESSAGE_DECRYPTED_FULL) { @@ -409,6 +424,10 @@ mime_node_child (mime_node_t *parent, int child) GMIME_MULTIPART (parent->part), child); } else if (GMIME_IS_MESSAGE (parent->part)) { sub = g_mime_message_get_mime_part (GMIME_MESSAGE (parent->part)); + } else if (GMIME_IS_APPLICATION_PKCS7_MIME (parent->part) && + parent->unwrapped_child && + child == 0) { + sub = parent->unwrapped_child; } else { /* This should have been caught by _mime_node_set_up_part */ INTERNAL_ERROR ("Unexpected GMimeObject type: %s", diff --git a/test/T355-smime.sh b/test/T355-smime.sh index 7c28282a..4de0fbef 100755 --- a/test/T355-smime.sh +++ b/test/T355-smime.sh @@ -142,7 +142,6 @@ expected='#notmuch-dump batch-tag:3 config,properties,tags test_expect_equal "$expected" "$output" test_begin_subtest "show contents of PKCS#7 SignedData message" -test_subtest_known_broken output=$(notmuch show --format=raw --part=2 id:smime-onepart-signed@protected-headers.example) whitespace=' ' expected="Bob, we need to cancel this contract. @@ -178,6 +177,7 @@ On Tue, 26 Nov 2019 20:11:29 -0400, Alice Lovelace wrote: test_expect_equal "$expected" "$output" test_begin_subtest "show PKCS#7 SignedData outputs valid JSON" +test_subtest_known_broken output=$(notmuch show --format=json id:smime-onepart-signed@protected-headers.example) test_valid_json "$output" -- 2.26.2