Debian Codegraph @

test/functional/cases/320_arc_signing/003_roundtrip.robot

raw
1 *** Settings ***
2 Suite Setup Rspamd Setup
3 Suite Teardown Rspamd Teardown
4 Library ${RSPAMD_TESTDIR}/lib/rspamd.py
5 Library String
6 Resource ${RSPAMD_TESTDIR}/lib/rspamd.robot
7 Variables ${RSPAMD_TESTDIR}/lib/vars.py
8
9 *** Variables ***
10 ${CONFIG} ${RSPAMD_TESTDIR}/configs/arc_signing/roundtrip.conf
11 ${MESSAGE_RSA} ${RSPAMD_TESTDIR}/messages/dmarc/fail_none.eml
12 ${MESSAGE_ED25519} ${RSPAMD_TESTDIR}/messages/dmarc/ed25519_from.eml
13 ${REDIS_SCOPE} Suite
14 ${RSPAMD_SCOPE} Suite
15 ${RSPAMD_URL_TLD} ${RSPAMD_TESTDIR}/../lua/unit/test_tld.dat
16
17 *** Test Cases ***
18 ARC ROUNDTRIP RSA SIGN AND VERIFY
19 # First pass: Sign the message with RSA key and check for ARC_SIGNED
20 ${result} = Scan Message With Rspamc ${MESSAGE_RSA} -u [email protected] --mime
21 Should Contain ${result.stdout} ARC_SIGNED
22
23 # Write signed message to robot-save directory for debugging
24 ${signed_file} = Write Mime Message To File ${result} rsa_signed.eml
25
26 # Second pass: Verify the ARC signature we just created
27 ${verify_result} = Scan Message With Rspamc ${signed_file} --header=Settings-Id:arc_verify
28 Should Contain ${verify_result.stdout} ARC_ALLOW
29 Should Not Contain ${verify_result.stdout} ARC_INVALID
30 Should Not Contain ${verify_result.stdout} ARC_REJECT
31
32 # Cleanup
33 Remove File ${signed_file}
34
35 ARC ROUNDTRIP ED25519 SIGN AND VERIFY
36 # First pass: Sign the message with ed25519 key and check for ARC_SIGNED
37 ${result} = Scan Message With Rspamc ${MESSAGE_ED25519} -u [email protected] --mime
38 Should Contain ${result.stdout} ARC_SIGNED
39
40 # Write signed message to robot-save directory for debugging
41 ${signed_file} = Write Mime Message To File ${result} ed25519_signed.eml
42
43 # Second pass: Verify the ARC signature we just created
44 ${verify_result} = Scan Message With Rspamc ${signed_file} --header=Settings-Id:arc_verify
45 Should Contain ${verify_result.stdout} ARC_ALLOW
46 Should Not Contain ${verify_result.stdout} ARC_INVALID
47 Should Not Contain ${verify_result.stdout} ARC_REJECT
48
49 # Cleanup
50 Remove File ${signed_file}
51
52 ARC ED25519 ALGORITHM CHECK
53 # Sign with ed25519 and verify the algorithm is correctly set
54 ${result} = Scan Message With Rspamc ${MESSAGE_ED25519} -u [email protected] --mime
55 Should Contain ${result.stdout} ARC_SIGNED
56 Should Contain ${result.stdout} a=ed25519-sha256
57 Should Not Contain ${result.stdout} a=rsa-sha256
58
59 ARC RSA ALGORITHM CHECK
60 # Sign with RSA and verify the algorithm is correctly set
61 ${result} = Scan Message With Rspamc ${MESSAGE_RSA} -u [email protected] --mime
62 Should Contain ${result.stdout} ARC_SIGNED
63 Should Contain ${result.stdout} a=rsa-sha256
64 Should Not Contain ${result.stdout} a=ed25519-sha256
65
66 ARC CHAIN ROUNDTRIP RSA DOUBLE SIGN AND VERIFY
67 # First sign: Create i=1
68 ${result1} = Scan Message With Rspamc ${MESSAGE_RSA} -u [email protected] --mime
69 Should Contain ${result1.stdout} ARC_SIGNED
70
71 # Write first signed message
72 ${signed_file1} = Write Mime Message To File ${result1} rsa_chain_i1.eml
73
74 # Verify i=1 header is present
75 Should Contain ${result1.stdout} i=1
76
77 # Second sign: Create i=2 (sign the already-signed message)
78 ${result2} = Scan Message With Rspamc ${signed_file1} -u [email protected] --mime
79 Should Contain ${result2.stdout} ARC_SIGNED
80
81 # Write second signed message
82 ${signed_file2} = Write Mime Message To File ${result2} rsa_chain_i2.eml
83
84 # Verify both i=1 and i=2 headers are present in the chain
85 Should Contain ${result2.stdout} i=1
86 Should Contain ${result2.stdout} i=2
87
88 # Verify the whole chain
89 ${verify_result} = Scan Message With Rspamc ${signed_file2} --header=Settings-Id:arc_verify
90 Should Contain ${verify_result.stdout} ARC_ALLOW
91 Should Not Contain ${verify_result.stdout} ARC_INVALID
92 Should Not Contain ${verify_result.stdout} ARC_REJECT
93
94 # Cleanup
95 Remove File ${signed_file1}
96 Remove File ${signed_file2}
97
98 ARC CHAIN ROUNDTRIP ED25519 DOUBLE SIGN AND VERIFY
99 # First sign: Create i=1
100 ${result1} = Scan Message With Rspamc ${MESSAGE_ED25519} -u [email protected] --mime
101 Should Contain ${result1.stdout} ARC_SIGNED
102
103 # Write first signed message
104 ${signed_file1} = Write Mime Message To File ${result1} ed25519_chain_i1.eml
105
106 # Verify i=1 header is present
107 Should Contain ${result1.stdout} i=1
108
109 # Second sign: Create i=2 (sign the already-signed message)
110 ${result2} = Scan Message With Rspamc ${signed_file1} -u [email protected] --mime
111 Should Contain ${result2.stdout} ARC_SIGNED
112
113 # Write second signed message
114 ${signed_file2} = Write Mime Message To File ${result2} ed25519_chain_i2.eml
115
116 # Verify both i=1 and i=2 headers are present in the chain
117 Should Contain ${result2.stdout} i=1
118 Should Contain ${result2.stdout} i=2
119
120 # Verify the whole chain
121 ${verify_result} = Scan Message With Rspamc ${signed_file2} --header=Settings-Id:arc_verify
122 Should Contain ${verify_result.stdout} ARC_ALLOW
123 Should Not Contain ${verify_result.stdout} ARC_INVALID
124 Should Not Contain ${verify_result.stdout} ARC_REJECT
125
126 # Cleanup
127 Remove File ${signed_file1}
128 Remove File ${signed_file2}
129
130 *** Keywords ***
131 Write Mime Message To File
132 [Arguments] ${mime_result} ${filename}
133 # Save to robot-save directory for artifact preservation
134 ${artifact_file} = Set Variable ${EXECDIR}/robot-save/${filename}
135 Create File ${artifact_file} ${mime_result.stdout}
136 Log Saved signed message to ${artifact_file}
137
138 # Also save to temp directory for test use
139 ${temp_file} = Set Variable ${RSPAMD_TMPDIR}/${filename}
140 Create File ${temp_file} ${mime_result.stdout}
141
142 # Count ARC headers for debugging
143 ${lines} = Split To Lines ${mime_result.stdout}
144 ${arc_count} = Set Variable ${0}
145 FOR ${line} IN @{lines}
146 ${is_arc_header} = Run Keyword And Return Status Should Match Regexp ${line} ^ARC-.*:
147 IF ${is_arc_header}
148 ${arc_count} = Evaluate ${arc_count} + 1
149 END
150 END
151 Log Total ARC headers found in mime output: ${arc_count}
152
153 # Log first few lines of the created file for debugging
154 ${lines} = Split To Lines ${mime_result.stdout}
155 ${first_10_lines} = Get Slice From List ${lines} 0 10
156 Log First 10 lines of signed message file:
157 FOR ${line} IN @{first_10_lines}
158 Log ${line}
159 END
160
161 # Log any ARC headers found
162 FOR ${line} IN @{lines}
163 ${is_arc_header} = Run Keyword And Return Status Should Match Regexp ${line} ^ARC-.*:
164 IF ${is_arc_header}
165 Log Found ARC header: ${line}
166 END
167 END
168
169 [Return] ${temp_file}
170
171 Write Signed Message To File
172 [Arguments] ${scan_result} ${filename}
173 # DEPRECATED: This method doesn't work with -p flag
174 # Use Write Mime Message To File instead
175 Log WARNING: Write Signed Message To File is deprecated, use Write Mime Message To File
176 ${temp_file} = Set Variable ${RSPAMD_TMPDIR}/${filename}
177 Create File ${temp_file} ${scan_result.stdout}
178 [Return] ${temp_file}