-
-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Macos redirector rust side #69
Macos redirector rust side #69
Conversation
src/packet_sources/macos.rs
Outdated
#[allow(dead_code)] | ||
pub struct PipeServer { | ||
ip_rx: pipe::Receiver, | ||
ip_tx: pipe::Sender, | ||
net_rx: pipe::Receiver, | ||
net_tx: pipe::Sender, | ||
filter_rx: pipe::Receiver, | ||
filter_tx: pipe::Sender, | ||
ip_path: PathBuf, | ||
net_path: PathBuf, | ||
filter_path: PathBuf, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may sound strange but we have to save both ends of the pipe somewhere because otherwise rust compiler notices that the variable is not used and it make it out of scope, and if it makes it out of scope it makes the pipe unreadable or unwritable and swift can't read or write from it
src/packet_sources/macos.rs
Outdated
let ip_path = Path::new(&home_dir).join(format!("Downloads/{}.pipe", &ip_pipe)); | ||
let net_path = Path::new(&home_dir).join(format!("Downloads/{}.pipe", &net_pipe)); | ||
let filter_path = Path::new(&home_dir).join(format!("Downloads/{}.pipe", &filter_pipe)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only Downloads or Movies or Pictures dir are avalaible to be written or read from swift (for now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should eventually take a closer look at https://developer.apple.com/documentation/security/app_sandbox/accessing_files_from_the_macos_app_sandbox#4144035, but let's get things working first. :)
net_rx: Receiver<NetworkCommand>, | ||
sd_watcher: broadcast::Receiver<()>, | ||
) -> Result<(MacosTask, Self::Data)> { | ||
let executable_path = "/Applications/MitmproxyAppleTunnel.app/"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The app works only if we launch it from /Applications/ folder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, when/how are we moving it there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀🚀🚀
src/messages.rs
Outdated
@@ -15,6 +15,9 @@ pub enum TunnelInfo { | |||
pid: u32, | |||
process_name: Option<PathBuf>, | |||
}, | |||
Macos { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: MacOS
?
net_rx: Receiver<NetworkCommand>, | ||
sd_watcher: broadcast::Receiver<()>, | ||
) -> Result<(MacosTask, Self::Data)> { | ||
let executable_path = "/Applications/MitmproxyAppleTunnel.app/"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, when/how are we moving it there?
src/packet_sources/macos.rs
Outdated
let tx = match pipe::OpenOptions::new().unchecked(true).open_sender(path) { | ||
Ok(tx) => tx, | ||
Err(e) => Err(anyhow!("Failed to open fifo transmitter: {:?}", e))?, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we opening all pipes both for reading and for sending? I would have expected that we open one for reading, and one for sending, and the Swift side does the same (just opposite).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that drove me crazy, too. It seems in swift these pipes are handled as normal input and output files, however, if they are not already open (and saved, otherwise rust destroys the variables) then swift returns an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to replicate these issues at https://github.com/mhils/rust-swift-fifo, things seem to work as expected here.
The one tricky part is waiting on the Rust side until the pipe becomes readable, see my example here. Can we check this again please? :)
src/packet_sources/macos.rs
Outdated
let ip_path = Path::new(&home_dir).join(format!("Downloads/{}.pipe", &ip_pipe)); | ||
let net_path = Path::new(&home_dir).join(format!("Downloads/{}.pipe", &net_pipe)); | ||
let filter_path = Path::new(&home_dir).join(format!("Downloads/{}.pipe", &filter_pipe)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should eventually take a closer look at https://developer.apple.com/documentation/security/app_sandbox/accessing_files_from_the_macos_app_sandbox#4144035, but let's get things working first. :)
Co-authored-by: Maximilian Hils <[email protected]>
…ele-em/mitmproxy_rs into macos_redirector_rust_side
365b4e9
to
be37cfa
Compare
fs::copy(&src_path, &dst_path).expect("Failed to copy {src_path} to {dst_path}"); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return a result instead of a blind panic (and not use expect/unwrap internally). :)
In contrast to the build.rs script (where panic is an ok user experience), this happens on the user's machine, so we should have a proper error message.
ffi/src/server.rs
Outdated
#[cfg(target_os = "macos")] | ||
{ | ||
copy_dir( | ||
Path::new("mitmproxy_rs/MitmProxyAppleTunnel.app/"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This here won't work depending on your current working directory. Take a look at how we do it for Windows above with py.import(...).filename()
. :)
macos-redirector rust side without ipc protobuf