modified: src/client.rs
Some checks failed
gitea/Frida-android-native/pipeline/head There was a failure building this commit

This commit is contained in:
Michael Wain 2024-10-08 01:38:14 +03:00
parent 96c02d824b
commit e481f4c2cf

View File

@ -46,15 +46,6 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32, env: &JNIE
let cipher_shared: Arc<Mutex<Option<x25519_dalek::SharedSecret>>> = Arc::new(Mutex::new(None)); let cipher_shared: Arc<Mutex<Option<x25519_dalek::SharedSecret>>> = Arc::new(Mutex::new(None));
let m_env = Arc::new(Mutex::new(env));
tokio::spawn(async move {
while let Ok(bytes) = lrx.recv() {
let d_env = m_env.lock().await;
FridaLib::traceFromNative(&d_env, String::from_utf8_lossy(&bytes).to_string());
drop(d_env);
}
});
tokio::spawn(async move { tokio::spawn(async move {
while let Ok(bytes) = rx.recv() { while let Ok(bytes) = rx.recv() {
ltx.send("Write to tun.".as_bytes().to_vec()); ltx.send("Write to tun.".as_bytes().to_vec());
@ -131,24 +122,30 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32, env: &JNIE
let s_cipher = cipher_shared.clone(); let s_cipher = cipher_shared.clone();
loop { loop {
if let Ok(bytes) = mx.recv() { tokio::select! {
let s_c = s_cipher.lock().await; b = lrx.recv() => {
FridaLib::traceFromNative(&env, String::from_utf8_lossy(&b.unwrap()).to_string());
if s_c.is_some() { }
let aes = Aes256Gcm::new(s_c.as_ref().unwrap().as_bytes().into()); b = mx.recv() => {
let nonce = Aes256Gcm::generate_nonce(&mut OsRng); let bytes = b.unwrap();
let ciphered_data = aes.encrypt(&nonce, &bytes[..]); let s_c = s_cipher.lock().await;
if let Ok(ciphered_d) = ciphered_data { if s_c.is_some() {
let vpn_packet = UDPVpnPacket{ data: ciphered_d, nonce: nonce.to_vec()}; let aes = Aes256Gcm::new(s_c.as_ref().unwrap().as_bytes().into());
let serialized_data = vpn_packet.serialize(); let nonce = Aes256Gcm::generate_nonce(&mut OsRng);
ltx.send("Write to socket".as_bytes().to_vec()); let ciphered_data = aes.encrypt(&nonce, &bytes[..]);
sock_snd.send(&serialized_data).await.unwrap();
if let Ok(ciphered_d) = ciphered_data {
let vpn_packet = UDPVpnPacket{ data: ciphered_d, nonce: nonce.to_vec()};
let serialized_data = vpn_packet.serialize();
ltx.send("Write to socket".as_bytes().to_vec());
sock_snd.send(&serialized_data).await.unwrap();
} else {
ltx.send("Socket encryption failed.".as_bytes().to_vec());
}
} else { } else {
ltx.send("Socket encryption failed.".as_bytes().to_vec()); ltx.send("There is no shared_secret in main loop".as_bytes().to_vec());
} }
} else {
ltx.send("There is no shared_secret in main loop".as_bytes().to_vec());
} }
} }
} }