diff --git a/Cargo.lock b/Cargo.lock index f5ba0da..07d7d86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,17 +33,6 @@ version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" -[[package]] -name = "argon2" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25df3c03f1040d0069fcd3907e24e36d59f9b6fa07ba49be0eb25a794f036ba7" -dependencies = [ - "base64ct", - "blake2", - "password-hash 0.3.2", -] - [[package]] name = "argon2" version = "0.4.1" @@ -52,7 +41,7 @@ checksum = "db4ce4441f99dbd377ca8a8f57b698c44d0d6e712d8329b5040da5a64aa1ce73" dependencies = [ "base64ct", "blake2", - "password-hash 0.4.2", + "password-hash", ] [[package]] @@ -85,9 +74,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "axum" -version = "0.5.12" +version = "0.5.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d16705af05732b7d3258ec0f7b73c03a658a28925e050d8852d5b568ee8bcf4e" +checksum = "c943a505c17b494638a38a9af129067f760c9c06794b9f57d499266909be8e72" dependencies = [ "async-trait", "axum-core", @@ -137,9 +126,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "base64ct" -version = "1.0.1" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a32fd6af2b5827bce66c29053ba0e7c42b9dcab01835835058558c10851a46b" +checksum = "3bdca834647821e0b13d9539a8634eb62d3501b6b6c2cec1722786ee6671b851" [[package]] name = "bincode" @@ -222,9 +211,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" +checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e" dependencies = [ "serde", ] @@ -325,9 +314,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.8" +version = "3.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190814073e85d238f31ff738fcb0bf6910cedeb73376c87cd69291028966fd83" +checksum = "44bbe24bbd31a185bc2c4f7c2abe80bea13a20d57ee4e55be70ac512bdc76417" dependencies = [ "atty", "bitflags", @@ -342,9 +331,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.2.7" +version = "3.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759bf187376e1afa7b85b959e6a664a3e7a95203415dba952ad19139e798f902" +checksum = "9ba52acd3b0a5c33aeada5cdaa3267cdc7c594a98731d4268cdc1532f4264cb4" dependencies = [ "heck", "proc-macro-error", @@ -392,9 +381,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.10" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d82ee10ce34d7bc12c2122495e7593a9c41347ecdd64185af4ecf72cb1a7f83" +checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" dependencies = [ "cfg-if", "once_cell", @@ -402,9 +391,9 @@ dependencies = [ [[package]] name = "crypto-common" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ccfd8c0ee4cce11e45b3fd6f9d5e69e0cc62912aa6a0cb1bf4617b0eba5a12f" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array", "typenum", @@ -656,9 +645,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "607c8a29735385251a339424dd462993c0fed8fa09d378f259377df08c126022" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "headers" @@ -821,9 +810,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.58" +version = "0.3.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27" +checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" dependencies = [ "wasm-bindgen", ] @@ -998,7 +987,7 @@ dependencies = [ "anyhow", "atty", "clap", - "omegaupload-common 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "omegaupload-common", "reqwest", "rpassword", ] @@ -1007,7 +996,7 @@ dependencies = [ name = "omegaupload-common" version = "0.2.0" dependencies = [ - "argon2 0.4.1", + "argon2", "base64", "bytes", "chacha20poly1305", @@ -1025,27 +1014,6 @@ dependencies = [ "url", ] -[[package]] -name = "omegaupload-common" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0e6112dcb442b5d280f65cf14b9d6749f3585709d1ed2f1b8821f12c3b6c16" -dependencies = [ - "argon2 0.3.4", - "base64", - "bytes", - "chacha20poly1305", - "chrono", - "headers", - "lazy_static", - "rand", - "secrecy", - "serde", - "thiserror", - "typenum", - "url", -] - [[package]] name = "omegaupload-server" version = "0.1.0" @@ -1058,7 +1026,7 @@ dependencies = [ "futures", "headers", "lazy_static", - "omegaupload-common 0.2.0", + "omegaupload-common", "rand", "rocksdb", "serde", @@ -1084,7 +1052,7 @@ dependencies = [ "http", "js-sys", "mime_guess", - "omegaupload-common 0.2.0", + "omegaupload-common", "reqwasm", "serde", "tar", @@ -1109,20 +1077,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "os_str_bytes" -version = "6.1.0" +version = "6.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa" - -[[package]] -name = "password-hash" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d791538a6dcc1e7cb7fe6f6b58aca40e7f79403c45b2bc274008b5e647af1d8" -dependencies = [ - "base64ct", - "rand_core", - "subtle", -] +checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" [[package]] name = "password-hash" @@ -1238,9 +1195,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.40" +version = "1.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" +checksum = "c278e965f1d8cf32d6e0e96de3d3e79712178ae67986d9cf9151f51e95aac89b" dependencies = [ "unicode-ident", ] @@ -1286,9 +1243,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.13" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] @@ -1383,13 +1340,11 @@ dependencies = [ [[package]] name = "rpassword" -version = "6.0.1" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bf099a1888612545b683d2661a1940089f6c2e5a8e38979b2159da876bfd956" +checksum = "26b763cb66df1c928432cc35053f8bd4cec3335d8559fc16010017d16b3c1680" dependencies = [ "libc", - "serde", - "serde_json", "winapi", ] @@ -1447,18 +1402,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.138" +version = "1.0.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1578c6245786b9d168c5447eeacfb96856573ca56c9d68fdcf394be134882a47" +checksum = "fc855a42c7967b7c369eb5860f7164ef1f6f81c20c7cc1141f2a604e18723b03" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.138" +version = "1.0.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "023e9b1467aef8a10fb88f25611870ada9800ef7e22afce356bb0d2387b6f27c" +checksum = "6f2122636b9fe3b81f1cb25099fcf2d3f542cdb1d45940d56c713158884a05da" dependencies = [ "proc-macro2", "quote", @@ -1547,9 +1502,12 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg", +] [[package]] name = "smallvec" @@ -1685,10 +1643,11 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.19.2" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c51a52ed6686dd62c320f9b89299e9dfb46f730c7a48e635c19f21d116cb1439" +checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" dependencies = [ + "autocfg", "bytes", "libc", "memchr", @@ -1837,9 +1796,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a713421342a5a666b7577783721d3117f1b69a393df803ee17bb73b1e122a59" +checksum = "60db860322da191b40952ad9affe65ea23e7dd6a5c442c2c42865810c6ab8e6b" dependencies = [ "ansi_term", "sharded-slab", @@ -1899,9 +1858,9 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" +checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" [[package]] name = "unicode-normalization" @@ -1988,9 +1947,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994" +checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" dependencies = [ "cfg-if", "serde", @@ -2000,13 +1959,13 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a" +checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" dependencies = [ "bumpalo", - "lazy_static", "log", + "once_cell", "proc-macro2", "quote", "syn", @@ -2015,9 +1974,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.31" +version = "0.4.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de9a9cec1733468a8c657e57fa2413d2ae2c0129b95e87c5b72b8ace4d13f31f" +checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad" dependencies = [ "cfg-if", "js-sys", @@ -2027,9 +1986,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" +checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2037,9 +1996,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" +checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" dependencies = [ "proc-macro2", "quote", @@ -2050,15 +2009,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" +checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" [[package]] name = "web-sys" -version = "0.3.58" +version = "0.3.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90" +checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" dependencies = [ "js-sys", "wasm-bindgen", @@ -2177,9 +2136,9 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.5.6" +version = "1.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20b578acffd8516a6c3f2a1bdefc1ec37e547bb4e0fb8b6b01a4cafc886b4442" +checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" [[package]] name = "zip" diff --git a/README.md b/README.md index a0b0d9c..315673e 100644 --- a/README.md +++ b/README.md @@ -113,5 +113,4 @@ There are a few reasons to not use OmegaUpload: - Cannot download files larger than 512 MiB through the web frontend—this is a technical limitation of the current web frontend not using a web worker in addition to the fact that browsers are not optimized for XChaCha20. - - Right now, you must upload via the CLI tool. - The frontend uses WASM, which is a novel attack surface. diff --git a/cli/Cargo.toml b/cli/Cargo.toml index d0b0a2c..157e672 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -9,10 +9,9 @@ license = "GPL-3.0-or-later" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -omegaupload-common = "0.2.0" - +omegaupload-common = { path = "../common" } anyhow = "1.0.58" atty = "0.2.14" -clap = { version = "3.2.8", features = ["derive"] } +clap = { version = "3.2.15", features = ["derive"] } reqwest = { version = "0.11.11", default-features = false, features = ["rustls-tls", "blocking"] } -rpassword = "6.0.1" +rpassword = "7.0.0" diff --git a/cli/src/main.rs b/cli/src/main.rs index 1ac3907..cdac41a 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -24,6 +24,7 @@ use anyhow::{anyhow, bail, Context, Result}; use atty::Stream; use clap::Parser; use omegaupload_common::crypto::{open_in_place, seal_in_place}; +use omegaupload_common::fragment::Builder; use omegaupload_common::secrecy::{ExposeSecret, SecretString, SecretVec}; use omegaupload_common::{ base64, Expiration, ParsedUrl, Url, API_ENDPOINT, EXPIRATION_HEADER_NAME, @@ -33,10 +34,6 @@ use reqwest::header::EXPIRES; use reqwest::StatusCode; use rpassword::prompt_password; -use crate::fragment::Builder; - -mod fragment; - #[derive(Parser)] struct Opts { #[clap(subcommand)] diff --git a/common/Cargo.toml b/common/Cargo.toml index 52a22f7..07ba038 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -10,14 +10,14 @@ license = "MIT" [dependencies] base64 = "0.13.0" -bytes = { version = "1.1.0", features = ["serde"] } +bytes = { version = "1.2.0", features = ["serde"] } chacha20poly1305 = { version = "0.9.1", features = ["stream", "std"] } chrono = { version = "0.4.19", features = ["serde"] } headers = "0.3.7" lazy_static = "1.4.0" rand = "0.8.5" secrecy = "0.8.0" -serde = { version = "1.0.138", features = ["derive"] } +serde = { version = "1.0.140", features = ["derive"] } thiserror = "1.0.31" typenum = "1.15.0" url = "2.2.2" diff --git a/cli/src/fragment.rs b/common/src/fragment.rs similarity index 92% rename from cli/src/fragment.rs rename to common/src/fragment.rs index 39ce094..3bce5c9 100644 --- a/cli/src/fragment.rs +++ b/common/src/fragment.rs @@ -1,4 +1,4 @@ -use omegaupload_common::secrecy::{ExposeSecret, SecretString}; +use crate::secrecy::{ExposeSecret, SecretString}; pub struct Builder { decryption_key: SecretString, @@ -8,6 +8,7 @@ pub struct Builder { } impl Builder { + #[must_use] pub fn new(decryption_key: SecretString) -> Self { Self { decryption_key, @@ -17,6 +18,7 @@ impl Builder { } } + #[must_use] pub const fn needs_password(mut self) -> Self { self.needs_password = true; self @@ -24,6 +26,7 @@ impl Builder { // False positive #[allow(clippy::missing_const_for_fn)] + #[must_use] pub fn file_name(mut self, name: String) -> Self { self.file_name = Some(name); self @@ -31,11 +34,13 @@ impl Builder { // False positive #[allow(clippy::missing_const_for_fn)] + #[must_use] pub fn language(mut self, language: String) -> Self { self.language = Some(language); self } + #[must_use] pub fn build(self) -> SecretString { if !self.needs_password && self.file_name.is_none() && self.language.is_none() { return self.decryption_key; diff --git a/common/src/lib.rs b/common/src/lib.rs index 54af80b..c4383f7 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -41,6 +41,7 @@ use crate::crypto::Key; pub mod base64; pub mod crypto; +pub mod fragment; pub const API_ENDPOINT: &str = "/api"; diff --git a/package.json b/package.json index 04d5c5c..153a29d 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "highlight.js": "^11.4.0", "highlightjs-line-numbers.js": "^2.8.0", "react": "^17.0.2", - "react-dom": "^17.0.2" + "react-dom": "^17.0.2", + "source-map-loader": "^4.0.0" }, "scripts": { "build": "webpack --mode production", diff --git a/server/Cargo.toml b/server/Cargo.toml index 1df7e2f..1b296fb 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -8,23 +8,23 @@ edition = "2021" [dependencies] omegaupload-common = { path = "../common" } anyhow = "1.0.58" -axum = { version = "0.5.12", features = ["http2", "headers"] } +axum = { version = "0.5.14", features = ["http2", "headers"] } bincode = "1.3.3" # We don't care about which version (We want to match with axum), we just need # to enable the feature -bytes = { version = "1.1.0", features = ["serde"] } +bytes = { version = "1.2.0", features = ["serde"] } chrono = { version = "0.4.19", features = ["serde"] } futures = "0.3.21" # We just need to pull in whatever axum is pulling in headers = "0.3.7" lazy_static = "1.4.0" # Disable `random()` and `thread_rng()` -rand = { version = "0.8.5", default_features = false } -rocksdb = { version = "0.18.0", default_features = false, features = ["zstd"] } -serde = { version = "1.0.138", features = ["derive"] } +rand = { version = "0.8.5", default-features = false } +rocksdb = { version = "0.18.0", default-features = false, features = ["zstd"] } +serde = { version = "1.0.140", features = ["derive"] } signal-hook = "0.3.14" signal-hook-tokio = { version = "0.3.1", features = ["futures-v0_3"] } -tokio = { version = "1.19.2", features = ["macros", "rt-multi-thread"] } +tokio = { version = "1.20.1", features = ["macros", "rt-multi-thread"] } tower-http = { version = "0.3.4", features = ["fs"] } tracing = "0.1.35" -tracing-subscriber = "0.3.14" +tracing-subscriber = "0.3.15" diff --git a/web/Cargo.toml b/web/Cargo.toml index 0b08a0e..785c528 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -12,24 +12,24 @@ omegaupload-common = { path = "../common", features = ["wasm"] } getrandom = { version = "0.2.7", features = ["js"] } anyhow = "1.0.58" -bytes = "1.1.0" +bytes = "1.2.0" byte-unit = "4.0.14" console_error_panic_hook = "0.1.7" gloo-console = "0.2.1" http = "0.2.8" -js-sys = "0.3.58" +js-sys = "0.3.59" mime_guess = "2.0.4" reqwasm = "0.5.0" tree_magic_mini = { version = "3.0.3", features = ["with-gpl-data"] } -serde = { version = "1.0.138", features = ["derive"] } -wasm-bindgen = { version = "0.2.81", features = ["serde-serialize"] } -wasm-bindgen-futures = "0.4.31" +serde = { version = "1.0.140", features = ["derive"] } +wasm-bindgen = { version = "0.2.82", features = ["serde-serialize"] } +wasm-bindgen-futures = "0.4.32" zip = { version = "0.6.2", default-features = false, features = ["deflate"] } flate2 = "1.0.24" tar = "0.4.38" [dependencies.web-sys] -version = "0.3.58" +version = "0.3.59" features = [ "BlobPropertyBag", "TextDecoder", diff --git a/web/src/lib.rs b/web/src/lib.rs index f88bea2..ff09e37 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -25,9 +25,12 @@ use gloo_console::{error, log}; use http::uri::PathAndQuery; use http::{StatusCode, Uri}; use js_sys::{Array, JsString, Object, Uint8Array}; +use omegaupload_common::base64; +use omegaupload_common::crypto::seal_in_place; use omegaupload_common::crypto::{Error as CryptoError, Key}; -use omegaupload_common::secrecy::{Secret, SecretVec}; -use omegaupload_common::{Expiration, PartialParsedUrl}; +use omegaupload_common::fragment::Builder; +use omegaupload_common::secrecy::{ExposeSecret, Secret, SecretString, SecretVec}; +use omegaupload_common::{Expiration, PartialParsedUrl, Url}; use reqwasm::http::Request; use wasm_bindgen::prelude::{wasm_bindgen, Closure}; use wasm_bindgen::{JsCast, JsValue}; @@ -50,6 +53,8 @@ extern "C" { pub fn load_from_db(mime_type: JsString, name: Option, language: Option); #[wasm_bindgen(js_name = renderMessage)] pub fn render_message(message: JsString); + #[wasm_bindgen(js_name = createUploadUi)] + pub fn create_upload_ui(); } fn window() -> Window { @@ -75,7 +80,7 @@ pub fn start() { std::panic::set_hook(Box::new(console_error_panic_hook::hook)); if location().pathname().unwrap() == "/" { - render_message("Go away".into()); + create_upload_ui(); return; } @@ -166,6 +171,55 @@ pub fn start() { }); } +#[wasm_bindgen] +#[allow(clippy::future_not_send)] +pub fn encrypt_string(data: String) { + spawn_local(async move { + if let Err(e) = do_encrypt(data.into_bytes()).await { + log!(format!("[rs] Error encrypting string: {}", e)); + } + }); +} + +#[wasm_bindgen] +#[allow(clippy::future_not_send)] +pub fn encrypt_array_buffer(data: Vec) { + spawn_local(async move { + if let Err(e) = do_encrypt(data).await { + log!(format!("[rs] Error encrypting array buffer: {}", e)); + } + }); +} + +#[allow(clippy::future_not_send)] +async fn do_encrypt(mut data: Vec) -> Result<()> { + let (data, key) = { + let enc_key = seal_in_place(&mut data, None)?; + let key = SecretString::new(base64::encode(&enc_key.expose_secret().as_ref())); + (data, key) + }; + + let s: String = location().to_string().into(); + let mut url = Url::from_str(&s)?; + let fragment = Builder::new(key); + + let js_data = Uint8Array::new_with_length(u32::try_from(data.len()).expect("Data too large")); + js_data.copy_from(&data); + + let short_code = Request::post(url.as_ref()) + .body(js_data) + .send() + .await? + .text() + .await?; + url.set_path(&short_code); + url.set_fragment(Some(fragment.build().expose_secret())); + location() + .set_href(url.as_ref()) + .expect("Unable to navigate to encrypted upload"); + Ok(()) +} + #[allow(clippy::future_not_send)] async fn fetch_resources( request_uri: Uri, diff --git a/web/src/main.scss b/web/src/main.scss index 695872e..bc5aeb5 100644 --- a/web/src/main.scss +++ b/web/src/main.scss @@ -95,6 +95,14 @@ img, audio, video { max-width: 75vw; } +textarea { + width: 100%; + height: 100%; + min-width: 75vw; + min-height: 75vh; + box-sizing: border-box; +} + .primary { @extend .hljs; } @@ -108,4 +116,4 @@ img, audio, video { @extend .align-right; padding-left: $padding; } -} \ No newline at end of file +} diff --git a/web/src/render.tsx b/web/src/render.tsx index 1d2fe24..4317d07 100644 --- a/web/src/render.tsx +++ b/web/src/render.tsx @@ -16,14 +16,64 @@ import './main.scss'; import ReactDom from 'react-dom'; -import React from 'react'; +import React, { useState } from 'react'; +import { encrypt_string, encrypt_array_buffer } from '../pkg'; -const hljs = require('highlight.js'); +import hljs from 'highlight.js' (window as any).hljs = hljs; require('highlightjs-line-numbers.js'); +const FileForm = () => { + const handleChange = (event: React.ChangeEvent) => { + const fr = new FileReader(); + fr.onload = (e) => { + const { result } = e.target; + if (result instanceof ArrayBuffer) { + let data = new Uint8Array(result); + encrypt_array_buffer(data); + } + } + fr.readAsArrayBuffer((event.target as HTMLInputElement).files[0]); + } + + return ( + + ) +} + +const PasteForm = () => { + const [value, setValue] = useState(""); + + const handleSubmit = (event: React.FormEvent) => { + event.preventDefault(); + encrypt_string(value); + } + + return ( +
+      
+