interplane.Get Omega
Read in your language

mailhand

mailhand: agents look after a person's email in seeded Omega. Maildir + MIME parsing, JSONL CLI and MCP, rule triage, policy-gated sending, hash-chained audit. Free (Apache-2.0).

Brought by drakestapleton

branch main Branches Tags History

mailhand / tests / scenarios / 70-smtp-tls.txt

186 lines · 11038 bytes Raw Blame History
1# SMTP submission over TLS (SmtpTls, src/ss.om) against the fake SMTP server "srv smtp"
2# (tests/srv/smtp.om) over real TLS 1.3 (omtls from DEPS; host mail.test, the omtls test certificates). Config "smtp account:work" names the account whose smtp line
3# is submission://HOST:587 (STARTTLS) or smtps://HOST:465 (implicit TLS). The send gate (policy,
4# exact-draft approval, audit) is unchanged and runs before any connection; every failure before the
5# TLS handshake completes aborts, so AUTH and MAIL never travel in plaintext (the server logs
6# "PLAINTEXT AUTH" / "PLAINTEXT MAIL" if they ever did). Draft shas as in 30-send: plain 8ae0c21f..,
7# two f995de68... The TLS failure texts checked on stderr are omtls's (ot_tl_why).
8mkdir @S/Mail
9mkdir @S/c
10run 0 - -- mh setup --home @S/h --maildir @S/Mail --me alice@example.org --name Alice
11append @S/h/config smtp account:work\naccounts @S/c/accounts\n
12copy tests/fixtures/send/plain.eml @S/h/drafts/8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb.eml
13append @S/h/approvals 8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb 1762862400\n
14run 0 - -- mh queue-send --home @S/h --draft 8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb
15out-has "gate":"approved"
16#
17# policy_refused_no_connection: the approval is withdrawn after queueing; deliver re-runs the gate,
18# refuses, and the server (which fails if any connection arrives within 3 s) sees none
19write @S/h/approvals \n
20mkdir @S/k0
21write @S/k0/state user alice@example.org\npass s3cret-SYNTH-pw\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
22bg srv smtp @S/k0 sub 0
23run 0 - -- srv acct @S/c/accounts @S/k0 work submission mail.test alice@example.org s3cret-SYNTH-pw 600
24run 3 - -- mh deliver --home @S/h
25out-has "op":"deliver","ok":false
26wait 0
27file-eq @S/k0/conns tests/fixtures/imap/zero.txt
28absent @S/k0/log
29append @S/h/approvals 8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb 1762862400\n
30#
31# no_starttls: the server does not offer STARTTLS: abort after the plaintext EHLO (exit 8, queued)
32mkdir @S/k1
33write @S/k1/state user alice@example.org\npass s3cret-SYNTH-pw\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
34bg srv smtp @S/k1 nostarttls 1
35run 0 - -- srv acct @S/c/accounts @S/k1 work submission mail.test alice@example.org s3cret-SYNTH-pw 600
36run 8 - -- mh deliver --home @S/h
37out-has "why":"smtp_failed"
38err-has smtp: server does not offer STARTTLS: aborted before any credential or mail was sent
39wait 0
40file-not @S/k1/log AUTH
41file-not @S/k1/log MAIL
42exists @S/h/outbox/8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb.eml
43#
44# starttls_454: STARTTLS refused by the server: abort
45mkdir @S/k2
46write @S/k2/state user alice@example.org\npass s3cret-SYNTH-pw\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
47bg srv smtp @S/k2 tls454 1
48run 0 - -- srv acct @S/c/accounts @S/k2 work submission mail.test alice@example.org s3cret-SYNTH-pw 600
49run 8 - -- mh deliver --home @S/h
50err-has smtp: STARTTLS refused by the server: aborted before any credential or mail was sent
51wait 0
52file-not @S/k2/log AUTH
53file-not @S/k2/log MAIL
54#
55# starttls_injection: plaintext bytes sent together with the "220" go-ahead are refused (they would
56# be read as if they had come over TLS)
57mkdir @S/k3
58write @S/k3/state user alice@example.org\npass s3cret-SYNTH-pw\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
59bg srv smtp @S/k3 inject 1
60run 0 - -- srv acct @S/c/accounts @S/k3 work submission mail.test alice@example.org s3cret-SYNTH-pw 600
61run 8 - -- mh deliver --home @S/h
62err-has smtp: bytes arrived before the TLS handshake (refused)
63wait 0
64file-not @S/k3/log AUTH
65file-not @S/k3/log MAIL
66#
67# plaintext_after_starttls: the server answers 220, then answers the ClientHello with a plaintext SMTP line:
68# the handshake fails (unexpected message) and nothing more is sent
69mkdir @S/k4
70write @S/k4/state user alice@example.org\npass s3cret-SYNTH-pw\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
71bg srv smtp @S/k4 plainafter 1
72run 0 - -- srv acct @S/c/accounts @S/k4 work submission mail.test alice@example.org s3cret-SYNTH-pw 600
73run 8 - -- mh deliver --home @S/h
74err-has smtp: TLS:
75err-has smtp: TLS: unexpected message
76wait 0
77file-not @S/k4/log AUTH
78file-not @S/k4/log MAIL
79#
80# auth_refused: 535 after AUTH PLAIN over TLS: no MAIL, the draft stays queued
81mkdir @S/k5
82write @S/k5/state user alice@example.org\npass s3cret-SYNTH-pw\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
83bg srv smtp @S/k5 authfail 1
84run 0 - -- srv acct @S/c/accounts @S/k5 work submission mail.test alice@example.org s3cret-SYNTH-pw 600
85run 8 - -- mh deliver --home @S/h
86err-has smtp: authentication refused by the server
87wait 0
88file-has @S/k5/log TLS OK
89file-has @S/k5/log AUTH REFUSED
90file-not @S/k5/log PLAINTEXT
91file-not @S/k5/log MAIL
92#
93# no_auth_plain: the server offers AUTH LOGIN only: abort
94mkdir @S/k6
95write @S/k6/state user alice@example.org\npass s3cret-SYNTH-pw\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
96bg srv smtp @S/k6 noplain 1
97run 0 - -- srv acct @S/c/accounts @S/k6 work submission mail.test alice@example.org s3cret-SYNTH-pw 600
98run 8 - -- mh deliver --home @S/h
99err-has smtp: server does not offer AUTH PLAIN
100wait 0
101file-not @S/k6/log AUTH
102#
103# refused handshakes (real TLS 1.3, omtls): another name (STARTTLS), expired (smtps), an untrusted root
104# (STARTTLS). Each is a defined refusal (exit 8, the draft stays queued) with the omtls reason on
105# stderr; the server log shows the TLS failure and no AUTH and no MAIL.
106mkdir @S/q1
107write @S/q1/state user alice@example.org\npass s3cret-SYNTH-pw\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-other.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
108bg srv smtp @S/q1 sub 1
109run 0 - -- srv acct @S/c/accounts @S/q1 work submission mail.test alice@example.org s3cret-SYNTH-pw 600
110run 8 - -- mh deliver --home @S/h
111err-has smtp: TLS: certificate does not match the host name
112wait 0
113file-has @S/q1/log TLS FAILED
114file-not @S/q1/log AUTH
115file-not @S/q1/log MAIL
116exists @S/h/outbox/8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb.eml
117mkdir @S/q2
118write @S/q2/state user alice@example.org\npass s3cret-SYNTH-pw\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-expired.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
119bg srv smtp @S/q2 smtps 1
120run 0 - -- srv acct @S/c/accounts @S/q2 work smtps mail.test alice@example.org s3cret-SYNTH-pw 600
121run 8 - -- mh deliver --home @S/h
122err-has smtp: TLS: certificate expired or not yet valid
123wait 0
124file-has @S/q2/log TLS FAILED
125file-not @S/q2/log AUTH
126file-not @S/q2/log MAIL
127mkdir @S/q3
128write @S/q3/state user alice@example.org\npass s3cret-SYNTH-pw\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-untrusted.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
129bg srv smtp @S/q3 sub 1
130run 0 - -- srv acct @S/c/accounts @S/q3 work submission mail.test alice@example.org s3cret-SYNTH-pw 600
131run 8 - -- mh deliver --home @S/h
132err-has smtp: TLS: certificate not issued by a trusted root
133wait 0
134file-has @S/q3/log TLS FAILED
135file-not @S/q3/log AUTH
136file-not @S/q3/log MAIL
137#
138# roots_missing: a trust store that cannot be loaded is refused before any connection (the server,
139# which fails when any connection arrives within 3 s, sees none)
140mkdir @S/q4
141write @S/q4/state user alice@example.org\npass s3cret-SYNTH-pw\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @S/no-such-roots.pem\n
142bg srv smtp @S/q4 sub 0
143run 0 - -- srv acct @S/c/accounts @S/q4 work submission mail.test alice@example.org s3cret-SYNTH-pw 600
144run 8 - -- mh deliver --home @S/h
145err-has smtp: trust store could not be loaded
146wait 0
147file-eq @S/q4/conns tests/fixtures/imap/zero.txt
148#
149# starttls_sent: STARTTLS, EHLO again, AUTH PLAIN over TLS, then the exact draft bytes are delivered
150mkdir @S/k7
151write @S/k7/state user alice@example.org\npass s3cret-SYNTH-pw\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
152bg srv smtp @S/k7 sub 1
153run 0 - -- srv acct @S/c/accounts @S/k7 work submission mail.test alice@example.org s3cret-SYNTH-pw 600
154run 0 - -- mh deliver --home @S/h
155out-has "op":"deliver","ok":true,"why":"sent"
156out-not s3cret
157err-not s3cret
158wait 0
159file-eq @S/k7/1.eml tests/fixtures/send/plain.eml
160file-has @S/k7/1.env RCPT TO:<friend@example.org>
161file-has @S/k7/log TLS OK
162file-has @S/k7/log AUTH OK
163file-has @S/k7/log MAIL FROM:<alice@example.org>
164file-not @S/k7/log PLAINTEXT
165absent @S/h/outbox/8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb.eml
166#
167# smtps_sent: implicit TLS on the smtps endpoint; both recipients
168copy tests/fixtures/send/two.eml @S/h/drafts/f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464.eml
169append @S/h/approvals f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464 1762862400\n
170run 0 - -- mh queue-send --home @S/h --draft f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464
171mkdir @S/k8
172write @S/k8/state user alice@example.org\npass s3cret-SYNTH-pw\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
173bg srv smtp @S/k8 smtps 1
174run 0 - -- srv acct @S/c/accounts @S/k8 work smtps mail.test alice@example.org s3cret-SYNTH-pw 600
175run 0 - -- mh deliver --home @S/h
176out-has "why":"sent"
177wait 0
178file-eq @S/k8/1.eml tests/fixtures/send/two.eml
179file-has @S/k8/log TLS OK
180file-not @S/k8/log PLAINTEXT
181#
182# credential_leak_scan: no password and no AUTH PLAIN blob in anything mailhand wrote
183tree-not @S/h s3cret-SYNTH-pw
184tree-not @S/h AGFsaWNlQGV4YW1wbGUub3JnAHMzY3JldC1TWU5USC1wdw==
185tree-not @S/Mail s3cret-SYNTH-pw
186file-has @S/h/sent.log 8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb