Skip to content

Fixes sending to Tor addresses with subdomains, paths, query strings, etc. #16

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions impls/src/adapters/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,15 @@ impl SlateSender for HttpDataSender {
) -> Result<Option<(SlateVersion, Option<String>)>, Error> {
// we need to keep _tor in scope so that the process is not killed by drop.
let (url_str, _tor) = self.set_up_tor_send_process()?;
Ok(Some(self.check_other_version(
let (slate_version, slatepack_address) = self.check_other_version(
&url_str,
None,
destination_address,
)?))
)?;
if tor::status::get_tor_sender_running() {
tor::status::set_tor_sender_running(false);
}
Ok(Some((slate_version, slatepack_address)))
}

fn send_tx(
Expand Down
30 changes: 19 additions & 11 deletions impls/src/tor/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,20 +312,28 @@ pub fn is_tor_address(input: &str) -> Result<(), Error> {
}

pub fn complete_tor_address(input: &str) -> Result<String, Error> {
let input = if input.ends_with("/") {
&input[..input.len() - 1]
} else {
input
let (subdomain, domain, trailing_data) = match input.to_uppercase().find(".ONION") {
Some(index) => {
let (host, trailing_data) = input.split_at(index + ".ONION".len());
let (subdomain, domain) = match host[..host.len() - ".ONION".len()].rfind(".") {
Some(index) => {
host.split_at(index + ".".len())
}
None => ("", host)
};
(subdomain, domain, trailing_data)
}
None => ("", input, "")
};
is_tor_address(input)?;
let mut input = input.to_uppercase();
if !input.starts_with("HTTP://") && !input.starts_with("HTTPS://") {
input = format!("HTTP://{}", input);
is_tor_address(domain)?;
let mut domain = format!("{}{}", subdomain.to_uppercase(), domain.to_uppercase());
if !domain.starts_with("HTTP://") && !domain.starts_with("HTTPS://") {
domain = format!("HTTP://{}", domain);
}
if !input.ends_with(".ONION") {
input = format!("{}.ONION", input);
if !domain.ends_with(".ONION") {
domain = format!("{}.ONION", domain);
}
Ok(input.to_lowercase())
Ok(format!("{}{}", domain.to_lowercase(), trailing_data))
}

#[cfg(test)]
Expand Down