1// Wire
2// Copyright (C) 2022 Wire Swiss GmbH
34// 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.
89// 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.
1314// 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)]
1718use color_eyre::eyre::Result;
19use core_crypto::prelude::MlsCiphersuite;
2021pub(crate) mod corecrypto;
22#[cfg(feature = "proteus")]
23pub(crate) mod cryptobox;
2425bitflags::bitflags! {
26pub(crate) struct EmulatedClientProtocol: u8 {
27const MLS = 0x01;
28const PROTEUS = 0x02;
29 }
30}
3132#[derive(Debug)]
33#[non_exhaustive]
34#[allow(dead_code)]
35pub(crate) enum EmulatedClientType {
36 Native,
37// Natively test the FFI in `generic.rs`
38NativeFfi,
39 Web,
40// TODO: Bind with & drive iOS Emulator. Tracking issue: WPB-9646
41AppleiOS,
42// TODO: Bind with & drive Android Emulator. Tracking issue: WPB-9646
43Android,
44}
4546impl std::fmt::Display for EmulatedClientType {
47fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48let repr = match self {
49Self::Native => "Native",
50Self::NativeFfi => "Native FFI",
51Self::Web => "Web",
52Self::AppleiOS => "iOS",
53Self::Android => "Android",
54 };
5556write!(f, "{repr}")
57 }
58}
5960#[async_trait::async_trait(?Send)]
61#[allow(dead_code)]
62pub(crate) trait EmulatedClient {
63fn client_name(&self) -> &str;
64fn client_type(&self) -> EmulatedClientType;
65fn client_id(&self) -> &[u8];
66fn client_protocol(&self) -> EmulatedClientProtocol;
67async fn wipe(mut self) -> Result<()>;
68}
6970#[async_trait::async_trait(?Send)]
71#[allow(dead_code)]
72pub(crate) trait EmulatedMlsClient: EmulatedClient {
73async fn get_keypackage(&self) -> Result<Vec<u8>>;
74async fn add_client(&self, conversation_id: &[u8], kp: &[u8]) -> Result<()>;
75async fn kick_client(&self, conversation_id: &[u8], client_id: &[u8]) -> Result<()>;
76async fn process_welcome(&self, welcome: &[u8]) -> Result<Vec<u8>>;
77async 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
79async fn decrypt_message(&self, conversation_id: &[u8], message: &[u8]) -> Result<Option<Vec<u8>>>;
80}
8182#[async_trait::async_trait(?Send)]
83#[allow(dead_code)]
84pub(crate) trait EmulatedProteusClient: EmulatedClient {
85async fn init(&mut self) -> Result<()> {
86Ok(())
87 }
88async fn get_prekey(&self) -> Result<Vec<u8>>;
89async fn session_from_prekey(&self, session_id: &str, prekey: &[u8]) -> Result<()>;
90async fn session_from_message(&self, session_id: &str, message: &[u8]) -> Result<Vec<u8>>;
91async fn encrypt(&self, session_id: &str, plaintext: &[u8]) -> Result<Vec<u8>>;
92async fn decrypt(&self, session_id: &str, ciphertext: &[u8]) -> Result<Vec<u8>>;
93async fn fingerprint(&self) -> Result<String>;
94}
9596#[async_trait::async_trait(?Send)]
97#[allow(dead_code)]
98pub(crate) trait EmulatedE2eIdentityClient: EmulatedClient {
99async fn e2ei_new_enrollment(&mut self, ciphersuite: MlsCiphersuite) -> Result<()>;
100}