Commit ec60c8b
security: zeroize sensitive key material from memory after use
Adds the `zeroize` crate (transitive via chacha20poly1305, zero binary increase)
to explicitly overwrite sensitive data in memory before deallocation, preventing
extraction via memory dumps, forensic tools, or malware with process read access.
What's zeroized:
- PIN/password: cleared immediately after Argon2 key derivation (~100ms lifetime)
- Encryption key copies: zeroed after every encrypt/decrypt call + all error paths
- Plaintext input to encrypt: zeroed right after ChaCha20 reads it (nsec, seed, messages)
- Mnemonic seed phrase: zeroed after persisting to DB (was session-lifetime, now seconds)
Changed MNEMONIC_SEED from OnceLock to Mutex<Option<>> to enable clearing
- Logout: ENCRYPTION_KEY, PENDING_NSEC, and MNEMONIC_SEED all explicitly zeroed
before process restart
- Key generation params: raw key bytes zeroed after hex conversion
Without zeroize, Rust's String/Vec drop deallocates but doesn't overwrite — sensitive
bytes persist in heap until the allocator reuses that page (seconds to hours). With
zeroize, the compiler cannot optimize away the volatile memory writes.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 3b05d63 commit ec60c8b
5 files changed
Lines changed: 95 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
197 | 229 | | |
198 | 230 | | |
199 | 231 | | |
| |||
235 | 267 | | |
236 | 268 | | |
237 | 269 | | |
238 | | - | |
| 270 | + | |
239 | 271 | | |
240 | 272 | | |
241 | 273 | | |
| |||
259 | 291 | | |
260 | 292 | | |
261 | 293 | | |
262 | | - | |
263 | | - | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
264 | 297 | | |
265 | 298 | | |
266 | 299 | | |
| |||
288 | 321 | | |
289 | 322 | | |
290 | 323 | | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
297 | 327 | | |
298 | 328 | | |
299 | 329 | | |
| |||
478 | 508 | | |
479 | 509 | | |
480 | 510 | | |
481 | | - | |
| 511 | + | |
482 | 512 | | |
483 | 513 | | |
484 | 514 | | |
| |||
488 | 518 | | |
489 | 519 | | |
490 | 520 | | |
491 | | - | |
492 | | - | |
493 | | - | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
494 | 533 | | |
495 | 534 | | |
496 | 535 | | |
| |||
536 | 575 | | |
537 | 576 | | |
538 | 577 | | |
539 | | - | |
540 | | - | |
541 | | - | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
542 | 590 | | |
543 | 591 | | |
544 | 592 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | | - | |
| 24 | + | |
24 | 25 | | |
25 | | - | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | | - | |
29 | | - | |
| 29 | + | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
| |||
62 | 65 | | |
63 | 66 | | |
64 | 67 | | |
65 | | - | |
| 68 | + | |
66 | 69 | | |
67 | 70 | | |
68 | 71 | | |
| |||
80 | 83 | | |
81 | 84 | | |
82 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
83 | 89 | | |
84 | 90 | | |
85 | 91 | | |
86 | 92 | | |
87 | | - | |
| 93 | + | |
88 | 94 | | |
89 | | - | |
| 95 | + | |
90 | 96 | | |
91 | 97 | | |
92 | 98 | | |
| |||
105 | 111 | | |
106 | 112 | | |
107 | 113 | | |
108 | | - | |
| 114 | + | |
109 | 115 | | |
110 | 116 | | |
111 | 117 | | |
| 118 | + | |
112 | 119 | | |
113 | 120 | | |
114 | 121 | | |
| |||
123 | 130 | | |
124 | 131 | | |
125 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
126 | 136 | | |
127 | 137 | | |
128 | 138 | | |
| |||
133 | 143 | | |
134 | 144 | | |
135 | 145 | | |
136 | | - | |
| 146 | + | |
137 | 147 | | |
138 | 148 | | |
139 | 149 | | |
| |||
148 | 158 | | |
149 | 159 | | |
150 | 160 | | |
151 | | - | |
| 161 | + | |
152 | 162 | | |
153 | 163 | | |
154 | 164 | | |
| |||
157 | 167 | | |
158 | 168 | | |
159 | 169 | | |
160 | | - | |
| 170 | + | |
161 | 171 | | |
162 | 172 | | |
163 | 173 | | |
164 | 174 | | |
165 | 175 | | |
166 | 176 | | |
167 | 177 | | |
168 | | - | |
| 178 | + | |
169 | 179 | | |
170 | 180 | | |
171 | 181 | | |
| |||
176 | 186 | | |
177 | 187 | | |
178 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
179 | 192 | | |
180 | 193 | | |
181 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
136 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
| |||
0 commit comments