element-hq / element-hq/element-ios

NSE process can encrypt events which can cause UTDs due to key reuse

Open
#7,751 0 comments 0 reactions 0 assignees View on GitHub
A-E2EE A-Notifications O-Uncommon S-Critical T-Defect
Dominant language
Swift
Stars
1.8k
Forks
544
PR merge metrics
PR metrics pending

Description

### Steps to reproduce

It is possible for the NSE process to encrypt events in response to key share requests as shown in the log line below (redacted):

`2024-01-02 10:53:06.653 RiotNSE[646:107755] [MXCryptoSDK] TRACE receive_sync_changes:handle_supported_key_request{user_id=@xxxx:matrix.org device_id=XXX room_id=!xxxx:matrix.org}:encrypt{recipient=@xxxx:matrix.org recipient_device=XXX recipient_key=Some("curve25519:xxx") session=Session { session_id: "xxx", sending_chain_index: None, receiving_chains: [ReceiverChain { chain_index: 2, skipped_message_keys: [], .. }], config: SessionConfig { version: V1 }, .. }}: matrix_sdk_crypto::identities::device: Successfully encrypted an event`

This is bad for the same reason it's [bad for the ShareExtension](https://github.com/element-hq/element-ios/issues/7499). It corrupts the ratchet position, causing unable to decrypt (UTD) errors.

### Outcome

Users see UTDs for messages sent from EI devices.

### Your phone model

iPad Air 5th Gen (WiFi)

### Operating system version

iPadOS 17.2

### Application version

v1.11.5 #20231128120740 with Rust Crypto SDK 0.6.0 (Vodozemac 0.4.0)

### Homeserver

matrix.org

### Will you send logs?

No

Contributor guide

Open the contributing guide

Research direction

Start by tracing how the NSE process handles key share requests and compare its behavior with the ShareExtension issue 7499. Use the provided encryption log and the Rust Crypto SDK/Vodozemac versions as context; done means the NSE no longer causes ratchet corruption that produces UTDs.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, rust, swift
Domain
cryptography, mobile-dev, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.