feat: Store symmetric key non-redundantly in the database

This commit is contained in:
Hocuri
2025-07-21 17:37:17 +02:00
parent 547f750073
commit 789b923bb8
3 changed files with 17 additions and 13 deletions

View File

@@ -1143,7 +1143,7 @@ impl MimeFactory {
Loaded::Mdn { .. } => true,
};
let symmetric_key = match &self.loaded {
let symmetric_key: Option<String> = match &self.loaded {
Loaded::Message { chat, .. } if chat.typ == Chattype::OutBroadcast => {
// If there is no symmetric key yet
// (because this is an old broadcast channel,
@@ -1152,7 +1152,13 @@ impl MimeFactory {
// Symmetric encryption exists since 2025-08;
// some time after that, we can think about requiring everyone
// to switch to symmetrically-encrypted broadcast lists.
chat.param.get(Param::SymmetricKey)
context
.sql
.query_get_value(
"SELECT secret FROM broadcasts_shared_secrets WHERE chat_id=?",
(chat.id,),
)
.await?
}
_ => None,
};
@@ -1160,7 +1166,7 @@ impl MimeFactory {
let encrypted = if let Some(symmetric_key) = symmetric_key {
info!(context, "Symmetrically encrypting for broadcast channel.");
encrypt_helper
.encrypt_for_broadcast(context, symmetric_key, message, compress)
.encrypt_for_broadcast(context, &symmetric_key, message, compress)
.await?
} else {
// Asymmetric encryption