From c992da0a8c12f717bbc70a5c3c94eda6c2fe7ca6 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Tue, 12 Apr 2022 09:19:08 -0500 Subject: [PATCH 1/3] update Rust used for build --- Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6ce3c98..02f5370 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,10 @@ # TODO: https://stackoverflow.com/questions/57389547/how-to-define-the-context-for-a-docker-build-as-a-specific-commit-on-one-of-the # rust:1.50-slim-buster -FROM rust@sha256:5dd85eb0c60bbdea14a6ecba1f6fe4a0f5c878bcf06d2cdfae0aff3a19ed4b10 as build +# FROM rust@sha256:5dd85eb0c60bbdea14a6ecba1f6fe4a0f5c878bcf06d2cdfae0aff3a19ed4b10 as build + +# rust:1.60-slim-buster +FROM rust@sha256:c0f26a0b299a8a74cd87be0b4bd291d55aa292198bab1bafd906edd8665edb82 as build WORKDIR / ENV USER root From 820c5aeef45b4c2e586504008fb720d5f902fb74 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Fri, 22 Apr 2022 11:37:20 -0500 Subject: [PATCH 2/3] :white_check_mark: bring tests up to date I definitely remember doing this already. I must have left the changes on my home PC. --- crates/ptth_server/src/file_server/tests.rs | 17 +++++++++++++---- src/tests.rs | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/ptth_server/src/file_server/tests.rs b/crates/ptth_server/src/file_server/tests.rs index 90352a3..f1411d9 100644 --- a/crates/ptth_server/src/file_server/tests.rs +++ b/crates/ptth_server/src/file_server/tests.rs @@ -67,7 +67,16 @@ fn file_server () { let rt = Runtime::new ().expect ("Can't create runtime"); rt.block_on (async { + use super::internal::FileRoots; + let file_server_root = PathBuf::from ("./"); + let dirs = Default::default (); + + let roots = FileRoots { + files: &file_server_root, + dirs: &dirs, + }; + let headers = Default::default (); { @@ -100,7 +109,7 @@ fn file_server () { })), ] { let resp = internal::serve_all ( - &file_server_root, + roots, Method::Get, uri_path, &headers, @@ -117,7 +126,7 @@ fn file_server () { }), ] { let resp = internal::serve_all ( - &file_server_root, + roots, Method::Get, uri_path, &headers, @@ -128,7 +137,7 @@ fn file_server () { } let resp = internal::serve_all ( - &file_server_root, + roots, Method::Get, bad_passwords_path, &hashmap! { @@ -140,7 +149,7 @@ fn file_server () { assert_eq! (resp.expect ("Should be Ok (_)"), RangeNotSatisfiable (1_048_576)); let resp = internal::serve_all ( - &file_server_root, + roots, Method::Head, bad_passwords_path, &headers, diff --git a/src/tests.rs b/src/tests.rs index e01bcaf..903b845 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -151,7 +151,7 @@ impl TestingServer { let (stop_tx, stop_rx) = oneshot::channel (); let task = { spawn (async move { - ptth_server::run_server (config_file, stop_rx, None, None).await + ptth_server::run_server (config_file, stop_rx, None, None, None).await }) }; From 097c9cf313dcb7551e0054f6cf0651422453d647 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Fri, 22 Apr 2022 11:53:19 -0500 Subject: [PATCH 3/3] :heavy_plus_sign: add diceware subcommand --- Cargo.lock | 1 + crates/ptth_multi_call_server/Cargo.toml | 1 + crates/ptth_multi_call_server/src/diceware.rs | 23 +++++++++++++++++++ .../src/eff_short_wordlist_1.txt | 0 crates/ptth_multi_call_server/src/main.rs | 4 ++++ 5 files changed, 29 insertions(+) create mode 100644 crates/ptth_multi_call_server/src/diceware.rs rename eff_short_wordlist_1.txt => crates/ptth_multi_call_server/src/eff_short_wordlist_1.txt (100%) diff --git a/Cargo.lock b/Cargo.lock index 9e44124..af842dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1243,6 +1243,7 @@ dependencies = [ "ptth_file_server", "ptth_server", "quic_demo", + "rand", "reqwest", "rusty_ulid", "sha2", diff --git a/crates/ptth_multi_call_server/Cargo.toml b/crates/ptth_multi_call_server/Cargo.toml index b854b1e..c252fa7 100644 --- a/crates/ptth_multi_call_server/Cargo.toml +++ b/crates/ptth_multi_call_server/Cargo.toml @@ -19,6 +19,7 @@ hex = "0.4.3" ptth_file_server = { path = "../ptth_file_server_bin" } ptth_server = { path = "../ptth_server" } quic_demo = { path = "../../prototypes/quic_demo" } +rand = "0.8.4" rusty_ulid = "0.10.1" sha2 = "0.9.8" tokio = { version = "1.8.1", features = ["full"] } diff --git a/crates/ptth_multi_call_server/src/diceware.rs b/crates/ptth_multi_call_server/src/diceware.rs new file mode 100644 index 0000000..741ca27 --- /dev/null +++ b/crates/ptth_multi_call_server/src/diceware.rs @@ -0,0 +1,23 @@ +use rand::Rng; + +pub fn main () { + let wordlist = include_str! ("eff_short_wordlist_1.txt"); + let words: Vec <_> = wordlist.split ('\n').take (1253).collect (); + + assert_eq! (words.len (), 1253); + assert_eq! (words [0], "acid"); + assert_eq! (words [600], "large"); + assert_eq! (words [1252], "zoom"); + + let mut rng = rand::thread_rng (); + + let random_words: Vec <&str> = (0..8) + .map (|_| { + words [rng.gen_range (0..words.len ())] + }) + .collect (); + + let passphrase = random_words.join (" "); + + println! ("{}", passphrase); +} diff --git a/eff_short_wordlist_1.txt b/crates/ptth_multi_call_server/src/eff_short_wordlist_1.txt similarity index 100% rename from eff_short_wordlist_1.txt rename to crates/ptth_multi_call_server/src/eff_short_wordlist_1.txt diff --git a/crates/ptth_multi_call_server/src/main.rs b/crates/ptth_multi_call_server/src/main.rs index 343f5bd..1757884 100644 --- a/crates/ptth_multi_call_server/src/main.rs +++ b/crates/ptth_multi_call_server/src/main.rs @@ -5,11 +5,13 @@ use std::{ use tokio::sync::watch; +mod diceware; mod download; mod ulid; #[derive (Clone, Copy, Debug, PartialEq)] enum Subcommand { + Diceware, Download, PtthServer, PtthFileServer, @@ -27,6 +29,7 @@ async fn main () -> anyhow::Result <()> { let (subcommand, args) = parse_args (&args)?; match subcommand { + Diceware => Ok (diceware::main ()), Download => download::main (&args).await, PtthServer => ptth_server::executable::main (&args).await, PtthFileServer => ptth_file_server::main (&args).await, @@ -50,6 +53,7 @@ fn parse_subcommand (arg: &str) -> Option use Subcommand::*; let map = vec! [ + ("diceware", Diceware), ("download", Download), ("ptth_server", PtthServer), ("ptth_file_server", PtthFileServer),