crypto: Store the trust state of our own identities as well.
parent
9810a2f630
commit
70ffc43ce0
|
@ -347,6 +347,21 @@ impl SqliteStore {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
connection
|
||||||
|
.execute(
|
||||||
|
r#"
|
||||||
|
CREATE TABLE IF NOT EXISTS users_trust_state (
|
||||||
|
"id" INTEGER NOT NULL PRIMARY KEY,
|
||||||
|
"trusted" INTEGER NOT NULL,
|
||||||
|
"user_id" INTEGER NOT NULL,
|
||||||
|
FOREIGN KEY ("user_id") REFERENCES "users" ("id")
|
||||||
|
ON DELETE CASCADE
|
||||||
|
UNIQUE(user_id)
|
||||||
|
);
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
connection
|
connection
|
||||||
.execute(
|
.execute(
|
||||||
r#"
|
r#"
|
||||||
|
@ -865,13 +880,27 @@ impl SqliteStore {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(Some(UserIdentities::Own(
|
let verified: Option<(bool,)> =
|
||||||
|
query_as("SELECT trusted FROM users_trust_state WHERE user_id = ?")
|
||||||
|
.bind(user_row_id)
|
||||||
|
.fetch_optional(&mut *connection)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let verified = verified.map_or(false, |r| r.0);
|
||||||
|
|
||||||
|
let identity =
|
||||||
OwnUserIdentity::new(master.into(), self_singing.into(), user_signing.into())
|
OwnUserIdentity::new(master.into(), self_singing.into(), user_signing.into())
|
||||||
.unwrap(),
|
.expect("Signature check failed on stored identity");
|
||||||
)))
|
|
||||||
|
if verified {
|
||||||
|
identity.mark_as_verified();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Some(UserIdentities::Own(identity)))
|
||||||
} else {
|
} else {
|
||||||
Ok(Some(UserIdentities::Other(
|
Ok(Some(UserIdentities::Other(
|
||||||
UserIdentity::new(master.into(), self_singing.into()).unwrap(),
|
UserIdentity::new(master.into(), self_singing.into())
|
||||||
|
.expect("Signature check failed on stored identity"),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -978,14 +1007,20 @@ impl SqliteStore {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let Some(user_signing_key) = user.user_signing_key() {
|
if let UserIdentities::Own(own_identity) = user {
|
||||||
SqliteStore::save_cross_signing_key(
|
SqliteStore::save_cross_signing_key(
|
||||||
&mut connection,
|
&mut connection,
|
||||||
user_row_id,
|
user_row_id,
|
||||||
CrosssigningKeyType::UserSigning,
|
CrosssigningKeyType::UserSigning,
|
||||||
user_signing_key,
|
own_identity.user_signing_key(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
query("REPLACE INTO users_trust_state (user_id, trusted) VALUES (?1, ?2)")
|
||||||
|
.bind(user_row_id)
|
||||||
|
.bind(own_identity.is_verified())
|
||||||
|
.execute(&mut *connection)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1684,7 +1719,7 @@ mod test {
|
||||||
loaded_user.self_signing_key(),
|
loaded_user.self_signing_key(),
|
||||||
own_identity.self_signing_key()
|
own_identity.self_signing_key()
|
||||||
);
|
);
|
||||||
assert_eq!(loaded_user, own_identity.into());
|
assert_eq!(loaded_user, own_identity.clone().into());
|
||||||
|
|
||||||
let other_identity = get_other_identity();
|
let other_identity = get_other_identity();
|
||||||
|
|
||||||
|
@ -1705,5 +1740,14 @@ mod test {
|
||||||
other_identity.self_signing_key()
|
other_identity.self_signing_key()
|
||||||
);
|
);
|
||||||
assert_eq!(loaded_user, other_identity.into());
|
assert_eq!(loaded_user, other_identity.into());
|
||||||
|
|
||||||
|
own_identity.mark_as_verified();
|
||||||
|
|
||||||
|
store
|
||||||
|
.save_user_identities(&[own_identity.into()])
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let loaded_user = store.load_user(&user_id).await.unwrap().unwrap();
|
||||||
|
assert!(loaded_user.own().unwrap().is_verified())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue