interop/clients/
mod.rs

1// Wire
2// Copyright (C) 2022 Wire Swiss GmbH
3
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see http://www.gnu.org/licenses/.
16#![allow(clippy::assign_op_pattern)]
17
18use color_eyre::eyre::Result;
19use core_crypto::prelude::MlsCiphersuite;
20
21pub(crate) mod corecrypto;
22#[cfg(feature = "proteus")]
23pub(crate) mod cryptobox;
24
25bitflags::bitflags! {
26    pub(crate) struct EmulatedClientProtocol: u8 {
27        const MLS = 0x01;
28        const PROTEUS = 0x02;
29    }
30}
31
32#[derive(Debug)]
33#[non_exhaustive]
34#[allow(dead_code)]
35pub(crate) enum EmulatedClientType {
36    Native,
37    // Natively test the FFI in `generic.rs`
38    NativeFfi,
39    Web,
40    // TODO: Bind with & drive iOS Emulator. Tracking issue: WPB-9646
41    AppleiOS,
42    // TODO: Bind with & drive Android Emulator. Tracking issue: WPB-9646
43    Android,
44}
45
46impl std::fmt::Display for EmulatedClientType {
47    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48        let repr = match self {
49            Self::Native => "Native",
50            Self::NativeFfi => "Native FFI",
51            Self::Web => "Web",
52            Self::AppleiOS => "iOS",
53            Self::Android => "Android",
54        };
55
56        write!(f, "{repr}")
57    }
58}
59
60#[async_trait::async_trait(?Send)]
61#[allow(dead_code)]
62pub(crate) trait EmulatedClient {
63    fn client_name(&self) -> &str;
64    fn client_type(&self) -> EmulatedClientType;
65    fn client_id(&self) -> &[u8];
66    fn client_protocol(&self) -> EmulatedClientProtocol;
67    async fn wipe(mut self) -> Result<()>;
68}
69
70#[async_trait::async_trait(?Send)]
71#[allow(dead_code)]
72pub(crate) trait EmulatedMlsClient: EmulatedClient {
73    async fn get_keypackage(&self) -> Result<Vec<u8>>;
74    async fn add_client(&self, conversation_id: &[u8], kp: &[u8]) -> Result<()>;
75    async fn kick_client(&self, conversation_id: &[u8], client_id: &[u8]) -> Result<()>;
76    async fn process_welcome(&self, welcome: &[u8]) -> Result<Vec<u8>>;
77    async fn encrypt_message(&self, conversation_id: &[u8], message: &[u8]) -> Result<Vec<u8>>;
78    // TODO: Make it more complex so that we can extract other things like proposals etc. Tracking issue: WPB-9647
79    async fn decrypt_message(&self, conversation_id: &[u8], message: &[u8]) -> Result<Option<Vec<u8>>>;
80}
81
82#[async_trait::async_trait(?Send)]
83#[allow(dead_code)]
84pub(crate) trait EmulatedProteusClient: EmulatedClient {
85    async fn init(&mut self) -> Result<()> {
86        Ok(())
87    }
88    async fn get_prekey(&self) -> Result<Vec<u8>>;
89    async fn session_from_prekey(&self, session_id: &str, prekey: &[u8]) -> Result<()>;
90    async fn session_from_message(&self, session_id: &str, message: &[u8]) -> Result<Vec<u8>>;
91    async fn encrypt(&self, session_id: &str, plaintext: &[u8]) -> Result<Vec<u8>>;
92    async fn decrypt(&self, session_id: &str, ciphertext: &[u8]) -> Result<Vec<u8>>;
93    async fn fingerprint(&self) -> Result<String>;
94}
95
96#[async_trait::async_trait(?Send)]
97#[allow(dead_code)]
98pub(crate) trait EmulatedE2eIdentityClient: EmulatedClient {
99    async fn e2ei_new_enrollment(&mut self, ciphersuite: MlsCiphersuite) -> Result<()>;
100}