Changes to be committed:
modified: Cargo.lock modified: Cargo.toml modified: src/client.rs modified: src/server.rs
This commit is contained in:
parent
faf1855311
commit
378feed415
56
Cargo.lock
generated
56
Cargo.lock
generated
@ -530,6 +530,34 @@ version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "frida_vpn"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"aes-gcm",
|
||||
"base64 0.22.1",
|
||||
"block-modes",
|
||||
"block-padding",
|
||||
"chrono",
|
||||
"clap",
|
||||
"console-subscriber",
|
||||
"crossbeam-channel",
|
||||
"env_logger",
|
||||
"futures",
|
||||
"generic-array",
|
||||
"hex",
|
||||
"log",
|
||||
"packet",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_yaml",
|
||||
"socket2 0.4.10",
|
||||
"tokio",
|
||||
"tun2",
|
||||
"x25519-dalek",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures"
|
||||
version = "0.3.30"
|
||||
@ -1337,34 +1365,6 @@ version = "1.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6"
|
||||
|
||||
[[package]]
|
||||
name = "rustvpn"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"aes-gcm",
|
||||
"base64 0.22.1",
|
||||
"block-modes",
|
||||
"block-padding",
|
||||
"chrono",
|
||||
"clap",
|
||||
"console-subscriber",
|
||||
"crossbeam-channel",
|
||||
"env_logger",
|
||||
"futures",
|
||||
"generic-array",
|
||||
"hex",
|
||||
"log",
|
||||
"packet",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_yaml",
|
||||
"socket2 0.4.10",
|
||||
"tokio",
|
||||
"tun2",
|
||||
"x25519-dalek",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.18"
|
||||
|
10
Cargo.toml
10
Cargo.toml
@ -1,10 +1,12 @@
|
||||
[package]
|
||||
name = "rustvpn"
|
||||
name = "frida_vpn"
|
||||
version = "0.1.2"
|
||||
edition = "2021"
|
||||
|
||||
[build]
|
||||
rustflags = ["--cfg", "tokio_unstable"]
|
||||
license = "Apache-2.0"
|
||||
authors = ["alterdekim"]
|
||||
keywords = ["tun", "network", "tunnel", "vpn"]
|
||||
categories = ["network-programming", "asynchronous"]
|
||||
readme = "README.md"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -5,7 +5,6 @@ use base64::prelude::*;
|
||||
use log::{error, info, warn};
|
||||
use std::sync::Arc;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::process::Command;
|
||||
use x25519_dalek::{PublicKey, StaticSecret};
|
||||
use aes_gcm::{
|
||||
aead::{Aead, AeadCore, KeyInit, OsRng},
|
||||
@ -14,54 +13,6 @@ use aes_gcm::{
|
||||
use crate::config::ClientConfiguration;
|
||||
use crate::udp::{UDPVpnPacket, UDPVpnHandshake, UDPSerializable};
|
||||
|
||||
fn configure_routes() {
|
||||
let ip_output = Command::new("ip")
|
||||
.arg("-4")
|
||||
.arg("address")
|
||||
.arg("add")
|
||||
.arg("10.66.66.2/32")
|
||||
.arg("dev")
|
||||
.arg("tun0")
|
||||
.output()
|
||||
.expect("Failed to execute IP command");
|
||||
|
||||
if !ip_output.status.success() {
|
||||
eprintln!("Failed to set IP: {}", String::from_utf8_lossy(&ip_output.stderr));
|
||||
return;
|
||||
}
|
||||
|
||||
let link_output = Command::new("ip")
|
||||
.arg("link")
|
||||
.arg("set")
|
||||
.arg("mtu")
|
||||
.arg("1420")
|
||||
.arg("up")
|
||||
.arg("dev")
|
||||
.arg("tun0")
|
||||
.output()
|
||||
.expect("Failed to execute IP LINK command");
|
||||
|
||||
if !link_output.status.success() {
|
||||
eprintln!("Failed to set link up: {}", String::from_utf8_lossy(&link_output.stderr));
|
||||
return;
|
||||
}
|
||||
|
||||
let route_output = Command::new("ip")
|
||||
.arg("route")
|
||||
.arg("add")
|
||||
.arg("0.0.0.0/0")
|
||||
.arg("via")
|
||||
.arg("10.8.0.1")
|
||||
.arg("dev")
|
||||
.arg("tun0")
|
||||
.output()
|
||||
.expect("Failed to execute IP ROUTE command");
|
||||
|
||||
if !route_output.status.success() {
|
||||
eprintln!("Failed to set route: {}", String::from_utf8_lossy(&route_output.stderr));
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn client_mode(client_config: ClientConfiguration) {
|
||||
info!("Starting client...");
|
||||
|
||||
@ -81,9 +32,6 @@ pub async fn client_mode(client_config: ClientConfiguration) {
|
||||
let dev = tun2::create(&config).unwrap();
|
||||
let (mut dev_reader, mut dev_writer) = dev.split();
|
||||
|
||||
//#[cfg(target_os = "linux")]
|
||||
//configure_routes();
|
||||
|
||||
let sock_rec = Arc::new(sock);
|
||||
let sock_snd = sock_rec.clone();
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
//use crossbeam_channel::unbounded;
|
||||
use futures::{SinkExt, StreamExt};
|
||||
use tokio::sync::mpsc;
|
||||
use tokio::task::JoinSet;
|
||||
use tokio::{net::UdpSocket, sync::Mutex, time};
|
||||
use x25519_dalek::{PublicKey, StaticSecret};
|
||||
use std::io::{Read, Write};
|
||||
use base64::prelude::*;
|
||||
use log::{error, info};
|
||||
use std::sync::Arc;
|
||||
@ -50,19 +48,19 @@ pub async fn server_mode(server_config: ServerConfiguration) {
|
||||
let keepalive_sec = server_config.interface.keepalive.clone();
|
||||
let send2hnd_cl = send2hnd.clone();
|
||||
let addrs_lcl = addresses.clone();
|
||||
/* if keepalive_sec > 0 {
|
||||
set.spawn(async move {
|
||||
let kp_sc = keepalive_sec.clone();
|
||||
loop {
|
||||
time::sleep(time::Duration::from_secs(kp_sc.into())).await;
|
||||
let mmp = addrs_lcl.lock().await;
|
||||
mmp.values().for_each(|p| {
|
||||
let _ = send2hnd_cl.send((UDPKeepAlive{}.serialize(), p.addr));
|
||||
});
|
||||
drop(mmp);
|
||||
}
|
||||
});
|
||||
}*/
|
||||
|
||||
let alive_task = tokio::spawn(async move {
|
||||
let kp_sc = keepalive_sec.clone();
|
||||
if kp_sc <= 0 { return; }
|
||||
loop {
|
||||
time::sleep(time::Duration::from_secs(kp_sc.into())).await;
|
||||
let mmp = addrs_lcl.lock().await;
|
||||
mmp.values().for_each(|p| {
|
||||
let _ = send2hnd_cl.send((UDPKeepAlive{}.serialize(), p.addr));
|
||||
});
|
||||
drop(mmp);
|
||||
}
|
||||
});
|
||||
|
||||
let sock_writer_task = tokio::spawn(async move {
|
||||
loop {
|
||||
@ -90,7 +88,7 @@ pub async fn server_mode(server_config: ServerConfiguration) {
|
||||
|
||||
if let Ok(ciphered_d) = ciphered_data {
|
||||
let vpn_packet = UDPVpnPacket{ data: ciphered_d, nonce: nonce.to_vec()};
|
||||
send2hnd_sr.send((vpn_packet.serialize(), peer.addr));
|
||||
let _ = send2hnd_sr.send((vpn_packet.serialize(), peer.addr));
|
||||
} else {
|
||||
error!("Traffic encryption failed.");
|
||||
}
|
||||
@ -171,7 +169,7 @@ pub async fn server_mode(server_config: ServerConfiguration) {
|
||||
}
|
||||
});
|
||||
|
||||
tokio::join!(tun_reader_task, sock_reader_task, sock_writer_task, tun_writer_task);
|
||||
tokio::join!(tun_reader_task, sock_reader_task, sock_writer_task, tun_writer_task, alive_task);
|
||||
}
|
||||
|
||||
struct UDPeer {
|
||||
|
Loading…
x
Reference in New Issue
Block a user