mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
api!: remove public APIs to check if the chat is protected
This commit is contained in:
@@ -19,18 +19,6 @@ pub struct FullChat {
|
|||||||
id: u32,
|
id: u32,
|
||||||
name: String,
|
name: String,
|
||||||
|
|
||||||
/// True if the chat is protected.
|
|
||||||
///
|
|
||||||
/// Only verified contacts
|
|
||||||
/// as determined by [`ContactObject::is_verified`] / `Contact.isVerified`
|
|
||||||
/// can be added to protected chats.
|
|
||||||
///
|
|
||||||
/// Protected chats are created using [`create_group_chat`] / `createGroupChat()`
|
|
||||||
/// by setting the 'protect' parameter to true.
|
|
||||||
///
|
|
||||||
/// [`create_group_chat`]: crate::api::CommandApi::create_group_chat
|
|
||||||
is_protected: bool,
|
|
||||||
|
|
||||||
/// True if the chat is encrypted.
|
/// True if the chat is encrypted.
|
||||||
/// This means that all messages in the chat are encrypted,
|
/// This means that all messages in the chat are encrypted,
|
||||||
/// and all contacts in the chat are "key-contacts",
|
/// and all contacts in the chat are "key-contacts",
|
||||||
@@ -131,7 +119,6 @@ impl FullChat {
|
|||||||
Ok(FullChat {
|
Ok(FullChat {
|
||||||
id: chat_id,
|
id: chat_id,
|
||||||
name: chat.name.clone(),
|
name: chat.name.clone(),
|
||||||
is_protected: chat.is_protected(),
|
|
||||||
is_encrypted: chat.is_encrypted(context).await?,
|
is_encrypted: chat.is_encrypted(context).await?,
|
||||||
profile_image, //BLOBS ?
|
profile_image, //BLOBS ?
|
||||||
archived: chat.get_visibility() == chat::ChatVisibility::Archived,
|
archived: chat.get_visibility() == chat::ChatVisibility::Archived,
|
||||||
@@ -172,18 +159,6 @@ pub struct BasicChat {
|
|||||||
id: u32,
|
id: u32,
|
||||||
name: String,
|
name: String,
|
||||||
|
|
||||||
/// True if the chat is protected.
|
|
||||||
///
|
|
||||||
/// UI should display a green checkmark
|
|
||||||
/// in the chat title,
|
|
||||||
/// in the chat profile title and
|
|
||||||
/// in the chatlist item
|
|
||||||
/// if chat protection is enabled.
|
|
||||||
/// UI should also display a green checkmark
|
|
||||||
/// in the contact profile
|
|
||||||
/// if 1:1 chat with this contact exists and is protected.
|
|
||||||
is_protected: bool,
|
|
||||||
|
|
||||||
/// True if the chat is encrypted.
|
/// True if the chat is encrypted.
|
||||||
/// This means that all messages in the chat are encrypted,
|
/// This means that all messages in the chat are encrypted,
|
||||||
/// and all contacts in the chat are "key-contacts",
|
/// and all contacts in the chat are "key-contacts",
|
||||||
@@ -234,7 +209,6 @@ impl BasicChat {
|
|||||||
Ok(BasicChat {
|
Ok(BasicChat {
|
||||||
id: chat_id,
|
id: chat_id,
|
||||||
name: chat.name.clone(),
|
name: chat.name.clone(),
|
||||||
is_protected: chat.is_protected(),
|
|
||||||
is_encrypted: chat.is_encrypted(context).await?,
|
is_encrypted: chat.is_encrypted(context).await?,
|
||||||
profile_image, //BLOBS ?
|
profile_image, //BLOBS ?
|
||||||
archived: chat.get_visibility() == chat::ChatVisibility::Archived,
|
archived: chat.get_visibility() == chat::ChatVisibility::Archived,
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ pub enum ChatListItemFetchResult {
|
|||||||
summary_status: u32,
|
summary_status: u32,
|
||||||
/// showing preview if last chat message is image
|
/// showing preview if last chat message is image
|
||||||
summary_preview_image: Option<String>,
|
summary_preview_image: Option<String>,
|
||||||
is_protected: bool,
|
|
||||||
|
|
||||||
/// True if the chat is encrypted.
|
/// True if the chat is encrypted.
|
||||||
/// This means that all messages in the chat are encrypted,
|
/// This means that all messages in the chat are encrypted,
|
||||||
@@ -161,7 +160,6 @@ pub(crate) async fn get_chat_list_item_by_id(
|
|||||||
summary_text2,
|
summary_text2,
|
||||||
summary_status: summary.state.to_u32().expect("impossible"), // idea and a function to transform the constant to strings? or return string enum
|
summary_status: summary.state.to_u32().expect("impossible"), // idea and a function to transform the constant to strings? or return string enum
|
||||||
summary_preview_image,
|
summary_preview_image,
|
||||||
is_protected: chat.is_protected(),
|
|
||||||
is_encrypted: chat.is_encrypted(ctx).await?,
|
is_encrypted: chat.is_encrypted(ctx).await?,
|
||||||
is_group: chat.get_type() == Chattype::Group,
|
is_group: chat.get_type() == Chattype::Group,
|
||||||
fresh_message_counter,
|
fresh_message_counter,
|
||||||
|
|||||||
@@ -532,7 +532,6 @@ pub struct MessageSearchResult {
|
|||||||
chat_color: String,
|
chat_color: String,
|
||||||
chat_name: String,
|
chat_name: String,
|
||||||
chat_type: u32,
|
chat_type: u32,
|
||||||
is_chat_protected: bool,
|
|
||||||
is_chat_contact_request: bool,
|
is_chat_contact_request: bool,
|
||||||
is_chat_archived: bool,
|
is_chat_archived: bool,
|
||||||
message: String,
|
message: String,
|
||||||
@@ -572,7 +571,6 @@ impl MessageSearchResult {
|
|||||||
chat_color,
|
chat_color,
|
||||||
chat_type: chat.get_type().to_u32().context("unknown chat type id")?,
|
chat_type: chat.get_type().to_u32().context("unknown chat type id")?,
|
||||||
chat_profile_image,
|
chat_profile_image,
|
||||||
is_chat_protected: chat.is_protected(),
|
|
||||||
is_chat_contact_request: chat.is_contact_request(),
|
is_chat_contact_request: chat.is_contact_request(),
|
||||||
is_chat_archived: chat.get_visibility() == ChatVisibility::Archived,
|
is_chat_archived: chat.get_visibility() == ChatVisibility::Archived,
|
||||||
message: message.get_text(),
|
message: message.get_text(),
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ def test_qr_securejoin(acfactory, protect):
|
|||||||
|
|
||||||
logging.info("Alice creates a group")
|
logging.info("Alice creates a group")
|
||||||
alice_chat = alice.create_group("Group", protect=protect)
|
alice_chat = alice.create_group("Group", protect=protect)
|
||||||
assert alice_chat.get_basic_snapshot().is_protected == protect
|
|
||||||
|
|
||||||
logging.info("Bob joins the group")
|
logging.info("Bob joins the group")
|
||||||
qr_code = alice_chat.get_qr_code()
|
qr_code = alice_chat.get_qr_code()
|
||||||
@@ -89,7 +88,6 @@ def test_qr_securejoin(acfactory, protect):
|
|||||||
|
|
||||||
snapshot = bob.get_message_by_id(bob.wait_for_incoming_msg_event().msg_id).get_snapshot()
|
snapshot = bob.get_message_by_id(bob.wait_for_incoming_msg_event().msg_id).get_snapshot()
|
||||||
assert snapshot.text == "Member Me added by {}.".format(alice.get_config("addr"))
|
assert snapshot.text == "Member Me added by {}.".format(alice.get_config("addr"))
|
||||||
assert snapshot.chat.get_basic_snapshot().is_protected == protect
|
|
||||||
|
|
||||||
# Test that Bob verified Alice's profile.
|
# Test that Bob verified Alice's profile.
|
||||||
bob_contact_alice = bob.create_contact(alice)
|
bob_contact_alice = bob.create_contact(alice)
|
||||||
@@ -218,7 +216,6 @@ def test_verified_group_member_added_recovery(acfactory) -> None:
|
|||||||
|
|
||||||
logging.info("ac1 creates verified group")
|
logging.info("ac1 creates verified group")
|
||||||
chat = ac1.create_group("Verified group", protect=True)
|
chat = ac1.create_group("Verified group", protect=True)
|
||||||
assert chat.get_basic_snapshot().is_protected
|
|
||||||
|
|
||||||
logging.info("ac2 joins verified group")
|
logging.info("ac2 joins verified group")
|
||||||
qr_code = chat.get_qr_code()
|
qr_code = chat.get_qr_code()
|
||||||
@@ -313,7 +310,6 @@ def test_qr_join_chat_with_pending_bobstate_issue4894(acfactory):
|
|||||||
while 1:
|
while 1:
|
||||||
snapshot = ac2.get_message_by_id(ac2.wait_for_incoming_msg_event().msg_id).get_snapshot()
|
snapshot = ac2.get_message_by_id(ac2.wait_for_incoming_msg_event().msg_id).get_snapshot()
|
||||||
if snapshot.text == "ac1 says hello":
|
if snapshot.text == "ac1 says hello":
|
||||||
assert snapshot.chat.get_basic_snapshot().is_protected
|
|
||||||
break
|
break
|
||||||
|
|
||||||
logging.info("ac1: let ac2 join again but shutoff ac1 in the middle of securejoin")
|
logging.info("ac1: let ac2 join again but shutoff ac1 in the middle of securejoin")
|
||||||
@@ -335,7 +331,6 @@ def test_qr_join_chat_with_pending_bobstate_issue4894(acfactory):
|
|||||||
while 1:
|
while 1:
|
||||||
msg = ac2.get_message_by_id(ac2.wait_for_incoming_msg_event().msg_id).get_snapshot()
|
msg = ac2.get_message_by_id(ac2.wait_for_incoming_msg_event().msg_id).get_snapshot()
|
||||||
if msg.text == "hello":
|
if msg.text == "hello":
|
||||||
assert msg.chat.get_basic_snapshot().is_protected
|
|
||||||
break
|
break
|
||||||
|
|
||||||
logging.info("ac3: create a join-code for group VG and let ac4 join, check that ac2 got it")
|
logging.info("ac3: create a join-code for group VG and let ac4 join, check that ac2 got it")
|
||||||
@@ -385,7 +380,6 @@ def test_aeap_flow_verified(acfactory):
|
|||||||
|
|
||||||
logging.info("ac1: create verified-group QR, ac2 scans and joins")
|
logging.info("ac1: create verified-group QR, ac2 scans and joins")
|
||||||
chat = ac1.create_group("hello", protect=True)
|
chat = ac1.create_group("hello", protect=True)
|
||||||
assert chat.get_basic_snapshot().is_protected
|
|
||||||
qr_code = chat.get_qr_code()
|
qr_code = chat.get_qr_code()
|
||||||
logging.info("ac2: start QR-code based join-group protocol")
|
logging.info("ac2: start QR-code based join-group protocol")
|
||||||
ac2.secure_join(qr_code)
|
ac2.secure_join(qr_code)
|
||||||
@@ -439,7 +433,6 @@ def test_gossip_verification(acfactory) -> None:
|
|||||||
|
|
||||||
logging.info("Bob creates an Autocrypt group")
|
logging.info("Bob creates an Autocrypt group")
|
||||||
bob_group_chat = bob.create_group("Autocrypt Group")
|
bob_group_chat = bob.create_group("Autocrypt Group")
|
||||||
assert not bob_group_chat.get_basic_snapshot().is_protected
|
|
||||||
bob_group_chat.add_contact(bob_contact_alice)
|
bob_group_chat.add_contact(bob_contact_alice)
|
||||||
bob_group_chat.add_contact(bob_contact_carol)
|
bob_group_chat.add_contact(bob_contact_carol)
|
||||||
bob_group_chat.send_message(text="Hello Autocrypt group")
|
bob_group_chat.send_message(text="Hello Autocrypt group")
|
||||||
@@ -454,7 +447,6 @@ def test_gossip_verification(acfactory) -> None:
|
|||||||
|
|
||||||
logging.info("Bob creates a Securejoin group")
|
logging.info("Bob creates a Securejoin group")
|
||||||
bob_group_chat = bob.create_group("Securejoin Group", protect=True)
|
bob_group_chat = bob.create_group("Securejoin Group", protect=True)
|
||||||
assert bob_group_chat.get_basic_snapshot().is_protected
|
|
||||||
bob_group_chat.add_contact(bob_contact_alice)
|
bob_group_chat.add_contact(bob_contact_alice)
|
||||||
bob_group_chat.add_contact(bob_contact_carol)
|
bob_group_chat.add_contact(bob_contact_carol)
|
||||||
bob_group_chat.send_message(text="Hello Securejoin group")
|
bob_group_chat.send_message(text="Hello Securejoin group")
|
||||||
@@ -525,7 +517,6 @@ def test_securejoin_after_contact_resetup(acfactory) -> None:
|
|||||||
snapshot = ac2.get_message_by_id(ac2.wait_for_incoming_msg_event().msg_id).get_snapshot()
|
snapshot = ac2.get_message_by_id(ac2.wait_for_incoming_msg_event().msg_id).get_snapshot()
|
||||||
assert snapshot.is_info
|
assert snapshot.is_info
|
||||||
ac2_chat = snapshot.chat
|
ac2_chat = snapshot.chat
|
||||||
assert ac2_chat.get_basic_snapshot().is_protected
|
|
||||||
assert len(ac2_chat.get_contacts()) == 3
|
assert len(ac2_chat.get_contacts()) == 3
|
||||||
|
|
||||||
# ac1 is still "not verified" for ac2 due to inconsistent state.
|
# ac1 is still "not verified" for ac2 due to inconsistent state.
|
||||||
@@ -537,7 +528,6 @@ def test_withdraw_securejoin_qr(acfactory):
|
|||||||
|
|
||||||
logging.info("Alice creates a verified group")
|
logging.info("Alice creates a verified group")
|
||||||
alice_chat = alice.create_group("Verified group", protect=True)
|
alice_chat = alice.create_group("Verified group", protect=True)
|
||||||
assert alice_chat.get_basic_snapshot().is_protected
|
|
||||||
logging.info("Bob joins verified group")
|
logging.info("Bob joins verified group")
|
||||||
|
|
||||||
qr_code = alice_chat.get_qr_code()
|
qr_code = alice_chat.get_qr_code()
|
||||||
@@ -548,7 +538,6 @@ def test_withdraw_securejoin_qr(acfactory):
|
|||||||
|
|
||||||
snapshot = bob.get_message_by_id(bob.wait_for_incoming_msg_event().msg_id).get_snapshot()
|
snapshot = bob.get_message_by_id(bob.wait_for_incoming_msg_event().msg_id).get_snapshot()
|
||||||
assert snapshot.text == "Member Me added by {}.".format(alice.get_config("addr"))
|
assert snapshot.text == "Member Me added by {}.".format(alice.get_config("addr"))
|
||||||
assert snapshot.chat.get_basic_snapshot().is_protected
|
|
||||||
bob_chat.leave()
|
bob_chat.leave()
|
||||||
|
|
||||||
snapshot = alice.get_message_by_id(alice.wait_for_msgs_changed_event().msg_id).get_snapshot()
|
snapshot = alice.get_message_by_id(alice.wait_for_msgs_changed_event().msg_id).get_snapshot()
|
||||||
|
|||||||
@@ -142,13 +142,6 @@ class Chat:
|
|||||||
"""
|
"""
|
||||||
return bool(lib.dc_chat_can_send(self._dc_chat))
|
return bool(lib.dc_chat_can_send(self._dc_chat))
|
||||||
|
|
||||||
def is_protected(self) -> bool:
|
|
||||||
"""return True if this chat is a protected chat.
|
|
||||||
|
|
||||||
:returns: True if chat is protected, False otherwise.
|
|
||||||
"""
|
|
||||||
return bool(lib.dc_chat_is_protected(self._dc_chat))
|
|
||||||
|
|
||||||
def get_name(self) -> Optional[str]:
|
def get_name(self) -> Optional[str]:
|
||||||
"""return name of this chat.
|
"""return name of this chat.
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,6 @@ def test_qr_verified_group_and_chatting(acfactory, lp):
|
|||||||
ac1_addr = ac1.get_self_contact().addr
|
ac1_addr = ac1.get_self_contact().addr
|
||||||
lp.sec("ac1: create verified-group QR, ac2 scans and joins")
|
lp.sec("ac1: create verified-group QR, ac2 scans and joins")
|
||||||
chat1 = ac1.create_group_chat("hello", verified=True)
|
chat1 = ac1.create_group_chat("hello", verified=True)
|
||||||
assert chat1.is_protected()
|
|
||||||
qr = chat1.get_join_qr()
|
qr = chat1.get_join_qr()
|
||||||
lp.sec("ac2: start QR-code based join-group protocol")
|
lp.sec("ac2: start QR-code based join-group protocol")
|
||||||
chat2 = ac2.qr_join_chat(qr)
|
chat2 = ac2.qr_join_chat(qr)
|
||||||
@@ -142,7 +141,6 @@ def test_qr_verified_group_and_chatting(acfactory, lp):
|
|||||||
lp.sec("ac2: read message and check that it's a verified chat")
|
lp.sec("ac2: read message and check that it's a verified chat")
|
||||||
msg = ac2._evtracker.wait_next_incoming_message()
|
msg = ac2._evtracker.wait_next_incoming_message()
|
||||||
assert msg.text == "hello"
|
assert msg.text == "hello"
|
||||||
assert msg.chat.is_protected()
|
|
||||||
assert msg.is_encrypted()
|
assert msg.is_encrypted()
|
||||||
|
|
||||||
lp.sec("ac2: Check that ac2 verified ac1")
|
lp.sec("ac2: Check that ac2 verified ac1")
|
||||||
@@ -267,7 +265,6 @@ def test_see_new_verified_member_after_going_online(acfactory, tmp_path, lp):
|
|||||||
|
|
||||||
lp.sec("ac1: create verified-group QR, ac2 scans and joins")
|
lp.sec("ac1: create verified-group QR, ac2 scans and joins")
|
||||||
chat = ac1.create_group_chat("hello", verified=True)
|
chat = ac1.create_group_chat("hello", verified=True)
|
||||||
assert chat.is_protected()
|
|
||||||
qr = chat.get_join_qr()
|
qr = chat.get_join_qr()
|
||||||
lp.sec("ac2: start QR-code based join-group protocol")
|
lp.sec("ac2: start QR-code based join-group protocol")
|
||||||
chat2 = ac2.qr_join_chat(qr)
|
chat2 = ac2.qr_join_chat(qr)
|
||||||
@@ -322,7 +319,6 @@ def test_use_new_verified_group_after_going_online(acfactory, data, tmp_path, lp
|
|||||||
|
|
||||||
lp.sec("ac1: create verified-group QR, ac2 scans and joins")
|
lp.sec("ac1: create verified-group QR, ac2 scans and joins")
|
||||||
chat = ac1.create_group_chat("hello", verified=True)
|
chat = ac1.create_group_chat("hello", verified=True)
|
||||||
assert chat.is_protected()
|
|
||||||
qr = chat.get_join_qr()
|
qr = chat.get_join_qr()
|
||||||
lp.sec("ac2: start QR-code based join-group protocol")
|
lp.sec("ac2: start QR-code based join-group protocol")
|
||||||
ac2.qr_join_chat(qr)
|
ac2.qr_join_chat(qr)
|
||||||
@@ -336,7 +332,6 @@ def test_use_new_verified_group_after_going_online(acfactory, data, tmp_path, lp
|
|||||||
assert msg_in.is_system_message()
|
assert msg_in.is_system_message()
|
||||||
assert contact.addr == ac1.get_config("addr")
|
assert contact.addr == ac1.get_config("addr")
|
||||||
chat2 = msg_in.chat
|
chat2 = msg_in.chat
|
||||||
assert chat2.is_protected()
|
|
||||||
assert chat2.get_messages()[0].text == "Messages are end-to-end encrypted."
|
assert chat2.get_messages()[0].text == "Messages are end-to-end encrypted."
|
||||||
assert open(contact.get_profile_image(), "rb").read() == open(avatar_path, "rb").read()
|
assert open(contact.get_profile_image(), "rb").read() == open(avatar_path, "rb").read()
|
||||||
|
|
||||||
@@ -377,7 +372,6 @@ def test_verified_group_vs_delete_server_after(acfactory, tmp_path, lp):
|
|||||||
|
|
||||||
lp.sec("ac1: create verified-group QR, ac2 scans and joins")
|
lp.sec("ac1: create verified-group QR, ac2 scans and joins")
|
||||||
chat1 = ac1.create_group_chat("hello", verified=True)
|
chat1 = ac1.create_group_chat("hello", verified=True)
|
||||||
assert chat1.is_protected()
|
|
||||||
qr = chat1.get_join_qr()
|
qr = chat1.get_join_qr()
|
||||||
lp.sec("ac2: start QR-code based join-group protocol")
|
lp.sec("ac2: start QR-code based join-group protocol")
|
||||||
chat2 = ac2.qr_join_chat(qr)
|
chat2 = ac2.qr_join_chat(qr)
|
||||||
@@ -402,7 +396,6 @@ def test_verified_group_vs_delete_server_after(acfactory, tmp_path, lp):
|
|||||||
assert ac2_offl_ac1_contact.addr == ac1.get_config("addr")
|
assert ac2_offl_ac1_contact.addr == ac1.get_config("addr")
|
||||||
assert not ac2_offl_ac1_contact.is_verified()
|
assert not ac2_offl_ac1_contact.is_verified()
|
||||||
chat2_offl = msg_in.chat
|
chat2_offl = msg_in.chat
|
||||||
assert not chat2_offl.is_protected()
|
|
||||||
|
|
||||||
lp.sec("ac2: sending message re-gossiping Autocrypt keys")
|
lp.sec("ac2: sending message re-gossiping Autocrypt keys")
|
||||||
chat2.send_text("hi2")
|
chat2.send_text("hi2")
|
||||||
@@ -423,7 +416,6 @@ def test_verified_group_vs_delete_server_after(acfactory, tmp_path, lp):
|
|||||||
assert msg_in.text == "hi2"
|
assert msg_in.text == "hi2"
|
||||||
assert msg_in.chat == chat2_offl
|
assert msg_in.chat == chat2_offl
|
||||||
assert msg_in.get_sender_contact().addr == ac2.get_config("addr")
|
assert msg_in.get_sender_contact().addr == ac2.get_config("addr")
|
||||||
assert msg_in.chat.is_protected()
|
|
||||||
assert ac2_offl_ac1_contact.is_verified()
|
assert ac2_offl_ac1_contact.is_verified()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1397,7 +1397,7 @@ impl ChatId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the chat is protected.
|
/// Returns true if the chat is protected.
|
||||||
pub async fn is_protected(self, context: &Context) -> Result<ProtectionStatus> {
|
pub(crate) async fn is_protected(self, context: &Context) -> Result<ProtectionStatus> {
|
||||||
let protection_status = context
|
let protection_status = context
|
||||||
.sql
|
.sql
|
||||||
.query_get_value("SELECT protected FROM chats WHERE id=?", (self,))
|
.query_get_value("SELECT protected FROM chats WHERE id=?", (self,))
|
||||||
|
|||||||
Reference in New Issue
Block a user