Skip to content

Simon/feat/decrypt targeted message - #2425

Open
SimonThormeyer wants to merge 25 commits into
mainfrom
simon/feat/decrypt-targeted-message
Open

Simon/feat/decrypt targeted message#2425
SimonThormeyer wants to merge 25 commits into
mainfrom
simon/feat/decrypt-targeted-message

Conversation

@SimonThormeyer

Copy link
Copy Markdown
Member

No description provided.

@SimonThormeyer
SimonThormeyer force-pushed the simon/feat/decrypt-targeted-message branch 3 times, most recently from 1fb2154 to 3ce3db2 Compare August 3, 2026 15:08
Base automatically changed from simon/feat/targeted-message-message-enum to main August 12, 2026 12:45
@SimonThormeyer
SimonThormeyer force-pushed the simon/feat/decrypt-targeted-message branch 4 times, most recently from 8f64620 to c12991b Compare August 19, 2026 11:39
@SimonThormeyer
SimonThormeyer force-pushed the simon/feat/decrypt-targeted-message branch from d96cc23 to b0dc974 Compare August 19, 2026 13:31
This tests
- basic encryption/decryption roundtrip
- decrypting messages as far back as `MAX_PAST_EPOCHS`, and failure
beyond
- protection from replays via `DuplicateMessageError`
- buffering of targeted messages from epochs one step in the future
@SimonThormeyer
SimonThormeyer force-pushed the simon/feat/decrypt-targeted-message branch from b0dc974 to 95a4841 Compare August 19, 2026 14:02
@SimonThormeyer
SimonThormeyer force-pushed the simon/feat/decrypt-targeted-message branch from 95a4841 to 09eb4dc Compare August 19, 2026 14:13
Comment thread keystore/src/entities/mls/tnt_secret.rs Outdated
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, derive_more::Constructor)]
pub struct TntSecretPk {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a good opportunity to have TntSecretPkRef<'a> containing an &'a ConversationRef, so that you can impl EntityGetBorrowed and EntityDeleteBorrowed.

Comment thread keystore/src/entities/mls/targeted_message_rx_counter.rs Outdated
let epoch_before_operation = group.epoch();

// Save the tnt secret. We need to do this exactly once per epoch.
let tnt_secret_key = TntSecretPk::new(id.as_ref().to_vec(), epoch_before_operation.as_u64());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The needed to_vec() here is why I'm suggesting EntityGetBorrowed for TntSecret.

group.reset_targeted_message_tx_counters(tx).await;

let oldest_retained_epoch = group.epoch().as_u64().saturating_sub(MAX_PAST_EPOCHS as u64);
let conversation_id = DbConversationId::from(id.as_ref().to_vec());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet we could also invent a borrowed form of ConversationId that we could implement searching for.

Comment on lines +74 to +83
// This is not a lot of data: just `MAX_PAST_EPOCHS` records. In practice, we could in most cases just
// delete the single one with the oldest epoch. However, to avoid any assumptions about the data, let's just
// check each of the `MAX_PAST_EPOCHS` records.
for secret in secrets {
if secret.epoch < oldest_retained_epoch {
tx.remove::<TntSecret>(&TntSecretPk::new(secret.conversation_id.clone(), secret.epoch))
.await
.map_err(KeystoreError::wrap("removing old tnt secret"))?;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is acceptable as a first draft but I'd rather see an AnyEpochOlderThan(pub u64) newtype with a DeletableBySearchKey impl which ultimately delegates down to DELETE FROM tnt_secrets WHERE epoch < ?.

}

let database = self.database().await?;
let counter_pk = TargetedMessageRxCounterPk::new(self.id.to_bytes(), message.sender().u32(), group_epoch);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Borrowed form! 😄

@SimonThormeyer
SimonThormeyer marked this pull request as ready for review August 19, 2026 14:52
@SimonThormeyer
SimonThormeyer requested a review from a team August 19, 2026 14:52
}

let database = self.database().await?;
let key = TntSecretPk::new(mls_group.group_id().to_vec(), message.epoch.as_u64());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Borrowed form.

@SimonThormeyer
SimonThormeyer force-pushed the simon/feat/decrypt-targeted-message branch from 0a3dbb9 to ffa32fa Compare August 19, 2026 15:08
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.

2 participants