Merge pull request #2 from Ninja3047/master

add support for encrypting text files from web
This commit is contained in:
Ninja3047 2022-07-27 21:35:08 -04:00 committed by GitHub
commit 253fccaf78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 543 additions and 399 deletions

169
Cargo.lock generated
View file

@ -33,17 +33,6 @@ version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" 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]] [[package]]
name = "argon2" name = "argon2"
version = "0.4.1" version = "0.4.1"
@ -52,7 +41,7 @@ checksum = "db4ce4441f99dbd377ca8a8f57b698c44d0d6e712d8329b5040da5a64aa1ce73"
dependencies = [ dependencies = [
"base64ct", "base64ct",
"blake2", "blake2",
"password-hash 0.4.2", "password-hash",
] ]
[[package]] [[package]]
@ -85,9 +74,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]] [[package]]
name = "axum" name = "axum"
version = "0.5.12" version = "0.5.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d16705af05732b7d3258ec0f7b73c03a658a28925e050d8852d5b568ee8bcf4e" checksum = "c943a505c17b494638a38a9af129067f760c9c06794b9f57d499266909be8e72"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"axum-core", "axum-core",
@ -137,9 +126,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]] [[package]]
name = "base64ct" name = "base64ct"
version = "1.0.1" version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a32fd6af2b5827bce66c29053ba0e7c42b9dcab01835835058558c10851a46b" checksum = "3bdca834647821e0b13d9539a8634eb62d3501b6b6c2cec1722786ee6671b851"
[[package]] [[package]]
name = "bincode" name = "bincode"
@ -222,9 +211,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]] [[package]]
name = "bytes" name = "bytes"
version = "1.1.0" version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e"
dependencies = [ dependencies = [
"serde", "serde",
] ]
@ -325,9 +314,9 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "3.2.8" version = "3.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "190814073e85d238f31ff738fcb0bf6910cedeb73376c87cd69291028966fd83" checksum = "44bbe24bbd31a185bc2c4f7c2abe80bea13a20d57ee4e55be70ac512bdc76417"
dependencies = [ dependencies = [
"atty", "atty",
"bitflags", "bitflags",
@ -342,9 +331,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "3.2.7" version = "3.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "759bf187376e1afa7b85b959e6a664a3e7a95203415dba952ad19139e798f902" checksum = "9ba52acd3b0a5c33aeada5cdaa3267cdc7c594a98731d4268cdc1532f4264cb4"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro-error", "proc-macro-error",
@ -392,9 +381,9 @@ dependencies = [
[[package]] [[package]]
name = "crossbeam-utils" name = "crossbeam-utils"
version = "0.8.10" version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d82ee10ce34d7bc12c2122495e7593a9c41347ecdd64185af4ecf72cb1a7f83" checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"once_cell", "once_cell",
@ -402,9 +391,9 @@ dependencies = [
[[package]] [[package]]
name = "crypto-common" name = "crypto-common"
version = "0.1.5" version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ccfd8c0ee4cce11e45b3fd6f9d5e69e0cc62912aa6a0cb1bf4617b0eba5a12f" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [ dependencies = [
"generic-array", "generic-array",
"typenum", "typenum",
@ -656,9 +645,9 @@ dependencies = [
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.12.2" version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "607c8a29735385251a339424dd462993c0fed8fa09d378f259377df08c126022" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]] [[package]]
name = "headers" name = "headers"
@ -821,9 +810,9 @@ dependencies = [
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.58" version = "0.3.59"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27" checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2"
dependencies = [ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
@ -998,7 +987,7 @@ dependencies = [
"anyhow", "anyhow",
"atty", "atty",
"clap", "clap",
"omegaupload-common 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "omegaupload-common",
"reqwest", "reqwest",
"rpassword", "rpassword",
] ]
@ -1007,7 +996,7 @@ dependencies = [
name = "omegaupload-common" name = "omegaupload-common"
version = "0.2.0" version = "0.2.0"
dependencies = [ dependencies = [
"argon2 0.4.1", "argon2",
"base64", "base64",
"bytes", "bytes",
"chacha20poly1305", "chacha20poly1305",
@ -1025,27 +1014,6 @@ dependencies = [
"url", "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]] [[package]]
name = "omegaupload-server" name = "omegaupload-server"
version = "0.1.0" version = "0.1.0"
@ -1058,7 +1026,7 @@ dependencies = [
"futures", "futures",
"headers", "headers",
"lazy_static", "lazy_static",
"omegaupload-common 0.2.0", "omegaupload-common",
"rand", "rand",
"rocksdb", "rocksdb",
"serde", "serde",
@ -1084,7 +1052,7 @@ dependencies = [
"http", "http",
"js-sys", "js-sys",
"mime_guess", "mime_guess",
"omegaupload-common 0.2.0", "omegaupload-common",
"reqwasm", "reqwasm",
"serde", "serde",
"tar", "tar",
@ -1109,20 +1077,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]] [[package]]
name = "os_str_bytes" name = "os_str_bytes"
version = "6.1.0" version = "6.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa" checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4"
[[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",
]
[[package]] [[package]]
name = "password-hash" name = "password-hash"
@ -1238,9 +1195,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.40" version = "1.0.42"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" checksum = "c278e965f1d8cf32d6e0e96de3d3e79712178ae67986d9cf9151f51e95aac89b"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -1286,9 +1243,9 @@ dependencies = [
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.2.13" version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [ dependencies = [
"bitflags", "bitflags",
] ]
@ -1383,13 +1340,11 @@ dependencies = [
[[package]] [[package]]
name = "rpassword" name = "rpassword"
version = "6.0.1" version = "7.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bf099a1888612545b683d2661a1940089f6c2e5a8e38979b2159da876bfd956" checksum = "26b763cb66df1c928432cc35053f8bd4cec3335d8559fc16010017d16b3c1680"
dependencies = [ dependencies = [
"libc", "libc",
"serde",
"serde_json",
"winapi", "winapi",
] ]
@ -1447,18 +1402,18 @@ dependencies = [
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.138" version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1578c6245786b9d168c5447eeacfb96856573ca56c9d68fdcf394be134882a47" checksum = "fc855a42c7967b7c369eb5860f7164ef1f6f81c20c7cc1141f2a604e18723b03"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.138" version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "023e9b1467aef8a10fb88f25611870ada9800ef7e22afce356bb0d2387b6f27c" checksum = "6f2122636b9fe3b81f1cb25099fcf2d3f542cdb1d45940d56c713158884a05da"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1547,9 +1502,12 @@ dependencies = [
[[package]] [[package]]
name = "slab" name = "slab"
version = "0.4.6" version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "smallvec" name = "smallvec"
@ -1685,10 +1643,11 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.19.2" version = "1.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c51a52ed6686dd62c320f9b89299e9dfb46f730c7a48e635c19f21d116cb1439" checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581"
dependencies = [ dependencies = [
"autocfg",
"bytes", "bytes",
"libc", "libc",
"memchr", "memchr",
@ -1837,9 +1796,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-subscriber" name = "tracing-subscriber"
version = "0.3.14" version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a713421342a5a666b7577783721d3117f1b69a393df803ee17bb73b1e122a59" checksum = "60db860322da191b40952ad9affe65ea23e7dd6a5c442c2c42865810c6ab8e6b"
dependencies = [ dependencies = [
"ansi_term", "ansi_term",
"sharded-slab", "sharded-slab",
@ -1899,9 +1858,9 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.1" version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7"
[[package]] [[package]]
name = "unicode-normalization" name = "unicode-normalization"
@ -1988,9 +1947,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.81" version = "0.2.82"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994" checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"serde", "serde",
@ -2000,13 +1959,13 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-backend" name = "wasm-bindgen-backend"
version = "0.2.81" version = "0.2.82"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a" checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"lazy_static",
"log", "log",
"once_cell",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn",
@ -2015,9 +1974,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-futures" name = "wasm-bindgen-futures"
version = "0.4.31" version = "0.4.32"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de9a9cec1733468a8c657e57fa2413d2ae2c0129b95e87c5b72b8ace4d13f31f" checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys", "js-sys",
@ -2027,9 +1986,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.81" version = "0.2.82"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602"
dependencies = [ dependencies = [
"quote", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@ -2037,9 +1996,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.81" version = "0.2.82"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2050,15 +2009,15 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.81" version = "0.2.82"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a"
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.58" version = "0.3.59"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90" checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
@ -2177,9 +2136,9 @@ dependencies = [
[[package]] [[package]]
name = "zeroize" name = "zeroize"
version = "1.5.6" version = "1.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20b578acffd8516a6c3f2a1bdefc1ec37e547bb4e0fb8b6b01a4cafc886b4442" checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f"
[[package]] [[package]]
name = "zip" name = "zip"

View file

@ -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 - 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 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. 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. - The frontend uses WASM, which is a novel attack surface.

View file

@ -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 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
omegaupload-common = "0.2.0" omegaupload-common = { path = "../common" }
anyhow = "1.0.58" anyhow = "1.0.58"
atty = "0.2.14" 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"] } reqwest = { version = "0.11.11", default-features = false, features = ["rustls-tls", "blocking"] }
rpassword = "6.0.1" rpassword = "7.0.0"

View file

@ -24,6 +24,7 @@ use anyhow::{anyhow, bail, Context, Result};
use atty::Stream; use atty::Stream;
use clap::Parser; use clap::Parser;
use omegaupload_common::crypto::{open_in_place, seal_in_place}; 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::secrecy::{ExposeSecret, SecretString, SecretVec};
use omegaupload_common::{ use omegaupload_common::{
base64, Expiration, ParsedUrl, Url, API_ENDPOINT, EXPIRATION_HEADER_NAME, base64, Expiration, ParsedUrl, Url, API_ENDPOINT, EXPIRATION_HEADER_NAME,
@ -33,10 +34,6 @@ use reqwest::header::EXPIRES;
use reqwest::StatusCode; use reqwest::StatusCode;
use rpassword::prompt_password; use rpassword::prompt_password;
use crate::fragment::Builder;
mod fragment;
#[derive(Parser)] #[derive(Parser)]
struct Opts { struct Opts {
#[clap(subcommand)] #[clap(subcommand)]

View file

@ -10,14 +10,14 @@ license = "MIT"
[dependencies] [dependencies]
base64 = "0.13.0" 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"] } chacha20poly1305 = { version = "0.9.1", features = ["stream", "std"] }
chrono = { version = "0.4.19", features = ["serde"] } chrono = { version = "0.4.19", features = ["serde"] }
headers = "0.3.7" headers = "0.3.7"
lazy_static = "1.4.0" lazy_static = "1.4.0"
rand = "0.8.5" rand = "0.8.5"
secrecy = "0.8.0" secrecy = "0.8.0"
serde = { version = "1.0.138", features = ["derive"] } serde = { version = "1.0.140", features = ["derive"] }
thiserror = "1.0.31" thiserror = "1.0.31"
typenum = "1.15.0" typenum = "1.15.0"
url = "2.2.2" url = "2.2.2"

View file

@ -1,4 +1,4 @@
use omegaupload_common::secrecy::{ExposeSecret, SecretString}; use crate::secrecy::{ExposeSecret, SecretString};
pub struct Builder { pub struct Builder {
decryption_key: SecretString, decryption_key: SecretString,
@ -8,6 +8,7 @@ pub struct Builder {
} }
impl Builder { impl Builder {
#[must_use]
pub fn new(decryption_key: SecretString) -> Self { pub fn new(decryption_key: SecretString) -> Self {
Self { Self {
decryption_key, decryption_key,
@ -17,6 +18,7 @@ impl Builder {
} }
} }
#[must_use]
pub const fn needs_password(mut self) -> Self { pub const fn needs_password(mut self) -> Self {
self.needs_password = true; self.needs_password = true;
self self
@ -24,6 +26,7 @@ impl Builder {
// False positive // False positive
#[allow(clippy::missing_const_for_fn)] #[allow(clippy::missing_const_for_fn)]
#[must_use]
pub fn file_name(mut self, name: String) -> Self { pub fn file_name(mut self, name: String) -> Self {
self.file_name = Some(name); self.file_name = Some(name);
self self
@ -31,11 +34,13 @@ impl Builder {
// False positive // False positive
#[allow(clippy::missing_const_for_fn)] #[allow(clippy::missing_const_for_fn)]
#[must_use]
pub fn language(mut self, language: String) -> Self { pub fn language(mut self, language: String) -> Self {
self.language = Some(language); self.language = Some(language);
self self
} }
#[must_use]
pub fn build(self) -> SecretString { pub fn build(self) -> SecretString {
if !self.needs_password && self.file_name.is_none() && self.language.is_none() { if !self.needs_password && self.file_name.is_none() && self.language.is_none() {
return self.decryption_key; return self.decryption_key;

View file

@ -41,6 +41,7 @@ use crate::crypto::Key;
pub mod base64; pub mod base64;
pub mod crypto; pub mod crypto;
pub mod fragment;
pub const API_ENDPOINT: &str = "/api"; pub const API_ENDPOINT: &str = "/api";

View file

@ -17,7 +17,8 @@
"highlight.js": "^11.4.0", "highlight.js": "^11.4.0",
"highlightjs-line-numbers.js": "^2.8.0", "highlightjs-line-numbers.js": "^2.8.0",
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2" "react-dom": "^17.0.2",
"source-map-loader": "^4.0.0"
}, },
"scripts": { "scripts": {
"build": "webpack --mode production", "build": "webpack --mode production",

View file

@ -8,23 +8,23 @@ edition = "2021"
[dependencies] [dependencies]
omegaupload-common = { path = "../common" } omegaupload-common = { path = "../common" }
anyhow = "1.0.58" anyhow = "1.0.58"
axum = { version = "0.5.12", features = ["http2", "headers"] } axum = { version = "0.5.14", features = ["http2", "headers"] }
bincode = "1.3.3" bincode = "1.3.3"
# We don't care about which version (We want to match with axum), we just need # We don't care about which version (We want to match with axum), we just need
# to enable the feature # 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"] } chrono = { version = "0.4.19", features = ["serde"] }
futures = "0.3.21" futures = "0.3.21"
# We just need to pull in whatever axum is pulling in # We just need to pull in whatever axum is pulling in
headers = "0.3.7" headers = "0.3.7"
lazy_static = "1.4.0" lazy_static = "1.4.0"
# Disable `random()` and `thread_rng()` # Disable `random()` and `thread_rng()`
rand = { version = "0.8.5", default_features = false } rand = { version = "0.8.5", default-features = false }
rocksdb = { version = "0.18.0", default_features = false, features = ["zstd"] } rocksdb = { version = "0.18.0", default-features = false, features = ["zstd"] }
serde = { version = "1.0.138", features = ["derive"] } serde = { version = "1.0.140", features = ["derive"] }
signal-hook = "0.3.14" signal-hook = "0.3.14"
signal-hook-tokio = { version = "0.3.1", features = ["futures-v0_3"] } 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"] } tower-http = { version = "0.3.4", features = ["fs"] }
tracing = "0.1.35" tracing = "0.1.35"
tracing-subscriber = "0.3.14" tracing-subscriber = "0.3.15"

View file

@ -12,24 +12,24 @@ omegaupload-common = { path = "../common", features = ["wasm"] }
getrandom = { version = "0.2.7", features = ["js"] } getrandom = { version = "0.2.7", features = ["js"] }
anyhow = "1.0.58" anyhow = "1.0.58"
bytes = "1.1.0" bytes = "1.2.0"
byte-unit = "4.0.14" byte-unit = "4.0.14"
console_error_panic_hook = "0.1.7" console_error_panic_hook = "0.1.7"
gloo-console = "0.2.1" gloo-console = "0.2.1"
http = "0.2.8" http = "0.2.8"
js-sys = "0.3.58" js-sys = "0.3.59"
mime_guess = "2.0.4" mime_guess = "2.0.4"
reqwasm = "0.5.0" reqwasm = "0.5.0"
tree_magic_mini = { version = "3.0.3", features = ["with-gpl-data"] } tree_magic_mini = { version = "3.0.3", features = ["with-gpl-data"] }
serde = { version = "1.0.138", features = ["derive"] } serde = { version = "1.0.140", features = ["derive"] }
wasm-bindgen = { version = "0.2.81", features = ["serde-serialize"] } wasm-bindgen = { version = "0.2.82", features = ["serde-serialize"] }
wasm-bindgen-futures = "0.4.31" wasm-bindgen-futures = "0.4.32"
zip = { version = "0.6.2", default-features = false, features = ["deflate"] } zip = { version = "0.6.2", default-features = false, features = ["deflate"] }
flate2 = "1.0.24" flate2 = "1.0.24"
tar = "0.4.38" tar = "0.4.38"
[dependencies.web-sys] [dependencies.web-sys]
version = "0.3.58" version = "0.3.59"
features = [ features = [
"BlobPropertyBag", "BlobPropertyBag",
"TextDecoder", "TextDecoder",

View file

@ -25,9 +25,12 @@ use gloo_console::{error, log};
use http::uri::PathAndQuery; use http::uri::PathAndQuery;
use http::{StatusCode, Uri}; use http::{StatusCode, Uri};
use js_sys::{Array, JsString, Object, Uint8Array}; 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::crypto::{Error as CryptoError, Key};
use omegaupload_common::secrecy::{Secret, SecretVec}; use omegaupload_common::fragment::Builder;
use omegaupload_common::{Expiration, PartialParsedUrl}; use omegaupload_common::secrecy::{ExposeSecret, Secret, SecretString, SecretVec};
use omegaupload_common::{Expiration, PartialParsedUrl, Url};
use reqwasm::http::Request; use reqwasm::http::Request;
use wasm_bindgen::prelude::{wasm_bindgen, Closure}; use wasm_bindgen::prelude::{wasm_bindgen, Closure};
use wasm_bindgen::{JsCast, JsValue}; use wasm_bindgen::{JsCast, JsValue};
@ -50,6 +53,8 @@ extern "C" {
pub fn load_from_db(mime_type: JsString, name: Option<JsString>, language: Option<JsString>); pub fn load_from_db(mime_type: JsString, name: Option<JsString>, language: Option<JsString>);
#[wasm_bindgen(js_name = renderMessage)] #[wasm_bindgen(js_name = renderMessage)]
pub fn render_message(message: JsString); pub fn render_message(message: JsString);
#[wasm_bindgen(js_name = createUploadUi)]
pub fn create_upload_ui();
} }
fn window() -> Window { fn window() -> Window {
@ -75,7 +80,7 @@ pub fn start() {
std::panic::set_hook(Box::new(console_error_panic_hook::hook)); std::panic::set_hook(Box::new(console_error_panic_hook::hook));
if location().pathname().unwrap() == "/" { if location().pathname().unwrap() == "/" {
render_message("Go away".into()); create_upload_ui();
return; 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<u8>) {
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<u8>) -> 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)] #[allow(clippy::future_not_send)]
async fn fetch_resources( async fn fetch_resources(
request_uri: Uri, request_uri: Uri,

View file

@ -95,6 +95,14 @@ img, audio, video {
max-width: 75vw; max-width: 75vw;
} }
textarea {
width: 100%;
height: 100%;
min-width: 75vw;
min-height: 75vh;
box-sizing: border-box;
}
.primary { .primary {
@extend .hljs; @extend .hljs;
} }
@ -108,4 +116,4 @@ img, audio, video {
@extend .align-right; @extend .align-right;
padding-left: $padding; padding-left: $padding;
} }
} }

View file

@ -16,14 +16,64 @@
import './main.scss'; import './main.scss';
import ReactDom from 'react-dom'; 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; (window as any).hljs = hljs;
require('highlightjs-line-numbers.js'); require('highlightjs-line-numbers.js');
const FileForm = () => {
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
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 (
<input type="file" onChange={handleChange} />
)
}
const PasteForm = () => {
const [value, setValue] = useState("");
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
encrypt_string(value);
}
return (
<pre className='paste'>
<form className='hljs centered' onSubmit={handleSubmit}>
<textarea
placeholder="Sample text"
value={value}
onChange={(e) => setValue(e.target.value)}
/>
<input type="submit" value="submit" />
</form>
</pre>
)
}
function createUploadUi() {
const html = <main className='hljs centered fullscreen'>
<FileForm />
<PasteForm />
</main>;
ReactDom.render(html, document.body);
}
function loadFromDb(mimeType: string, name?: string, language?: string) { function loadFromDb(mimeType: string, name?: string, language?: string) {
let resolvedName; let resolvedName: string;
if (name) { if (name) {
resolvedName = name; resolvedName = name;
} else { } else {
@ -287,4 +337,4 @@ function getObjectUrl(data, mimeType?: string) {
window.addEventListener("hashchange", () => location.reload()); window.addEventListener("hashchange", () => location.reload());
export { renderMessage, loadFromDb }; export { renderMessage, createUploadUi, loadFromDb };

View file

@ -2,6 +2,7 @@ const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack'); const webpack = require('webpack');
const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin"); const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin");
const { SourceMapDevToolPlugin } = require('webpack');
module.exports = { module.exports = {
entry: './web/src/index.js', entry: './web/src/index.js',
@ -21,6 +22,8 @@ module.exports = {
"css-loader", "css-loader",
// Compiles Sass to CSS // Compiles Sass to CSS
"sass-loader", "sass-loader",
// source map for debugging
"source-map-loader"
], ],
}, },
], ],
@ -41,6 +44,7 @@ module.exports = {
crateDirectory: path.resolve(__dirname, "web"), crateDirectory: path.resolve(__dirname, "web"),
outDir: path.resolve(__dirname, "web/pkg"), outDir: path.resolve(__dirname, "web/pkg"),
}), }),
new SourceMapDevToolPlugin({}),
], ],
experiments: { experiments: {
asyncWebAssembly: true, asyncWebAssembly: true,

587
yarn.lock

File diff suppressed because it is too large Load diff