Skip to content

Commit

Permalink
android: in favor of a TCP service when protecting sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
eycorsican committed Aug 31, 2021
1 parent 3773a02 commit 517172d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions leaf/src/option/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ lazy_static! {
get_env_var_or("SOCKET_PROTECT_PATH", "".to_string())
};

pub static ref SOCKET_PROTECT_SERVER: Option<SocketAddr> = {
get_env_var_or("SOCKET_PROTECT_SERVER", "".to_string()).parse().ok()
};

pub static ref GATEWAY_MODE: bool = {
get_env_var_or("GATEWAY_MODE", false)
};
Expand Down
10 changes: 10 additions & 0 deletions leaf/src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ pub enum OutboundBind {
#[cfg(target_os = "android")]
async fn protect_socket(fd: RawFd) -> io::Result<()> {
// TODO Warns about empty protect path?
if let Some(addr) = &*option::SOCKET_PROTECT_SERVER {
let mut stream = TcpStream::connect(addr).await?;
stream.write_i32(fd as i32).await?;
if stream.read_i32().await? != 0 {
return Err(io::Error::new(
io::ErrorKind::Other,
format!("failed to protect outbound socket {}", fd),
));
}
}
if !option::SOCKET_PROTECT_PATH.is_empty() {
let mut stream = UnixStream::connect(&*option::SOCKET_PROTECT_PATH).await?;
stream.write_i32(fd as i32).await?;
Expand Down

0 comments on commit 517172d

Please sign in to comment.