From b3b9d7e9ed6304c2352c1310f04fd35e07f9bc30 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Mon, 14 Apr 2025 12:55:51 +0300 Subject: [PATCH 1/6] feat: add check to prevent people from sharing from the current directory --- src/main.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.rs b/src/main.rs index 2ead104..7cfa3ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -610,6 +610,10 @@ async fn send(args: SendArgs) -> anyhow::Result<()> { ); std::process::exit(1); } + if cwd.join(&args.path) == cwd { + println!("can not share from the current directory"); + std::process::exit(1); + } tokio::fs::create_dir_all(&blobs_data_dir).await?; From b5b71ce796492a0dd65d2ab8cffbc8f1fdc2be87 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Mon, 14 Apr 2025 12:56:55 +0300 Subject: [PATCH 2/6] WIP use newest iroh-blobs --- Cargo.lock | 42 ++++++++++++++++++++---------------------- Cargo.toml | 2 +- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 45c1b0f..51fb5ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -280,14 +280,14 @@ dependencies = [ [[package]] name = "bao-tree" -version = "0.13.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1f7a89a8ee5889d2593ae422ce6e1bb03e48a0e8a16e4fa0882dfcbe7e182ef" +checksum = "ff16d65e48353db458be63ee395c03028f24564fd48668389bd65fd945f5ac36" dependencies = [ + "blake3", "bytes", "futures-lite", "genawaiter", - "iroh-blake3", "iroh-io", "positioned-io", "range-collections", @@ -331,6 +331,19 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" +[[package]] +name = "blake3" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389a099b34312839e16420d499a9cad9650541715937ffbdd40d36f49e77eeb3" +dependencies = [ + "arrayref", + "arrayvec", + "cc", + "cfg-if", + "constant_time_eq", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -2036,28 +2049,14 @@ dependencies = [ "url", ] -[[package]] -name = "iroh-blake3" -version = "1.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efbba31f40a650f58fa28dd585a8ca76d8ae3ba63aacab4c8269004a0c803930" -dependencies = [ - "arrayref", - "arrayvec", - "cc", - "cfg-if", - "constant_time_eq", -] - [[package]] name = "iroh-blobs" -version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8d7a6872c7ec4a2613d0386b4dc19b5f3cf4822d81361c5136a63fd56ba2372" +version = "0.34.1" dependencies = [ "anyhow", "async-channel", "bao-tree", + "blake3", "bytes", "chrono", "data-encoding", @@ -2070,7 +2069,6 @@ dependencies = [ "hex", "iroh", "iroh-base", - "iroh-blake3", "iroh-io", "iroh-metrics", "nested_enum_utils", @@ -2103,9 +2101,9 @@ dependencies = [ [[package]] name = "iroh-io" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17e302c5ad649c6a7aa9ae8468e1c4dc2469321af0c6de7341c1be1bdaab434b" +checksum = "e0a5feb781017b983ff1b155cd1faf8174da2acafd807aa482876da2d7e6577a" dependencies = [ "bytes", "futures-lite", diff --git a/Cargo.toml b/Cargo.toml index d8c647e..a97261a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ derive_more = { version = "1.0.0", features = [ futures-buffered = "0.2.4" futures-lite = "2.3.0" indicatif = "0.17.7" -iroh-blobs = { version = "0.34", features = ["net_protocol"] } +iroh-blobs = { version = "0.34.1", features = ["net_protocol"], path = "../iroh-blobs" } iroh-io = "0.6" iroh = "0.34" num_cpus = "1.16.0" From 55f0c29a266cd223ac287a6a6a06bda0250e601d Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Mon, 14 Apr 2025 13:07:23 +0300 Subject: [PATCH 3/6] Add an alias "recv" for receive This is unrelated to the bugfix of course, but I have entered sendme recv soo many times... --- src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.rs b/src/main.rs index 7cfa3ab..14273b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -98,6 +98,7 @@ pub enum Commands { Send(SendArgs), /// Receive a file or directory. + #[clap(visible_alias = "recv")] Receive(ReceiveArgs), } From 5fb87f866bddfc4722071b1ee17b0dc344fba44b Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Mon, 14 Apr 2025 14:05:24 +0300 Subject: [PATCH 4/6] Add test to make sure that attempting to send the current dir will fail --- tests/cli.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/cli.rs b/tests/cli.rs index 7ef738c..00a8528 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -136,3 +136,17 @@ fn send_recv_dir() { } } } + +#[test] +fn send_send_current() { + let src_dir = tempfile::tempdir().unwrap(); + let output = duct::cmd(sendme_bin(), ["send", "."]) + .dir(src_dir.path()) + .env_remove("RUST_LOG") // disable tracing + .stderr_to_stdout() + .unchecked() + .run() + .unwrap(); + // attempting to send the current directory should fail + assert_eq!(output.status.code(), Some(1)); +} From d53e7019eb977e2ab1d55c60297daa5081cc463d Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Mon, 14 Apr 2025 14:05:43 +0300 Subject: [PATCH 5/6] fmt --- src/main.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 14273b6..5082777 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,15 @@ //! Command line arguments. +use std::{ + collections::BTreeMap, + fmt::{Display, Formatter}, + net::{SocketAddrV4, SocketAddrV6}, + path::{Component, Path, PathBuf}, + str::FromStr, + sync::Arc, + time::Duration, +}; + use anyhow::Context; use arboard::Clipboard; use clap::{ @@ -32,15 +42,6 @@ use iroh_blobs::{ use n0_future::{future::Boxed, StreamExt}; use rand::Rng; use serde::{Deserialize, Serialize}; -use std::{ - collections::BTreeMap, - fmt::{Display, Formatter}, - net::{SocketAddrV4, SocketAddrV6}, - path::{Component, Path, PathBuf}, - str::FromStr, - sync::Arc, - time::Duration, -}; use walkdir::WalkDir; /// Send a file or directory between two machines, using blake3 verified streaming. From 7fe0939605b95af811afccca080b53949a55eee6 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Mon, 14 Apr 2025 14:15:22 +0300 Subject: [PATCH 6/6] Add test to make sure recv fails when the send side data is modified --- tests/cli.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/cli.rs b/tests/cli.rs index 00a8528..2f37892 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -150,3 +150,41 @@ fn send_send_current() { // attempting to send the current directory should fail assert_eq!(output.status.code(), Some(1)); } + +#[test] +fn send_recv_modified() { + let name = "somefile.bin"; + let data = vec![0u8; 20000]; + let data2 = vec![1u8; 20000]; + // create src and tgt dir, and src file + let src_dir = tempfile::tempdir().unwrap(); + let tgt_dir = tempfile::tempdir().unwrap(); + let src_file = src_dir.path().join(name); + std::fs::write(&src_file, &data).unwrap(); + let mut send_cmd = duct::cmd( + sendme_bin(), + ["send", src_file.as_os_str().to_str().unwrap()], + ) + .dir(src_dir.path()) + .env_remove("RUST_LOG") // disable tracing + .stderr_to_stdout() + .reader() + .unwrap(); + let output = read_ascii_lines(3, &mut send_cmd).unwrap(); + let output = String::from_utf8(output).unwrap(); + let ticket = output.split_ascii_whitespace().last().unwrap(); + let ticket = BlobTicket::from_str(ticket).unwrap(); + + // modify the file + std::fs::write(&src_file, &data2).unwrap(); + + // check that download fails + let receive_output = duct::cmd(sendme_bin(), ["receive", &ticket.to_string()]) + .dir(tgt_dir.path()) + .env_remove("RUST_LOG") // disable tracing + .stderr_to_stdout() + .unchecked() + .run() + .unwrap(); + assert_eq!(receive_output.status.code(), Some(1)); +}