mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 05:16:28 +03:00
feat: AEAP: Check that the old peerstate verified key fingerprint hasn't changed when removing it
This commit is contained in:
@@ -542,6 +542,8 @@ impl Peerstate {
|
|||||||
/// * `old_addr`: Old address of the peerstate in case of an AEAP transition.
|
/// * `old_addr`: Old address of the peerstate in case of an AEAP transition.
|
||||||
pub(crate) async fn save_to_db_ex(&self, sql: &Sql, old_addr: Option<&str>) -> Result<()> {
|
pub(crate) async fn save_to_db_ex(&self, sql: &Sql, old_addr: Option<&str>) -> Result<()> {
|
||||||
let trans_fn = |t: &mut rusqlite::Transaction| {
|
let trans_fn = |t: &mut rusqlite::Transaction| {
|
||||||
|
let verified_key_fingerprint =
|
||||||
|
self.verified_key_fingerprint.as_ref().map(|fp| fp.hex());
|
||||||
if let Some(old_addr) = old_addr {
|
if let Some(old_addr) = old_addr {
|
||||||
// We are doing an AEAP transition to the new address and the SQL INSERT below will
|
// We are doing an AEAP transition to the new address and the SQL INSERT below will
|
||||||
// save the existing peerstate as belonging to this new address. We now need to
|
// save the existing peerstate as belonging to this new address. We now need to
|
||||||
@@ -551,11 +553,14 @@ impl Peerstate {
|
|||||||
// existing peerstate as this would break encryption to it. This is critical for
|
// existing peerstate as this would break encryption to it. This is critical for
|
||||||
// non-verified groups -- if we can't encrypt to the old address, we can't securely
|
// non-verified groups -- if we can't encrypt to the old address, we can't securely
|
||||||
// remove it from the group (to add the new one instead).
|
// remove it from the group (to add the new one instead).
|
||||||
|
//
|
||||||
|
// NB: We check that `verified_key_fingerprint` hasn't changed to protect from
|
||||||
|
// possible races.
|
||||||
t.execute(
|
t.execute(
|
||||||
"UPDATE acpeerstates \
|
"UPDATE acpeerstates
|
||||||
SET verified_key=NULL, verified_key_fingerprint='', verifier='' \
|
SET verified_key=NULL, verified_key_fingerprint='', verifier=''
|
||||||
WHERE addr=?",
|
WHERE addr=? AND verified_key_fingerprint=?",
|
||||||
(old_addr,),
|
(old_addr, &verified_key_fingerprint),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
t.execute(
|
t.execute(
|
||||||
@@ -604,7 +609,7 @@ impl Peerstate {
|
|||||||
self.public_key_fingerprint.as_ref().map(|fp| fp.hex()),
|
self.public_key_fingerprint.as_ref().map(|fp| fp.hex()),
|
||||||
self.gossip_key_fingerprint.as_ref().map(|fp| fp.hex()),
|
self.gossip_key_fingerprint.as_ref().map(|fp| fp.hex()),
|
||||||
self.verified_key.as_ref().map(|k| k.to_bytes()),
|
self.verified_key.as_ref().map(|k| k.to_bytes()),
|
||||||
self.verified_key_fingerprint.as_ref().map(|fp| fp.hex()),
|
&verified_key_fingerprint,
|
||||||
self.verifier.as_deref().unwrap_or(""),
|
self.verifier.as_deref().unwrap_or(""),
|
||||||
self.secondary_verified_key.as_ref().map(|k| k.to_bytes()),
|
self.secondary_verified_key.as_ref().map(|k| k.to_bytes()),
|
||||||
self.secondary_verified_key_fingerprint
|
self.secondary_verified_key_fingerprint
|
||||||
|
|||||||
Reference in New Issue
Block a user