Skip to content

fix(observer): decrypt attachments with K_conv (v2) - #162

Open
arkanoider wants to merge 2 commits into
mainfrom
fix/observer-attachment-k-conv-decrypt
Open

fix(observer): decrypt attachments with K_conv (v2)#162
arkanoider wants to merge 2 commits into
mainfrom
fix/observer-attachment-k-conv-decrypt

Conversation

@arkanoider

@arkanoider arkanoider commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Order-chat attachments were ChaCha-encrypted with the raw ECDH IKM, while the Observer tab only holds disclosed K_conv — Ctrl+S failed with decrypt failed: aead::Error.
  • Encrypt (and prefer decrypt) with K_conv so Observer matches My Trades after Shift+K disclosure; try legacy ECDH as a decrypt fallback for older/mobile blobs.
  • Admin dispute save path derives the same K_conv-first candidate list from the admin↔party ECDH secret.
  • Rustdoc aligned for ChatAttachment, blossom save helpers, send path, and order_chat_shared_key_hex.

Test plan

  • cargo test --all-features --lib attachment_key_is_k_conv
  • cargo test --all-features --lib decrypt_blob_with_keys
  • cargo clippy --all-targets --all-features -- -D warnings
  • Manual: My Trades send a new image → Ctrl+S saves successfully
  • Manual: Shift+K copy Shared key → Observer paste → load chat → Ctrl+S on attachment succeeds (re-send after this fix; pre-fix ECDH blobs still need My Trades ECDH fallback)
  • Manual: older ECDH-encrypted attachment still opens from My Trades via fallback

Summary by CodeRabbit

  • New Features

    • Order chat attachments can now be decrypted by Observers using the disclosed Shared key.
    • Attachment downloads support multiple decryption keys, improving compatibility across chat contexts.
  • Bug Fixes

    • Improved decryption of existing attachments encrypted with legacy key formats.
    • Attachment encryption and decryption now use the conversation key consistently for order chat.
  • Documentation

    • Clarified attachment encryption and decryption behavior across order chat, disputes, and Observer views.

Attachments were ChaCha-encrypted with the ECDH IKM while Observer
only holds disclosed K_conv, causing aead::Error on Ctrl+S. Encrypt and
prefer decrypt with K_conv so Observer matches My Trades; keep ECDH as
a decrypt fallback for legacy/mobile blobs.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 2845fb5b-cb69-49cf-ad85-53dce4f60cf9

📥 Commits

Reviewing files that changed from the base of the PR and between 0f0a0a1 and fc86f13.

📒 Files selected for processing (9)
  • src/models.rs
  • src/ui/chat.rs
  • src/ui/helpers/attachments.rs
  • src/ui/helpers/chat_storage.rs
  • src/ui/key_handler/mod.rs
  • src/util/blossom.rs
  • src/util/chat_utils.rs
  • src/util/mod.rs
  • src/util/send_attachment.rs

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

Attachment decryption now uses K_conv as the primary key and supports legacy ECDH fallbacks. Chat attachments store fallback keys, and admin, user, and observer save paths populate the updated key data. Blossom decryption tries candidates in order.

Changes

Attachment key compatibility

Layer / File(s) Summary
Key candidate derivation
src/util/chat_utils.rs
Order-chat helpers now derive K_conv, preserve raw ECDH IKM support, and return ordered, deduplicated candidates. Tests cover observer decryption and legacy fallback behavior.
Fallback decryption engine
src/util/blossom.rs, src/util/mod.rs
Blossom download and save paths now accept ordered key lists. Decryption tries each candidate and preserves encrypted files when no keys are supplied.
Attachment save-path integration
src/ui/chat.rs, src/ui/key_handler/mod.rs, src/ui/helpers/..., src/models.rs, src/util/send_attachment.rs
ChatAttachment stores fallback keys. Admin, user, and observer paths populate or read the updated keys. Related documentation and fixtures were updated.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to fc86f

Attachments now use the disclosed-compatible K_conv key while retaining legacy ECDH decryption fallback, enabling Observer saves without dropping compatibility for older encrypted attachments. No current merge-blocking risk remains.

Suggested reviewers: vidarte-alberto

Poem

A rabbit packed keys in a neat little row
K_conv led first, with old keys below
Blossom tried each through the encrypted gate
The observer found blobs in a decryptable state
Fallbacks stood ready, reliable and bright

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 96.30% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 27 functions across 9 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: enabling Observer attachment decryption with K_conv. The version marker is acceptable and does not obscure the change.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/observer-attachment-k-conv-decrypt

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant