]> git.notmuchmail.org Git - notmuch/blob - test/T356-protected-headers.sh
test: after reindexing, only legitimate protected subjects are searchable
[notmuch] / test / T356-protected-headers.sh
1 #!/usr/bin/env bash
2
3 # TODO:
4 #  * check S/MIME as well as PGP/MIME
5
6 test_description='Message decryption with protected headers'
7 . $(dirname "$0")/test-lib.sh || exit 1
8
9 ##################################################
10
11 add_gnupg_home
12
13 add_email_corpus protected-headers
14
15 test_begin_subtest "verify protected header is not visible without decryption"
16 output=$(notmuch show --format=json id:protected-header@crypto.notmuchmail.org)
17 test_json_nodes <<<"$output" \
18                 'no_crypto_info:[0][0][0]["crypto"]={}' \
19                 'subject:[0][0][0]["headers"]["Subject"]="Subject Unavailable"'
20
21 test_begin_subtest "verify protected header is visible with decryption"
22 output=$(notmuch show --decrypt=true --format=json id:protected-header@crypto.notmuchmail.org)
23 test_json_nodes <<<"$output" \
24                 'crypto:[0][0][0]["crypto"]={"decrypted": {"status": "full", "header-mask": {"Subject": "Subject Unavailable"}}}' \
25                 'subject:[0][0][0]["headers"]["Subject"]="This is a protected header"'
26
27 test_begin_subtest "when no external header is present, show masked subject as null"
28 output=$(notmuch show --decrypt=true --format=json id:subjectless-protected-header@crypto.notmuchmail.org)
29 test_json_nodes <<<"$output" \
30                 'crypto:[0][0][0]["crypto"]={"decrypted": {"status": "full", "header-mask": {"Subject": null}}}' \
31                 'subject:[0][0][0]["headers"]["Subject"]="This is a protected header"'
32
33 test_begin_subtest "misplaced protected headers should not be made visible during decryption"
34 output=$(notmuch show --decrypt=true --format=json id:misplaced-protected-header@crypto.notmuchmail.org)
35 test_json_nodes <<<"$output" \
36                 'crypto:[0][0][0]["crypto"]={"decrypted": {"status": "full"}}' \
37                 'subject:[0][0][0]["headers"]["Subject"]="Subject Unavailable"'
38
39 test_begin_subtest "verify double-wrapped phony protected header is not visible when inner decryption fails"
40 output=$(notmuch show --decrypt=true --format=json id:double-wrapped-with-phony-protected-header@crypto.notmuchmail.org)
41 test_json_nodes <<<"$output" \
42                 'crypto:[0][0][0]["crypto"]={"decrypted": {"status": "full"}}' \
43                 'subject:[0][0][0]["headers"]["Subject"]="Subject Unavailable"'
44
45 test_begin_subtest "cleartext phony protected headers should not be made visible when decryption fails"
46 output=$(notmuch show --decrypt=true --format=json id:phony-protected-header-bad-encryption@crypto.notmuchmail.org)
47 test_json_nodes <<<"$output" \
48                 'no_crypto_info:[0][0][0]["crypto"]={}' \
49                 'subject:[0][0][0]["headers"]["Subject"]="Subject Unavailable"'
50
51 test_begin_subtest "wrapped protected headers should not be made visible during decryption"
52 output=$(notmuch show --decrypt=true --format=json id:wrapped-protected-header@crypto.notmuchmail.org)
53 test_json_nodes <<<"$output" \
54                 'crypto:[0][0][0]["crypto"]={"decrypted": {"status": "partial"}}' \
55                 'subject:[0][0][0]["headers"]["Subject"]="[mailing-list] Subject Unavailable"'
56
57 test_begin_subtest "internal headers without protected-header attribute should be skipped"
58 output=$(notmuch show --decrypt=true --format=json id:no-protected-header-attribute@crypto.notmuchmail.org)
59 test_json_nodes <<<"$output" \
60                 'crypto:[0][0][0]["crypto"]={"decrypted": {"status": "full"}}' \
61                 'subject:[0][0][0]["headers"]["Subject"]="Subject Unavailable"'
62
63 test_begin_subtest "verify nested message/rfc822 protected header is visible"
64 output=$(notmuch show --decrypt=true --format=json id:nested-rfc822-message@crypto.notmuchmail.org)
65 test_json_nodes <<<"$output" \
66                 'crypto:[0][0][0]["crypto"]={"decrypted": {"status": "full", "header-mask": {"Subject": "Subject Unavailable"}}}' \
67                 'subject:[0][0][0]["headers"]["Subject"]="This is a message using draft-melnikov-smime-header-signing"'
68
69 test_begin_subtest "show cryptographic envelope on signed mail"
70 output=$(notmuch show --verify --format=json id:simple-signed-mail@crypto.notmuchmail.org)
71 test_json_nodes <<<"$output" \
72                 'crypto:[0][0][0]["crypto"]={"signed": {"status": [{"created": 1525609971, "fingerprint": "'$FINGERPRINT'", "userid": "'"$SELF_USERID"'", "status": "good"}]}}'
73
74 test_begin_subtest "verify signed protected header"
75 output=$(notmuch show --verify --format=json id:signed-protected-header@crypto.notmuchmail.org)
76 test_json_nodes <<<"$output" \
77                 'crypto:[0][0][0]["crypto"]={"signed": {"status": [{"created": 1525350527, "fingerprint": "'$FINGERPRINT'", "userid": "'"$SELF_USERID"'", "status": "good"}], "headers": ["Subject"]}}'
78
79 test_begin_subtest "protected subject does not leak by default in replies"
80 output=$(notmuch reply --decrypt=true --format=json id:protected-header@crypto.notmuchmail.org)
81 test_json_nodes <<<"$output" \
82                 'crypto:["original"]["crypto"]={"decrypted": {"status": "full", "header-mask": {"Subject": "Subject Unavailable"}}}' \
83                 'subject:["original"]["headers"]["Subject"]="This is a protected header"' \
84                 'reply-subject:["reply-headers"]["Subject"]="Re: Subject Unavailable"'
85
86 test_begin_subtest "protected subject is not indexed by default"
87 output=$(notmuch search --output=messages 'subject:"This is a protected header"')
88 test_expect_equal "$output" ''
89
90 test_begin_subtest "reindex message with protected header"
91 test_expect_success 'notmuch reindex --decrypt=true id:protected-header@crypto.notmuchmail.org'
92
93 test_begin_subtest "protected subject is indexed when cleartext is indexed"
94 output=$(notmuch search --output=messages 'subject:"This is a protected header"')
95 test_expect_equal "$output" 'id:protected-header@crypto.notmuchmail.org'
96
97 test_begin_subtest "indexed protected subject is visible in search"
98 output=$(notmuch search --format=json 'id:protected-header@crypto.notmuchmail.org')
99 test_json_nodes <<<"$output" \
100                 'subject:[0]["subject"]="This is a protected header"'
101
102 test_begin_subtest "verify protected header is both signed and encrypted"
103 output=$(notmuch show --decrypt=true --format=json id:encrypted-signed@crypto.notmuchmail.org)
104 test_json_nodes <<<"$output" \
105                 'crypto:[0][0][0]["crypto"]={
106                    "signed":{"status": [{"status": "good", "fingerprint": "'$FINGERPRINT'", "userid": "'"$SELF_USERID"'", "created": 1525812676}],
107                    "encrypted": true, "headers": ["Subject"]},"decrypted": {"status": "full", "header-mask": {"Subject": "Subject Unavailable"}}}' \
108                 'subject:[0][0][0]["headers"]["Subject"]="Rhinoceros dinner"'
109
110 test_begin_subtest "verify protected header is signed even when not masked"
111 output=$(notmuch show --decrypt=true --format=json id:encrypted-signed-not-masked@crypto.notmuchmail.org)
112 test_json_nodes <<<"$output" \
113                 'crypto:[0][0][0]["crypto"]={
114                    "signed":{"status": [{"status": "good", "fingerprint": "'$FINGERPRINT'", "userid": "'"$SELF_USERID"'", "created": 1525812676}],
115                    "encrypted": true, "headers": ["Subject"]},"decrypted": {"status": "full"}}' \
116                 'subject:[0][0][0]["headers"]["Subject"]="Rhinoceros dinner"'
117
118 test_begin_subtest "reindex everything, ensure headers are as expected"
119 notmuch reindex --decrypt=true from:test_suite@notmuchmail.org
120 output=$(notmuch search --output=messages 'subject:"protected header" or subject:"Rhinoceros" or subject:"draft-melnikov-smime-header-signing" or subject:"valid"' | sort)
121 test_expect_equal "$output" 'id:encrypted-signed-not-masked@crypto.notmuchmail.org
122 id:encrypted-signed@crypto.notmuchmail.org
123 id:nested-rfc822-message@crypto.notmuchmail.org
124 id:protected-header@crypto.notmuchmail.org
125 id:subjectless-protected-header@crypto.notmuchmail.org'
126
127 test_done