Fix clippy lints
Automated via `cargo clippy --workspace --all-targets -Zunstable-options --fix`.master
parent
e18f248dbb
commit
3bac536daf
|
@ -333,7 +333,7 @@ impl QrVerification {
|
||||||
/// This represents the ID as a string even if it is a `EventId`.
|
/// This represents the ID as a string even if it is a `EventId`.
|
||||||
pub fn flow_id(&self) -> &str {
|
pub fn flow_id(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
QrVerification::Verification(v) => &v.event_id.as_str(),
|
QrVerification::Verification(v) => v.event_id.as_str(),
|
||||||
QrVerification::SelfVerification(v) => &v.transaction_id,
|
QrVerification::SelfVerification(v) => &v.transaction_id,
|
||||||
QrVerification::SelfVerificationNoMasterKey(v) => &v.transaction_id,
|
QrVerification::SelfVerificationNoMasterKey(v) => &v.transaction_id,
|
||||||
}
|
}
|
||||||
|
@ -434,7 +434,7 @@ impl VerificationData {
|
||||||
pub fn to_bytes(&self) -> Result<Vec<u8>, EncodingError> {
|
pub fn to_bytes(&self) -> Result<Vec<u8>, EncodingError> {
|
||||||
to_bytes(
|
to_bytes(
|
||||||
Self::QR_MODE,
|
Self::QR_MODE,
|
||||||
&self.event_id.as_str(),
|
self.event_id.as_str(),
|
||||||
&self.first_master_key,
|
&self.first_master_key,
|
||||||
&self.second_master_key,
|
&self.second_master_key,
|
||||||
&self.shared_secret,
|
&self.shared_secret,
|
||||||
|
|
|
@ -89,7 +89,7 @@ async fn login(
|
||||||
&sas.other_device().user_id(),
|
&sas.other_device().user_id(),
|
||||||
&sas.other_device().device_id()
|
&sas.other_device().device_id()
|
||||||
);
|
);
|
||||||
print_devices(&e.sender, &client).await;
|
print_devices(&e.sender, client).await;
|
||||||
sas.accept().await.unwrap();
|
sas.accept().await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ async fn login(
|
||||||
|
|
||||||
if sas.is_done() {
|
if sas.is_done() {
|
||||||
print_result(&sas);
|
print_result(&sas);
|
||||||
print_devices(&e.sender, &client).await;
|
print_devices(&e.sender, client).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ async fn login(
|
||||||
}
|
}
|
||||||
AnySyncMessageEvent::KeyVerificationKey(e) => {
|
AnySyncMessageEvent::KeyVerificationKey(e) => {
|
||||||
let sas = client
|
let sas = client
|
||||||
.get_verification(&e.content.relation.event_id.as_str())
|
.get_verification(e.content.relation.event_id.as_str())
|
||||||
.await
|
.await
|
||||||
.expect("Sas object wasn't created");
|
.expect("Sas object wasn't created");
|
||||||
|
|
||||||
|
@ -149,13 +149,13 @@ async fn login(
|
||||||
}
|
}
|
||||||
AnySyncMessageEvent::KeyVerificationMac(e) => {
|
AnySyncMessageEvent::KeyVerificationMac(e) => {
|
||||||
let sas = client
|
let sas = client
|
||||||
.get_verification(&e.content.relation.event_id.as_str())
|
.get_verification(e.content.relation.event_id.as_str())
|
||||||
.await
|
.await
|
||||||
.expect("Sas object wasn't created");
|
.expect("Sas object wasn't created");
|
||||||
|
|
||||||
if sas.is_done() {
|
if sas.is_done() {
|
||||||
print_result(&sas);
|
print_result(&sas);
|
||||||
print_devices(&e.sender, &client).await;
|
print_devices(&e.sender, client).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|
|
@ -27,7 +27,7 @@ impl EventHandler for EventCallback {
|
||||||
..
|
..
|
||||||
} = event
|
} = event
|
||||||
{
|
{
|
||||||
let member = room.get_member(&sender).await.unwrap().unwrap();
|
let member = room.get_member(sender).await.unwrap().unwrap();
|
||||||
let name = member.display_name().unwrap_or_else(|| member.user_id().as_str());
|
let name = member.display_name().unwrap_or_else(|| member.user_id().as_str());
|
||||||
println!("{}: {}", name, msg_body);
|
println!("{}: {}", name, msg_body);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2033,15 +2033,15 @@ impl Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OutgoingRequests::KeysUpload(request) => {
|
OutgoingRequests::KeysUpload(request) => {
|
||||||
if let Err(e) = self.keys_upload(&r.request_id(), request).await {
|
if let Err(e) = self.keys_upload(r.request_id(), request).await {
|
||||||
warn!("Error while querying device keys {:?}", e);
|
warn!("Error while querying device keys {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OutgoingRequests::ToDeviceRequest(request) => {
|
OutgoingRequests::ToDeviceRequest(request) => {
|
||||||
// TODO remove this unwrap
|
// TODO remove this unwrap
|
||||||
if let Ok(resp) = self.send_to_device(&request).await {
|
if let Ok(resp) = self.send_to_device(request).await {
|
||||||
self.base_client
|
self.base_client
|
||||||
.mark_request_as_sent(&r.request_id(), &resp)
|
.mark_request_as_sent(r.request_id(), &resp)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -2050,7 +2050,7 @@ impl Client {
|
||||||
// TODO remove this unwrap.
|
// TODO remove this unwrap.
|
||||||
if let Ok(resp) = self.send(request.clone(), None).await {
|
if let Ok(resp) = self.send(request.clone(), None).await {
|
||||||
self.base_client
|
self.base_client
|
||||||
.mark_request_as_sent(&r.request_id(), &resp)
|
.mark_request_as_sent(r.request_id(), &resp)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -2058,7 +2058,7 @@ impl Client {
|
||||||
OutgoingRequests::RoomMessage(request) => {
|
OutgoingRequests::RoomMessage(request) => {
|
||||||
if let Ok(resp) = self.room_send_helper(request).await {
|
if let Ok(resp) = self.room_send_helper(request).await {
|
||||||
self.base_client
|
self.base_client
|
||||||
.mark_request_as_sent(&r.request_id(), &resp)
|
.mark_request_as_sent(r.request_id(), &resp)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -2523,17 +2523,13 @@ impl Client {
|
||||||
MediaType::Uri(uri) => {
|
MediaType::Uri(uri) => {
|
||||||
if let MediaFormat::Thumbnail(size) = &request.format {
|
if let MediaFormat::Thumbnail(size) = &request.format {
|
||||||
self.send(
|
self.send(
|
||||||
get_content_thumbnail::Request::from_url(
|
get_content_thumbnail::Request::from_url(uri, size.width, size.height)?,
|
||||||
&uri,
|
|
||||||
size.width,
|
|
||||||
size.height,
|
|
||||||
)?,
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
.file
|
.file
|
||||||
} else {
|
} else {
|
||||||
self.send(get_content::Request::from_url(&uri)?, None).await?.file
|
self.send(get_content::Request::from_url(uri)?, None).await?.file
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -2562,7 +2558,7 @@ impl Client {
|
||||||
///
|
///
|
||||||
/// * `uri` - The `MxcUri` of the files.
|
/// * `uri` - The `MxcUri` of the files.
|
||||||
pub async fn remove_media_content_for_uri(&self, uri: &MxcUri) -> Result<()> {
|
pub async fn remove_media_content_for_uri(&self, uri: &MxcUri) -> Result<()> {
|
||||||
Ok(self.base_client.store().remove_media_content_for_uri(&uri).await?)
|
Ok(self.base_client.store().remove_media_content_for_uri(uri).await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the file of the given media event content.
|
/// Get the file of the given media event content.
|
||||||
|
|
|
@ -141,7 +141,7 @@ impl Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (room_id, notifications) in &response.notifications {
|
for (room_id, notifications) in &response.notifications {
|
||||||
if let Some(room) = self.get_room(&room_id) {
|
if let Some(room) = self.get_room(room_id) {
|
||||||
for notification in notifications {
|
for notification in notifications {
|
||||||
self.on_room_notification(room.clone(), notification.clone()).await;
|
self.on_room_notification(room.clone(), notification.clone()).await;
|
||||||
}
|
}
|
||||||
|
@ -191,20 +191,20 @@ impl Handler {
|
||||||
|
|
||||||
async fn handle_state_event(&self, room: Room, event: &AnySyncStateEvent) {
|
async fn handle_state_event(&self, room: Room, event: &AnySyncStateEvent) {
|
||||||
match event {
|
match event {
|
||||||
AnySyncStateEvent::RoomMember(member) => self.on_state_member(room, &member).await,
|
AnySyncStateEvent::RoomMember(member) => self.on_state_member(room, member).await,
|
||||||
AnySyncStateEvent::RoomName(name) => self.on_state_name(room, &name).await,
|
AnySyncStateEvent::RoomName(name) => self.on_state_name(room, name).await,
|
||||||
AnySyncStateEvent::RoomCanonicalAlias(canonical) => {
|
AnySyncStateEvent::RoomCanonicalAlias(canonical) => {
|
||||||
self.on_state_canonical_alias(room, &canonical).await
|
self.on_state_canonical_alias(room, canonical).await
|
||||||
}
|
}
|
||||||
AnySyncStateEvent::RoomAliases(aliases) => self.on_state_aliases(room, &aliases).await,
|
AnySyncStateEvent::RoomAliases(aliases) => self.on_state_aliases(room, aliases).await,
|
||||||
AnySyncStateEvent::RoomAvatar(avatar) => self.on_state_avatar(room, &avatar).await,
|
AnySyncStateEvent::RoomAvatar(avatar) => self.on_state_avatar(room, avatar).await,
|
||||||
AnySyncStateEvent::RoomPowerLevels(power) => {
|
AnySyncStateEvent::RoomPowerLevels(power) => {
|
||||||
self.on_state_power_levels(room, &power).await
|
self.on_state_power_levels(room, power).await
|
||||||
}
|
}
|
||||||
AnySyncStateEvent::RoomJoinRules(rules) => self.on_state_join_rules(room, &rules).await,
|
AnySyncStateEvent::RoomJoinRules(rules) => self.on_state_join_rules(room, rules).await,
|
||||||
AnySyncStateEvent::RoomTombstone(tomb) => {
|
AnySyncStateEvent::RoomTombstone(tomb) => {
|
||||||
// TODO make `on_state_tombstone` method
|
// TODO make `on_state_tombstone` method
|
||||||
self.on_room_tombstone(room, &tomb).await
|
self.on_room_tombstone(room, tomb).await
|
||||||
}
|
}
|
||||||
AnySyncStateEvent::Custom(custom) => {
|
AnySyncStateEvent::Custom(custom) => {
|
||||||
self.on_custom_event(room, &CustomEvent::State(custom)).await
|
self.on_custom_event(room, &CustomEvent::State(custom)).await
|
||||||
|
@ -221,23 +221,23 @@ impl Handler {
|
||||||
) {
|
) {
|
||||||
match event {
|
match event {
|
||||||
AnyStrippedStateEvent::RoomMember(member) => {
|
AnyStrippedStateEvent::RoomMember(member) => {
|
||||||
self.on_stripped_state_member(room, &member, None).await
|
self.on_stripped_state_member(room, member, None).await
|
||||||
}
|
}
|
||||||
AnyStrippedStateEvent::RoomName(name) => self.on_stripped_state_name(room, &name).await,
|
AnyStrippedStateEvent::RoomName(name) => self.on_stripped_state_name(room, name).await,
|
||||||
AnyStrippedStateEvent::RoomCanonicalAlias(canonical) => {
|
AnyStrippedStateEvent::RoomCanonicalAlias(canonical) => {
|
||||||
self.on_stripped_state_canonical_alias(room, &canonical).await
|
self.on_stripped_state_canonical_alias(room, canonical).await
|
||||||
}
|
}
|
||||||
AnyStrippedStateEvent::RoomAliases(aliases) => {
|
AnyStrippedStateEvent::RoomAliases(aliases) => {
|
||||||
self.on_stripped_state_aliases(room, &aliases).await
|
self.on_stripped_state_aliases(room, aliases).await
|
||||||
}
|
}
|
||||||
AnyStrippedStateEvent::RoomAvatar(avatar) => {
|
AnyStrippedStateEvent::RoomAvatar(avatar) => {
|
||||||
self.on_stripped_state_avatar(room, &avatar).await
|
self.on_stripped_state_avatar(room, avatar).await
|
||||||
}
|
}
|
||||||
AnyStrippedStateEvent::RoomPowerLevels(power) => {
|
AnyStrippedStateEvent::RoomPowerLevels(power) => {
|
||||||
self.on_stripped_state_power_levels(room, &power).await
|
self.on_stripped_state_power_levels(room, power).await
|
||||||
}
|
}
|
||||||
AnyStrippedStateEvent::RoomJoinRules(rules) => {
|
AnyStrippedStateEvent::RoomJoinRules(rules) => {
|
||||||
self.on_stripped_state_join_rules(room, &rules).await
|
self.on_stripped_state_join_rules(room, rules).await
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -249,18 +249,16 @@ impl Handler {
|
||||||
event: &AnyRoomAccountDataEvent,
|
event: &AnyRoomAccountDataEvent,
|
||||||
) {
|
) {
|
||||||
if let AnyRoomAccountDataEvent::FullyRead(event) = event {
|
if let AnyRoomAccountDataEvent::FullyRead(event) = event {
|
||||||
self.on_non_room_fully_read(room, &event).await
|
self.on_non_room_fully_read(room, event).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn handle_account_data_event(&self, event: &AnyGlobalAccountDataEvent) {
|
pub(crate) async fn handle_account_data_event(&self, event: &AnyGlobalAccountDataEvent) {
|
||||||
match event {
|
match event {
|
||||||
AnyGlobalAccountDataEvent::IgnoredUserList(ignored) => {
|
AnyGlobalAccountDataEvent::IgnoredUserList(ignored) => {
|
||||||
self.on_non_room_ignored_users(&ignored).await
|
self.on_non_room_ignored_users(ignored).await
|
||||||
}
|
|
||||||
AnyGlobalAccountDataEvent::PushRules(rules) => {
|
|
||||||
self.on_non_room_push_rules(&rules).await
|
|
||||||
}
|
}
|
||||||
|
AnyGlobalAccountDataEvent::PushRules(rules) => self.on_non_room_push_rules(rules).await,
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -368,6 +368,6 @@ impl HttpSend for Client {
|
||||||
request: http::Request<Bytes>,
|
request: http::Request<Bytes>,
|
||||||
config: RequestConfig,
|
config: RequestConfig,
|
||||||
) -> Result<http::Response<Bytes>, HttpError> {
|
) -> Result<http::Response<Bytes>, HttpError> {
|
||||||
send_request(&self, request, config).await
|
send_request(self, request, config).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -392,7 +392,7 @@ impl Joined {
|
||||||
};
|
};
|
||||||
|
|
||||||
let txn_id = txn_id.unwrap_or_else(Uuid::new_v4).to_string();
|
let txn_id = txn_id.unwrap_or_else(Uuid::new_v4).to_string();
|
||||||
let request = send_message_event::Request::new(&self.inner.room_id(), &txn_id, &content);
|
let request = send_message_event::Request::new(self.inner.room_id(), &txn_id, &content);
|
||||||
|
|
||||||
let response = self.client.send(request, None).await?;
|
let response = self.client.send(request, None).await?;
|
||||||
Ok(response)
|
Ok(response)
|
||||||
|
@ -480,7 +480,7 @@ impl Joined {
|
||||||
|
|
||||||
(response, keys)
|
(response, keys)
|
||||||
} else {
|
} else {
|
||||||
let response = self.client.upload(&content_type, &mut reader).await?;
|
let response = self.client.upload(content_type, &mut reader).await?;
|
||||||
(response, None)
|
(response, None)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ impl RoomMember {
|
||||||
if let Some(url) = self.avatar_url() {
|
if let Some(url) = self.avatar_url() {
|
||||||
if let (Some(width), Some(height)) = (width, height) {
|
if let (Some(width), Some(height)) = (width, height) {
|
||||||
let request =
|
let request =
|
||||||
get_content_thumbnail::Request::from_url(&url, width.into(), height.into())?;
|
get_content_thumbnail::Request::from_url(url, width.into(), height.into())?;
|
||||||
let response = self.client.send(request, None).await?;
|
let response = self.client.send(request, None).await?;
|
||||||
Ok(Some(response.file))
|
Ok(Some(response.file))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -504,7 +504,7 @@ impl BaseClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(context) = &push_context {
|
if let Some(context) = &push_context {
|
||||||
let actions = push_rules.get_actions(&event.event, &context).to_vec();
|
let actions = push_rules.get_actions(&event.event, context).to_vec();
|
||||||
|
|
||||||
if actions.iter().any(|a| matches!(a, Action::Notify)) {
|
if actions.iter().any(|a| matches!(a, Action::Notify)) {
|
||||||
changes.add_notification(
|
changes.add_notification(
|
||||||
|
@ -941,7 +941,7 @@ impl BaseClient {
|
||||||
|
|
||||||
async fn apply_changes(&self, changes: &StateChanges) {
|
async fn apply_changes(&self, changes: &StateChanges) {
|
||||||
for (room_id, room_info) in &changes.room_infos {
|
for (room_id, room_info) in &changes.room_infos {
|
||||||
if let Some(room) = self.store.get_room(&room_id) {
|
if let Some(room) = self.store.get_room(room_id) {
|
||||||
room.update_summary(room_info.clone())
|
room.update_summary(room_info.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -978,7 +978,7 @@ impl BaseClient {
|
||||||
let mut user_ids = BTreeSet::new();
|
let mut user_ids = BTreeSet::new();
|
||||||
|
|
||||||
for member in &members {
|
for member in &members {
|
||||||
if self.store.get_member_event(&room_id, &member.state_key).await?.is_none() {
|
if self.store.get_member_event(room_id, &member.state_key).await?.is_none() {
|
||||||
#[cfg(feature = "encryption")]
|
#[cfg(feature = "encryption")]
|
||||||
match member.content.membership {
|
match member.content.membership {
|
||||||
MembershipState::Join | MembershipState::Invite => {
|
MembershipState::Join | MembershipState::Invite => {
|
||||||
|
@ -987,7 +987,7 @@ impl BaseClient {
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
ambiguity_cache.handle_event(&changes, room_id, &member).await?;
|
ambiguity_cache.handle_event(&changes, room_id, member).await?;
|
||||||
|
|
||||||
if member.state_key == member.sender {
|
if member.state_key == member.sender {
|
||||||
changes
|
changes
|
||||||
|
|
|
@ -92,7 +92,7 @@ impl RoomMember {
|
||||||
.map(|e| {
|
.map(|e| {
|
||||||
e.content
|
e.content
|
||||||
.users
|
.users
|
||||||
.get(&self.user_id())
|
.get(self.user_id())
|
||||||
.map(|p| (*p).into())
|
.map(|p| (*p).into())
|
||||||
.unwrap_or_else(|| e.content.users_default.into())
|
.unwrap_or_else(|| e.content.users_default.into())
|
||||||
})
|
})
|
||||||
|
|
|
@ -335,12 +335,7 @@ impl Room {
|
||||||
let is_own_user_id = |u: &str| u == self.own_user_id().as_str();
|
let is_own_user_id = |u: &str| u == self.own_user_id().as_str();
|
||||||
|
|
||||||
let members: Vec<RoomMember> = if summary.heroes.is_empty() {
|
let members: Vec<RoomMember> = if summary.heroes.is_empty() {
|
||||||
self.active_members()
|
self.active_members().await?.into_iter().filter(|u| !is_own_member(u)).take(5).collect()
|
||||||
.await?
|
|
||||||
.into_iter()
|
|
||||||
.filter(|u| !is_own_member(&u))
|
|
||||||
.take(5)
|
|
||||||
.collect()
|
|
||||||
} else {
|
} else {
|
||||||
let members: Vec<_> = stream::iter(summary.heroes.iter())
|
let members: Vec<_> = stream::iter(summary.heroes.iter())
|
||||||
.filter(|u| future::ready(!is_own_user_id(u)))
|
.filter(|u| future::ready(!is_own_user_id(u)))
|
||||||
|
@ -528,7 +523,7 @@ impl RoomInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn handle_state_event(&mut self, event: &AnyStateEventContent) -> bool {
|
pub(crate) fn handle_state_event(&mut self, event: &AnyStateEventContent) -> bool {
|
||||||
self.base_info.handle_state_event(&event)
|
self.base_info.handle_state_event(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn update_notification_count(
|
pub(crate) fn update_notification_count(
|
||||||
|
|
|
@ -197,7 +197,7 @@ impl AmbiguityCache {
|
||||||
{
|
{
|
||||||
u.clone()
|
u.clone()
|
||||||
} else {
|
} else {
|
||||||
self.store.get_users_with_display_name(&room_id, &old_name).await?
|
self.store.get_users_with_display_name(room_id, old_name).await?
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(AmbiguityMap { display_name: old_name.to_string(), users: old_display_name_map })
|
Some(AmbiguityMap { display_name: old_name.to_string(), users: old_display_name_map })
|
||||||
|
@ -231,7 +231,7 @@ impl AmbiguityCache {
|
||||||
{
|
{
|
||||||
u.clone()
|
u.clone()
|
||||||
} else {
|
} else {
|
||||||
self.store.get_users_with_display_name(&room_id, &new_display_name).await?
|
self.store.get_users_with_display_name(room_id, new_display_name).await?
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(AmbiguityMap {
|
Some(AmbiguityMap {
|
||||||
|
|
|
@ -304,7 +304,7 @@ impl SledStore {
|
||||||
event: &[u8],
|
event: &[u8],
|
||||||
) -> Result<T, SerializationError> {
|
) -> Result<T, SerializationError> {
|
||||||
if let Some(key) = &*self.store_key {
|
if let Some(key) = &*self.store_key {
|
||||||
let encrypted: EncryptedEvent = serde_json::from_slice(&event)?;
|
let encrypted: EncryptedEvent = serde_json::from_slice(event)?;
|
||||||
Ok(key.decrypt(encrypted)?)
|
Ok(key.decrypt(encrypted)?)
|
||||||
} else {
|
} else {
|
||||||
Ok(serde_json::from_slice(event)?)
|
Ok(serde_json::from_slice(event)?)
|
||||||
|
|
|
@ -139,7 +139,7 @@ impl StoreKey {
|
||||||
/// Expand the given passphrase into a KEY_SIZE long key.
|
/// Expand the given passphrase into a KEY_SIZE long key.
|
||||||
fn expand_key(passphrase: &str, salt: &[u8], rounds: u32) -> Zeroizing<Vec<u8>> {
|
fn expand_key(passphrase: &str, salt: &[u8], rounds: u32) -> Zeroizing<Vec<u8>> {
|
||||||
let mut key = Zeroizing::from(vec![0u8; KEY_SIZE]);
|
let mut key = Zeroizing::from(vec![0u8; KEY_SIZE]);
|
||||||
pbkdf2::<Hmac<Sha256>>(passphrase.as_bytes(), &salt, rounds, &mut *key);
|
pbkdf2::<Hmac<Sha256>>(passphrase.as_bytes(), salt, rounds, &mut *key);
|
||||||
key
|
key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ impl StoreKey {
|
||||||
|
|
||||||
let key = StoreKey::expand_key(passphrase, &salt, KDF_ROUNDS);
|
let key = StoreKey::expand_key(passphrase, &salt, KDF_ROUNDS);
|
||||||
let key = Key::from_slice(key.as_ref());
|
let key = Key::from_slice(key.as_ref());
|
||||||
let cipher = ChaCha20Poly1305::new(&key);
|
let cipher = ChaCha20Poly1305::new(key);
|
||||||
|
|
||||||
let mut nonce = vec![0u8; NONCE_SIZE];
|
let mut nonce = vec![0u8; NONCE_SIZE];
|
||||||
nonce.try_fill(&mut rng)?;
|
nonce.try_fill(&mut rng)?;
|
||||||
|
@ -230,7 +230,7 @@ impl StoreKey {
|
||||||
|
|
||||||
let decrypted = match encrypted.ciphertext_info {
|
let decrypted = match encrypted.ciphertext_info {
|
||||||
CipherTextInfo::ChaCha20Poly1305 { nonce, ciphertext } => {
|
CipherTextInfo::ChaCha20Poly1305 { nonce, ciphertext } => {
|
||||||
let cipher = ChaCha20Poly1305::new(&key);
|
let cipher = ChaCha20Poly1305::new(key);
|
||||||
let nonce = Nonce::from_slice(&nonce);
|
let nonce = Nonce::from_slice(&nonce);
|
||||||
cipher.decrypt(nonce, ciphertext.as_ref())?
|
cipher.decrypt(nonce, ciphertext.as_ref())?
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,7 +161,7 @@ fn encrypt_helper(mut plaintext: &mut [u8], passphrase: &str, rounds: u32) -> St
|
||||||
pbkdf2::<Hmac<Sha512>>(passphrase.as_bytes(), &salt, rounds, &mut derived_keys);
|
pbkdf2::<Hmac<Sha512>>(passphrase.as_bytes(), &salt, rounds, &mut derived_keys);
|
||||||
let (key, hmac_key) = derived_keys.split_at(KEY_SIZE);
|
let (key, hmac_key) = derived_keys.split_at(KEY_SIZE);
|
||||||
|
|
||||||
let mut aes = Aes256Ctr::new_var(&key, &iv.to_be_bytes()).expect("Can't create AES object");
|
let mut aes = Aes256Ctr::new_var(key, &iv.to_be_bytes()).expect("Can't create AES object");
|
||||||
|
|
||||||
aes.apply_keystream(&mut plaintext);
|
aes.apply_keystream(&mut plaintext);
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ fn encrypt_helper(mut plaintext: &mut [u8], passphrase: &str, rounds: u32) -> St
|
||||||
payload.extend(&salt);
|
payload.extend(&salt);
|
||||||
payload.extend(&iv.to_be_bytes());
|
payload.extend(&iv.to_be_bytes());
|
||||||
payload.extend(&rounds.to_be_bytes());
|
payload.extend(&rounds.to_be_bytes());
|
||||||
payload.extend_from_slice(&plaintext);
|
payload.extend_from_slice(plaintext);
|
||||||
|
|
||||||
let mut hmac = Hmac::<Sha256>::new_varkey(hmac_key).expect("Can't create HMAC object");
|
let mut hmac = Hmac::<Sha256>::new_varkey(hmac_key).expect("Can't create HMAC object");
|
||||||
hmac.update(&payload);
|
hmac.update(&payload);
|
||||||
|
@ -218,7 +218,7 @@ fn decrypt_helper(ciphertext: &str, passphrase: &str) -> Result<String, KeyExpor
|
||||||
hmac.verify(&mac).map_err(|_| KeyExportError::InvalidMac)?;
|
hmac.verify(&mac).map_err(|_| KeyExportError::InvalidMac)?;
|
||||||
|
|
||||||
let mut ciphertext = &mut decoded[ciphertext_start..ciphertext_end];
|
let mut ciphertext = &mut decoded[ciphertext_start..ciphertext_end];
|
||||||
let mut aes = Aes256Ctr::new_var(&key, &iv).expect("Can't create an AES object");
|
let mut aes = Aes256Ctr::new_var(key, &iv).expect("Can't create an AES object");
|
||||||
aes.apply_keystream(&mut ciphertext);
|
aes.apply_keystream(&mut ciphertext);
|
||||||
|
|
||||||
Ok(String::from_utf8(ciphertext.to_owned())?)
|
Ok(String::from_utf8(ciphertext.to_owned())?)
|
||||||
|
|
|
@ -398,7 +398,7 @@ impl ReadOnlyDevice {
|
||||||
// If it's one of our own devices, just check that
|
// If it's one of our own devices, just check that
|
||||||
// we signed the device.
|
// we signed the device.
|
||||||
UserIdentities::Own(_) => {
|
UserIdentities::Own(_) => {
|
||||||
own_identity.is_device_signed(&self).map_or(false, |_| true)
|
own_identity.is_device_signed(self).map_or(false, |_| true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's a device from someone else, first check
|
// If it's a device from someone else, first check
|
||||||
|
@ -406,10 +406,10 @@ impl ReadOnlyDevice {
|
||||||
// check if the other user has signed this device.
|
// check if the other user has signed this device.
|
||||||
UserIdentities::Other(device_identity) => {
|
UserIdentities::Other(device_identity) => {
|
||||||
own_identity
|
own_identity
|
||||||
.is_identity_signed(&device_identity)
|
.is_identity_signed(device_identity)
|
||||||
.map_or(false, |_| true)
|
.map_or(false, |_| true)
|
||||||
&& device_identity
|
&& device_identity
|
||||||
.is_device_signed(&self)
|
.is_device_signed(self)
|
||||||
.map_or(false, |_| true)
|
.map_or(false, |_| true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -455,7 +455,7 @@ impl ReadOnlyDevice {
|
||||||
return Err(OlmError::MissingSession);
|
return Err(OlmError::MissingSession);
|
||||||
};
|
};
|
||||||
|
|
||||||
let message = session.encrypt(&self, event_type, content).await?;
|
let message = session.encrypt(self, event_type, content).await?;
|
||||||
|
|
||||||
Ok((session, message))
|
Ok((session, message))
|
||||||
}
|
}
|
||||||
|
|
|
@ -540,7 +540,7 @@ impl KeyRequestMachine {
|
||||||
&self,
|
&self,
|
||||||
key_info: &RequestedKeyInfo,
|
key_info: &RequestedKeyInfo,
|
||||||
) -> Result<bool, CryptoStoreError> {
|
) -> Result<bool, CryptoStoreError> {
|
||||||
let request = self.store.get_key_request_by_info(&key_info).await?;
|
let request = self.store.get_key_request_by_info(key_info).await?;
|
||||||
|
|
||||||
// Don't send out duplicate requests, users can re-request them if they
|
// Don't send out duplicate requests, users can re-request them if they
|
||||||
// think a second request might succeed.
|
// think a second request might succeed.
|
||||||
|
@ -1244,7 +1244,7 @@ mod test {
|
||||||
.store
|
.store
|
||||||
.get_inbound_group_session(
|
.get_inbound_group_session(
|
||||||
&room_id(),
|
&room_id(),
|
||||||
&bob_account.identity_keys().curve25519(),
|
bob_account.identity_keys().curve25519(),
|
||||||
group_session.session_id()
|
group_session.session_id()
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -1393,7 +1393,7 @@ mod test {
|
||||||
.store
|
.store
|
||||||
.get_inbound_group_session(
|
.get_inbound_group_session(
|
||||||
&room_id(),
|
&room_id(),
|
||||||
&bob_account.identity_keys().curve25519(),
|
bob_account.identity_keys().curve25519(),
|
||||||
group_session.session_id()
|
group_session.session_id()
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -123,7 +123,7 @@ impl OlmMachine {
|
||||||
pub fn new(user_id: &UserId, device_id: &DeviceId) -> Self {
|
pub fn new(user_id: &UserId, device_id: &DeviceId) -> Self {
|
||||||
let store: Box<dyn CryptoStore> = Box::new(MemoryStore::new());
|
let store: Box<dyn CryptoStore> = Box::new(MemoryStore::new());
|
||||||
let device_id: DeviceIdBox = device_id.into();
|
let device_id: DeviceIdBox = device_id.into();
|
||||||
let account = ReadOnlyAccount::new(&user_id, &device_id);
|
let account = ReadOnlyAccount::new(user_id, &device_id);
|
||||||
|
|
||||||
OlmMachine::new_helper(
|
OlmMachine::new_helper(
|
||||||
user_id,
|
user_id,
|
||||||
|
@ -334,7 +334,7 @@ impl OlmMachine {
|
||||||
self.receive_keys_claim_response(response).await?;
|
self.receive_keys_claim_response(response).await?;
|
||||||
}
|
}
|
||||||
IncomingResponse::ToDevice(_) => {
|
IncomingResponse::ToDevice(_) => {
|
||||||
self.mark_to_device_request_as_sent(&request_id).await?;
|
self.mark_to_device_request_as_sent(request_id).await?;
|
||||||
}
|
}
|
||||||
IncomingResponse::SigningKeysUpload(_) => {
|
IncomingResponse::SigningKeysUpload(_) => {
|
||||||
self.receive_cross_signing_upload_response().await?;
|
self.receive_cross_signing_upload_response().await?;
|
||||||
|
@ -738,7 +738,7 @@ impl OlmMachine {
|
||||||
async fn handle_to_device_event(&self, event: &AnyToDeviceEvent) {
|
async fn handle_to_device_event(&self, event: &AnyToDeviceEvent) {
|
||||||
match event {
|
match event {
|
||||||
AnyToDeviceEvent::RoomKeyRequest(e) => {
|
AnyToDeviceEvent::RoomKeyRequest(e) => {
|
||||||
self.key_request_machine.receive_incoming_key_request(&e)
|
self.key_request_machine.receive_incoming_key_request(e)
|
||||||
}
|
}
|
||||||
AnyToDeviceEvent::KeyVerificationAccept(..)
|
AnyToDeviceEvent::KeyVerificationAccept(..)
|
||||||
| AnyToDeviceEvent::KeyVerificationCancel(..)
|
| AnyToDeviceEvent::KeyVerificationCancel(..)
|
||||||
|
@ -748,7 +748,7 @@ impl OlmMachine {
|
||||||
| AnyToDeviceEvent::KeyVerificationReady(..)
|
| AnyToDeviceEvent::KeyVerificationReady(..)
|
||||||
| AnyToDeviceEvent::KeyVerificationDone(..)
|
| AnyToDeviceEvent::KeyVerificationDone(..)
|
||||||
| AnyToDeviceEvent::KeyVerificationStart(..) => {
|
| AnyToDeviceEvent::KeyVerificationStart(..) => {
|
||||||
self.handle_verification_event(&event).await;
|
self.handle_verification_event(event).await;
|
||||||
}
|
}
|
||||||
AnyToDeviceEvent::Dummy(_) => {}
|
AnyToDeviceEvent::Dummy(_) => {}
|
||||||
AnyToDeviceEvent::RoomKey(_) => {}
|
AnyToDeviceEvent::RoomKey(_) => {}
|
||||||
|
@ -794,7 +794,7 @@ impl OlmMachine {
|
||||||
self.update_one_time_key_count(one_time_keys_counts).await;
|
self.update_one_time_key_count(one_time_keys_counts).await;
|
||||||
|
|
||||||
for user_id in &changed_devices.changed {
|
for user_id in &changed_devices.changed {
|
||||||
if let Err(e) = self.identity_manager.mark_user_as_changed(&user_id).await {
|
if let Err(e) = self.identity_manager.mark_user_as_changed(user_id).await {
|
||||||
error!("Error marking a tracked user as changed {:?}", e);
|
error!("Error marking a tracked user as changed {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1200,7 +1200,7 @@ impl OlmMachine {
|
||||||
.get_inbound_group_sessions()
|
.get_inbound_group_sessions()
|
||||||
.await?
|
.await?
|
||||||
.drain(..)
|
.drain(..)
|
||||||
.filter(|s| predicate(&s))
|
.filter(|s| predicate(s))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
for session in sessions.drain(..) {
|
for session in sessions.drain(..) {
|
||||||
|
|
|
@ -376,7 +376,7 @@ impl Account {
|
||||||
plaintext: &str,
|
plaintext: &str,
|
||||||
) -> OlmResult<(Raw<AnyToDeviceEvent>, String)> {
|
) -> OlmResult<(Raw<AnyToDeviceEvent>, String)> {
|
||||||
// TODO make the errors a bit more specific.
|
// TODO make the errors a bit more specific.
|
||||||
let decrypted_json: Value = serde_json::from_str(&plaintext)?;
|
let decrypted_json: Value = serde_json::from_str(plaintext)?;
|
||||||
|
|
||||||
let encrypted_sender = decrypted_json
|
let encrypted_sender = decrypted_json
|
||||||
.get("sender")
|
.get("sender")
|
||||||
|
@ -874,7 +874,7 @@ impl ReadOnlyAccount {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
device.verify_one_time_key(&one_time_key).map_err(|e| {
|
device.verify_one_time_key(one_time_key).map_err(|e| {
|
||||||
SessionCreationError::InvalidSignature(
|
SessionCreationError::InvalidSignature(
|
||||||
device.user_id().to_owned(),
|
device.user_id().to_owned(),
|
||||||
device.device_id().into(),
|
device.device_id().into(),
|
||||||
|
@ -889,7 +889,7 @@ impl ReadOnlyAccount {
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
self.create_outbound_session_helper(curve_key, &one_time_key).await.map_err(|e| {
|
self.create_outbound_session_helper(curve_key, one_time_key).await.map_err(|e| {
|
||||||
SessionCreationError::OlmError(
|
SessionCreationError::OlmError(
|
||||||
device.user_id().to_owned(),
|
device.user_id().to_owned(),
|
||||||
device.device_id().into(),
|
device.device_id().into(),
|
||||||
|
@ -974,7 +974,7 @@ impl ReadOnlyAccount {
|
||||||
let inbound = InboundGroupSession::new(
|
let inbound = InboundGroupSession::new(
|
||||||
sender_key,
|
sender_key,
|
||||||
signing_key,
|
signing_key,
|
||||||
&room_id,
|
room_id,
|
||||||
outbound.session_key().await,
|
outbound.session_key().await,
|
||||||
Some(visibility),
|
Some(visibility),
|
||||||
)
|
)
|
||||||
|
|
|
@ -144,7 +144,7 @@ impl PrivateCrossSigningIdentity {
|
||||||
.await
|
.await
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(SignatureError::MissingSigningKey)?
|
.ok_or(SignatureError::MissingSigningKey)?
|
||||||
.sign_user(&user_identity)
|
.sign_user(user_identity)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(SignatureUploadRequest::new(signed_keys))
|
Ok(SignatureUploadRequest::new(signed_keys))
|
||||||
|
|
|
@ -320,7 +320,7 @@ impl Signing {
|
||||||
let ciphertext = &decode(pickled.ciphertext)?;
|
let ciphertext = &decode(pickled.ciphertext)?;
|
||||||
|
|
||||||
let seed = cipher
|
let seed = cipher
|
||||||
.decrypt(&nonce, ciphertext.as_slice())
|
.decrypt(nonce, ciphertext.as_slice())
|
||||||
.map_err(|e| SigningError::Decryption(e.to_string()))?;
|
.map_err(|e| SigningError::Decryption(e.to_string()))?;
|
||||||
|
|
||||||
Ok(Self::from_seed(seed))
|
Ok(Self::from_seed(seed))
|
||||||
|
|
|
@ -133,7 +133,7 @@ mod test {
|
||||||
.verify_json(
|
.verify_json(
|
||||||
&user_id!("@example:localhost"),
|
&user_id!("@example:localhost"),
|
||||||
&DeviceKeyId::from_parts(DeviceKeyAlgorithm::Ed25519, "GBEWHQOYGS".into()),
|
&DeviceKeyId::from_parts(DeviceKeyAlgorithm::Ed25519, "GBEWHQOYGS".into()),
|
||||||
&signing_key,
|
signing_key,
|
||||||
&mut device_keys,
|
&mut device_keys,
|
||||||
)
|
)
|
||||||
.expect("Can't verify device keys");
|
.expect("Can't verify device keys");
|
||||||
|
|
|
@ -210,7 +210,7 @@ impl GroupSessionManager {
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
settings: EncryptionSettings,
|
settings: EncryptionSettings,
|
||||||
) -> OlmResult<(OutboundGroupSession, Option<InboundGroupSession>)> {
|
) -> OlmResult<(OutboundGroupSession, Option<InboundGroupSession>)> {
|
||||||
let outbound_session = self.sessions.get_or_load(&room_id).await?;
|
let outbound_session = self.sessions.get_or_load(room_id).await?;
|
||||||
|
|
||||||
// If there is no session or the session has expired or is invalid,
|
// If there is no session or the session has expired or is invalid,
|
||||||
// create a new one.
|
// create a new one.
|
||||||
|
@ -331,7 +331,7 @@ impl GroupSessionManager {
|
||||||
let mut should_rotate = user_left || visibility_changed;
|
let mut should_rotate = user_left || visibility_changed;
|
||||||
|
|
||||||
for user_id in users {
|
for user_id in users {
|
||||||
let user_devices = self.store.get_user_devices(&user_id).await?;
|
let user_devices = self.store.get_user_devices(user_id).await?;
|
||||||
let non_blacklisted_devices: Vec<Device> =
|
let non_blacklisted_devices: Vec<Device> =
|
||||||
user_devices.devices().filter(|d| !d.is_blacklisted()).collect();
|
user_devices.devices().filter(|d| !d.is_blacklisted()).collect();
|
||||||
|
|
||||||
|
|
|
@ -246,7 +246,7 @@ impl SessionManager {
|
||||||
|
|
||||||
for (user_id, user_devices) in &response.one_time_keys {
|
for (user_id, user_devices) in &response.one_time_keys {
|
||||||
for (device_id, key_map) in user_devices {
|
for (device_id, key_map) in user_devices {
|
||||||
let device = match self.store.get_readonly_device(&user_id, device_id).await {
|
let device = match self.store.get_readonly_device(user_id, device_id).await {
|
||||||
Ok(Some(d)) => d,
|
Ok(Some(d)) => d,
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
warn!(
|
warn!(
|
||||||
|
@ -267,7 +267,7 @@ impl SessionManager {
|
||||||
|
|
||||||
info!("Creating outbound Session for {} {}", user_id, device_id);
|
info!("Creating outbound Session for {} {}", user_id, device_id);
|
||||||
|
|
||||||
let session = match self.account.create_outbound_session(device, &key_map).await {
|
let session = match self.account.create_outbound_session(device, key_map).await {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("Error creating new outbound session {:?}", e);
|
warn!("Error creating new outbound session {:?}", e);
|
||||||
|
@ -277,9 +277,9 @@ impl SessionManager {
|
||||||
|
|
||||||
changes.sessions.push(session);
|
changes.sessions.push(session);
|
||||||
|
|
||||||
self.key_request_machine.retry_keyshare(&user_id, device_id);
|
self.key_request_machine.retry_keyshare(user_id, device_id);
|
||||||
|
|
||||||
if let Err(e) = self.check_if_unwedged(&user_id, device_id).await {
|
if let Err(e) = self.check_if_unwedged(user_id, device_id).await {
|
||||||
error!(
|
error!(
|
||||||
"Error while treating an unwedged device {} {} {:?}",
|
"Error while treating an unwedged device {} {} {:?}",
|
||||||
user_id, device_id, e
|
user_id, device_id, e
|
||||||
|
@ -426,7 +426,7 @@ mod test {
|
||||||
|
|
||||||
assert!(!manager.users_for_key_claim.contains_key(bob.user_id()));
|
assert!(!manager.users_for_key_claim.contains_key(bob.user_id()));
|
||||||
assert!(!manager.is_device_wedged(&bob_device));
|
assert!(!manager.is_device_wedged(&bob_device));
|
||||||
manager.mark_device_as_wedged(bob_device.user_id(), &curve_key).await.unwrap();
|
manager.mark_device_as_wedged(bob_device.user_id(), curve_key).await.unwrap();
|
||||||
assert!(manager.is_device_wedged(&bob_device));
|
assert!(manager.is_device_wedged(&bob_device));
|
||||||
assert!(manager.users_for_key_claim.contains_key(bob.user_id()));
|
assert!(manager.users_for_key_claim.contains_key(bob.user_id()));
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ impl PickleKey {
|
||||||
|
|
||||||
fn expand_key(passphrase: &str, salt: &[u8], rounds: u32) -> Zeroizing<Vec<u8>> {
|
fn expand_key(passphrase: &str, salt: &[u8], rounds: u32) -> Zeroizing<Vec<u8>> {
|
||||||
let mut key = Zeroizing::from(vec![0u8; KEY_SIZE]);
|
let mut key = Zeroizing::from(vec![0u8; KEY_SIZE]);
|
||||||
pbkdf2::<Hmac<Sha256>>(passphrase.as_bytes(), &salt, rounds, &mut *key);
|
pbkdf2::<Hmac<Sha256>>(passphrase.as_bytes(), salt, rounds, &mut *key);
|
||||||
key
|
key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,13 +133,13 @@ impl PickleKey {
|
||||||
|
|
||||||
let key = PickleKey::expand_key(passphrase, &salt, KDF_ROUNDS);
|
let key = PickleKey::expand_key(passphrase, &salt, KDF_ROUNDS);
|
||||||
let key = GenericArray::from_slice(key.as_ref());
|
let key = GenericArray::from_slice(key.as_ref());
|
||||||
let cipher = Aes256Gcm::new(&key);
|
let cipher = Aes256Gcm::new(key);
|
||||||
|
|
||||||
let mut nonce = vec![0u8; NONCE_SIZE];
|
let mut nonce = vec![0u8; NONCE_SIZE];
|
||||||
getrandom(&mut nonce).expect("Can't generate new random nonce for the pickle key");
|
getrandom(&mut nonce).expect("Can't generate new random nonce for the pickle key");
|
||||||
|
|
||||||
let ciphertext = cipher
|
let ciphertext = cipher
|
||||||
.encrypt(&GenericArray::from_slice(nonce.as_ref()), self.aes256_key.as_slice())
|
.encrypt(GenericArray::from_slice(nonce.as_ref()), self.aes256_key.as_slice())
|
||||||
.expect("Can't encrypt pickle key");
|
.expect("Can't encrypt pickle key");
|
||||||
|
|
||||||
EncryptedPickleKey {
|
EncryptedPickleKey {
|
||||||
|
@ -169,7 +169,7 @@ impl PickleKey {
|
||||||
|
|
||||||
let decrypted = match encrypted.ciphertext_info {
|
let decrypted = match encrypted.ciphertext_info {
|
||||||
CipherTextInfo::Aes256Gcm { nonce, ciphertext } => {
|
CipherTextInfo::Aes256Gcm { nonce, ciphertext } => {
|
||||||
let cipher = Aes256Gcm::new(&key);
|
let cipher = Aes256Gcm::new(key);
|
||||||
let nonce = GenericArray::from_slice(&nonce);
|
let nonce = GenericArray::from_slice(&nonce);
|
||||||
cipher.decrypt(nonce, ciphertext.as_ref())?
|
cipher.decrypt(nonce, ciphertext.as_ref())?
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,7 +213,7 @@ impl SledStore {
|
||||||
let session_cache = SessionStore::new();
|
let session_cache = SessionStore::new();
|
||||||
|
|
||||||
let pickle_key = if let Some(passphrase) = passphrase {
|
let pickle_key = if let Some(passphrase) = passphrase {
|
||||||
Self::get_or_create_pickle_key(&passphrase, &db)?
|
Self::get_or_create_pickle_key(passphrase, &db)?
|
||||||
} else {
|
} else {
|
||||||
PickleKey::try_from(DEFAULT_PICKLE.as_bytes().to_vec())
|
PickleKey::try_from(DEFAULT_PICKLE.as_bytes().to_vec())
|
||||||
.expect("Can't create default pickle key")
|
.expect("Can't create default pickle key")
|
||||||
|
@ -1111,7 +1111,7 @@ mod test {
|
||||||
|
|
||||||
let store = SledStore::open_with_passphrase(tmpdir_path, None).expect("Can't create store");
|
let store = SledStore::open_with_passphrase(tmpdir_path, None).expect("Can't create store");
|
||||||
|
|
||||||
let account = ReadOnlyAccount::new(&user_id, &device_id);
|
let account = ReadOnlyAccount::new(&user_id, device_id);
|
||||||
|
|
||||||
store.save_account(account.clone()).await.expect("Can't save account");
|
store.save_account(account.clone()).await.expect("Can't save account");
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,8 @@ pub enum AnyEvent<'a> {
|
||||||
impl AnyEvent<'_> {
|
impl AnyEvent<'_> {
|
||||||
pub fn sender(&self) -> &UserId {
|
pub fn sender(&self) -> &UserId {
|
||||||
match self {
|
match self {
|
||||||
Self::Room(e) => &e.sender(),
|
Self::Room(e) => e.sender(),
|
||||||
Self::ToDevice(e) => &e.sender(),
|
Self::ToDevice(e) => e.sender(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,7 +382,7 @@ impl<'a> StartContent<'a> {
|
||||||
pub fn flow_id(&self) -> &str {
|
pub fn flow_id(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
Self::ToDevice(c) => &c.transaction_id,
|
Self::ToDevice(c) => &c.transaction_id,
|
||||||
Self::Room(c) => &c.relation.event_id.as_str(),
|
Self::Room(c) => c.relation.event_id.as_str(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,7 +434,7 @@ impl<'a> DoneContent<'a> {
|
||||||
pub fn flow_id(&self) -> &str {
|
pub fn flow_id(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
Self::ToDevice(c) => &c.transaction_id,
|
Self::ToDevice(c) => &c.transaction_id,
|
||||||
Self::Room(c) => &c.relation.event_id.as_str(),
|
Self::Room(c) => c.relation.event_id.as_str(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,7 @@ impl VerificationMachine {
|
||||||
AnyVerificationContent::Start(c) => {
|
AnyVerificationContent::Start(c) => {
|
||||||
if let Some(request) = self.requests.get(flow_id.as_str()) {
|
if let Some(request) = self.requests.get(flow_id.as_str()) {
|
||||||
if request.flow_id() == &flow_id {
|
if request.flow_id() == &flow_id {
|
||||||
request.receive_start(event.sender(), &c).await?
|
request.receive_start(event.sender(), c).await?
|
||||||
} else {
|
} else {
|
||||||
flow_id_mismatch();
|
flow_id_mismatch();
|
||||||
}
|
}
|
||||||
|
|
|
@ -275,7 +275,7 @@ impl IdentitiesBeingVerified {
|
||||||
// We only sign other users here.
|
// We only sign other users here.
|
||||||
let request = if let Some(i) = i.other() {
|
let request = if let Some(i) = i.other() {
|
||||||
// Signing can fail if the user signing key is missing.
|
// Signing can fail if the user signing key is missing.
|
||||||
match self.private_identity.sign_user(&i).await {
|
match self.private_identity.sign_user(i).await {
|
||||||
Ok(r) => Some(r),
|
Ok(r) => Some(r),
|
||||||
Err(SignatureError::MissingSigningKey) => {
|
Err(SignatureError::MissingSigningKey) => {
|
||||||
warn!(
|
warn!(
|
||||||
|
|
|
@ -582,7 +582,7 @@ impl RequestState<Ready> {
|
||||||
"Received a new verification start event",
|
"Received a new verification start event",
|
||||||
);
|
);
|
||||||
|
|
||||||
let device = if let Some(d) = self.store.get_device(&sender, content.from_device()).await? {
|
let device = if let Some(d) = self.store.get_device(sender, content.from_device()).await? {
|
||||||
d
|
d
|
||||||
} else {
|
} else {
|
||||||
warn!(
|
warn!(
|
||||||
|
@ -594,7 +594,7 @@ impl RequestState<Ready> {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
let identity = self.store.get_user_identity(&sender).await?;
|
let identity = self.store.get_user_identity(sender).await?;
|
||||||
|
|
||||||
match content.method() {
|
match content.method() {
|
||||||
StartMethod::SasV1(_) => match self.to_started_sas(content, device.clone(), identity) {
|
StartMethod::SasV1(_) => match self.to_started_sas(content, device.clone(), identity) {
|
||||||
|
|
|
@ -188,7 +188,7 @@ pub fn receive_mac_event(
|
||||||
let mut verified_devices = Vec::new();
|
let mut verified_devices = Vec::new();
|
||||||
let mut verified_identities = Vec::new();
|
let mut verified_identities = Vec::new();
|
||||||
|
|
||||||
let info = extra_mac_info_receive(&ids, flow_id);
|
let info = extra_mac_info_receive(ids, flow_id);
|
||||||
|
|
||||||
trace!(
|
trace!(
|
||||||
"Received a key.verification.mac event from {} {}",
|
"Received a key.verification.mac event from {} {}",
|
||||||
|
@ -395,7 +395,7 @@ pub fn get_emoji(
|
||||||
) -> [(&'static str, &'static str); 7] {
|
) -> [(&'static str, &'static str); 7] {
|
||||||
let bytes = sas
|
let bytes = sas
|
||||||
.generate_bytes(
|
.generate_bytes(
|
||||||
&extra_info_sas(&ids, &sas.public_key(), their_pubkey, &flow_id, we_started),
|
&extra_info_sas(ids, &sas.public_key(), their_pubkey, flow_id, we_started),
|
||||||
6,
|
6,
|
||||||
)
|
)
|
||||||
.expect("Can't generate bytes");
|
.expect("Can't generate bytes");
|
||||||
|
@ -432,7 +432,7 @@ pub fn get_emoji_index(
|
||||||
) -> [u8; 7] {
|
) -> [u8; 7] {
|
||||||
let bytes = sas
|
let bytes = sas
|
||||||
.generate_bytes(
|
.generate_bytes(
|
||||||
&extra_info_sas(&ids, &sas.public_key(), their_pubkey, &flow_id, we_started),
|
&extra_info_sas(ids, &sas.public_key(), their_pubkey, flow_id, we_started),
|
||||||
6,
|
6,
|
||||||
)
|
)
|
||||||
.expect("Can't generate bytes");
|
.expect("Can't generate bytes");
|
||||||
|
@ -507,7 +507,7 @@ pub fn get_decimal(
|
||||||
) -> (u16, u16, u16) {
|
) -> (u16, u16, u16) {
|
||||||
let bytes = sas
|
let bytes = sas
|
||||||
.generate_bytes(
|
.generate_bytes(
|
||||||
&extra_info_sas(&ids, &sas.public_key(), their_pubkey, &flow_id, we_started),
|
&extra_info_sas(ids, &sas.public_key(), their_pubkey, flow_id, we_started),
|
||||||
5,
|
5,
|
||||||
)
|
)
|
||||||
.expect("Can't generate bytes");
|
.expect("Can't generate bytes");
|
||||||
|
|
|
@ -584,7 +584,7 @@ mod test {
|
||||||
let content = MacContent::try_from(&content).unwrap();
|
let content = MacContent::try_from(&content).unwrap();
|
||||||
alice.receive_any_event(bob.user_id(), &content.into());
|
alice.receive_any_event(bob.user_id(), &content.into());
|
||||||
|
|
||||||
assert!(alice.verified_devices().unwrap().contains(&alice.other_device()));
|
assert!(alice.verified_devices().unwrap().contains(alice.other_device()));
|
||||||
assert!(bob.verified_devices().unwrap().contains(&bob.other_device()));
|
assert!(bob.verified_devices().unwrap().contains(bob.other_device()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -285,12 +285,12 @@ impl<S: Clone> SasState<S> {
|
||||||
/// Get our own user id.
|
/// Get our own user id.
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn user_id(&self) -> &UserId {
|
pub fn user_id(&self) -> &UserId {
|
||||||
&self.ids.account.user_id()
|
self.ids.account.user_id()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get our own device id.
|
/// Get our own device id.
|
||||||
pub fn device_id(&self) -> &DeviceId {
|
pub fn device_id(&self) -> &DeviceId {
|
||||||
&self.ids.account.device_id()
|
self.ids.account.device_id()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -448,7 +448,7 @@ impl SasState<Created> {
|
||||||
sender: &UserId,
|
sender: &UserId,
|
||||||
content: &AcceptContent,
|
content: &AcceptContent,
|
||||||
) -> Result<SasState<Accepted>, SasState<Cancelled>> {
|
) -> Result<SasState<Accepted>, SasState<Cancelled>> {
|
||||||
self.check_event(&sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
|
self.check_event(sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
|
||||||
|
|
||||||
if let AcceptMethod::MSasV1(content) = content.method() {
|
if let AcceptMethod::MSasV1(content) = content.method() {
|
||||||
let accepted_protocols =
|
let accepted_protocols =
|
||||||
|
@ -604,7 +604,7 @@ impl SasState<Started> {
|
||||||
sender: &UserId,
|
sender: &UserId,
|
||||||
content: &KeyContent,
|
content: &KeyContent,
|
||||||
) -> Result<SasState<KeyReceived>, SasState<Cancelled>> {
|
) -> Result<SasState<KeyReceived>, SasState<Cancelled>> {
|
||||||
self.check_event(&sender, &content.flow_id()).map_err(|c| self.clone().cancel(c))?;
|
self.check_event(sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
|
||||||
|
|
||||||
let their_pubkey = content.public_key().to_owned();
|
let their_pubkey = content.public_key().to_owned();
|
||||||
|
|
||||||
|
@ -644,7 +644,7 @@ impl SasState<Accepted> {
|
||||||
sender: &UserId,
|
sender: &UserId,
|
||||||
content: &KeyContent,
|
content: &KeyContent,
|
||||||
) -> Result<SasState<KeyReceived>, SasState<Cancelled>> {
|
) -> Result<SasState<KeyReceived>, SasState<Cancelled>> {
|
||||||
self.check_event(&sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
|
self.check_event(sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
|
||||||
|
|
||||||
let commitment = calculate_commitment(
|
let commitment = calculate_commitment(
|
||||||
content.public_key(),
|
content.public_key(),
|
||||||
|
@ -781,14 +781,14 @@ impl SasState<KeyReceived> {
|
||||||
sender: &UserId,
|
sender: &UserId,
|
||||||
content: &MacContent,
|
content: &MacContent,
|
||||||
) -> Result<SasState<MacReceived>, SasState<Cancelled>> {
|
) -> Result<SasState<MacReceived>, SasState<Cancelled>> {
|
||||||
self.check_event(&sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
|
self.check_event(sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
|
||||||
|
|
||||||
let (devices, master_keys) = receive_mac_event(
|
let (devices, master_keys) = receive_mac_event(
|
||||||
&self.inner.lock().unwrap(),
|
&self.inner.lock().unwrap(),
|
||||||
&self.ids,
|
&self.ids,
|
||||||
self.verification_flow_id.as_str(),
|
self.verification_flow_id.as_str(),
|
||||||
sender,
|
sender,
|
||||||
&content,
|
content,
|
||||||
)
|
)
|
||||||
.map_err(|c| self.clone().cancel(c))?;
|
.map_err(|c| self.clone().cancel(c))?;
|
||||||
|
|
||||||
|
@ -846,9 +846,9 @@ impl SasState<Confirmed> {
|
||||||
let (devices, master_keys) = receive_mac_event(
|
let (devices, master_keys) = receive_mac_event(
|
||||||
&self.inner.lock().unwrap(),
|
&self.inner.lock().unwrap(),
|
||||||
&self.ids,
|
&self.ids,
|
||||||
&self.verification_flow_id.as_str(),
|
self.verification_flow_id.as_str(),
|
||||||
sender,
|
sender,
|
||||||
&content,
|
content,
|
||||||
)
|
)
|
||||||
.map_err(|c| self.clone().cancel(c))?;
|
.map_err(|c| self.clone().cancel(c))?;
|
||||||
|
|
||||||
|
@ -881,14 +881,14 @@ impl SasState<Confirmed> {
|
||||||
sender: &UserId,
|
sender: &UserId,
|
||||||
content: &MacContent,
|
content: &MacContent,
|
||||||
) -> Result<SasState<WaitingForDone>, SasState<Cancelled>> {
|
) -> Result<SasState<WaitingForDone>, SasState<Cancelled>> {
|
||||||
self.check_event(&sender, &content.flow_id()).map_err(|c| self.clone().cancel(c))?;
|
self.check_event(sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
|
||||||
|
|
||||||
let (devices, master_keys) = receive_mac_event(
|
let (devices, master_keys) = receive_mac_event(
|
||||||
&self.inner.lock().unwrap(),
|
&self.inner.lock().unwrap(),
|
||||||
&self.ids,
|
&self.ids,
|
||||||
&self.verification_flow_id.as_str(),
|
self.verification_flow_id.as_str(),
|
||||||
sender,
|
sender,
|
||||||
&content,
|
content,
|
||||||
)
|
)
|
||||||
.map_err(|c| self.clone().cancel(c))?;
|
.map_err(|c| self.clone().cancel(c))?;
|
||||||
|
|
||||||
|
@ -965,7 +965,7 @@ impl SasState<MacReceived> {
|
||||||
&self.inner.lock().unwrap(),
|
&self.inner.lock().unwrap(),
|
||||||
&self.ids,
|
&self.ids,
|
||||||
&self.state.their_pubkey,
|
&self.state.their_pubkey,
|
||||||
&self.verification_flow_id.as_str(),
|
self.verification_flow_id.as_str(),
|
||||||
self.state.we_started,
|
self.state.we_started,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -993,7 +993,7 @@ impl SasState<MacReceived> {
|
||||||
&self.inner.lock().unwrap(),
|
&self.inner.lock().unwrap(),
|
||||||
&self.ids,
|
&self.ids,
|
||||||
&self.state.their_pubkey,
|
&self.state.their_pubkey,
|
||||||
&self.verification_flow_id.as_str(),
|
self.verification_flow_id.as_str(),
|
||||||
self.state.we_started,
|
self.state.we_started,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1036,7 +1036,7 @@ impl SasState<WaitingForDone> {
|
||||||
sender: &UserId,
|
sender: &UserId,
|
||||||
content: &DoneContent,
|
content: &DoneContent,
|
||||||
) -> Result<SasState<Done>, SasState<Cancelled>> {
|
) -> Result<SasState<Done>, SasState<Cancelled>> {
|
||||||
self.check_event(&sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
|
self.check_event(sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
|
||||||
|
|
||||||
Ok(SasState {
|
Ok(SasState {
|
||||||
inner: self.inner,
|
inner: self.inner,
|
||||||
|
|
Loading…
Reference in New Issue