Skip to content

Commit 6fda103

Browse files
committed
fixup! feat: add rust client for the android interop application.
1 parent 1843675 commit 6fda103

File tree

2 files changed

+25
-71
lines changed

2 files changed

+25
-71
lines changed

interop/src/clients/corecrypto/android.rs

Lines changed: 24 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
#[cfg(feature = "proteus")]
2+
use std::cell::Cell;
13
use std::{
2-
cell::{Cell, RefCell},
3-
io::{BufRead, BufReader, Read},
4-
process::{Child, ChildStdout, Command, Output, Stdio},
4+
cell::RefCell,
5+
io::{BufRead as _, BufReader, Read as _},
6+
process::{Child, ChildStdout, Command, Stdio},
57
time::Duration,
68
};
79

810
use anyhow::Result;
911
use base64::{Engine as _, engine::general_purpose};
1012
use core_crypto::{KeyPackageIn, Keypackage};
11-
use thiserror::Error;
12-
use tls_codec::Deserialize;
13+
use tls_codec::Deserialize as _;
1314

1415
use crate::{
1516
CIPHERSUITE_IN_USE,
@@ -32,15 +33,15 @@ enum InteropResult {
3233
Failure { message: String },
3334
}
3435

35-
#[derive(Error, Debug)]
36+
#[derive(thiserror::Error, Debug)]
3637
#[error("simulator driver error: {msg}")]
3738
struct SimulatorDriverError {
3839
msg: String,
3940
}
4041

4142
impl SimulatorDriver {
4243
fn new(device: String, application: String) -> Self {
43-
let application = Self::launch_application(&device, &application, true).expect("Failed to launch application");
44+
let application = Self::launch_application(&device, &application).expect("Failed to launch application");
4445

4546
Self {
4647
device,
@@ -49,15 +50,7 @@ impl SimulatorDriver {
4950
}
5051
}
5152

52-
fn boot_device(device: &str) -> std::io::Result<Output> {
53-
Command::new("xcrun").args(["simctl", "boot", device]).output()
54-
}
55-
56-
fn launch_application(
57-
device: &str,
58-
application: &str,
59-
boot_device: bool,
60-
) -> Result<(Child, BufReader<ChildStdout>)> {
53+
fn launch_application(device: &str, application: &str) -> Result<(Child, BufReader<ChildStdout>)> {
6154
log::info!("launching application: {} on {}", application, device);
6255

6356
let activity = format!("{}/.MainActivity", application);
@@ -89,6 +82,9 @@ impl SimulatorDriver {
8982
log::info!("retrieved {} pid", pid);
9083

9184
// Start monitoring the system output of our application
85+
//
86+
// without formatting (raw)
87+
// only include system out and silence all other logs (System.out:I *:S)
9288
let mut process = Command::new("adb")
9389
.args([
9490
"-s",
@@ -117,12 +113,6 @@ impl SimulatorDriver {
117113
match process.try_wait() {
118114
Ok(None) => {}
119115
Ok(Some(exit_status)) => {
120-
if boot_device && exit_status.code() == Some(149) {
121-
log::info!("device is shutdown, booting...");
122-
Self::boot_device(device)?;
123-
return Self::launch_application(device, application, false);
124-
}
125-
126116
let mut error_message = String::new();
127117
process
128118
.stderr
@@ -216,11 +206,10 @@ impl CoreCryptoAndroidClient {
216206
.trim()
217207
.to_string();
218208
let driver = SimulatorDriver::new(device, "com.wire.androidinterop".into());
219-
log::info!("initialising core crypto with ciphersuite {}", ciphersuite);
209+
log::info!("initialising core crypto with ciphersuite {ciphersuite}");
220210
driver
221211
.execute(format!(
222-
"--es action init-mls --es client_id {} --ei ciphersuite {}",
223-
client_id_base64, ciphersuite
212+
"--es action init-mls --es client_id {client_id_base64} --ei ciphersuite {ciphersuite}"
224213
))
225214
.await?;
226215

@@ -263,7 +252,7 @@ impl EmulatedMlsClient for CoreCryptoAndroidClient {
263252
let start = std::time::Instant::now();
264253
let kp_base64 = self
265254
.driver
266-
.execute(format!("--es action get-key-package --ei ciphersuite {}", ciphersuite))
255+
.execute(format!("--es action get-key-package --ei ciphersuite {ciphersuite}"))
267256
.await?;
268257
let kp_raw = general_purpose::STANDARD.decode(kp_base64)?;
269258
let kp: Keypackage = KeyPackageIn::tls_deserialize(&mut kp_raw.as_slice())?.into();
@@ -279,27 +268,12 @@ impl EmulatedMlsClient for CoreCryptoAndroidClient {
279268
Ok(kp_raw)
280269
}
281270

282-
async fn add_client(&self, conversation_id: &[u8], kp: &[u8]) -> Result<()> {
283-
let cid_base64 = general_purpose::STANDARD.encode(conversation_id);
284-
let kp_base64 = general_purpose::STANDARD.encode(kp);
285-
let ciphersuite = CIPHERSUITE_IN_USE as u16;
286-
self.driver
287-
.execute(format!(
288-
"--es action add-client --es cid {} --ei ciphersuite={} --es kp {}",
289-
cid_base64, ciphersuite, kp_base64
290-
))
291-
.await?;
292-
293-
Ok(())
294-
}
295-
296271
async fn kick_client(&self, conversation_id: &[u8], client_id: &[u8]) -> Result<()> {
297272
let cid_base64 = general_purpose::STANDARD.encode(conversation_id);
298273
let client_id_base64 = general_purpose::STANDARD.encode(client_id);
299274
self.driver
300275
.execute(format!(
301-
"--es action remove-client --es cid {} --es client {}",
302-
cid_base64, client_id_base64
276+
"--es action remove-client --es cid {cid_base64} --es client {client_id_base64}"
303277
))
304278
.await?;
305279

@@ -310,7 +284,7 @@ impl EmulatedMlsClient for CoreCryptoAndroidClient {
310284
let welcome_base64 = general_purpose::STANDARD.encode(welcome);
311285
let conversation_id_base64 = self
312286
.driver
313-
.execute(format!("--es action process-welcome --es welcome {}", welcome_base64))
287+
.execute(format!("--es action process-welcome --es welcome {welcome_base64}"))
314288
.await?;
315289
let conversation_id = general_purpose::STANDARD.decode(conversation_id_base64)?;
316290

@@ -323,8 +297,7 @@ impl EmulatedMlsClient for CoreCryptoAndroidClient {
323297
let encrypted_message_base64 = self
324298
.driver
325299
.execute(format!(
326-
"--es action encrypt-message --es cid {} --es message {}",
327-
cid_base64, message_base64
300+
"--es action encrypt-message --es cid {cid_base64} --es message {message_base64}"
328301
))
329302
.await?;
330303
let encrypted_message = general_purpose::STANDARD.decode(encrypted_message_base64)?;
@@ -338,8 +311,7 @@ impl EmulatedMlsClient for CoreCryptoAndroidClient {
338311
let result = self
339312
.driver
340313
.execute(format!(
341-
"--es action decrypt-message --es cid {} --es message {}",
342-
cid_base64, message_base64
314+
"--es action decrypt-message --es cid {cid_base64} --es message {message_base64}"
343315
))
344316
.await?;
345317

@@ -366,7 +338,7 @@ impl crate::clients::EmulatedProteusClient for CoreCryptoAndroidClient {
366338

367339
let prekey_base64 = self
368340
.driver
369-
.execute(format!("--es action get-prekey --es id {}", prekey_last_id))
341+
.execute(format!("--es action get-prekey --es id {prekey_last_id}"))
370342
.await?;
371343
let prekey = general_purpose::STANDARD.decode(prekey_base64)?;
372344

@@ -377,8 +349,7 @@ impl crate::clients::EmulatedProteusClient for CoreCryptoAndroidClient {
377349
let prekey_base64 = general_purpose::STANDARD.encode(prekey);
378350
self.driver
379351
.execute(format!(
380-
"--es action session-from-prekey --es session_id {} --es prekey {}",
381-
session_id, prekey_base64
352+
"--es action session-from-prekey --es session_id {session_id} --es prekey {prekey_base64}"
382353
))
383354
.await?;
384355

@@ -390,8 +361,7 @@ impl crate::clients::EmulatedProteusClient for CoreCryptoAndroidClient {
390361
let decrypted_message_base64 = self
391362
.driver
392363
.execute(format!(
393-
"--es action session-from-message --es session_id {} --es message {}",
394-
session_id, message_base64
364+
"--es action session-from-message --es session_id {session_id} --es message {message_base64}"
395365
))
396366
.await?;
397367
let decrypted_message = general_purpose::STANDARD.decode(decrypted_message_base64)?;
@@ -403,8 +373,7 @@ impl crate::clients::EmulatedProteusClient for CoreCryptoAndroidClient {
403373
let encrypted_message_base64 = self
404374
.driver
405375
.execute(format!(
406-
"--es action encrypt-proteus --es session_id {} --es message {}",
407-
session_id, plaintext_base64
376+
"--es action encrypt-proteus --es session_id {session_id} --es message {plaintext_base64}"
408377
))
409378
.await?;
410379
let encrypted_message = general_purpose::STANDARD.decode(encrypted_message_base64)?;
@@ -417,8 +386,7 @@ impl crate::clients::EmulatedProteusClient for CoreCryptoAndroidClient {
417386
let decrypted_message_base64 = self
418387
.driver
419388
.execute(format!(
420-
"--es action decrypt-proteus --es session_id {} --es message {}",
421-
session_id, ciphertext_base64
389+
"--es action decrypt-proteus --es session_id {session_id} --es message {ciphertext_base64}"
422390
))
423391
.await?;
424392
let decrypted_message = general_purpose::STANDARD.decode(decrypted_message_base64)?;

interop/src/clients/corecrypto/ios.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -230,21 +230,7 @@ impl EmulatedMlsClient for CoreCryptoIosClient {
230230

231231
Ok(kp_raw)
232232
}
233-
234-
async fn add_client(&self, conversation_id: &[u8], kp: &[u8]) -> Result<()> {
235-
let cid_base64 = general_purpose::STANDARD.encode(conversation_id);
236-
let kp_base64 = general_purpose::STANDARD.encode(kp);
237-
let ciphersuite = CIPHERSUITE_IN_USE as u16;
238-
self.driver
239-
.execute(format!(
240-
"add-client?cid={}&ciphersuite={}&kp={}",
241-
cid_base64, ciphersuite, kp_base64
242-
))
243-
.await?;
244-
245-
Ok(())
246-
}
247-
233+
248234
async fn kick_client(&self, conversation_id: &[u8], client_id: &[u8]) -> Result<()> {
249235
let cid_base64 = general_purpose::STANDARD.encode(conversation_id);
250236
let client_id_base64 = general_purpose::STANDARD.encode(client_id);

0 commit comments

Comments
 (0)