Commit 6e244a9
feat(upload): dedup encrypted binaries on the plaintext hash (#101)
`--encrypt` uses a fresh random DEK per upload, so identical plaintext produces
different ciphertext every time. Since the dedup key was the hash of whatever
gets uploaded, encryption silently disabled dedup entirely: every run re-uploaded
and re-stored the full binary. Verified on dev — two `--encrypt` runs of a
byte-identical APK produced two distinct binaries, while the plaintext run
deduped.
Hash the plaintext first, dedup on that, and only encrypt on a miss. Because the
check now happens before encryption, a hit skips the encryption work too, not
just the upload — an encrypted re-run is now faster than the old plaintext path
rather than merely matching it.
`binaries.sha` is untouched and remains the ciphertext hash: the hosts that
verify it (B2, Supabase Storage, storage-cache, Mac LRU) hold ciphertext and no
DEK, so they can only hash the bytes they actually have. The plaintext hash rides
alongside as `shaPlain` and is sent only when encrypting.
A dedup hit is honoured only if the server confirms the matched binary is itself
encrypted. This matters: a previously-uploaded *plaintext* copy of the same app
has the same plaintext hash, so a lookup blind to encryption state would hand
back an unencrypted binary to someone who asked for encryption. The API applies
the same predicate (devicecloud-dev/dcd#1168); this is the client refusing to
depend on that, so an older or misbehaving deployment degrades into a redundant
upload instead of a silent loss of encryption.
Requires the API side of dcd#1168 for the encrypted path to dedup; against an
older deployment the check finds nothing and behaviour is exactly as it is today.
The unencrypted path is unchanged on the wire.
One cost worth naming: an encrypted upload that misses now hashes twice (once
plaintext, once ciphertext). Hashing is cheap next to encrypt + upload, and only
the miss path pays it.
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent a34d9d4 commit 6e244a9
4 files changed
Lines changed: 485 additions & 29 deletions
File tree
- src
- config/flags
- gateways
- test/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
260 | 274 | | |
261 | 275 | | |
262 | 276 | | |
263 | | - | |
| 277 | + | |
264 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
265 | 283 | | |
266 | 284 | | |
267 | | - | |
| 285 | + | |
268 | 286 | | |
269 | 287 | | |
270 | 288 | | |
| |||
277 | 295 | | |
278 | 296 | | |
279 | 297 | | |
280 | | - | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
281 | 301 | | |
282 | 302 | | |
283 | 303 | | |
| |||
342 | 362 | | |
343 | 363 | | |
344 | 364 | | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
345 | 371 | | |
346 | 372 | | |
347 | | - | |
| 373 | + | |
348 | 374 | | |
349 | 375 | | |
350 | 376 | | |
| |||
354 | 380 | | |
355 | 381 | | |
356 | 382 | | |
| 383 | + | |
357 | 384 | | |
358 | 385 | | |
359 | 386 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
193 | 191 | | |
194 | 192 | | |
195 | 193 | | |
| |||
203 | 201 | | |
204 | 202 | | |
205 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
206 | 219 | | |
207 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
208 | 233 | | |
209 | 234 | | |
210 | 235 | | |
| |||
425 | 450 | | |
426 | 451 | | |
427 | 452 | | |
428 | | - | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
429 | 466 | | |
430 | 467 | | |
431 | | - | |
| 468 | + | |
432 | 469 | | |
433 | 470 | | |
434 | 471 | | |
435 | 472 | | |
436 | 473 | | |
437 | 474 | | |
438 | | - | |
| 475 | + | |
439 | 476 | | |
440 | 477 | | |
441 | 478 | | |
442 | 479 | | |
443 | 480 | | |
| 481 | + | |
444 | 482 | | |
445 | 483 | | |
446 | 484 | | |
447 | 485 | | |
448 | | - | |
| 486 | + | |
449 | 487 | | |
450 | 488 | | |
451 | | - | |
| 489 | + | |
452 | 490 | | |
453 | 491 | | |
454 | 492 | | |
| |||
459 | 497 | | |
460 | 498 | | |
461 | 499 | | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
462 | 510 | | |
463 | 511 | | |
464 | 512 | | |
| |||
493 | 541 | | |
494 | 542 | | |
495 | 543 | | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
496 | 549 | | |
497 | 550 | | |
498 | 551 | | |
| |||
769 | 822 | | |
770 | 823 | | |
771 | 824 | | |
772 | | - | |
| 825 | + | |
773 | 826 | | |
774 | 827 | | |
775 | 828 | | |
| |||
832 | 885 | | |
833 | 886 | | |
834 | 887 | | |
| 888 | + | |
835 | 889 | | |
836 | 890 | | |
837 | 891 | | |
| |||
0 commit comments