Compare commits
27 Commits
1ae56389fc
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
f44cfc6190
|
|||
|
126a86ec07
|
|||
|
227f78a767
|
|||
|
1ea1e65deb
|
|||
|
90707cc364
|
|||
|
6febf8ee22
|
|||
|
d79e96c498
|
|||
|
99705afa9e
|
|||
|
3f53c221c8
|
|||
|
725d33939e
|
|||
|
81ac1475ad
|
|||
|
d7b0127d20
|
|||
|
67b412a1a5
|
|||
|
6898297973
|
|||
|
45571c98fe
|
|||
|
acd2712ade
|
|||
|
ea2e43fe3d
|
|||
|
2c101abdbd
|
|||
|
91b459657e
|
|||
|
53bb927a87
|
|||
|
75afadb1ec
|
|||
|
f72f9034f3
|
|||
|
669f5ed073
|
|||
|
898697016a
|
|||
|
fe65e1f899
|
|||
|
4eee8e7a95
|
|||
|
5e51b4bfe1
|
Generated
+783
-128
@@ -1,6 +1,6 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aead"
|
name = "aead"
|
||||||
@@ -14,57 +14,169 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstream"
|
name = "anstream"
|
||||||
version = "0.6.12"
|
version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "96b09b5178381e0874812a9b157f7fe84982617e48f71f4e3235482775e5b540"
|
checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstyle",
|
"anstyle",
|
||||||
"anstyle-parse",
|
"anstyle-parse",
|
||||||
"anstyle-query",
|
"anstyle-query",
|
||||||
"anstyle-wincon",
|
"anstyle-wincon",
|
||||||
"colorchoice",
|
"colorchoice",
|
||||||
|
"is_terminal_polyfill",
|
||||||
"utf8parse",
|
"utf8parse",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstyle"
|
name = "anstyle"
|
||||||
version = "1.0.6"
|
version = "1.0.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc"
|
checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstyle-parse"
|
name = "anstyle-parse"
|
||||||
version = "0.2.3"
|
version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
|
checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"utf8parse",
|
"utf8parse",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstyle-query"
|
name = "anstyle-query"
|
||||||
version = "1.0.2"
|
version = "1.1.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
|
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstyle-wincon"
|
name = "anstyle-wincon"
|
||||||
version = "3.0.2"
|
version = "3.0.11"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
|
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstyle",
|
"anstyle",
|
||||||
|
"once_cell_polyfill",
|
||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "anyhow"
|
||||||
version = "1.0.0"
|
version = "1.0.102"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "argon2"
|
||||||
|
version = "0.5.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3c3610892ee6e0cbce8ae2700349fcf8f98adb0dbfbee85aec3c9179d29cc072"
|
||||||
|
dependencies = [
|
||||||
|
"base64ct",
|
||||||
|
"blake2",
|
||||||
|
"cpufeatures 0.2.17",
|
||||||
|
"password-hash",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arrayref"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arrayvec"
|
||||||
|
version = "0.7.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "assert_cmd"
|
||||||
|
version = "2.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2aa3a22042e45de04255c7bf3626e239f450200fd0493c1e382263544b20aea6"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"bstr",
|
||||||
|
"libc",
|
||||||
|
"predicates",
|
||||||
|
"predicates-core",
|
||||||
|
"predicates-tree",
|
||||||
|
"wait-timeout",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64ct"
|
||||||
|
version = "1.8.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "blake2"
|
||||||
|
version = "0.10.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe"
|
||||||
|
dependencies = [
|
||||||
|
"digest",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "blake3"
|
||||||
|
version = "1.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0aa83c34e62843d924f905e0f5c866eb1dd6545fc4d719e803d9ba6030371fce"
|
||||||
|
dependencies = [
|
||||||
|
"arrayref",
|
||||||
|
"arrayvec",
|
||||||
|
"cc",
|
||||||
|
"cfg-if",
|
||||||
|
"constant_time_eq",
|
||||||
|
"cpufeatures 0.3.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "block-buffer"
|
||||||
|
version = "0.10.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bstr"
|
||||||
|
version = "1.12.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "63044e1ae8e69f3b5a92c736ca6269b8d12fa7efe39bf34ddb06d102cf0e2cab"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
"regex-automata",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cc"
|
||||||
|
version = "1.2.63"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "556e016178bb5662a08681bbe0f00f8e17631781a4dfc8c45e466e4b185ec27f"
|
||||||
|
dependencies = [
|
||||||
|
"find-msvc-tools",
|
||||||
|
"shlex",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chacha20"
|
name = "chacha20"
|
||||||
@@ -74,7 +186,7 @@ checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"cipher",
|
"cipher",
|
||||||
"cpufeatures",
|
"cpufeatures 0.2.17",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -103,9 +215,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.5.1"
|
version = "4.6.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da"
|
checksum = "1ddb117e43bbf7dacf0a4190fef4d345b9bad68dfc649cb349e7d17d28428e51"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap_builder",
|
"clap_builder",
|
||||||
"clap_derive",
|
"clap_derive",
|
||||||
@@ -113,9 +225,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_builder"
|
name = "clap_builder"
|
||||||
version = "4.5.1"
|
version = "4.6.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb"
|
checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstream",
|
"anstream",
|
||||||
"anstyle",
|
"anstyle",
|
||||||
@@ -125,9 +237,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_derive"
|
name = "clap_derive"
|
||||||
version = "4.5.0"
|
version = "4.6.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47"
|
checksum = "f2ce8604710f6733aa641a2b3731eaa1e8b3d9973d5e3565da11800813f997a9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
@@ -137,30 +249,60 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_lex"
|
name = "clap_lex"
|
||||||
version = "0.7.0"
|
version = "1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
|
checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "colorchoice"
|
name = "colorchoice"
|
||||||
version = "1.0.0"
|
version = "1.0.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
|
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "constant_time_eq"
|
||||||
|
version = "0.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cpufeatures"
|
name = "cpufeatures"
|
||||||
version = "0.2.12"
|
version = "0.2.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504"
|
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crypto-common"
|
name = "cpufeatures"
|
||||||
version = "0.1.6"
|
version = "0.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-channel"
|
||||||
|
version = "0.5.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2"
|
||||||
|
dependencies = [
|
||||||
|
"crossbeam-utils",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-utils"
|
||||||
|
version = "0.8.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crypto-common"
|
||||||
|
version = "0.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"generic-array",
|
"generic-array",
|
||||||
"rand_core",
|
"rand_core",
|
||||||
@@ -168,14 +310,77 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fcry"
|
name = "difflib"
|
||||||
version = "0.9.0"
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "digest"
|
||||||
|
version = "0.10.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"block-buffer",
|
||||||
|
"crypto-common",
|
||||||
|
"subtle",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "equivalent"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "errno"
|
||||||
|
version = "0.3.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fastrand"
|
||||||
|
version = "2.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fcry"
|
||||||
|
version = "0.12.0"
|
||||||
|
dependencies = [
|
||||||
|
"argon2",
|
||||||
|
"assert_cmd",
|
||||||
|
"blake3",
|
||||||
"chacha20poly1305",
|
"chacha20poly1305",
|
||||||
"clap",
|
"clap",
|
||||||
"rand",
|
"crossbeam-channel",
|
||||||
|
"getrandom 0.4.2",
|
||||||
|
"libc",
|
||||||
|
"rlimit",
|
||||||
|
"same-file",
|
||||||
|
"secrets",
|
||||||
|
"tempfile",
|
||||||
|
"unicode-normalization",
|
||||||
|
"windows-sys",
|
||||||
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "find-msvc-tools"
|
||||||
|
version = "0.1.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "foldhash"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "generic-array"
|
name = "generic-array"
|
||||||
version = "0.14.7"
|
version = "0.14.7"
|
||||||
@@ -188,9 +393,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.12"
|
version = "0.2.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5"
|
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -198,31 +403,152 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "getrandom"
|
||||||
version = "0.4.1"
|
version = "0.4.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"r-efi",
|
||||||
|
"wasip2",
|
||||||
|
"wasip3",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.15.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
|
||||||
|
dependencies = [
|
||||||
|
"foldhash",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.17.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "heck"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "id-arena"
|
||||||
|
version = "2.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "indexmap"
|
||||||
|
version = "2.14.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
|
||||||
|
dependencies = [
|
||||||
|
"equivalent",
|
||||||
|
"hashbrown 0.17.1",
|
||||||
|
"serde",
|
||||||
|
"serde_core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "inout"
|
name = "inout"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5"
|
checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "is_terminal_polyfill"
|
||||||
version = "0.2.153"
|
version = "1.70.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "1.0.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "leb128fmt"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.186"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "linux-raw-sys"
|
||||||
|
version = "0.12.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.4.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "953f07c43838f8e6f9758cab68bf5bed85465e7587ebe0b823f1bcd81978ad3a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.8.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.21.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell_polyfill"
|
||||||
|
version = "1.70.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "opaque-debug"
|
name = "opaque-debug"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "page_size"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "30d5b2194ed13191c1999ae0704b7839fb18384fa22e49b57eeaa97d79ce40da"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "password-hash"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166"
|
||||||
|
dependencies = [
|
||||||
|
"base64ct",
|
||||||
|
"rand_core",
|
||||||
|
"subtle",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pkg-config"
|
||||||
|
version = "0.3.33"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "poly1305"
|
name = "poly1305"
|
||||||
@@ -230,55 +556,71 @@ version = "0.8.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf"
|
checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cpufeatures",
|
"cpufeatures 0.2.17",
|
||||||
"opaque-debug",
|
"opaque-debug",
|
||||||
"universal-hash",
|
"universal-hash",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ppv-lite86"
|
name = "predicates"
|
||||||
version = "0.2.17"
|
version = "3.1.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
checksum = "ada8f2932f28a27ee7b70dd6c1c39ea0675c55a36879ab92f3a715eaa1e63cfe"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"difflib",
|
||||||
|
"predicates-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "predicates-core"
|
||||||
|
version = "1.0.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cad38746f3166b4031b1a0d39ad9f954dd291e7854fcc0eed52ee41a0b50d144"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "predicates-tree"
|
||||||
|
version = "1.0.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d0de1b847b39c8131db0467e9df1ff60e6d0562ab8e9a16e568ad0fdb372e2f2"
|
||||||
|
dependencies = [
|
||||||
|
"predicates-core",
|
||||||
|
"termtree",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "prettyplease"
|
||||||
|
version = "0.2.37"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.78"
|
version = "1.0.106"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
|
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.35"
|
version = "1.0.45"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
|
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand"
|
name = "r-efi"
|
||||||
version = "0.8.5"
|
version = "6.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"rand_chacha",
|
|
||||||
"rand_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rand_chacha"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
|
||||||
dependencies = [
|
|
||||||
"ppv-lite86",
|
|
||||||
"rand_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_core"
|
name = "rand_core"
|
||||||
@@ -286,26 +628,129 @@ version = "0.6.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom",
|
"getrandom 0.2.17",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "strsim"
|
name = "regex-automata"
|
||||||
|
version = "0.4.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rlimit"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01"
|
checksum = "f35ee2729c56bb610f6dba436bf78135f728b7373bdffae2ec815b2d3eb98cc3"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustix"
|
||||||
|
version = "1.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"errno",
|
||||||
|
"libc",
|
||||||
|
"linux-raw-sys",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "same-file"
|
||||||
|
version = "1.0.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "secrets"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "71f5325144404085953b8078fa4a0b4d224d13f17ee3854534260ad7ff3dfb5c"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"page_size",
|
||||||
|
"pkg-config",
|
||||||
|
"vcpkg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "semver"
|
||||||
|
version = "1.0.28"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.228"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||||
|
dependencies = [
|
||||||
|
"serde_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_core"
|
||||||
|
version = "1.0.228"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
||||||
|
dependencies = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.228"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_json"
|
||||||
|
version = "1.0.150"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9"
|
||||||
|
dependencies = [
|
||||||
|
"itoa",
|
||||||
|
"memchr",
|
||||||
|
"serde",
|
||||||
|
"serde_core",
|
||||||
|
"zmij",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shlex"
|
||||||
|
version = "2.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "subtle"
|
name = "subtle"
|
||||||
version = "2.5.0"
|
version = "2.6.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
|
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.49"
|
version = "2.0.117"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "915aea9e586f80826ee59f8453c1101f9d1c4b3964cd2460185ee8e299ada496"
|
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -313,16 +758,65 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "typenum"
|
name = "tempfile"
|
||||||
version = "1.17.0"
|
version = "3.27.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
|
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
|
||||||
|
dependencies = [
|
||||||
|
"fastrand",
|
||||||
|
"getrandom 0.4.2",
|
||||||
|
"once_cell",
|
||||||
|
"rustix",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "termtree"
|
||||||
|
version = "0.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tinyvec"
|
||||||
|
version = "1.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3e61e67053d25a4e82c844e8424039d9745781b3fc4f32b8d55ed50f5f667ef3"
|
||||||
|
dependencies = [
|
||||||
|
"tinyvec_macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tinyvec_macros"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typenum"
|
||||||
|
version = "1.20.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.12"
|
version = "1.0.24"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-normalization"
|
||||||
|
version = "0.1.25"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8"
|
||||||
|
dependencies = [
|
||||||
|
"tinyvec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-xid"
|
||||||
|
version = "0.2.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "universal-hash"
|
name = "universal-hash"
|
||||||
@@ -336,90 +830,251 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "utf8parse"
|
name = "utf8parse"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "vcpkg"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version_check"
|
name = "version_check"
|
||||||
version = "0.9.4"
|
version = "0.9.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wait-timeout"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasi"
|
name = "wasi"
|
||||||
version = "0.11.0+wasi-snapshot-preview1"
|
version = "0.11.1+wasi-snapshot-preview1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasip2"
|
||||||
|
version = "1.0.3+wasi-0.2.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6"
|
||||||
|
dependencies = [
|
||||||
|
"wit-bindgen 0.57.1",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasip3"
|
||||||
|
version = "0.4.0+wasi-0.3.0-rc-2026-01-06"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5"
|
||||||
|
dependencies = [
|
||||||
|
"wit-bindgen 0.51.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-encoder"
|
||||||
|
version = "0.244.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319"
|
||||||
|
dependencies = [
|
||||||
|
"leb128fmt",
|
||||||
|
"wasmparser",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-metadata"
|
||||||
|
version = "0.244.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"indexmap",
|
||||||
|
"wasm-encoder",
|
||||||
|
"wasmparser",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasmparser"
|
||||||
|
version = "0.244.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"hashbrown 0.15.5",
|
||||||
|
"indexmap",
|
||||||
|
"semver",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-i686-pc-windows-gnu",
|
||||||
|
"winapi-x86_64-pc-windows-gnu",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-i686-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-util"
|
||||||
|
version = "0.1.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-x86_64-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-link"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.52.0"
|
version = "0.61.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-targets",
|
"windows-link",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-targets"
|
name = "wit-bindgen"
|
||||||
version = "0.52.0"
|
version = "0.51.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
|
checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows_aarch64_gnullvm",
|
"wit-bindgen-rust-macro",
|
||||||
"windows_aarch64_msvc",
|
|
||||||
"windows_i686_gnu",
|
|
||||||
"windows_i686_msvc",
|
|
||||||
"windows_x86_64_gnu",
|
|
||||||
"windows_x86_64_gnullvm",
|
|
||||||
"windows_x86_64_msvc",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_aarch64_gnullvm"
|
name = "wit-bindgen"
|
||||||
version = "0.52.0"
|
version = "0.57.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
|
checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_aarch64_msvc"
|
name = "wit-bindgen-core"
|
||||||
version = "0.52.0"
|
version = "0.51.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
|
checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"heck",
|
||||||
|
"wit-parser",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_gnu"
|
name = "wit-bindgen-rust"
|
||||||
version = "0.52.0"
|
version = "0.51.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
|
checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"heck",
|
||||||
|
"indexmap",
|
||||||
|
"prettyplease",
|
||||||
|
"syn",
|
||||||
|
"wasm-metadata",
|
||||||
|
"wit-bindgen-core",
|
||||||
|
"wit-component",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_msvc"
|
name = "wit-bindgen-rust-macro"
|
||||||
version = "0.52.0"
|
version = "0.51.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
|
checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"prettyplease",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"wit-bindgen-core",
|
||||||
|
"wit-bindgen-rust",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_gnu"
|
name = "wit-component"
|
||||||
version = "0.52.0"
|
version = "0.244.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
|
checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"bitflags",
|
||||||
|
"indexmap",
|
||||||
|
"log",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
"serde_json",
|
||||||
|
"wasm-encoder",
|
||||||
|
"wasm-metadata",
|
||||||
|
"wasmparser",
|
||||||
|
"wit-parser",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_gnullvm"
|
name = "wit-parser"
|
||||||
version = "0.52.0"
|
version = "0.244.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
|
checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736"
|
||||||
|
dependencies = [
|
||||||
[[package]]
|
"anyhow",
|
||||||
name = "windows_x86_64_msvc"
|
"id-arena",
|
||||||
version = "0.52.0"
|
"indexmap",
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
"log",
|
||||||
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
|
"semver",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
"serde_json",
|
||||||
|
"unicode-xid",
|
||||||
|
"wasmparser",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zeroize"
|
name = "zeroize"
|
||||||
version = "1.7.0"
|
version = "1.8.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d"
|
checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0"
|
||||||
|
dependencies = [
|
||||||
|
"zeroize_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zeroize_derive"
|
||||||
|
version = "1.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zmij"
|
||||||
|
version = "1.0.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
|
||||||
|
|||||||
+45
-7
@@ -1,17 +1,55 @@
|
|||||||
[package]
|
[package]
|
||||||
authors = ["ddidderr <ddidderr@paul.network>"]
|
|
||||||
edition = "2021"
|
|
||||||
name = "fcry"
|
name = "fcry"
|
||||||
version = "0.9.0"
|
version = "0.12.0"
|
||||||
|
edition = "2024"
|
||||||
|
license = "MIT-0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chacha20poly1305 = {version = "0.10", features = ["stream"]}
|
argon2 = "0.5"
|
||||||
clap = {version = "4", features = ["derive"]}
|
blake3 = "1"
|
||||||
rand = {version = "0.8"}
|
chacha20poly1305 = "0.10"
|
||||||
|
clap = { version = "4", features = ["derive"] }
|
||||||
|
crossbeam-channel = "0.5"
|
||||||
|
getrandom = { version = "0.4" }
|
||||||
|
protected-secrets = { package = "secrets", version = "1.3" }
|
||||||
|
same-file = "1"
|
||||||
|
unicode-normalization = "0.1"
|
||||||
|
zeroize = { version = "1", features = ["derive"] }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
assert_cmd = "2"
|
||||||
|
tempfile = "3"
|
||||||
|
|
||||||
|
[target.'cfg(unix)'.dependencies]
|
||||||
|
libc = "0.2"
|
||||||
|
rlimit = "0.11"
|
||||||
|
|
||||||
|
[target.'cfg(windows)'.dependencies]
|
||||||
|
windows-sys = {
|
||||||
|
version = "0.61",
|
||||||
|
features = [
|
||||||
|
"Win32_Foundation",
|
||||||
|
"Win32_Security",
|
||||||
|
"Win32_Storage_FileSystem",
|
||||||
|
"Win32_System_Console",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
debug = true
|
||||||
|
strip = false
|
||||||
|
debug-assertions = true
|
||||||
|
overflow-checks = true
|
||||||
lto = false
|
lto = false
|
||||||
|
panic = "unwind"
|
||||||
|
incremental = true
|
||||||
|
|
||||||
|
[profile.production]
|
||||||
|
inherits = "release"
|
||||||
debug = false
|
debug = false
|
||||||
strip = true
|
strip = true
|
||||||
panic = "unwind"
|
debug-assertions = false
|
||||||
|
overflow-checks = false
|
||||||
|
lto = true
|
||||||
|
incremental = false
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
MIT No Attribution
|
||||||
|
|
||||||
|
Copyright 2026 fcry contributors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||||
|
software and associated documentation files (the "Software"), to deal in the Software
|
||||||
|
without restriction, including without limitation the rights to use, copy, modify,
|
||||||
|
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
-675
@@ -1,675 +0,0 @@
|
|||||||
### GNU GENERAL PUBLIC LICENSE
|
|
||||||
|
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc.
|
|
||||||
<https://fsf.org/>
|
|
||||||
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies of this
|
|
||||||
license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
### Preamble
|
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
|
||||||
software and other kinds of works.
|
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
|
||||||
to take away your freedom to share and change the works. By contrast,
|
|
||||||
the GNU General Public License is intended to guarantee your freedom
|
|
||||||
to share and change all versions of a program--to make sure it remains
|
|
||||||
free software for all its users. We, the Free Software Foundation, use
|
|
||||||
the GNU General Public License for most of our software; it applies
|
|
||||||
also to any other work released this way by its authors. You can apply
|
|
||||||
it to your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
|
||||||
these rights or asking you to surrender the rights. Therefore, you
|
|
||||||
have certain responsibilities if you distribute copies of the
|
|
||||||
software, or if you modify it: responsibilities to respect the freedom
|
|
||||||
of others.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
|
||||||
or can get the source code. And you must show them these terms so they
|
|
||||||
know their rights.
|
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
|
||||||
that there is no warranty for this free software. For both users' and
|
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
|
||||||
changed, so that their problems will not be attributed erroneously to
|
|
||||||
authors of previous versions.
|
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
|
||||||
modified versions of the software inside them, although the
|
|
||||||
manufacturer can do so. This is fundamentally incompatible with the
|
|
||||||
aim of protecting users' freedom to change the software. The
|
|
||||||
systematic pattern of such abuse occurs in the area of products for
|
|
||||||
individuals to use, which is precisely where it is most unacceptable.
|
|
||||||
Therefore, we have designed this version of the GPL to prohibit the
|
|
||||||
practice for those products. If such problems arise substantially in
|
|
||||||
other domains, we stand ready to extend this provision to those
|
|
||||||
domains in future versions of the GPL, as needed to protect the
|
|
||||||
freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
|
||||||
States should not allow patents to restrict development and use of
|
|
||||||
software on general-purpose computers, but in those that do, we wish
|
|
||||||
to avoid the special danger that patents applied to a free program
|
|
||||||
could make it effectively proprietary. To prevent this, the GPL
|
|
||||||
assures that patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
### TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
#### 0. Definitions.
|
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds
|
|
||||||
of works, such as semiconductor masks.
|
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
|
||||||
"recipients" may be individuals or organizations.
|
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
|
||||||
in a fashion requiring copyright permission, other than the making of
|
|
||||||
an exact copy. The resulting work is called a "modified version" of
|
|
||||||
the earlier work or a work "based on" the earlier work.
|
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
|
||||||
on the Program.
|
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user
|
|
||||||
through a computer network, with no transfer of a copy, is not
|
|
||||||
conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices" to
|
|
||||||
the extent that it includes a convenient and prominently visible
|
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
#### 1. Source Code.
|
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work for
|
|
||||||
making modifications to it. "Object code" means any non-source form of
|
|
||||||
a work.
|
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
"Major Component", in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users can
|
|
||||||
regenerate automatically from other parts of the Corresponding Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that same
|
|
||||||
work.
|
|
||||||
|
|
||||||
#### 2. Basic Permissions.
|
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not convey,
|
|
||||||
without conditions so long as your license otherwise remains in force.
|
|
||||||
You may convey covered works to others for the sole purpose of having
|
|
||||||
them make modifications exclusively for you, or provide you with
|
|
||||||
facilities for running those works, provided that you comply with the
|
|
||||||
terms of this License in conveying all material for which you do not
|
|
||||||
control copyright. Those thus making or running the covered works for
|
|
||||||
you must do so exclusively on your behalf, under your direction and
|
|
||||||
control, on terms that prohibit them from making any copies of your
|
|
||||||
copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under the
|
|
||||||
conditions stated below. Sublicensing is not allowed; section 10 makes
|
|
||||||
it unnecessary.
|
|
||||||
|
|
||||||
#### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such
|
|
||||||
circumvention is effected by exercising rights under this License with
|
|
||||||
respect to the covered work, and you disclaim any intention to limit
|
|
||||||
operation or modification of the work as a means of enforcing, against
|
|
||||||
the work's users, your or third parties' legal rights to forbid
|
|
||||||
circumvention of technological measures.
|
|
||||||
|
|
||||||
#### 4. Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
#### 5. Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these
|
|
||||||
conditions:
|
|
||||||
|
|
||||||
- a) The work must carry prominent notices stating that you modified
|
|
||||||
it, and giving a relevant date.
|
|
||||||
- b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under
|
|
||||||
section 7. This requirement modifies the requirement in section 4
|
|
||||||
to "keep intact all notices".
|
|
||||||
- c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
- d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
#### 6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms of
|
|
||||||
sections 4 and 5, provided that you also convey the machine-readable
|
|
||||||
Corresponding Source under the terms of this License, in one of these
|
|
||||||
ways:
|
|
||||||
|
|
||||||
- a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
- b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the Corresponding
|
|
||||||
Source from a network server at no charge.
|
|
||||||
- c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
- d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
- e) Convey the object code using peer-to-peer transmission,
|
|
||||||
provided you inform other peers where the object code and
|
|
||||||
Corresponding Source of the work are being offered to the general
|
|
||||||
public at no charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal,
|
|
||||||
family, or household purposes, or (2) anything designed or sold for
|
|
||||||
incorporation into a dwelling. In determining whether a product is a
|
|
||||||
consumer product, doubtful cases shall be resolved in favor of
|
|
||||||
coverage. For a particular product received by a particular user,
|
|
||||||
"normally used" refers to a typical or common use of that class of
|
|
||||||
product, regardless of the status of the particular user or of the way
|
|
||||||
in which the particular user actually uses, or expects or is expected
|
|
||||||
to use, the product. A product is a consumer product regardless of
|
|
||||||
whether the product has substantial commercial, industrial or
|
|
||||||
non-consumer uses, unless such uses represent the only significant
|
|
||||||
mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to
|
|
||||||
install and execute modified versions of a covered work in that User
|
|
||||||
Product from a modified version of its Corresponding Source. The
|
|
||||||
information must suffice to ensure that the continued functioning of
|
|
||||||
the modified object code is in no case prevented or interfered with
|
|
||||||
solely because modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or
|
|
||||||
updates for a work that has been modified or installed by the
|
|
||||||
recipient, or for the User Product in which it has been modified or
|
|
||||||
installed. Access to a network may be denied when the modification
|
|
||||||
itself materially and adversely affects the operation of the network
|
|
||||||
or violates the rules and protocols for communication across the
|
|
||||||
network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
#### 7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders
|
|
||||||
of that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
- a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
- b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
- c) Prohibiting misrepresentation of the origin of that material,
|
|
||||||
or requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
- d) Limiting the use for publicity purposes of names of licensors
|
|
||||||
or authors of the material; or
|
|
||||||
- e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
- f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions
|
|
||||||
of it) with contractual assumptions of liability to the recipient,
|
|
||||||
for any liability that these contractual assumptions directly
|
|
||||||
impose on those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions; the
|
|
||||||
above requirements apply either way.
|
|
||||||
|
|
||||||
#### 8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your license
|
|
||||||
from a particular copyright holder is reinstated (a) provisionally,
|
|
||||||
unless and until the copyright holder explicitly and finally
|
|
||||||
terminates your license, and (b) permanently, if the copyright holder
|
|
||||||
fails to notify you of the violation by some reasonable means prior to
|
|
||||||
60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
#### 9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or run
|
|
||||||
a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
#### 10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
#### 11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims owned
|
|
||||||
or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within the
|
|
||||||
scope of its coverage, prohibits the exercise of, or is conditioned on
|
|
||||||
the non-exercise of one or more of the rights that are specifically
|
|
||||||
granted under this License. You may not convey a covered work if you
|
|
||||||
are a party to an arrangement with a third party that is in the
|
|
||||||
business of distributing software, under which you make payment to the
|
|
||||||
third party based on the extent of your activity of conveying the
|
|
||||||
work, and under which the third party grants, to any of the parties
|
|
||||||
who would receive the covered work from you, a discriminatory patent
|
|
||||||
license (a) in connection with copies of the covered work conveyed by
|
|
||||||
you (or copies made from those copies), or (b) primarily for and in
|
|
||||||
connection with specific products or compilations that contain the
|
|
||||||
covered work, unless you entered into that arrangement, or that patent
|
|
||||||
license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
#### 12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under
|
|
||||||
this License and any other pertinent obligations, then as a
|
|
||||||
consequence you may not convey it at all. For example, if you agree to
|
|
||||||
terms that obligate you to collect a royalty for further conveying
|
|
||||||
from those to whom you convey the Program, the only way you could
|
|
||||||
satisfy both those terms and this License would be to refrain entirely
|
|
||||||
from conveying the Program.
|
|
||||||
|
|
||||||
#### 13. Use with the GNU Affero General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the special requirements of the GNU Affero General Public License,
|
|
||||||
section 13, concerning interaction through a network will apply to the
|
|
||||||
combination as such.
|
|
||||||
|
|
||||||
#### 14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions
|
|
||||||
of the GNU General Public License from time to time. Such new versions
|
|
||||||
will be similar in spirit to the present version, but may differ in
|
|
||||||
detail to address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the Program
|
|
||||||
specifies that a certain numbered version of the GNU General Public
|
|
||||||
License "or any later version" applies to it, you have the option of
|
|
||||||
following the terms and conditions either of that numbered version or
|
|
||||||
of any later version published by the Free Software Foundation. If the
|
|
||||||
Program does not specify a version number of the GNU General Public
|
|
||||||
License, you may choose any version ever published by the Free
|
|
||||||
Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future versions
|
|
||||||
of the GNU General Public License can be used, that proxy's public
|
|
||||||
statement of acceptance of a version permanently authorizes you to
|
|
||||||
choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
#### 15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
|
|
||||||
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
|
|
||||||
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
|
|
||||||
DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
|
|
||||||
CORRECTION.
|
|
||||||
|
|
||||||
#### 16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR
|
|
||||||
CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
|
||||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
|
|
||||||
ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
|
|
||||||
NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR
|
|
||||||
LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM
|
|
||||||
TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER
|
|
||||||
PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
||||||
|
|
||||||
#### 17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
### How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these
|
|
||||||
terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest to
|
|
||||||
attach them to the start of each source file to most effectively state
|
|
||||||
the exclusion of warranty; and each file should have at least the
|
|
||||||
"copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper
|
|
||||||
mail.
|
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
|
||||||
notice like this when it starts in an interactive mode:
|
|
||||||
|
|
||||||
<program> Copyright (C) <year> <name of author>
|
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands \`show w' and \`show c' should show the
|
|
||||||
appropriate parts of the General Public License. Of course, your
|
|
||||||
program's commands might be different; for a GUI interface, you would
|
|
||||||
use an "about box".
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or
|
|
||||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
|
||||||
necessary. For more information on this, and how to apply and follow
|
|
||||||
the GNU GPL, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your
|
|
||||||
program into proprietary programs. If your program is a subroutine
|
|
||||||
library, you may consider it more useful to permit linking proprietary
|
|
||||||
applications with the library. If this is what you want to do, use the
|
|
||||||
GNU Lesser General Public License instead of this License. But first,
|
|
||||||
please read <https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
||||||
@@ -1,12 +1,172 @@
|
|||||||
# fcry - [f]ile[cry]pt
|
# fcry - filecrypt
|
||||||
A file en-/decryption tool for easy use.
|
|
||||||
|
|
||||||
Currently `fcry` uses `ChaCha20Poly1305` ([RFC 8439](https://datatracker.ietf.org/doc/html/rfc8439)) as [AEAD](https://en.wikipedia.org/wiki/Authenticated_encryption) cipher provided by the [chacha20poly1305](https://docs.rs/chacha20poly1305/latest/chacha20poly1305/) crate.
|
`fcry` encrypts and decrypts files with an authenticated chunked format. New
|
||||||
|
files use XChaCha20-Poly1305 in a STREAM-style construction: a 19-byte random
|
||||||
|
nonce prefix, a 32-bit chunk counter, and a last-chunk bit form each 24-byte
|
||||||
|
XChaCha nonce. Every chunk authenticates the full file header as AEAD
|
||||||
|
associated data.
|
||||||
|
|
||||||
## Status
|
The tool is intended for local file encryption, scripted backups, and
|
||||||
Currently `fcry` is __not thoroughly tested__ and in __early stages of development__.
|
streaming-friendly decrypts. It is not a general archive format, does not hide
|
||||||
There is a chance, that something is broken as of now.
|
file size, and does not protect plaintext after another process has received
|
||||||
Encryption __seems__ to work, but due to a possible lack of understanding of some underlying methods
|
it.
|
||||||
(or misinterpretation) it could theoretically be not effective at all.
|
|
||||||
|
|
||||||
See [TODO.md](/ddidderr/fcry/src/branch/main/TODO.md) for further information.
|
## Usage
|
||||||
|
|
||||||
|
Encrypt with an interactive passphrase:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
fcry -i plain.bin -o plain.bin.fcry --passphrase
|
||||||
|
```
|
||||||
|
|
||||||
|
Decrypt with the same passphrase:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
fcry -d -i plain.bin.fcry -o plain.bin --passphrase
|
||||||
|
```
|
||||||
|
|
||||||
|
Use a raw 32-byte key file instead of a passphrase:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
fcry -i plain.bin -o plain.bin.fcry --key-file key.bin
|
||||||
|
fcry -d -i plain.bin.fcry -o plain.bin --key-file key.bin
|
||||||
|
```
|
||||||
|
|
||||||
|
For non-interactive passphrase use:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
FCRY_PASSWORD='correct horse battery staple' \
|
||||||
|
fcry -i plain.bin -o plain.bin.fcry --passphrase-env FCRY_PASSWORD
|
||||||
|
```
|
||||||
|
|
||||||
|
`--passphrase-env` is useful for automation, but the environment variable can
|
||||||
|
remain visible to the current process environment and platform tooling. Prefer
|
||||||
|
interactive entry or a protected key file when possible.
|
||||||
|
|
||||||
|
## Safety Properties
|
||||||
|
|
||||||
|
- File outputs are written to private, randomly named temporary files and are
|
||||||
|
renamed into place only after encryption or decryption succeeds. Existing
|
||||||
|
outputs require `--force`, except for the self-replacement case that is
|
||||||
|
handled through the temporary file.
|
||||||
|
- New passphrase encryptions use Argon2id by default with 1024 MiB of memory,
|
||||||
|
2 passes, and 4 lanes. Passphrases must be non-empty and at least 12 UTF-8
|
||||||
|
bytes unless `--allow-weak-kdf` is explicitly supplied for tests or legacy
|
||||||
|
interop.
|
||||||
|
- Decryption enforces a memory ceiling for Argon2id headers. The default cap is
|
||||||
|
the lower of 4096 MiB, the architecture limit, and available Linux memory
|
||||||
|
when that can be detected. Override it with `--max-argon-memory-mib` only for
|
||||||
|
files you trust.
|
||||||
|
- Chunk size is bounded to `1..=64 MiB`. Worker threads are capped at 256, and
|
||||||
|
the pipeline bounds in-flight chunk memory.
|
||||||
|
- v3 files carry a key commitment derived from the stretched key and committed
|
||||||
|
header fields. This gives a fast, clear wrong-key failure before chunk
|
||||||
|
processing and prevents stripping or downgrading the commitment without
|
||||||
|
authentication failure.
|
||||||
|
- On Unix, `fcry` makes a best-effort call to disable core dumps for the process
|
||||||
|
before handling secrets.
|
||||||
|
|
||||||
|
## Format
|
||||||
|
|
||||||
|
The current on-disk format version is v3.
|
||||||
|
|
||||||
|
```text
|
||||||
|
magic "fcry" 4 bytes
|
||||||
|
version u8 1
|
||||||
|
alg_id u8 1 (1 = XChaCha20-Poly1305)
|
||||||
|
flags u8 1
|
||||||
|
reserved u8 1 (must be 0)
|
||||||
|
chunk_size u32 LE 4
|
||||||
|
kdf_id u8 1 (0 = raw key, 1 = Argon2id)
|
||||||
|
kdf_params variable
|
||||||
|
nonce_prefix [u8; 19]
|
||||||
|
plaintext_length u64 LE only when flags bit 0 is set
|
||||||
|
key_commitment [u8; 32] only when flags bit 1 is set
|
||||||
|
ciphertext chunks each plaintext chunk plus a 16-byte Poly1305 tag
|
||||||
|
```
|
||||||
|
|
||||||
|
The encoded header is AEAD associated data for every chunk. Changing the chunk
|
||||||
|
size, KDF parameters, nonce prefix, committed plaintext length, key commitment,
|
||||||
|
or other header bytes causes authentication failure.
|
||||||
|
|
||||||
|
Version history:
|
||||||
|
|
||||||
|
- v1: no flags and no committed plaintext length.
|
||||||
|
- v2: adds the length-committed flag and optional `plaintext_length`.
|
||||||
|
- v3: requires the key-commitment flag and stores the 32-byte key commitment.
|
||||||
|
|
||||||
|
Regular file encryption commits `plaintext_length` in the header. Stdin
|
||||||
|
encryption cannot know the final length up front, so stdin-produced files do
|
||||||
|
not support random-access decrypt.
|
||||||
|
|
||||||
|
## Streaming And Ranges
|
||||||
|
|
||||||
|
Normal decrypt-to-stdout emits each plaintext chunk after that chunk has
|
||||||
|
authenticated. This means a truncated ciphertext can produce an authentic
|
||||||
|
prefix on stdout before the final truncation error is reported. That is
|
||||||
|
inherent to chunked streaming AE when bytes are released immediately.
|
||||||
|
|
||||||
|
Use `--buffer-verify` when decrypting to stdout if downstream consumers must
|
||||||
|
not see any plaintext until the whole file has authenticated:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
fcry -d -i plain.bin.fcry --passphrase --buffer-verify > plain.bin
|
||||||
|
```
|
||||||
|
|
||||||
|
`--buffer-verify` writes plaintext to a private temporary file first, verifies
|
||||||
|
the complete ciphertext, and copies to stdout only after success. File outputs
|
||||||
|
already get atomic temporary-file behavior, so `--buffer-verify` is only valid
|
||||||
|
for decrypt-to-stdout.
|
||||||
|
|
||||||
|
Random-access decrypt requires `--decrypt`, `--input-file`, `--offset`, and
|
||||||
|
`--length`, and the input must have a length-committed header:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
fcry -d -i plain.bin.fcry --passphrase --offset 1048576 --length 4096 > slice.bin
|
||||||
|
```
|
||||||
|
|
||||||
|
A successful range decrypt authenticates the requested chunks and header. It
|
||||||
|
does not prove that the rest of the file is present or untampered. Use a full
|
||||||
|
decrypt when you need whole-file integrity. `--length 0` is rejected because it
|
||||||
|
would authenticate no chunks.
|
||||||
|
|
||||||
|
## Threat Model
|
||||||
|
|
||||||
|
`fcry` aims to provide confidentiality and integrity for file contents against
|
||||||
|
an attacker who can read, copy, truncate, replace, or modify ciphertext files
|
||||||
|
after encryption. With passphrase mode, offline guessing is still possible; the
|
||||||
|
Argon2id parameters make each guess expensive but cannot make a weak passphrase
|
||||||
|
safe.
|
||||||
|
|
||||||
|
The format authenticates all header fields that affect decryption, including
|
||||||
|
KDF parameters, chunk size, nonce prefix, committed plaintext length, and key
|
||||||
|
commitment. Unknown header flags and unsupported algorithms are rejected.
|
||||||
|
|
||||||
|
The following are explicit non-goals:
|
||||||
|
|
||||||
|
- Hiding plaintext length or access patterns. `plaintext_length` is cleartext
|
||||||
|
for regular-file encryptions, and ciphertext length already reveals an
|
||||||
|
approximate plaintext size. There is no padding scheme.
|
||||||
|
- Preventing plaintext exposure after successful decrypt. Plaintext written to
|
||||||
|
stdout, files, pipes, shell history, terminals, swap, backups, or downstream
|
||||||
|
tools is outside `fcry`'s control.
|
||||||
|
- Protecting plaintext chunk buffers from every local memory-forensics route.
|
||||||
|
Keys and passphrases use protected/zeroizing storage where practical, and
|
||||||
|
chunk buffers are zeroized on drop, but decrypted plaintext necessarily exists
|
||||||
|
in ordinary process memory while being processed.
|
||||||
|
- Disabling Windows Error Reporting or minidumps. Unlike Unix core dumps, those
|
||||||
|
are controlled by per-machine Windows policy; `fcry` records this as an
|
||||||
|
operator/deployment responsibility rather than changing host-wide policy.
|
||||||
|
- Recovering from loss of the passphrase or raw key file. There is no escrow or
|
||||||
|
backdoor.
|
||||||
|
|
||||||
|
## Operational Notes
|
||||||
|
|
||||||
|
- Keep backups of important plaintext until you have verified the encrypted
|
||||||
|
file and your recovery path.
|
||||||
|
- Store raw key files with restrictive permissions. On Unix, `fcry` warns when
|
||||||
|
a key file is group/world accessible.
|
||||||
|
- Use `--allow-weak-kdf` only for tests or compatibility with old intentionally
|
||||||
|
weak files.
|
||||||
|
- Use `--temp-dir` when the default temporary-file location is not acceptable
|
||||||
|
for decrypt-to-stdout buffering or output staging.
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
# Roadmap 1.0
|
|
||||||
## Summary
|
|
||||||
Make the program real-world usable and stable.
|
|
||||||
|
|
||||||
## Knowledge and Design
|
|
||||||
* understand `encrypt_next_in_place()`'s first argument better
|
|
||||||
* current understanding:
|
|
||||||
* associated data is used for parts of the data that cannot be
|
|
||||||
encrypted but should also be integrity protected by the authentication tag
|
|
||||||
* since there are no parts that cannot be encrypted in the context of `fcry` it is correct
|
|
||||||
to pass an empty slice to the first argument of `encrypt_next_in_place()`
|
|
||||||
* currently `fcry` uses 64 KiB blocks as single AEAD messages
|
|
||||||
* as stated [here](https://pycryptodome.readthedocs.io/en/latest/src/cipher/chacha20_poly1305.html) (limit of 13 billion messages) would imply a maximum file-size of `64 KiB * 13e9 = 832e9 KiB = 774.86 TiB`. While a file this size could be considered a special (and unsupported) use case anyway, performance is also a consideration. Does performance improve noticably with larger message sizes?
|
|
||||||
* unit tests
|
|
||||||
|
|
||||||
## Features
|
|
||||||
* password hashing
|
|
||||||
* configurable algorithm (sane default)
|
|
||||||
* configurable nr of rounds (sand default)
|
|
||||||
* a way to enter the password securely in a prompt while still being able to handle `stdin` data
|
|
||||||
* add usage examples to README.md
|
|
||||||
|
|
||||||
# Roadmap 2.0
|
|
||||||
* parallel processing: use all available (or configurable) CPU cores
|
|
||||||
|
|
||||||
# Roadmap later or never
|
|
||||||
* split into `lib` and `bin`
|
|
||||||
* other AEAD algorithms
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
set positional-arguments
|
||||||
|
|
||||||
|
run *args:
|
||||||
|
cargo run -- "$@"
|
||||||
|
|
||||||
|
build:
|
||||||
|
cargo build
|
||||||
|
|
||||||
|
build-release:
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
build-production:
|
||||||
|
cargo build --profile production
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
cargo +nightly fmt
|
||||||
|
tombi format
|
||||||
|
just --fmt
|
||||||
|
|
||||||
|
_fix:
|
||||||
|
cargo fix
|
||||||
|
cargo clippy --fix
|
||||||
|
|
||||||
|
fix: _fix fmt
|
||||||
|
|
||||||
|
clippy:
|
||||||
|
cargo clippy --workspace --all-targets --all-features -- -D warnings
|
||||||
|
|
||||||
|
test:
|
||||||
|
cargo test --workspace
|
||||||
|
|
||||||
|
clean:
|
||||||
|
cargo clean
|
||||||
+572
-55
@@ -1,104 +1,621 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: MIT-0
|
||||||
|
|
||||||
use chacha20poly1305::{aead::stream, KeyInit, XChaCha20Poly1305};
|
use chacha20poly1305::{KeyInit, XChaCha20Poly1305, XNonce, aead::AeadInPlace};
|
||||||
use rand::{rngs::OsRng, RngCore};
|
use std::fs::File;
|
||||||
|
use std::io::{BufReader, Read, Seek, SeekFrom, Write};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
use crate::reader::ReadInfo;
|
use crate::header::{
|
||||||
use crate::utils::BUFSIZE;
|
AlgId, FLAG_KEY_COMMITTED, FLAG_LENGTH_COMMITTED, Header, KdfParams, NONCE_PREFIX_LEN, TAG_LEN,
|
||||||
|
VERSION_CURRENT,
|
||||||
|
};
|
||||||
|
use crate::pipeline;
|
||||||
|
use crate::policy;
|
||||||
|
use crate::reader::{AheadReader, ReadInfoChunk};
|
||||||
|
use crate::secrets::{SecretBytes32, SecretVec};
|
||||||
use crate::utils::*;
|
use crate::utils::*;
|
||||||
|
use zeroize::Zeroizing;
|
||||||
|
|
||||||
|
/// XChaCha20Poly1305 nonce: 24 bytes total. STREAM splits the trailing 5 bytes
|
||||||
|
/// into a 4-byte big-endian counter and a 1-byte "last block" flag.
|
||||||
|
pub(crate) const NONCE_LEN: usize = 24;
|
||||||
|
pub(crate) const COUNTER_LEN: usize = 4;
|
||||||
|
const _: () = assert!(NONCE_PREFIX_LEN + COUNTER_LEN + 1 == NONCE_LEN);
|
||||||
|
|
||||||
|
pub(crate) fn make_nonce(prefix: &[u8; NONCE_PREFIX_LEN], counter: u32, last: bool) -> XNonce {
|
||||||
|
let mut n = [0u8; NONCE_LEN];
|
||||||
|
n[..NONCE_PREFIX_LEN].copy_from_slice(prefix);
|
||||||
|
n[NONCE_PREFIX_LEN..NONCE_PREFIX_LEN + COUNTER_LEN].copy_from_slice(&counter.to_be_bytes());
|
||||||
|
n[NONCE_LEN - 1] = u8::from(last);
|
||||||
|
XNonce::from(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Derive (or unwrap) the 32-byte AEAD key from KDF parameters and an optional passphrase.
|
||||||
|
/// For `KdfParams::Raw`, `raw_key` must be supplied.
|
||||||
|
/// For `KdfParams::Argon2id`, `passphrase` must be supplied.
|
||||||
|
pub fn derive_key(
|
||||||
|
kdf: &KdfParams,
|
||||||
|
raw_key: Option<&SecretBytes32>,
|
||||||
|
passphrase: Option<&SecretVec>,
|
||||||
|
) -> Result<SecretBytes32, FcryError> {
|
||||||
|
let mut out = SecretBytes32::zeroed();
|
||||||
|
match kdf {
|
||||||
|
KdfParams::Raw => {
|
||||||
|
let raw =
|
||||||
|
raw_key.ok_or_else(|| FcryError::Format("raw kdf requires --key-file".into()))?;
|
||||||
|
raw.with_array(|raw| out.with_mut_array(|out| out.copy_from_slice(raw)));
|
||||||
|
}
|
||||||
|
KdfParams::Argon2id {
|
||||||
|
salt,
|
||||||
|
m_cost,
|
||||||
|
t_cost,
|
||||||
|
p_cost,
|
||||||
|
} => {
|
||||||
|
let pw = passphrase
|
||||||
|
.ok_or_else(|| FcryError::Format("argon2id kdf requires a passphrase".into()))?;
|
||||||
|
let params = argon2::Params::new(*m_cost, *t_cost, *p_cost, Some(32))?;
|
||||||
|
let argon =
|
||||||
|
argon2::Argon2::new(argon2::Algorithm::Argon2id, argon2::Version::V0x13, params);
|
||||||
|
pw.with_slice(|pw| out.with_mut_array(|out| argon.hash_password_into(pw, salt, out)))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Build the AEAD cipher from the protected key. The cipher holds an
|
||||||
|
/// unprotected copy of the key while alive; `chacha20poly1305` zeroizes that
|
||||||
|
/// copy on drop. Wrapping in `Arc` lets us share it across worker threads.
|
||||||
|
fn build_aead(key: &SecretBytes32) -> Arc<XChaCha20Poly1305> {
|
||||||
|
Arc::new(key.with_array(|key| XChaCha20Poly1305::new(key.into())))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn compute_key_commitment(key: &SecretBytes32, header: &Header) -> [u8; 32] {
|
||||||
|
key.with_array(|key| {
|
||||||
|
let mut hasher = blake3::Hasher::new_keyed(key);
|
||||||
|
hasher.update(b"fcry-kcv-v3");
|
||||||
|
hasher.update(&[0]);
|
||||||
|
hasher.update(&header.commitment_input_encoding());
|
||||||
|
*hasher.finalize().as_bytes()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn verify_key_commitment(header: &Header, key: &SecretBytes32) -> Result<(), FcryError> {
|
||||||
|
let Some(expected) = header.key_commitment else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
let actual = compute_key_commitment(key, header);
|
||||||
|
let mut diff = 0u8;
|
||||||
|
for (a, b) in actual.iter().zip(expected.iter()) {
|
||||||
|
diff |= a ^ b;
|
||||||
|
}
|
||||||
|
if diff == 0 {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(FcryError::WrongKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Bump the per-chunk counter; surface a domain error on overflow rather than
|
||||||
|
/// panicking on debug or wrapping in release.
|
||||||
|
pub(crate) fn bump_counter(counter: u32) -> Result<u32, FcryError> {
|
||||||
|
counter
|
||||||
|
.checked_add(1)
|
||||||
|
.ok_or_else(|| FcryError::Format("STREAM counter overflow (input too large)".into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn encrypt<S: AsRef<str>>(
|
pub fn encrypt<S: AsRef<str>>(
|
||||||
input_file: Option<S>,
|
input_file: Option<S>,
|
||||||
output_file: Option<S>,
|
output_file: Option<S>,
|
||||||
key: [u8; 32],
|
key: &SecretBytes32,
|
||||||
|
chunk_size: u32,
|
||||||
|
kdf: KdfParams,
|
||||||
|
threads: usize,
|
||||||
) -> Result<(), FcryError> {
|
) -> Result<(), FcryError> {
|
||||||
let mut f_plain = read_from_file_or_stdin(input_file, BUFSIZE);
|
encrypt_with_output_options(
|
||||||
let mut f_encrypted = write_to_file_or_stdout(output_file);
|
input_file,
|
||||||
|
output_file,
|
||||||
|
key,
|
||||||
|
chunk_size,
|
||||||
|
kdf,
|
||||||
|
threads,
|
||||||
|
&OutSinkOptions::default(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
let mut nonce = [0u8; 19];
|
pub fn encrypt_with_output_options<S: AsRef<str>>(
|
||||||
OsRng.fill_bytes(&mut nonce);
|
input_file: Option<S>,
|
||||||
|
output_file: Option<S>,
|
||||||
|
key: &SecretBytes32,
|
||||||
|
chunk_size: u32,
|
||||||
|
kdf: KdfParams,
|
||||||
|
threads: usize,
|
||||||
|
output_options: &OutSinkOptions,
|
||||||
|
) -> Result<(), FcryError> {
|
||||||
|
let chunk_sz = policy::validate_chunk_size(chunk_size)?;
|
||||||
|
let input = open_input(input_file)?;
|
||||||
|
let plaintext_length = input.length;
|
||||||
|
let mut f_plain = AheadReader::from(input.reader, chunk_sz);
|
||||||
|
let mut f_encrypted = OutSink::open_with_options(output_file, output_options)?;
|
||||||
|
|
||||||
// let key = XChaCha20Poly1305::generate_key(&mut OsRng);
|
let mut nonce_prefix = [0u8; NONCE_PREFIX_LEN];
|
||||||
|
getrandom::fill(&mut nonce_prefix)?;
|
||||||
|
|
||||||
f_encrypted.write_all(&nonce)?;
|
let flags = if plaintext_length.is_some() {
|
||||||
|
FLAG_LENGTH_COMMITTED
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
} | FLAG_KEY_COMMITTED;
|
||||||
|
let mut header = Header {
|
||||||
|
version: VERSION_CURRENT,
|
||||||
|
alg: AlgId::XChaCha20Poly1305,
|
||||||
|
flags,
|
||||||
|
chunk_size,
|
||||||
|
kdf,
|
||||||
|
nonce_prefix,
|
||||||
|
plaintext_length,
|
||||||
|
key_commitment: None,
|
||||||
|
};
|
||||||
|
header.key_commitment = Some(compute_key_commitment(key, &header));
|
||||||
|
let aad = Arc::new(header.encode());
|
||||||
|
f_encrypted.write_all(&aad)?;
|
||||||
|
|
||||||
let aead = XChaCha20Poly1305::new(&key.into());
|
let aead = build_aead(key);
|
||||||
let mut stream_encryptor = stream::EncryptorBE32::from_aead(aead, &nonce.into());
|
|
||||||
|
|
||||||
let mut buf = vec![0; BUFSIZE];
|
if threads > 1 {
|
||||||
|
return pipeline::encrypt_parallel(
|
||||||
|
f_plain,
|
||||||
|
f_encrypted,
|
||||||
|
aead,
|
||||||
|
aad,
|
||||||
|
nonce_prefix,
|
||||||
|
chunk_sz,
|
||||||
|
threads,
|
||||||
|
plaintext_length,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut buf = Zeroizing::new(vec![0u8; chunk_sz]);
|
||||||
|
let mut counter: u32 = 0;
|
||||||
|
let mut bytes_seen: u64 = 0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let read_result = f_plain.read_ahead(&mut buf)?;
|
match f_plain.read_ahead(&mut buf)? {
|
||||||
|
ReadInfoChunk::Normal(_) => {
|
||||||
match read_result {
|
let nonce = make_nonce(&nonce_prefix, counter, false);
|
||||||
ReadInfo::NormalChunk(n) => {
|
aead.encrypt_in_place(&nonce, &aad, &mut *buf)?;
|
||||||
assert_eq!(n, BUFSIZE);
|
|
||||||
assert_eq!(buf.len(), BUFSIZE);
|
|
||||||
eprintln!("[encrypt]: read normal chunk");
|
|
||||||
stream_encryptor.encrypt_next_in_place(&[], &mut buf)?;
|
|
||||||
f_encrypted.write_all(&buf)?;
|
f_encrypted.write_all(&buf)?;
|
||||||
// buf grows after encrypt_next_in_place because of tag that is added
|
buf.truncate(chunk_sz);
|
||||||
// we shrink it to the BUFSIZE in order to read the correct size
|
bytes_seen = policy::checked_count_add(bytes_seen, chunk_sz, "bytes read")?;
|
||||||
buf.truncate(BUFSIZE);
|
counter = bump_counter(counter)?;
|
||||||
}
|
}
|
||||||
ReadInfo::LastChunk(n) => {
|
ReadInfoChunk::Last(n) => {
|
||||||
eprintln!("[encrypt]: read last chunk");
|
|
||||||
buf.truncate(n);
|
buf.truncate(n);
|
||||||
stream_encryptor.encrypt_last_in_place(&[], &mut buf)?;
|
let nonce = make_nonce(&nonce_prefix, counter, true);
|
||||||
|
aead.encrypt_in_place(&nonce, &aad, &mut *buf)?;
|
||||||
|
f_encrypted.write_all(&buf)?;
|
||||||
|
bytes_seen = policy::checked_count_add(bytes_seen, n, "bytes read")?;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ReadInfoChunk::Empty => {
|
||||||
|
// Empty plaintext: still emit a final "last" tag so the decryptor
|
||||||
|
// authenticates the (empty) stream rather than silently producing nothing.
|
||||||
|
buf.clear();
|
||||||
|
let nonce = make_nonce(&nonce_prefix, counter, true);
|
||||||
|
aead.encrypt_in_place(&nonce, &aad, &mut *buf)?;
|
||||||
f_encrypted.write_all(&buf)?;
|
f_encrypted.write_all(&buf)?;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ReadInfo::EmptyChunk => {
|
|
||||||
eprintln!("[encrypt]: read empty chunk");
|
|
||||||
panic!("[ERROR] Empty Chunk while reading");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(committed) = plaintext_length
|
||||||
|
&& committed != bytes_seen
|
||||||
|
{
|
||||||
|
// Defense in depth: the input changed between stat and EOF. The
|
||||||
|
// committed length is part of the AEAD AAD, so any decrypter would
|
||||||
|
// also surface this, but we prefer to fail before publishing the file.
|
||||||
|
return Err(FcryError::Format(format!(
|
||||||
|
"input length changed during encryption: committed {committed}, read {bytes_seen}"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
f_encrypted.commit()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn decrypt<S: AsRef<str>>(
|
pub fn decrypt<S: AsRef<str>>(
|
||||||
input_file: Option<S>,
|
input_file: Option<S>,
|
||||||
output_file: Option<S>,
|
output_file: Option<S>,
|
||||||
key: [u8; 32],
|
raw_key: Option<&SecretBytes32>,
|
||||||
|
passphrase: Option<&SecretVec>,
|
||||||
|
threads: usize,
|
||||||
) -> Result<(), FcryError> {
|
) -> Result<(), FcryError> {
|
||||||
let mut f_encrypted = read_from_file_or_stdin(input_file, BUFSIZE + 16);
|
decrypt_with_argon_cap(
|
||||||
let mut f_plain = write_to_file_or_stdout(output_file);
|
input_file,
|
||||||
|
output_file,
|
||||||
|
raw_key,
|
||||||
|
passphrase,
|
||||||
|
threads,
|
||||||
|
policy::default_argon_decrypt_cap_mib(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
let mut nonce = [0u8; 19];
|
#[allow(dead_code)]
|
||||||
f_encrypted.read_exact(&mut nonce)?;
|
pub fn decrypt_with_argon_cap<S: AsRef<str>>(
|
||||||
|
input_file: Option<S>,
|
||||||
|
output_file: Option<S>,
|
||||||
|
raw_key: Option<&SecretBytes32>,
|
||||||
|
passphrase: Option<&SecretVec>,
|
||||||
|
threads: usize,
|
||||||
|
max_argon_memory_mib: u32,
|
||||||
|
) -> Result<(), FcryError> {
|
||||||
|
decrypt_with_output_options(
|
||||||
|
input_file,
|
||||||
|
output_file,
|
||||||
|
raw_key,
|
||||||
|
passphrase,
|
||||||
|
threads,
|
||||||
|
max_argon_memory_mib,
|
||||||
|
&OutSinkOptions::default(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
let aead = XChaCha20Poly1305::new(&key.into());
|
pub fn decrypt_with_output_options<S: AsRef<str>>(
|
||||||
let mut stream_decryptor = stream::DecryptorBE32::from_aead(aead, &nonce.into());
|
input_file: Option<S>,
|
||||||
|
output_file: Option<S>,
|
||||||
|
raw_key: Option<&SecretBytes32>,
|
||||||
|
passphrase: Option<&SecretVec>,
|
||||||
|
threads: usize,
|
||||||
|
max_argon_memory_mib: u32,
|
||||||
|
output_options: &OutSinkOptions,
|
||||||
|
) -> Result<(), FcryError> {
|
||||||
|
let mut reader = open_input(input_file)?.reader;
|
||||||
|
let header = Header::read_with_argon_cap(&mut reader, max_argon_memory_mib)?;
|
||||||
|
let aad = Arc::new(header.encode());
|
||||||
|
|
||||||
let mut buf = vec![0; BUFSIZE + 16];
|
let key = derive_key(&header.kdf, raw_key, passphrase)?;
|
||||||
|
verify_key_commitment(&header, &key)?;
|
||||||
|
|
||||||
|
let chunk_sz = policy::validate_chunk_size(header.chunk_size)?;
|
||||||
|
let cipher_chunk = policy::cipher_chunk_len(chunk_sz)?;
|
||||||
|
|
||||||
|
let mut f_encrypted = AheadReader::from(reader, cipher_chunk);
|
||||||
|
let mut f_plain = OutSink::open_with_options(output_file, output_options)?;
|
||||||
|
|
||||||
|
let aead = build_aead(&key);
|
||||||
|
|
||||||
|
if threads > 1 {
|
||||||
|
return pipeline::decrypt_parallel(
|
||||||
|
f_encrypted,
|
||||||
|
f_plain,
|
||||||
|
aead,
|
||||||
|
aad,
|
||||||
|
header.nonce_prefix,
|
||||||
|
cipher_chunk,
|
||||||
|
threads,
|
||||||
|
header.plaintext_length,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut buf = Zeroizing::new(vec![0u8; cipher_chunk]);
|
||||||
|
let mut counter: u32 = 0;
|
||||||
|
let mut bytes_written: u64 = 0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let read_result = f_encrypted.read_ahead(&mut buf)?;
|
match f_encrypted.read_ahead(&mut buf)? {
|
||||||
|
ReadInfoChunk::Normal(_) => {
|
||||||
match read_result {
|
let nonce = make_nonce(&header.nonce_prefix, counter, false);
|
||||||
ReadInfo::NormalChunk(n) => {
|
aead.decrypt_in_place(&nonce, &aad, &mut *buf)?;
|
||||||
assert_eq!(n, BUFSIZE + 16);
|
|
||||||
eprintln!("[decrypt]: read normal chunk");
|
|
||||||
stream_decryptor.decrypt_next_in_place(&[], &mut buf)?;
|
|
||||||
f_plain.write_all(&buf)?;
|
f_plain.write_all(&buf)?;
|
||||||
buf.resize(BUFSIZE + 16, 0);
|
bytes_written =
|
||||||
|
policy::checked_count_add(bytes_written, buf.len(), "bytes written")?;
|
||||||
|
buf.resize(cipher_chunk, 0);
|
||||||
|
counter = bump_counter(counter)?;
|
||||||
}
|
}
|
||||||
ReadInfo::LastChunk(n) => {
|
ReadInfoChunk::Last(n) => {
|
||||||
eprintln!("[decrypt]: read last chunk");
|
|
||||||
buf.truncate(n);
|
buf.truncate(n);
|
||||||
stream_decryptor.decrypt_last_in_place(&[], &mut buf)?;
|
let nonce = make_nonce(&header.nonce_prefix, counter, true);
|
||||||
|
aead.decrypt_in_place(&nonce, &aad, &mut *buf)?;
|
||||||
f_plain.write_all(&buf)?;
|
f_plain.write_all(&buf)?;
|
||||||
|
bytes_written =
|
||||||
|
policy::checked_count_add(bytes_written, buf.len(), "bytes written")?;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ReadInfo::EmptyChunk => {
|
ReadInfoChunk::Empty => {
|
||||||
eprintln!("[decrypt]: read empty chunk");
|
return Err(FcryError::Format(
|
||||||
panic!("Empty Chunk while reading");
|
"truncated ciphertext: missing final chunk".into(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(committed) = header.plaintext_length
|
||||||
|
&& committed != bytes_written
|
||||||
|
{
|
||||||
|
return Err(FcryError::Format(format!(
|
||||||
|
"decrypted length {bytes_written} disagrees with committed {committed}"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
f_plain.commit()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Random-access decrypt of a byte range. Requires a seekable input file
|
||||||
|
/// whose header has `FLAG_LENGTH_COMMITTED` set, so we know exactly where
|
||||||
|
/// each ciphertext chunk lives and which chunk is the last (its nonce uses
|
||||||
|
/// the STREAM last-block flag).
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn decrypt_range<S: AsRef<str>>(
|
||||||
|
input_file: &str,
|
||||||
|
output_file: Option<S>,
|
||||||
|
raw_key: Option<&SecretBytes32>,
|
||||||
|
passphrase: Option<&SecretVec>,
|
||||||
|
offset: u64,
|
||||||
|
length: u64,
|
||||||
|
) -> Result<(), FcryError> {
|
||||||
|
decrypt_range_with_argon_cap(
|
||||||
|
input_file,
|
||||||
|
output_file,
|
||||||
|
raw_key,
|
||||||
|
passphrase,
|
||||||
|
offset,
|
||||||
|
length,
|
||||||
|
policy::default_argon_decrypt_cap_mib(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn decrypt_range_with_argon_cap<S: AsRef<str>>(
|
||||||
|
input_file: &str,
|
||||||
|
output_file: Option<S>,
|
||||||
|
raw_key: Option<&SecretBytes32>,
|
||||||
|
passphrase: Option<&SecretVec>,
|
||||||
|
offset: u64,
|
||||||
|
length: u64,
|
||||||
|
max_argon_memory_mib: u32,
|
||||||
|
) -> Result<(), FcryError> {
|
||||||
|
decrypt_range_with_output_options(
|
||||||
|
input_file,
|
||||||
|
output_file,
|
||||||
|
raw_key,
|
||||||
|
passphrase,
|
||||||
|
offset,
|
||||||
|
length,
|
||||||
|
max_argon_memory_mib,
|
||||||
|
&OutSinkOptions::default(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
pub fn decrypt_range_with_output_options<S: AsRef<str>>(
|
||||||
|
input_file: &str,
|
||||||
|
output_file: Option<S>,
|
||||||
|
raw_key: Option<&SecretBytes32>,
|
||||||
|
passphrase: Option<&SecretVec>,
|
||||||
|
offset: u64,
|
||||||
|
length: u64,
|
||||||
|
max_argon_memory_mib: u32,
|
||||||
|
output_options: &OutSinkOptions,
|
||||||
|
) -> Result<(), FcryError> {
|
||||||
|
if length == 0 {
|
||||||
|
return Err(FcryError::Format("--length 0 is not allowed".into()));
|
||||||
|
}
|
||||||
|
let file = File::open(input_file)?;
|
||||||
|
let mut reader = BufReader::new(file);
|
||||||
|
let header = Header::read_with_argon_cap(&mut reader, max_argon_memory_mib)?;
|
||||||
|
let aad = header.encode();
|
||||||
|
let header_len = aad.len() as u64;
|
||||||
|
|
||||||
|
let total = header.plaintext_length.ok_or_else(|| {
|
||||||
|
FcryError::Format(
|
||||||
|
"random-access decrypt requires a length-committed header (encrypt from a regular file)".into(),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let end = offset
|
||||||
|
.checked_add(length)
|
||||||
|
.ok_or_else(|| FcryError::Format("offset + length overflows u64".into()))?;
|
||||||
|
if end > total {
|
||||||
|
return Err(FcryError::Format(format!(
|
||||||
|
"range [{offset}, {end}) exceeds plaintext length {total}"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
let key = derive_key(&header.kdf, raw_key, passphrase)?;
|
||||||
|
verify_key_commitment(&header, &key)?;
|
||||||
|
let aead = build_aead(&key);
|
||||||
|
|
||||||
|
let chunk_sz_usize = policy::validate_chunk_size(header.chunk_size)?;
|
||||||
|
let cipher_chunk_usize = policy::cipher_chunk_len(chunk_sz_usize)?;
|
||||||
|
let chunk_sz = chunk_sz_usize as u64;
|
||||||
|
let cipher_chunk = cipher_chunk_usize as u64;
|
||||||
|
|
||||||
|
// Layout invariants:
|
||||||
|
// n_chunks = ceil(total / chunk_sz), but always ≥ 1 (the empty file
|
||||||
|
// still authenticates a single empty "last" chunk).
|
||||||
|
// last_idx = n_chunks - 1
|
||||||
|
// last_pt = total - last_idx * chunk_sz (in [0, chunk_sz])
|
||||||
|
let (n_chunks, last_pt) = if total == 0 {
|
||||||
|
(1u64, 0u64)
|
||||||
|
} else {
|
||||||
|
let n = total.div_ceil(chunk_sz);
|
||||||
|
let before_last = policy::checked_mul_u64(n - 1, chunk_sz, "last chunk offset")?;
|
||||||
|
let last = total
|
||||||
|
.checked_sub(before_last)
|
||||||
|
.ok_or_else(|| FcryError::Format("last chunk length underflow".into()))?;
|
||||||
|
(n, last)
|
||||||
|
};
|
||||||
|
let last_idx = n_chunks - 1;
|
||||||
|
|
||||||
|
let mut out = OutSink::open_with_options(output_file, output_options)?;
|
||||||
|
|
||||||
|
let start_chunk = offset / chunk_sz;
|
||||||
|
let end_chunk = (end - 1) / chunk_sz;
|
||||||
|
|
||||||
|
// Reusable buffer sized to a full chunk + tag.
|
||||||
|
let mut buf = Zeroizing::new(Vec::with_capacity(cipher_chunk_usize));
|
||||||
|
|
||||||
|
let mut file = reader.into_inner();
|
||||||
|
|
||||||
|
for i in start_chunk..=end_chunk {
|
||||||
|
let i_u32 =
|
||||||
|
u32::try_from(i).map_err(|_| FcryError::Format("chunk index exceeds u32".into()))?;
|
||||||
|
let is_last = i == last_idx;
|
||||||
|
let cipher_len = if is_last {
|
||||||
|
last_pt + TAG_LEN as u64
|
||||||
|
} else {
|
||||||
|
cipher_chunk
|
||||||
|
};
|
||||||
|
let cipher_len_usz =
|
||||||
|
usize::try_from(cipher_len).map_err(|_| FcryError::Format("chunk too big".into()))?;
|
||||||
|
|
||||||
|
let chunk_offset = policy::checked_add_u64(
|
||||||
|
header_len,
|
||||||
|
policy::checked_mul_u64(i, cipher_chunk, "ciphertext chunk offset")?,
|
||||||
|
"ciphertext chunk offset",
|
||||||
|
)?;
|
||||||
|
file.seek(SeekFrom::Start(chunk_offset))?;
|
||||||
|
buf.clear();
|
||||||
|
buf.resize(cipher_len_usz, 0);
|
||||||
|
file.read_exact(&mut buf)?;
|
||||||
|
|
||||||
|
let nonce = make_nonce(&header.nonce_prefix, i_u32, is_last);
|
||||||
|
aead.decrypt_in_place(&nonce, &aad, &mut *buf)?;
|
||||||
|
|
||||||
|
// `buf` is now plaintext for this chunk. Compute the chunk's plaintext
|
||||||
|
// window in absolute bytes and intersect with the requested range.
|
||||||
|
let chunk_start = policy::checked_mul_u64(i, chunk_sz, "plaintext chunk offset")?;
|
||||||
|
let chunk_end = policy::checked_count_add(chunk_start, buf.len(), "plaintext chunk end")?;
|
||||||
|
let lo = offset.max(chunk_start) - chunk_start;
|
||||||
|
let hi = end.min(chunk_end) - chunk_start;
|
||||||
|
out.write_all(&buf[lo as usize..hi as usize])?;
|
||||||
|
}
|
||||||
|
|
||||||
|
out.commit()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
//! Regression tests for cross-version compatibility. The on-disk header
|
||||||
|
//! is part of the AEAD AAD, so any byte that ends up in `Header::encode()`
|
||||||
|
//! must match the bytes that were authenticated when the file was
|
||||||
|
//! written. The v1 test below catches the regression where `encode()`
|
||||||
|
//! used to hard-code the current version on output.
|
||||||
|
use super::*;
|
||||||
|
use crate::header::{Header, KdfParams, NONCE_PREFIX_LEN};
|
||||||
|
use std::fs;
|
||||||
|
use tempfile::TempDir;
|
||||||
|
|
||||||
|
fn write_v1_ciphertext(path: &std::path::Path, key: &SecretBytes32, plaintext: &[u8]) {
|
||||||
|
// Build a v1 header by hand: same wire format as v2 with flags=0,
|
||||||
|
// but with version byte = 1.
|
||||||
|
let nonce_prefix = [0x42u8; NONCE_PREFIX_LEN];
|
||||||
|
let header = Header {
|
||||||
|
version: 1,
|
||||||
|
alg: AlgId::XChaCha20Poly1305,
|
||||||
|
flags: 0,
|
||||||
|
chunk_size: 64,
|
||||||
|
kdf: KdfParams::Raw,
|
||||||
|
nonce_prefix,
|
||||||
|
plaintext_length: None,
|
||||||
|
key_commitment: None,
|
||||||
|
};
|
||||||
|
let aad = header.encode();
|
||||||
|
// First byte after MAGIC is the version — verify our fixture really
|
||||||
|
// is v1 (so this test fails open if encode() ever reverts).
|
||||||
|
assert_eq!(aad[4], 1);
|
||||||
|
|
||||||
|
let chunk_sz = header.chunk_size as usize;
|
||||||
|
let aead = build_aead(key);
|
||||||
|
|
||||||
|
let mut out = Vec::new();
|
||||||
|
out.extend_from_slice(&aad);
|
||||||
|
|
||||||
|
let mut counter: u32 = 0;
|
||||||
|
let mut pos = 0;
|
||||||
|
while pos < plaintext.len() {
|
||||||
|
let end = (pos + chunk_sz).min(plaintext.len());
|
||||||
|
let last = end == plaintext.len() && (end - pos) < chunk_sz;
|
||||||
|
let mut buf = plaintext[pos..end].to_vec();
|
||||||
|
let nonce = make_nonce(&nonce_prefix, counter, last);
|
||||||
|
aead.encrypt_in_place(&nonce, &aad, &mut buf).unwrap();
|
||||||
|
out.extend_from_slice(&buf);
|
||||||
|
pos = end;
|
||||||
|
if last {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// If we hit a chunk-boundary EOF we still need a trailing "last"
|
||||||
|
// empty chunk to authenticate end-of-stream.
|
||||||
|
counter = bump_counter(counter).unwrap();
|
||||||
|
if pos == plaintext.len() {
|
||||||
|
let mut empty = Vec::new();
|
||||||
|
let nonce = make_nonce(&nonce_prefix, counter, true);
|
||||||
|
aead.encrypt_in_place(&nonce, &aad, &mut empty).unwrap();
|
||||||
|
out.extend_from_slice(&empty);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Empty plaintext: emit a single empty "last" chunk.
|
||||||
|
if plaintext.is_empty() {
|
||||||
|
let mut empty = Vec::new();
|
||||||
|
let nonce = make_nonce(&nonce_prefix, 0, true);
|
||||||
|
aead.encrypt_in_place(&nonce, &aad, &mut empty).unwrap();
|
||||||
|
out.extend_from_slice(&empty);
|
||||||
|
}
|
||||||
|
fs::write(path, &out).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn decrypts_v1_ciphertext() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let ct = dir.path().join("v1.bin");
|
||||||
|
let rt = dir.path().join("rt.bin");
|
||||||
|
|
||||||
|
let mut key = SecretBytes32::zeroed();
|
||||||
|
key.with_mut_array(|k| k.copy_from_slice(b"0123456789abcdef0123456789abcdef"));
|
||||||
|
|
||||||
|
// Multi-chunk plaintext (chunk_size = 64 in the fixture).
|
||||||
|
let plain: Vec<u8> = (0..200u8).collect();
|
||||||
|
write_v1_ciphertext(&ct, &key, &plain);
|
||||||
|
|
||||||
|
decrypt(
|
||||||
|
Some(ct.to_str().unwrap()),
|
||||||
|
Some(rt.to_str().unwrap()),
|
||||||
|
Some(&key),
|
||||||
|
None,
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
.expect("v1 decrypt should succeed");
|
||||||
|
let got = fs::read(&rt).unwrap();
|
||||||
|
assert_eq!(got, plain);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn decrypts_v1_ciphertext_parallel() {
|
||||||
|
// Same fixture, but exercising the multi-threaded pipeline.
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let ct = dir.path().join("v1.bin");
|
||||||
|
let rt = dir.path().join("rt.bin");
|
||||||
|
|
||||||
|
let mut key = SecretBytes32::zeroed();
|
||||||
|
key.with_mut_array(|k| k.copy_from_slice(b"0123456789abcdef0123456789abcdef"));
|
||||||
|
|
||||||
|
let plain: Vec<u8> = (0..200u8).collect();
|
||||||
|
write_v1_ciphertext(&ct, &key, &plain);
|
||||||
|
|
||||||
|
decrypt(
|
||||||
|
Some(ct.to_str().unwrap()),
|
||||||
|
Some(rt.to_str().unwrap()),
|
||||||
|
Some(&key),
|
||||||
|
None,
|
||||||
|
4,
|
||||||
|
)
|
||||||
|
.expect("v1 parallel decrypt should succeed");
|
||||||
|
assert_eq!(fs::read(&rt).unwrap(), plain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+15
-4
@@ -1,13 +1,18 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: MIT-0
|
||||||
|
|
||||||
use chacha20poly1305::aead;
|
use chacha20poly1305::aead;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum FcryError {
|
pub enum FcryError {
|
||||||
Io(io::Error),
|
Io(io::Error),
|
||||||
Crypto(aead::Error),
|
Crypto(aead::Error),
|
||||||
Rng(rand::Error),
|
Rng(getrandom::Error),
|
||||||
|
Format(String),
|
||||||
|
Kdf(String),
|
||||||
|
Passphrase(String),
|
||||||
|
WrongKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<io::Error> for FcryError {
|
impl From<io::Error> for FcryError {
|
||||||
@@ -22,8 +27,14 @@ impl From<aead::Error> for FcryError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<rand::Error> for FcryError {
|
impl From<getrandom::Error> for FcryError {
|
||||||
fn from(e: rand::Error) -> Self {
|
fn from(e: getrandom::Error) -> Self {
|
||||||
FcryError::Rng(e)
|
FcryError::Rng(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<argon2::Error> for FcryError {
|
||||||
|
fn from(e: argon2::Error) -> Self {
|
||||||
|
FcryError::Kdf(e.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+416
@@ -0,0 +1,416 @@
|
|||||||
|
// SPDX-License-Identifier: MIT-0
|
||||||
|
|
||||||
|
//! On-disk file format for fcry.
|
||||||
|
//!
|
||||||
|
//! Layout:
|
||||||
|
//! ```text
|
||||||
|
//! magic "fcry" 4 bytes
|
||||||
|
//! version u8 1
|
||||||
|
//! alg_id u8 1
|
||||||
|
//! flags u8 1
|
||||||
|
//! reserved u8 1 (must be 0)
|
||||||
|
//! chunk_size u32 LE 4 (plaintext bytes per chunk)
|
||||||
|
//! kdf_id u8 1
|
||||||
|
//! kdf_params variable (depends on kdf_id)
|
||||||
|
//! nonce_prefix [u8; 19] 19 (STREAM nonce prefix)
|
||||||
|
//! plaintext_length u64 LE 8 (only if version >= 2 and flags & 0x01)
|
||||||
|
//! key_commitment [u8; 32] 32 (only if version >= 3 and flags & 0x02)
|
||||||
|
//! --- end of header ---
|
||||||
|
//! chunk[0..N] each chunk_size + 16 bytes,
|
||||||
|
//! last may be shorter
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! The full encoded header is fed as AAD to every chunk, so any tampering
|
||||||
|
//! with chunk_size, nonce_prefix, kdf params, plaintext_length, etc. causes
|
||||||
|
//! authentication failure on every chunk.
|
||||||
|
//!
|
||||||
|
//! Versions:
|
||||||
|
//! * v1 — no length committed, no flag bits used.
|
||||||
|
//! * v2 — adds `FLAG_LENGTH_COMMITTED` (bit 0); when set, the total plaintext
|
||||||
|
//! length is appended after `nonce_prefix`. This enables random-access
|
||||||
|
//! decryption without scanning predecessors.
|
||||||
|
//! * v3 — adds `FLAG_KEY_COMMITTED` (bit 1) and an authenticated key
|
||||||
|
//! commitment for fast wrong-key detection before chunk processing.
|
||||||
|
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
|
use crate::error::FcryError;
|
||||||
|
use crate::policy;
|
||||||
|
|
||||||
|
const MAGIC: [u8; 4] = *b"fcry";
|
||||||
|
pub const VERSION_CURRENT: u8 = 3;
|
||||||
|
const VERSION_MIN: u8 = 1;
|
||||||
|
|
||||||
|
pub const NONCE_PREFIX_LEN: usize = 19;
|
||||||
|
pub const TAG_LEN: usize = 16;
|
||||||
|
|
||||||
|
/// Set in `flags` when the header carries an authenticated `plaintext_length`
|
||||||
|
/// field. Required for random-access decryption.
|
||||||
|
pub const FLAG_LENGTH_COMMITTED: u8 = 0x01;
|
||||||
|
pub const FLAG_KEY_COMMITTED: u8 = 0x02;
|
||||||
|
|
||||||
|
/// Mask of all flag bits this build understands. Unknown bits → reject.
|
||||||
|
const FLAG_KNOWN_MASK: u8 = FLAG_LENGTH_COMMITTED | FLAG_KEY_COMMITTED;
|
||||||
|
pub const KEY_COMMITMENT_LEN: usize = 32;
|
||||||
|
|
||||||
|
#[repr(u8)]
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
|
pub enum AlgId {
|
||||||
|
XChaCha20Poly1305 = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AlgId {
|
||||||
|
fn from_u8(v: u8) -> Result<Self, FcryError> {
|
||||||
|
match v {
|
||||||
|
1 => Ok(Self::XChaCha20Poly1305),
|
||||||
|
_ => Err(FcryError::Format(format!("unknown alg id: {v}"))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const ARGON2_SALT_LEN: usize = 16;
|
||||||
|
|
||||||
|
/// Key-derivation parameters stored in the header.
|
||||||
|
///
|
||||||
|
/// `Raw` means the key was supplied directly (no KDF). `Argon2id` carries
|
||||||
|
/// the salt and cost parameters needed to redo derivation on decrypt.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum KdfParams {
|
||||||
|
Raw,
|
||||||
|
Argon2id {
|
||||||
|
salt: [u8; ARGON2_SALT_LEN],
|
||||||
|
m_cost: u32,
|
||||||
|
t_cost: u32,
|
||||||
|
p_cost: u32,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl KdfParams {
|
||||||
|
fn id(&self) -> u8 {
|
||||||
|
match self {
|
||||||
|
Self::Raw => 0,
|
||||||
|
Self::Argon2id { .. } => 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_into(&self, out: &mut Vec<u8>) {
|
||||||
|
match self {
|
||||||
|
Self::Raw => {}
|
||||||
|
Self::Argon2id {
|
||||||
|
salt,
|
||||||
|
m_cost,
|
||||||
|
t_cost,
|
||||||
|
p_cost,
|
||||||
|
} => {
|
||||||
|
out.extend_from_slice(salt);
|
||||||
|
out.extend_from_slice(&m_cost.to_le_bytes());
|
||||||
|
out.extend_from_slice(&t_cost.to_le_bytes());
|
||||||
|
out.extend_from_slice(&p_cost.to_le_bytes());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_from(id: u8, r: &mut impl Read) -> Result<Self, FcryError> {
|
||||||
|
match id {
|
||||||
|
0 => Ok(Self::Raw),
|
||||||
|
1 => {
|
||||||
|
let mut salt = [0u8; ARGON2_SALT_LEN];
|
||||||
|
r.read_exact(&mut salt)?;
|
||||||
|
let mut buf = [0u8; 4];
|
||||||
|
r.read_exact(&mut buf)?;
|
||||||
|
let m_cost = u32::from_le_bytes(buf);
|
||||||
|
r.read_exact(&mut buf)?;
|
||||||
|
let t_cost = u32::from_le_bytes(buf);
|
||||||
|
r.read_exact(&mut buf)?;
|
||||||
|
let p_cost = u32::from_le_bytes(buf);
|
||||||
|
Ok(Self::Argon2id {
|
||||||
|
salt,
|
||||||
|
m_cost,
|
||||||
|
t_cost,
|
||||||
|
p_cost,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
_ => Err(FcryError::Format(format!("unknown kdf id: {id}"))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Header {
|
||||||
|
/// On-disk format version. Set to `VERSION_CURRENT` for new encrypts;
|
||||||
|
/// preserved as-read for decrypt so the AAD recomputed on decode matches
|
||||||
|
/// the bytes that were authenticated when the file was written.
|
||||||
|
pub version: u8,
|
||||||
|
pub alg: AlgId,
|
||||||
|
pub flags: u8,
|
||||||
|
pub chunk_size: u32,
|
||||||
|
pub kdf: KdfParams,
|
||||||
|
pub nonce_prefix: [u8; NONCE_PREFIX_LEN],
|
||||||
|
/// Total plaintext byte count. `Some` iff `flags & FLAG_LENGTH_COMMITTED`.
|
||||||
|
pub plaintext_length: Option<u64>,
|
||||||
|
/// v3 key commitment. `Some` iff `flags & FLAG_KEY_COMMITTED`.
|
||||||
|
pub key_commitment: Option<[u8; KEY_COMMITMENT_LEN]>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Header {
|
||||||
|
fn encode_without_commitment(&self) -> Vec<u8> {
|
||||||
|
let mut out = Vec::with_capacity(104);
|
||||||
|
out.extend_from_slice(&MAGIC);
|
||||||
|
out.push(self.version);
|
||||||
|
out.push(self.alg as u8);
|
||||||
|
out.push(self.flags);
|
||||||
|
out.push(0); // reserved
|
||||||
|
out.extend_from_slice(&self.chunk_size.to_le_bytes());
|
||||||
|
out.push(self.kdf.id());
|
||||||
|
self.kdf.write_into(&mut out);
|
||||||
|
out.extend_from_slice(&self.nonce_prefix);
|
||||||
|
if (self.flags & FLAG_LENGTH_COMMITTED) != 0 {
|
||||||
|
let len = self
|
||||||
|
.plaintext_length
|
||||||
|
.expect("FLAG_LENGTH_COMMITTED set but plaintext_length is None");
|
||||||
|
out.extend_from_slice(&len.to_le_bytes());
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn encode(&self) -> Vec<u8> {
|
||||||
|
let mut out = self.encode_without_commitment();
|
||||||
|
if (self.flags & FLAG_KEY_COMMITTED) != 0 {
|
||||||
|
let commitment = self
|
||||||
|
.key_commitment
|
||||||
|
.expect("FLAG_KEY_COMMITTED set but key_commitment is None");
|
||||||
|
out.extend_from_slice(&commitment);
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn commitment_input_encoding(&self) -> Vec<u8> {
|
||||||
|
self.encode_without_commitment()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn read(r: &mut impl Read) -> Result<Self, FcryError> {
|
||||||
|
Self::read_with_argon_cap(r, policy::default_argon_decrypt_cap_mib())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_with_argon_cap(
|
||||||
|
r: &mut impl Read,
|
||||||
|
max_argon_memory_mib: u32,
|
||||||
|
) -> Result<Self, FcryError> {
|
||||||
|
let mut magic = [0u8; 4];
|
||||||
|
r.read_exact(&mut magic)?;
|
||||||
|
if magic != MAGIC {
|
||||||
|
return Err(FcryError::Format("not an fcry file (bad magic)".into()));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut fixed = [0u8; 4];
|
||||||
|
r.read_exact(&mut fixed)?;
|
||||||
|
let [version, alg_id, flags, reserved] = fixed;
|
||||||
|
if !(VERSION_MIN..=VERSION_CURRENT).contains(&version) {
|
||||||
|
return Err(FcryError::Format(format!("unsupported version: {version}")));
|
||||||
|
}
|
||||||
|
if reserved != 0 {
|
||||||
|
return Err(FcryError::Format("reserved byte must be zero".into()));
|
||||||
|
}
|
||||||
|
if (flags & !FLAG_KNOWN_MASK) != 0 {
|
||||||
|
return Err(FcryError::Format(format!(
|
||||||
|
"unknown flag bits: 0x{flags:02x}"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
if version < 2 && flags != 0 {
|
||||||
|
return Err(FcryError::Format("v1 header must have flags == 0".into()));
|
||||||
|
}
|
||||||
|
if version < 3 && (flags & FLAG_KEY_COMMITTED) != 0 {
|
||||||
|
return Err(FcryError::Format(
|
||||||
|
"key commitment flag requires v3 header".into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if version >= 3 && (flags & FLAG_KEY_COMMITTED) == 0 {
|
||||||
|
return Err(FcryError::Format("v3 header must commit the key".into()));
|
||||||
|
}
|
||||||
|
let alg = AlgId::from_u8(alg_id)?;
|
||||||
|
|
||||||
|
let mut chunk_size_bytes = [0u8; 4];
|
||||||
|
r.read_exact(&mut chunk_size_bytes)?;
|
||||||
|
let chunk_size = u32::from_le_bytes(chunk_size_bytes);
|
||||||
|
policy::validate_chunk_size(chunk_size)?;
|
||||||
|
|
||||||
|
let mut kdf_id = [0u8; 1];
|
||||||
|
r.read_exact(&mut kdf_id)?;
|
||||||
|
let kdf = KdfParams::read_from(kdf_id[0], r)?;
|
||||||
|
policy::validate_header_kdf(&kdf, max_argon_memory_mib)?;
|
||||||
|
|
||||||
|
let mut nonce_prefix = [0u8; NONCE_PREFIX_LEN];
|
||||||
|
r.read_exact(&mut nonce_prefix)?;
|
||||||
|
|
||||||
|
let plaintext_length = if (flags & FLAG_LENGTH_COMMITTED) != 0 {
|
||||||
|
let mut b = [0u8; 8];
|
||||||
|
r.read_exact(&mut b)?;
|
||||||
|
Some(u64::from_le_bytes(b))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
let key_commitment = if (flags & FLAG_KEY_COMMITTED) != 0 {
|
||||||
|
let mut b = [0u8; KEY_COMMITMENT_LEN];
|
||||||
|
r.read_exact(&mut b)?;
|
||||||
|
Some(b)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
version,
|
||||||
|
alg,
|
||||||
|
flags,
|
||||||
|
chunk_size,
|
||||||
|
kdf,
|
||||||
|
nonce_prefix,
|
||||||
|
plaintext_length,
|
||||||
|
key_commitment,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use std::io::Cursor;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn roundtrip() {
|
||||||
|
let h = Header {
|
||||||
|
version: VERSION_CURRENT,
|
||||||
|
alg: AlgId::XChaCha20Poly1305,
|
||||||
|
flags: FLAG_KEY_COMMITTED,
|
||||||
|
chunk_size: 1024 * 1024,
|
||||||
|
kdf: KdfParams::Raw,
|
||||||
|
nonce_prefix: [7u8; NONCE_PREFIX_LEN],
|
||||||
|
plaintext_length: None,
|
||||||
|
key_commitment: Some([1u8; KEY_COMMITMENT_LEN]),
|
||||||
|
};
|
||||||
|
let bytes = h.encode();
|
||||||
|
let mut cur = Cursor::new(&bytes);
|
||||||
|
let parsed = Header::read(&mut cur).unwrap();
|
||||||
|
assert_eq!(parsed.version, h.version);
|
||||||
|
assert_eq!(parsed.alg, h.alg);
|
||||||
|
assert_eq!(parsed.flags, h.flags);
|
||||||
|
assert_eq!(parsed.chunk_size, h.chunk_size);
|
||||||
|
assert_eq!(parsed.nonce_prefix, h.nonce_prefix);
|
||||||
|
assert_eq!(parsed.plaintext_length, None);
|
||||||
|
assert_eq!(parsed.key_commitment, h.key_commitment);
|
||||||
|
assert_eq!(cur.position() as usize, bytes.len());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn roundtrip_length_committed() {
|
||||||
|
let h = Header {
|
||||||
|
version: VERSION_CURRENT,
|
||||||
|
alg: AlgId::XChaCha20Poly1305,
|
||||||
|
flags: FLAG_LENGTH_COMMITTED | FLAG_KEY_COMMITTED,
|
||||||
|
chunk_size: 65536,
|
||||||
|
kdf: KdfParams::Raw,
|
||||||
|
nonce_prefix: [9u8; NONCE_PREFIX_LEN],
|
||||||
|
plaintext_length: Some(123_456_789),
|
||||||
|
key_commitment: Some([2u8; KEY_COMMITMENT_LEN]),
|
||||||
|
};
|
||||||
|
let bytes = h.encode();
|
||||||
|
let mut cur = Cursor::new(&bytes);
|
||||||
|
let parsed = Header::read(&mut cur).unwrap();
|
||||||
|
assert_eq!(parsed.flags, FLAG_LENGTH_COMMITTED | FLAG_KEY_COMMITTED);
|
||||||
|
assert_eq!(parsed.plaintext_length, Some(123_456_789));
|
||||||
|
assert_eq!(parsed.key_commitment, h.key_commitment);
|
||||||
|
assert_eq!(cur.position() as usize, bytes.len());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn v3_encoding_layout_stable() {
|
||||||
|
let h = Header {
|
||||||
|
version: VERSION_CURRENT,
|
||||||
|
alg: AlgId::XChaCha20Poly1305,
|
||||||
|
flags: FLAG_LENGTH_COMMITTED | FLAG_KEY_COMMITTED,
|
||||||
|
chunk_size: 0x0102_0304,
|
||||||
|
kdf: KdfParams::Raw,
|
||||||
|
nonce_prefix: [0x55u8; NONCE_PREFIX_LEN],
|
||||||
|
plaintext_length: Some(0x0807_0605_0403_0201),
|
||||||
|
key_commitment: Some([0xaau8; KEY_COMMITMENT_LEN]),
|
||||||
|
};
|
||||||
|
let commitment_input = h.commitment_input_encoding();
|
||||||
|
assert_eq!(commitment_input.len(), 40);
|
||||||
|
assert_eq!(&commitment_input[..4], b"fcry");
|
||||||
|
assert_eq!(commitment_input[4], 3);
|
||||||
|
assert_eq!(
|
||||||
|
&commitment_input[32..40],
|
||||||
|
&0x0807_0605_0403_0201u64.to_le_bytes()
|
||||||
|
);
|
||||||
|
|
||||||
|
let aad = h.encode();
|
||||||
|
assert_eq!(aad.len(), 72);
|
||||||
|
assert_eq!(&aad[..40], &commitment_input);
|
||||||
|
assert_eq!(&aad[40..], &[0xaau8; KEY_COMMITMENT_LEN]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_bad_magic() {
|
||||||
|
let mut bytes = Header {
|
||||||
|
version: VERSION_CURRENT,
|
||||||
|
alg: AlgId::XChaCha20Poly1305,
|
||||||
|
flags: 0,
|
||||||
|
chunk_size: 4096,
|
||||||
|
kdf: KdfParams::Raw,
|
||||||
|
nonce_prefix: [0u8; NONCE_PREFIX_LEN],
|
||||||
|
plaintext_length: None,
|
||||||
|
key_commitment: Some([3u8; KEY_COMMITMENT_LEN]),
|
||||||
|
}
|
||||||
|
.encode();
|
||||||
|
bytes[0] ^= 1;
|
||||||
|
assert!(matches!(
|
||||||
|
Header::read(&mut Cursor::new(&bytes)),
|
||||||
|
Err(FcryError::Format(_))
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_unknown_flag_bits() {
|
||||||
|
let mut bytes = Header {
|
||||||
|
version: VERSION_CURRENT,
|
||||||
|
alg: AlgId::XChaCha20Poly1305,
|
||||||
|
flags: 0,
|
||||||
|
chunk_size: 4096,
|
||||||
|
kdf: KdfParams::Raw,
|
||||||
|
nonce_prefix: [0u8; NONCE_PREFIX_LEN],
|
||||||
|
plaintext_length: None,
|
||||||
|
key_commitment: Some([4u8; KEY_COMMITMENT_LEN]),
|
||||||
|
}
|
||||||
|
.encode();
|
||||||
|
// flags byte is at offset 6 (4 magic + version + alg)
|
||||||
|
bytes[6] = 0x80;
|
||||||
|
assert!(matches!(
|
||||||
|
Header::read(&mut Cursor::new(&bytes)),
|
||||||
|
Err(FcryError::Format(_))
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn reads_v1_header() {
|
||||||
|
// hand-crafted v1 header (raw kdf, no length field)
|
||||||
|
let mut bytes = Vec::new();
|
||||||
|
bytes.extend_from_slice(b"fcry");
|
||||||
|
bytes.push(1); // version
|
||||||
|
bytes.push(1); // alg
|
||||||
|
bytes.push(0); // flags
|
||||||
|
bytes.push(0); // reserved
|
||||||
|
bytes.extend_from_slice(&1024u32.to_le_bytes());
|
||||||
|
bytes.push(0); // kdf id raw
|
||||||
|
bytes.extend_from_slice(&[3u8; NONCE_PREFIX_LEN]);
|
||||||
|
let parsed = Header::read(&mut Cursor::new(&bytes)).unwrap();
|
||||||
|
assert_eq!(parsed.version, 1);
|
||||||
|
assert_eq!(parsed.flags, 0);
|
||||||
|
assert_eq!(parsed.chunk_size, 1024);
|
||||||
|
assert_eq!(parsed.plaintext_length, None);
|
||||||
|
assert_eq!(parsed.key_commitment, None);
|
||||||
|
// Re-encoding must reproduce the original v1 bytes exactly so the
|
||||||
|
// recomputed AAD matches what the file was authenticated with.
|
||||||
|
assert_eq!(parsed.encode(), bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
+344
-14
@@ -1,14 +1,26 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: MIT-0
|
||||||
|
|
||||||
mod crypto;
|
mod crypto;
|
||||||
mod error;
|
mod error;
|
||||||
|
mod header;
|
||||||
|
mod pipeline;
|
||||||
|
mod policy;
|
||||||
mod reader;
|
mod reader;
|
||||||
|
mod secrets;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
use crypto::*;
|
use crypto::*;
|
||||||
use error::FcryError;
|
use error::FcryError;
|
||||||
|
use header::{ARGON2_SALT_LEN, KdfParams};
|
||||||
|
use secrets::{SecretBytes32, SecretVec, read_passphrase_tty};
|
||||||
|
use utils::{DEFAULT_CHUNK_SIZE, OutSinkOptions};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Read;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use unicode_normalization::UnicodeNormalization;
|
||||||
|
use zeroize::Zeroizing;
|
||||||
|
|
||||||
/// fcry - [f]ile[cry]pt: A file en-/decryption tool for easy use
|
/// fcry - [f]ile[cry]pt: A file en-/decryption tool for easy use
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
@@ -27,33 +39,351 @@ struct Cli {
|
|||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
output_file: Option<String>,
|
output_file: Option<String>,
|
||||||
|
|
||||||
/// The raw bytes of the crypto key.
|
/// Read the raw 32-byte crypto key from a file.
|
||||||
/// Has to be exactly 32 bytes
|
#[clap(short = 'k', long, conflicts_with_all = ["passphrase", "passphrase_env"])]
|
||||||
/// *** DANGEROUS, use for testing purposes only! ***
|
key_file: Option<PathBuf>,
|
||||||
|
|
||||||
|
/// Read passphrase interactively (terminal). Implies argon2id KDF on encrypt.
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
raw_key: String,
|
passphrase: bool,
|
||||||
|
|
||||||
|
/// Read passphrase from the named environment variable (for non-interactive use).
|
||||||
|
/// Implies argon2id KDF on encrypt. Mutually exclusive with --passphrase.
|
||||||
|
#[clap(long, conflicts_with = "passphrase")]
|
||||||
|
passphrase_env: Option<String>,
|
||||||
|
|
||||||
|
/// Plaintext chunk size in bytes (encryption only; decryption reads it from the header).
|
||||||
|
#[clap(long, default_value_t = DEFAULT_CHUNK_SIZE)]
|
||||||
|
chunk_size: u32,
|
||||||
|
|
||||||
|
/// Argon2id memory in MiB (encryption only). Default: 1024 (= 1 GiB).
|
||||||
|
#[clap(long, default_value_t = policy::DEFAULT_ARGON_MEMORY_MIB)]
|
||||||
|
argon_memory: u32,
|
||||||
|
|
||||||
|
/// Argon2id passes / iterations (encryption only).
|
||||||
|
#[clap(long, default_value_t = policy::MIN_ARGON_PASSES)]
|
||||||
|
argon_passes: u32,
|
||||||
|
|
||||||
|
/// Argon2id parallelism / lanes (encryption only).
|
||||||
|
#[clap(long, default_value_t = policy::DEFAULT_ARGON_PARALLELISM)]
|
||||||
|
argon_parallelism: u32,
|
||||||
|
|
||||||
|
/// Permit intentionally weak passphrase/KDF parameters for tests or legacy interop.
|
||||||
|
#[clap(long)]
|
||||||
|
allow_weak_kdf: bool,
|
||||||
|
|
||||||
|
/// Maximum Argon2id memory accepted while decrypting, in MiB.
|
||||||
|
/// Overrides the dynamic default. Raising it can OOM constrained machines.
|
||||||
|
#[clap(long)]
|
||||||
|
max_argon_memory_mib: Option<u32>,
|
||||||
|
|
||||||
|
/// Number of worker threads for AEAD work. Defaults to the number of
|
||||||
|
/// available CPUs. Set to 1 for fully serial encrypt/decrypt.
|
||||||
|
#[clap(short = 'j', long, value_parser = clap::value_parser!(u32).range(1..))]
|
||||||
|
threads: Option<u32>,
|
||||||
|
|
||||||
|
/// Replace an existing different output file after encryption/decryption succeeds.
|
||||||
|
#[clap(long)]
|
||||||
|
force: bool,
|
||||||
|
|
||||||
|
/// Directory for private temporary files.
|
||||||
|
#[clap(long)]
|
||||||
|
temp_dir: Option<PathBuf>,
|
||||||
|
|
||||||
|
/// For decrypt-to-stdout, verify the whole plaintext in a private temp file before emitting it.
|
||||||
|
#[clap(long, requires = "decrypt")]
|
||||||
|
buffer_verify: bool,
|
||||||
|
|
||||||
|
/// Random-access decrypt: byte offset of the slice to read.
|
||||||
|
/// Requires `--decrypt`, an `--input-file` whose header has the
|
||||||
|
/// length-committed flag set, and `--length`.
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
requires = "length",
|
||||||
|
requires = "decrypt",
|
||||||
|
requires = "input_file"
|
||||||
|
)]
|
||||||
|
offset: Option<u64>,
|
||||||
|
|
||||||
|
/// Random-access decrypt: byte length of the slice to read.
|
||||||
|
/// Requires `--decrypt`, `--input-file`, and `--offset`.
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
requires = "offset",
|
||||||
|
requires = "decrypt",
|
||||||
|
requires = "input_file"
|
||||||
|
)]
|
||||||
|
length: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(cli: Cli) -> Result<(), FcryError> {
|
fn read_key_file(path: &Path) -> Result<SecretBytes32, FcryError> {
|
||||||
let input_file = cli.input_file;
|
warn_if_key_file_world_readable(path);
|
||||||
let output_file = cli.output_file;
|
let mut file = File::open(path)?;
|
||||||
|
let mut buf = Zeroizing::new([0u8; 33]);
|
||||||
|
let mut n = 0usize;
|
||||||
|
while n < buf.len() {
|
||||||
|
match file.read(&mut buf[n..]) {
|
||||||
|
Ok(0) => break,
|
||||||
|
Ok(read) => n += read,
|
||||||
|
Err(e) if e.kind() == std::io::ErrorKind::Interrupted => continue,
|
||||||
|
Err(e) => return Err(e.into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if n < 32 {
|
||||||
|
return Err(FcryError::Format(format!(
|
||||||
|
"key file {} is too short: expected exactly 32 bytes, got {n}",
|
||||||
|
path.display()
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
if n > 32 {
|
||||||
|
return Err(FcryError::Format(format!(
|
||||||
|
"key file {} is too long: expected exactly 32 bytes; possible trailing newline",
|
||||||
|
path.display()
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
let mut extra = Zeroizing::new([0u8; 1]);
|
||||||
|
if file.read(&mut *extra)? != 0 {
|
||||||
|
return Err(FcryError::Format(format!(
|
||||||
|
"key file {} is too long: expected exactly 32 bytes; possible trailing newline",
|
||||||
|
path.display()
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
let mut key = SecretBytes32::zeroed();
|
||||||
|
key.with_mut_array(|key| key.copy_from_slice(&buf[..32]));
|
||||||
|
Ok(key)
|
||||||
|
}
|
||||||
|
|
||||||
let mut key = [0u8; 32];
|
#[cfg(unix)]
|
||||||
dbg!(&cli.raw_key);
|
fn warn_if_key_file_world_readable(path: &Path) {
|
||||||
key.clone_from_slice(cli.raw_key.as_bytes());
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
if let Ok(meta) = std::fs::metadata(path) {
|
||||||
|
let mode = meta.permissions().mode();
|
||||||
|
if (mode & 0o077) != 0 {
|
||||||
|
eprintln!(
|
||||||
|
"Warning: key file {} is group/world accessible; consider chmod 600",
|
||||||
|
path.display()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if cli.decrypt {
|
#[cfg(not(unix))]
|
||||||
decrypt(input_file, output_file, key)?
|
fn warn_if_key_file_world_readable(_path: &Path) {}
|
||||||
|
|
||||||
|
/// Source of a passphrase: either the terminal or a named env var.
|
||||||
|
enum PassphraseSource {
|
||||||
|
Tty,
|
||||||
|
EnvVar(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn normalize_passphrase(pw: SecretVec) -> Result<SecretVec, FcryError> {
|
||||||
|
let normalized = pw.with_slice(|bytes| {
|
||||||
|
let s = std::str::from_utf8(bytes).map_err(|_| {
|
||||||
|
FcryError::Passphrase("passphrase must be valid UTF-8 after normalization".into())
|
||||||
|
})?;
|
||||||
|
Ok::<Zeroizing<String>, FcryError>(Zeroizing::new(s.nfc().collect::<String>()))
|
||||||
|
})?;
|
||||||
|
Ok(SecretVec::from_vec(normalized.as_bytes().to_vec()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_passphrase(src: &PassphraseSource, confirm: bool) -> Result<SecretVec, FcryError> {
|
||||||
|
match src {
|
||||||
|
PassphraseSource::EnvVar(var) => {
|
||||||
|
// Take the env value, then immediately copy it into upstream
|
||||||
|
// protected storage. The source Vec is zeroed after the copy.
|
||||||
|
// Note: a copy still exists in the process `environ` table; that is
|
||||||
|
// a known and accepted leak for the env-var path.
|
||||||
|
let v = Zeroizing::new(std::env::var(var).map_err(|_| {
|
||||||
|
FcryError::Passphrase(format!("environment variable {var} not set or not unicode"))
|
||||||
|
})?);
|
||||||
|
let normalized = Zeroizing::new(v.as_str().nfc().collect::<String>());
|
||||||
|
Ok(SecretVec::from_vec(normalized.as_bytes().to_vec()))
|
||||||
|
}
|
||||||
|
PassphraseSource::Tty => {
|
||||||
|
let pw = normalize_passphrase(
|
||||||
|
read_passphrase_tty("Passphrase: ")
|
||||||
|
.map_err(|e| FcryError::Passphrase(e.to_string()))?,
|
||||||
|
)?;
|
||||||
|
if confirm {
|
||||||
|
let pw2 = normalize_passphrase(
|
||||||
|
read_passphrase_tty("Confirm passphrase: ")
|
||||||
|
.map_err(|e| FcryError::Passphrase(e.to_string()))?,
|
||||||
|
)?;
|
||||||
|
if pw != pw2 {
|
||||||
|
return Err(FcryError::Passphrase("passphrases do not match".into()));
|
||||||
|
}
|
||||||
|
// pw2 dropped here -> zeroized + unlocked by the upstream crate.
|
||||||
|
}
|
||||||
|
Ok(pw)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Best-effort: prevent secrets from landing in a core dump.
|
||||||
|
#[cfg(unix)]
|
||||||
|
fn disable_core_dumps() {
|
||||||
|
use rlimit::Resource;
|
||||||
|
let _ = rlimit::setrlimit(Resource::CORE, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
fn disable_core_dumps() {
|
||||||
|
// Windows doesn't have rlimit-style core dumps. WER (Windows Error Reporting)
|
||||||
|
// and minidumps would be the analogue; disabling those requires per-machine
|
||||||
|
// policy and is intentionally not done here.
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(mut cli: Cli) -> Result<(), FcryError> {
|
||||||
|
// Move the secret-bearing fields out of `Cli` immediately so they don't
|
||||||
|
// sit in the parsed struct for the rest of the function.
|
||||||
|
let key_file: Option<PathBuf> = cli.key_file.take();
|
||||||
|
let pw_src: Option<PassphraseSource> = if cli.passphrase {
|
||||||
|
Some(PassphraseSource::Tty)
|
||||||
} else {
|
} else {
|
||||||
encrypt(input_file, output_file, key)?
|
cli.passphrase_env.take().map(PassphraseSource::EnvVar)
|
||||||
|
};
|
||||||
|
|
||||||
|
let decrypt_mode = cli.decrypt;
|
||||||
|
let input = cli.input_file.take();
|
||||||
|
let output = cli.output_file.take();
|
||||||
|
let chunk_size = cli.chunk_size;
|
||||||
|
let argon_memory = cli.argon_memory;
|
||||||
|
let argon_passes = cli.argon_passes;
|
||||||
|
let argon_parallelism = cli.argon_parallelism;
|
||||||
|
let allow_weak_kdf = cli.allow_weak_kdf;
|
||||||
|
let argon_cap = policy::resolve_argon_decrypt_cap(cli.max_argon_memory_mib)?;
|
||||||
|
if argon_cap.overridden && argon_cap.effective_mib > argon_cap.default_mib {
|
||||||
|
eprintln!(
|
||||||
|
"Warning: --max-argon-memory-mib raises the Argon2 decrypt trust ceiling from {} MiB to {} MiB; this can OOM constrained machines",
|
||||||
|
argon_cap.default_mib, argon_cap.effective_mib
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let (threads, thread_warning) = policy::normalize_worker_threads(cli.threads);
|
||||||
|
if let Some(requested) = thread_warning {
|
||||||
|
eprintln!(
|
||||||
|
"Warning: requested {requested} worker threads; capped at {}",
|
||||||
|
policy::MAX_WORKER_THREADS
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let force = cli.force;
|
||||||
|
let temp_dir = cli.temp_dir.take();
|
||||||
|
let buffer_verify = cli.buffer_verify;
|
||||||
|
let offset = cli.offset;
|
||||||
|
let length = cli.length;
|
||||||
|
drop(cli);
|
||||||
|
|
||||||
|
if pw_src.is_none() && key_file.is_none() {
|
||||||
|
return Err(FcryError::Format(
|
||||||
|
"must provide one of --key-file, --passphrase, --passphrase-env".into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if buffer_verify && !decrypt_mode {
|
||||||
|
return Err(FcryError::Format(
|
||||||
|
"--buffer-verify is only valid for decrypt".into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if buffer_verify && output.is_some() {
|
||||||
|
return Err(FcryError::Format(
|
||||||
|
"--buffer-verify is only meaningful when decrypting to stdout".into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let output_options = OutSinkOptions {
|
||||||
|
force,
|
||||||
|
input_file: input.as_ref().map(PathBuf::from),
|
||||||
|
temp_dir,
|
||||||
|
buffer_verify_stdout: buffer_verify,
|
||||||
|
};
|
||||||
|
|
||||||
|
if decrypt_mode {
|
||||||
|
let raw_key = match key_file.as_deref() {
|
||||||
|
Some(path) => Some(read_key_file(path)?),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
let pw = match &pw_src {
|
||||||
|
Some(src) => Some(read_passphrase(src, false)?),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
match (offset, length) {
|
||||||
|
(Some(o), Some(l)) => {
|
||||||
|
// clap's `requires` makes this unreachable, but keep the
|
||||||
|
// dynamic check so the failure mode is a clean error.
|
||||||
|
let path = input.as_deref().ok_or_else(|| {
|
||||||
|
FcryError::Format(
|
||||||
|
"--offset/--length require --input-file (random-access needs a seekable file)".into(),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
decrypt_range_with_output_options(
|
||||||
|
path,
|
||||||
|
output,
|
||||||
|
raw_key.as_ref(),
|
||||||
|
pw.as_ref(),
|
||||||
|
o,
|
||||||
|
l,
|
||||||
|
argon_cap.effective_mib,
|
||||||
|
&output_options,
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
(None, None) => {
|
||||||
|
decrypt_with_output_options(
|
||||||
|
input,
|
||||||
|
output,
|
||||||
|
raw_key.as_ref(),
|
||||||
|
pw.as_ref(),
|
||||||
|
threads,
|
||||||
|
argon_cap.effective_mib,
|
||||||
|
&output_options,
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
return Err(FcryError::Format(
|
||||||
|
"--offset and --length must be supplied together".into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let (key, kdf) = if let Some(src) = &pw_src {
|
||||||
|
let mut salt = [0u8; ARGON2_SALT_LEN];
|
||||||
|
getrandom::fill(&mut salt)?;
|
||||||
|
let m_cost_kib = policy::validate_new_argon_params(
|
||||||
|
argon_memory,
|
||||||
|
argon_passes,
|
||||||
|
argon_parallelism,
|
||||||
|
allow_weak_kdf,
|
||||||
|
)?;
|
||||||
|
let kdf = KdfParams::Argon2id {
|
||||||
|
salt,
|
||||||
|
m_cost: m_cost_kib,
|
||||||
|
t_cost: argon_passes,
|
||||||
|
p_cost: argon_parallelism,
|
||||||
|
};
|
||||||
|
let pw = read_passphrase(src, true)?;
|
||||||
|
policy::validate_new_passphrase(&pw, allow_weak_kdf)?;
|
||||||
|
let key = derive_key(&kdf, None, Some(&pw))?;
|
||||||
|
(key, kdf)
|
||||||
|
} else {
|
||||||
|
let key = read_key_file(key_file.as_deref().unwrap())?;
|
||||||
|
(key, KdfParams::Raw)
|
||||||
|
};
|
||||||
|
encrypt_with_output_options(
|
||||||
|
input,
|
||||||
|
output,
|
||||||
|
&key,
|
||||||
|
chunk_size,
|
||||||
|
kdf,
|
||||||
|
threads,
|
||||||
|
&output_options,
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
disable_core_dumps();
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
if let Err(e) = run(cli) {
|
if let Err(e) = run(cli) {
|
||||||
eprintln!("Error: {:?}", e);
|
eprintln!("Error: {:?}", e);
|
||||||
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+375
@@ -0,0 +1,375 @@
|
|||||||
|
// SPDX-License-Identifier: MIT-0
|
||||||
|
|
||||||
|
//! Multi-threaded encrypt/decrypt pipeline.
|
||||||
|
//!
|
||||||
|
//! Topology:
|
||||||
|
//!
|
||||||
|
//! ```text
|
||||||
|
//! reader thread → jobs (bounded MPMC) → N AEAD workers →
|
||||||
|
//! → results (bounded MPMC) → writer thread
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! The reader is sequential (one input handle, lookahead detects last chunk),
|
||||||
|
//! workers parallelize the AEAD step (independent per chunk), and the writer
|
||||||
|
//! reorders results by counter before writing them to `OutSink`.
|
||||||
|
//!
|
||||||
|
//! Bounded memory: a permit channel caps the total number of in-flight chunks
|
||||||
|
//! (queued jobs + in-progress at workers + pending in the writer's reorder
|
||||||
|
//! buffer). The reader acquires a permit before sending each job; the writer
|
||||||
|
//! releases a permit after flushing the chunk in order. A slow or stuck worker
|
||||||
|
//! therefore stalls the reader rather than letting the writer's reorder buffer
|
||||||
|
//! grow without bound.
|
||||||
|
//!
|
||||||
|
//! Fail-fast: a shared `cancel` flag lets workers signal an authentication or
|
||||||
|
//! AEAD error to the reader. The reader checks it each iteration and exits
|
||||||
|
//! early, so a tampered chunk doesn't waste full-file I/O on top of the
|
||||||
|
//! detection.
|
||||||
|
//!
|
||||||
|
//! Peak memory ≈ chunk_size × (in_flight_cap + 2). For 1 MiB chunks and 8
|
||||||
|
//! cores (cap = 32) that's ~34 MiB. Adjust `in_flight_capacity` if you need
|
||||||
|
//! a different memory/throughput tradeoff.
|
||||||
|
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
use std::thread::{self, JoinHandle};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use chacha20poly1305::{XChaCha20Poly1305, aead::AeadInPlace};
|
||||||
|
use crossbeam_channel::{Receiver, RecvTimeoutError, Sender, bounded};
|
||||||
|
|
||||||
|
use crate::crypto::{bump_counter, make_nonce};
|
||||||
|
use crate::error::FcryError;
|
||||||
|
use crate::header::NONCE_PREFIX_LEN;
|
||||||
|
use crate::policy;
|
||||||
|
use crate::reader::{AheadReader, ReadInfoChunk};
|
||||||
|
use crate::utils::OutSink;
|
||||||
|
use zeroize::Zeroizing;
|
||||||
|
|
||||||
|
struct Job {
|
||||||
|
counter: u32,
|
||||||
|
last: bool,
|
||||||
|
buf: Zeroizing<Vec<u8>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Done {
|
||||||
|
counter: u32,
|
||||||
|
buf: Zeroizing<Vec<u8>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Job-channel capacity: small multiples of worker count, enough to keep
|
||||||
|
/// workers fed without unbounded memory.
|
||||||
|
fn channel_capacity(threads: usize, in_flight: usize) -> usize {
|
||||||
|
policy::pipeline_channel_capacity(threads, in_flight)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Total in-flight chunk cap (jobs queued + at workers + in writer's reorder
|
||||||
|
/// buffer). Permit count; bounded above the job-channel capacity to absorb
|
||||||
|
/// reordering without blocking workers unnecessarily.
|
||||||
|
fn in_flight_capacity(threads: usize, chunk_len: usize) -> usize {
|
||||||
|
policy::pipeline_in_flight_capacity(threads, chunk_len)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
pub(crate) fn encrypt_parallel(
|
||||||
|
input: AheadReader,
|
||||||
|
output: OutSink,
|
||||||
|
aead: Arc<XChaCha20Poly1305>,
|
||||||
|
aad: Arc<Vec<u8>>,
|
||||||
|
nonce_prefix: [u8; NONCE_PREFIX_LEN],
|
||||||
|
chunk_sz: usize,
|
||||||
|
threads: usize,
|
||||||
|
expected_length: Option<u64>,
|
||||||
|
) -> Result<(), FcryError> {
|
||||||
|
let (sink, bytes_seen) = run_pipeline(
|
||||||
|
input,
|
||||||
|
output,
|
||||||
|
aead,
|
||||||
|
aad,
|
||||||
|
nonce_prefix,
|
||||||
|
chunk_sz,
|
||||||
|
threads,
|
||||||
|
true,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
if let Some(committed) = expected_length
|
||||||
|
&& committed != bytes_seen
|
||||||
|
{
|
||||||
|
return Err(FcryError::Format(format!(
|
||||||
|
"input length changed during encryption: committed {committed}, read {bytes_seen}"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
sink.commit()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
pub(crate) fn decrypt_parallel(
|
||||||
|
input: AheadReader,
|
||||||
|
output: OutSink,
|
||||||
|
aead: Arc<XChaCha20Poly1305>,
|
||||||
|
aad: Arc<Vec<u8>>,
|
||||||
|
nonce_prefix: [u8; NONCE_PREFIX_LEN],
|
||||||
|
cipher_chunk: usize,
|
||||||
|
threads: usize,
|
||||||
|
expected_length: Option<u64>,
|
||||||
|
) -> Result<(), FcryError> {
|
||||||
|
let (sink, written) = run_pipeline(
|
||||||
|
input,
|
||||||
|
output,
|
||||||
|
aead,
|
||||||
|
aad,
|
||||||
|
nonce_prefix,
|
||||||
|
cipher_chunk,
|
||||||
|
threads,
|
||||||
|
false,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
if let Some(committed) = expected_length
|
||||||
|
&& committed != written
|
||||||
|
{
|
||||||
|
return Err(FcryError::Format(format!(
|
||||||
|
"decrypted length {written} disagrees with committed {committed}"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
sink.commit()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Drives the reader/worker/writer pipeline. `is_encrypt = true` performs
|
||||||
|
/// `encrypt_in_place` and tracks bytes-read; `false` performs
|
||||||
|
/// `decrypt_in_place` and tracks bytes-written. The single shared topology
|
||||||
|
/// keeps backpressure, reorder, and fail-fast logic in one place.
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
fn run_pipeline(
|
||||||
|
mut input: AheadReader,
|
||||||
|
output: OutSink,
|
||||||
|
aead: Arc<XChaCha20Poly1305>,
|
||||||
|
aad: Arc<Vec<u8>>,
|
||||||
|
nonce_prefix: [u8; NONCE_PREFIX_LEN],
|
||||||
|
chunk_sz: usize,
|
||||||
|
threads: usize,
|
||||||
|
is_encrypt: bool,
|
||||||
|
) -> Result<(OutSink, u64), FcryError> {
|
||||||
|
let in_flight = in_flight_capacity(threads, chunk_sz);
|
||||||
|
let cap = channel_capacity(threads, in_flight);
|
||||||
|
let (jobs_tx, jobs_rx) = bounded::<Job>(cap);
|
||||||
|
let (done_tx, done_rx) = bounded::<Done>(cap);
|
||||||
|
|
||||||
|
// Pre-fill the permit channel. Each permit represents one in-flight chunk
|
||||||
|
// slot. The reader consumes a permit before sending a job; the writer
|
||||||
|
// returns a permit after flushing in order.
|
||||||
|
let (permit_tx, permit_rx) = bounded::<()>(in_flight);
|
||||||
|
for _ in 0..in_flight {
|
||||||
|
permit_tx
|
||||||
|
.send(())
|
||||||
|
.expect("pre-fill of permit channel cannot fail");
|
||||||
|
}
|
||||||
|
|
||||||
|
let cancel = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
|
// Reader thread: dispatches jobs in counter order and tracks bytes read
|
||||||
|
// (used for the encrypt-side length cross-check). On decrypt the count is
|
||||||
|
// ignored — the writer's count is authoritative there.
|
||||||
|
let reader_handle: JoinHandle<Result<u64, FcryError>> = {
|
||||||
|
let cancel = cancel.clone();
|
||||||
|
thread::spawn(move || {
|
||||||
|
let mut counter: u32 = 0;
|
||||||
|
let mut bytes_seen: u64 = 0;
|
||||||
|
loop {
|
||||||
|
// Acquire an in-flight slot. We recv with a short timeout so
|
||||||
|
// a worker error (which sets `cancel`) is observed even if
|
||||||
|
// the rest of the pipeline has quiesced and is no longer
|
||||||
|
// releasing permits — this avoids a 3-way deadlock between
|
||||||
|
// reader, idle workers, and a stalled writer.
|
||||||
|
loop {
|
||||||
|
if cancel.load(Ordering::Acquire) {
|
||||||
|
return Ok(bytes_seen);
|
||||||
|
}
|
||||||
|
match permit_rx.recv_timeout(Duration::from_millis(50)) {
|
||||||
|
Ok(()) => break,
|
||||||
|
Err(RecvTimeoutError::Timeout) => continue,
|
||||||
|
Err(RecvTimeoutError::Disconnected) => return Ok(bytes_seen),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut buf = Zeroizing::new(vec![0u8; chunk_sz]);
|
||||||
|
match input.read_ahead(&mut buf)? {
|
||||||
|
ReadInfoChunk::Normal(_) => {
|
||||||
|
if jobs_tx
|
||||||
|
.send(Job {
|
||||||
|
counter,
|
||||||
|
last: false,
|
||||||
|
buf,
|
||||||
|
})
|
||||||
|
.is_err()
|
||||||
|
{
|
||||||
|
return Ok(bytes_seen);
|
||||||
|
}
|
||||||
|
bytes_seen = policy::checked_count_add(bytes_seen, chunk_sz, "bytes read")?;
|
||||||
|
counter = bump_counter(counter)?;
|
||||||
|
}
|
||||||
|
ReadInfoChunk::Last(n) => {
|
||||||
|
buf.truncate(n);
|
||||||
|
let _ = jobs_tx.send(Job {
|
||||||
|
counter,
|
||||||
|
last: true,
|
||||||
|
buf,
|
||||||
|
});
|
||||||
|
bytes_seen = policy::checked_count_add(bytes_seen, n, "bytes read")?;
|
||||||
|
return Ok(bytes_seen);
|
||||||
|
}
|
||||||
|
ReadInfoChunk::Empty => {
|
||||||
|
if is_encrypt {
|
||||||
|
buf.clear();
|
||||||
|
let _ = jobs_tx.send(Job {
|
||||||
|
counter,
|
||||||
|
last: true,
|
||||||
|
buf,
|
||||||
|
});
|
||||||
|
return Ok(bytes_seen);
|
||||||
|
}
|
||||||
|
// On decrypt an unexpected EOF means the ciphertext is
|
||||||
|
// truncated. Surface it as an error so the writer
|
||||||
|
// doesn't commit a partial output.
|
||||||
|
return Err(FcryError::Format(
|
||||||
|
"truncated ciphertext: missing final chunk".into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
// Worker threads: AEAD encrypt/decrypt in place, ship to writer. On error
|
||||||
|
// we set the cancel flag so the reader exits early, and drop the senders
|
||||||
|
// so the writer drains and exits.
|
||||||
|
let mut worker_handles: Vec<JoinHandle<Result<(), FcryError>>> = Vec::with_capacity(threads);
|
||||||
|
for _ in 0..threads {
|
||||||
|
let jobs_rx = jobs_rx.clone();
|
||||||
|
let done_tx = done_tx.clone();
|
||||||
|
let aead = aead.clone();
|
||||||
|
let aad = aad.clone();
|
||||||
|
let cancel = cancel.clone();
|
||||||
|
worker_handles.push(thread::spawn(move || {
|
||||||
|
for mut job in jobs_rx.iter() {
|
||||||
|
if cancel.load(Ordering::Acquire) {
|
||||||
|
// Drain remaining queued jobs without doing AEAD work.
|
||||||
|
// Returning Ok here keeps the previously-set error from
|
||||||
|
// being clobbered by a fresh "ok" status.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let nonce = make_nonce(&nonce_prefix, job.counter, job.last);
|
||||||
|
let res = if is_encrypt {
|
||||||
|
aead.encrypt_in_place(&nonce, aad.as_slice(), &mut *job.buf)
|
||||||
|
} else {
|
||||||
|
aead.decrypt_in_place(&nonce, aad.as_slice(), &mut *job.buf)
|
||||||
|
};
|
||||||
|
if let Err(e) = res {
|
||||||
|
cancel.store(true, Ordering::Release);
|
||||||
|
return Err(e.into());
|
||||||
|
}
|
||||||
|
if done_tx
|
||||||
|
.send(Done {
|
||||||
|
counter: job.counter,
|
||||||
|
buf: job.buf,
|
||||||
|
})
|
||||||
|
.is_err()
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
drop(jobs_rx);
|
||||||
|
drop(done_tx);
|
||||||
|
|
||||||
|
// Writer thread: ordered writeback. Returns the `OutSink` ownership back
|
||||||
|
// without committing; the caller commits only after every other thread
|
||||||
|
// has joined cleanly so a failure anywhere drops the sink and unlinks the
|
||||||
|
// temp file. Releases one permit per chunk flushed so the reader can make
|
||||||
|
// forward progress in lockstep with the actual disk write.
|
||||||
|
let writer_handle: JoinHandle<Result<(OutSink, u64), FcryError>> =
|
||||||
|
thread::spawn(move || ordered_writer(done_rx, output, permit_tx));
|
||||||
|
|
||||||
|
let reader_res = reader_handle.join().expect("reader thread panicked");
|
||||||
|
let mut first_err: Option<FcryError> = None;
|
||||||
|
let bytes_seen = match reader_res {
|
||||||
|
Ok(n) => Some(n),
|
||||||
|
Err(e) => {
|
||||||
|
cancel.store(true, Ordering::Release);
|
||||||
|
first_err.get_or_insert(e);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
for h in worker_handles {
|
||||||
|
if let Err(e) = h.join().expect("worker thread panicked")
|
||||||
|
&& first_err.is_none()
|
||||||
|
{
|
||||||
|
first_err = Some(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let writer_res = writer_handle.join().expect("writer thread panicked");
|
||||||
|
let written = match writer_res {
|
||||||
|
Ok((sink, n)) => Some((sink, n)),
|
||||||
|
Err(e) => {
|
||||||
|
if first_err.is_none() {
|
||||||
|
first_err = Some(e);
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(e) = first_err {
|
||||||
|
return Err(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
let (sink, n) = written.expect("no error but no sink");
|
||||||
|
let count = if is_encrypt {
|
||||||
|
bytes_seen.expect("no error but no reader count")
|
||||||
|
} else {
|
||||||
|
n
|
||||||
|
};
|
||||||
|
Ok((sink, count))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Drain `done_rx` in counter order, writing each chunk to `output` and
|
||||||
|
/// returning a permit to `permit_tx` after every flush so the reader is held
|
||||||
|
/// in lockstep with disk writes (bounded reorder buffer).
|
||||||
|
fn ordered_writer(
|
||||||
|
done_rx: Receiver<Done>,
|
||||||
|
mut output: OutSink,
|
||||||
|
permit_tx: Sender<()>,
|
||||||
|
) -> Result<(OutSink, u64), FcryError> {
|
||||||
|
let mut next: u32 = 0;
|
||||||
|
let mut pending: BTreeMap<u32, Zeroizing<Vec<u8>>> = BTreeMap::new();
|
||||||
|
let mut total: u64 = 0;
|
||||||
|
for done in done_rx.iter() {
|
||||||
|
pending.insert(done.counter, done.buf);
|
||||||
|
while let Some(buf) = pending.remove(&next) {
|
||||||
|
output.write_all(&buf)?;
|
||||||
|
total = policy::checked_count_add(total, buf.len(), "bytes written")?;
|
||||||
|
// `bump_counter` rejects overflow upstream; a wrap here would be
|
||||||
|
// a real bug, so use plain addition and let it panic in debug.
|
||||||
|
next += 1;
|
||||||
|
// Release one in-flight slot. If the reader is gone the channel
|
||||||
|
// is closed; we don't care about the send result.
|
||||||
|
let _ = permit_tx.send(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !pending.is_empty() {
|
||||||
|
return Err(FcryError::Format(
|
||||||
|
"internal: ordered writer left chunks unflushed".into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok((output, total))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compile-time check that the job type is Send+Sync (channel sends across
|
||||||
|
// threads). Kept as a footgun for future struct edits.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn _assert_send_sync<T: Send + Sync>() {}
|
||||||
|
const _: fn() = || _assert_send_sync::<Sender<Job>>();
|
||||||
+299
@@ -0,0 +1,299 @@
|
|||||||
|
// SPDX-License-Identifier: MIT-0
|
||||||
|
|
||||||
|
//! Central resource and format policy.
|
||||||
|
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
use crate::error::FcryError;
|
||||||
|
use crate::header::{KdfParams, TAG_LEN};
|
||||||
|
use crate::secrets::SecretVec;
|
||||||
|
|
||||||
|
pub const MAX_CHUNK_SIZE: u32 = 64 * 1024 * 1024;
|
||||||
|
pub const DEFAULT_CHUNK_SIZE: u32 = 1024 * 1024;
|
||||||
|
|
||||||
|
pub const DEFAULT_ARGON_MEMORY_MIB: u32 = 1024;
|
||||||
|
pub const MIN_ARGON_MEMORY_MIB: u32 = 64;
|
||||||
|
pub const DEFAULT_ARGON_DECRYPT_CAP_MIB: u32 = 4096;
|
||||||
|
pub const MIN_ARGON_PASSES: u32 = 2;
|
||||||
|
pub const MAX_ARGON_PASSES: u32 = 64;
|
||||||
|
pub const DEFAULT_ARGON_PARALLELISM: u32 = 4;
|
||||||
|
pub const MAX_ARGON_PARALLELISM: u32 = 64;
|
||||||
|
pub const MIN_PASSPHRASE_BYTES: usize = 12;
|
||||||
|
|
||||||
|
pub const MAX_WORKER_THREADS: usize = 256;
|
||||||
|
pub const PIPELINE_IN_FLIGHT_BYTES: usize = 128 * 1024 * 1024;
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
|
pub struct ArgonDecryptCap {
|
||||||
|
pub default_mib: u32,
|
||||||
|
pub effective_mib: u32,
|
||||||
|
pub overridden: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn architecture_argon_cap_mib() -> u32 {
|
||||||
|
let usize_cap_mib = usize::MAX / 1024 / 1024;
|
||||||
|
let argon_m_cost_cap_mib = (u32::MAX / 1024) as usize;
|
||||||
|
usize_cap_mib
|
||||||
|
.min(argon_m_cost_cap_mib)
|
||||||
|
.min(u32::MAX as usize) as u32
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn available_memory_mib() -> Option<u32> {
|
||||||
|
let meminfo = fs::read_to_string("/proc/meminfo").ok()?;
|
||||||
|
for line in meminfo.lines() {
|
||||||
|
let Some(rest) = line.strip_prefix("MemAvailable:") else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let kib = rest.split_whitespace().next()?.parse::<u64>().ok()?;
|
||||||
|
return u32::try_from(kib / 1024).ok();
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "linux"))]
|
||||||
|
fn available_memory_mib() -> Option<u32> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn default_argon_decrypt_cap_mib() -> u32 {
|
||||||
|
let mut cap = DEFAULT_ARGON_DECRYPT_CAP_MIB.min(architecture_argon_cap_mib());
|
||||||
|
if let Some(available) = available_memory_mib() {
|
||||||
|
cap = cap.min(available);
|
||||||
|
}
|
||||||
|
cap.max(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn resolve_argon_decrypt_cap(override_mib: Option<u32>) -> Result<ArgonDecryptCap, FcryError> {
|
||||||
|
let default_mib = default_argon_decrypt_cap_mib();
|
||||||
|
let Some(effective_mib) = override_mib else {
|
||||||
|
return Ok(ArgonDecryptCap {
|
||||||
|
default_mib,
|
||||||
|
effective_mib: default_mib,
|
||||||
|
overridden: false,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
if effective_mib == 0 {
|
||||||
|
return Err(FcryError::Format(
|
||||||
|
"--max-argon-memory-mib must be at least 1".into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let arch = architecture_argon_cap_mib();
|
||||||
|
if effective_mib > arch {
|
||||||
|
return Err(FcryError::Format(format!(
|
||||||
|
"--max-argon-memory-mib {effective_mib} exceeds this build's supported cap {arch}"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
Ok(ArgonDecryptCap {
|
||||||
|
default_mib,
|
||||||
|
effective_mib,
|
||||||
|
overridden: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn mib_to_kib(mib: u32, name: &str) -> Result<u32, FcryError> {
|
||||||
|
mib.checked_mul(1024).ok_or_else(|| {
|
||||||
|
FcryError::Format(format!("{name} too large (overflow converting MiB to KiB)"))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn validate_chunk_size(chunk_size: u32) -> Result<usize, FcryError> {
|
||||||
|
if chunk_size == 0 {
|
||||||
|
return Err(FcryError::Format("chunk_size must be > 0".into()));
|
||||||
|
}
|
||||||
|
if chunk_size > MAX_CHUNK_SIZE {
|
||||||
|
return Err(FcryError::Format(format!(
|
||||||
|
"chunk_size {chunk_size} exceeds maximum {MAX_CHUNK_SIZE}"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
usize::try_from(chunk_size)
|
||||||
|
.map_err(|_| FcryError::Format("chunk_size does not fit in usize".into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cipher_chunk_len(plain_chunk_len: usize) -> Result<usize, FcryError> {
|
||||||
|
plain_chunk_len
|
||||||
|
.checked_add(TAG_LEN)
|
||||||
|
.ok_or_else(|| FcryError::Format("cipher chunk length overflow".into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn validate_new_argon_params(
|
||||||
|
memory_mib: u32,
|
||||||
|
passes: u32,
|
||||||
|
parallelism: u32,
|
||||||
|
allow_weak_kdf: bool,
|
||||||
|
) -> Result<u32, FcryError> {
|
||||||
|
if !allow_weak_kdf && memory_mib < MIN_ARGON_MEMORY_MIB {
|
||||||
|
return Err(FcryError::Kdf(format!(
|
||||||
|
"argon-memory must be at least {MIN_ARGON_MEMORY_MIB} MiB for new encryption (use --allow-weak-kdf only for tests/legacy interop)"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
if !allow_weak_kdf && passes < MIN_ARGON_PASSES {
|
||||||
|
return Err(FcryError::Kdf(format!(
|
||||||
|
"argon-passes must be at least {MIN_ARGON_PASSES} for new encryption (use --allow-weak-kdf only for tests/legacy interop)"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
validate_argon_common(memory_mib, passes, parallelism, "new encryption")?;
|
||||||
|
mib_to_kib(memory_mib, "argon-memory")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn validate_new_passphrase(pw: &SecretVec, allow_weak_kdf: bool) -> Result<(), FcryError> {
|
||||||
|
let len = pw.len();
|
||||||
|
if len == 0 {
|
||||||
|
return Err(FcryError::Passphrase("passphrase must not be empty".into()));
|
||||||
|
}
|
||||||
|
if !allow_weak_kdf && len < MIN_PASSPHRASE_BYTES {
|
||||||
|
return Err(FcryError::Passphrase(format!(
|
||||||
|
"passphrase must be at least {MIN_PASSPHRASE_BYTES} UTF-8 bytes for new encryption (use --allow-weak-kdf only for tests/legacy interop)"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn validate_header_kdf(kdf: &KdfParams, max_argon_memory_mib: u32) -> Result<(), FcryError> {
|
||||||
|
match kdf {
|
||||||
|
KdfParams::Raw => Ok(()),
|
||||||
|
KdfParams::Argon2id {
|
||||||
|
m_cost,
|
||||||
|
t_cost,
|
||||||
|
p_cost,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
let cap_kib = mib_to_kib(max_argon_memory_mib, "max argon memory")?;
|
||||||
|
if *m_cost == 0 {
|
||||||
|
return Err(FcryError::Format("argon2id memory cost must be > 0".into()));
|
||||||
|
}
|
||||||
|
if *t_cost == 0 {
|
||||||
|
return Err(FcryError::Format("argon2id passes must be > 0".into()));
|
||||||
|
}
|
||||||
|
if *p_cost == 0 {
|
||||||
|
return Err(FcryError::Format("argon2id parallelism must be > 0".into()));
|
||||||
|
}
|
||||||
|
if *m_cost > cap_kib {
|
||||||
|
return Err(FcryError::Kdf(format!(
|
||||||
|
"argon2id memory cost {} KiB exceeds configured decrypt cap {} MiB",
|
||||||
|
*m_cost, max_argon_memory_mib
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
if *t_cost > MAX_ARGON_PASSES {
|
||||||
|
return Err(FcryError::Kdf(format!(
|
||||||
|
"argon2id passes {} exceeds maximum {}",
|
||||||
|
*t_cost, MAX_ARGON_PASSES
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
if *p_cost > MAX_ARGON_PARALLELISM {
|
||||||
|
return Err(FcryError::Kdf(format!(
|
||||||
|
"argon2id parallelism {} exceeds maximum {}",
|
||||||
|
*p_cost, MAX_ARGON_PARALLELISM
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn validate_argon_common(
|
||||||
|
memory_mib: u32,
|
||||||
|
passes: u32,
|
||||||
|
parallelism: u32,
|
||||||
|
context: &str,
|
||||||
|
) -> Result<(), FcryError> {
|
||||||
|
if memory_mib == 0 {
|
||||||
|
return Err(FcryError::Kdf(format!(
|
||||||
|
"argon-memory must be > 0 for {context}"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
if passes == 0 {
|
||||||
|
return Err(FcryError::Kdf(format!(
|
||||||
|
"argon-passes must be > 0 for {context}"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
if passes > MAX_ARGON_PASSES {
|
||||||
|
return Err(FcryError::Kdf(format!(
|
||||||
|
"argon-passes {passes} exceeds maximum {MAX_ARGON_PASSES}"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
if parallelism == 0 {
|
||||||
|
return Err(FcryError::Kdf(format!(
|
||||||
|
"argon-parallelism must be > 0 for {context}"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
if parallelism > MAX_ARGON_PARALLELISM {
|
||||||
|
return Err(FcryError::Kdf(format!(
|
||||||
|
"argon-parallelism {parallelism} exceeds maximum {MAX_ARGON_PARALLELISM}"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
if memory_mib > architecture_argon_cap_mib() {
|
||||||
|
return Err(FcryError::Kdf(format!(
|
||||||
|
"argon-memory {memory_mib} exceeds this build's supported cap {}",
|
||||||
|
architecture_argon_cap_mib()
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn normalize_worker_threads(requested: Option<u32>) -> (usize, Option<u32>) {
|
||||||
|
let requested = requested.map(|n| n as usize).unwrap_or_else(|| {
|
||||||
|
std::thread::available_parallelism()
|
||||||
|
.map(|n| n.get())
|
||||||
|
.unwrap_or(1)
|
||||||
|
});
|
||||||
|
let capped = requested.clamp(1, MAX_WORKER_THREADS);
|
||||||
|
let warning = (requested > MAX_WORKER_THREADS).then_some(requested as u32);
|
||||||
|
(capped, warning)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pipeline_in_flight_capacity(threads: usize, chunk_len: usize) -> usize {
|
||||||
|
let chunk_len = chunk_len.max(1);
|
||||||
|
let thread_cap = threads.saturating_mul(4).max(1);
|
||||||
|
let byte_cap = (PIPELINE_IN_FLIGHT_BYTES / chunk_len).max(1);
|
||||||
|
thread_cap.min(byte_cap)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pipeline_channel_capacity(threads: usize, in_flight: usize) -> usize {
|
||||||
|
threads.saturating_mul(2).max(1).min(in_flight.max(1))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn checked_add_u64(a: u64, b: u64, what: &str) -> Result<u64, FcryError> {
|
||||||
|
a.checked_add(b)
|
||||||
|
.ok_or_else(|| FcryError::Format(format!("{what} overflow")))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn checked_mul_u64(a: u64, b: u64, what: &str) -> Result<u64, FcryError> {
|
||||||
|
a.checked_mul(b)
|
||||||
|
.ok_or_else(|| FcryError::Format(format!("{what} overflow")))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn checked_count_add(total: u64, delta: usize, what: &str) -> Result<u64, FcryError> {
|
||||||
|
checked_add_u64(total, delta as u64, what)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn chunk_size_bounds() {
|
||||||
|
assert!(validate_chunk_size(1).is_ok());
|
||||||
|
assert!(validate_chunk_size(MAX_CHUNK_SIZE).is_ok());
|
||||||
|
assert!(validate_chunk_size(0).is_err());
|
||||||
|
assert!(validate_chunk_size(MAX_CHUNK_SIZE + 1).is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn argon_cap_override_replaces_default() {
|
||||||
|
let down = resolve_argon_decrypt_cap(Some(1)).unwrap();
|
||||||
|
assert_eq!(down.effective_mib, 1);
|
||||||
|
assert!(down.overridden);
|
||||||
|
let default = resolve_argon_decrypt_cap(None).unwrap();
|
||||||
|
assert_eq!(default.effective_mib, default.default_mib);
|
||||||
|
assert!(!default.overridden);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pipeline_capacity_has_one_chunk_minimum() {
|
||||||
|
assert_eq!(
|
||||||
|
pipeline_in_flight_capacity(4, PIPELINE_IN_FLIGHT_BYTES * 2),
|
||||||
|
1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+20
-28
@@ -1,26 +1,27 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: MIT-0
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::{BufRead, Read};
|
use std::io::{BufRead, Read};
|
||||||
|
use zeroize::Zeroizing;
|
||||||
|
|
||||||
pub enum ReadInfo {
|
pub enum ReadInfoChunk {
|
||||||
NormalChunk(usize),
|
Normal(#[allow(dead_code)] usize),
|
||||||
LastChunk(usize),
|
Last(usize),
|
||||||
EmptyChunk,
|
Empty,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AheadReader {
|
pub struct AheadReader {
|
||||||
inner: Box<dyn BufRead>,
|
inner: Box<dyn BufRead + Send>,
|
||||||
buf: Vec<u8>,
|
buf: Zeroizing<Vec<u8>>,
|
||||||
bufsz: usize,
|
bufsz: usize,
|
||||||
capacity: usize,
|
capacity: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AheadReader {
|
impl AheadReader {
|
||||||
pub fn from(reader: Box<dyn BufRead>, capacity: usize) -> Self {
|
pub fn from(reader: Box<dyn BufRead + Send>, capacity: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inner: reader,
|
inner: reader,
|
||||||
buf: vec![0; capacity],
|
buf: Zeroizing::new(vec![0; capacity]),
|
||||||
bufsz: 0,
|
bufsz: 0,
|
||||||
capacity,
|
capacity,
|
||||||
}
|
}
|
||||||
@@ -46,55 +47,46 @@ impl AheadReader {
|
|||||||
Ok(total)
|
Ok(total)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_ahead(&mut self, userbuf: &mut [u8]) -> io::Result<ReadInfo> {
|
pub fn read_ahead(&mut self, userbuf: &mut [u8]) -> io::Result<ReadInfoChunk> {
|
||||||
// 1st read
|
|
||||||
if self.bufsz == 0 {
|
if self.bufsz == 0 {
|
||||||
eprintln!("[reader] first read");
|
|
||||||
return self.first_read(userbuf);
|
return self.first_read(userbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
eprintln!("[reader] normal read");
|
|
||||||
// normal read (not the 1st one)
|
|
||||||
self.normal_read(userbuf)
|
self.normal_read(userbuf)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_exact(&mut self, userbuf: &mut [u8]) -> io::Result<()> {
|
fn first_read(&mut self, userbuf: &mut [u8]) -> io::Result<ReadInfoChunk> {
|
||||||
self.inner.read_exact(userbuf)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn first_read(&mut self, userbuf: &mut [u8]) -> io::Result<ReadInfo> {
|
|
||||||
// 1st read directly to userbuf (we have no cached data yet)
|
// 1st read directly to userbuf (we have no cached data yet)
|
||||||
let n = self.read_until_full(userbuf)?;
|
let n = self.read_until_full(userbuf)?;
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
return Ok(ReadInfo::EmptyChunk);
|
return Ok(ReadInfoChunk::Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2nd read directly into our internal buf
|
// 2nd read directly into our internal buf
|
||||||
let mut tmp = vec![0u8; self.capacity];
|
let mut tmp = Zeroizing::new(vec![0u8; self.capacity]);
|
||||||
let n2 = self.read_until_full(&mut tmp)?;
|
let n2 = self.read_until_full(&mut tmp)?;
|
||||||
self.buf = tmp;
|
self.buf = tmp;
|
||||||
self.bufsz = n2;
|
self.bufsz = n2;
|
||||||
if n2 == 0 {
|
if n2 == 0 {
|
||||||
return Ok(ReadInfo::LastChunk(n));
|
return Ok(ReadInfoChunk::Last(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(ReadInfo::NormalChunk(n))
|
Ok(ReadInfoChunk::Normal(n))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn normal_read(&mut self, userbuf: &mut [u8]) -> io::Result<ReadInfo> {
|
fn normal_read(&mut self, userbuf: &mut [u8]) -> io::Result<ReadInfoChunk> {
|
||||||
// copy internal buf to userbuf
|
// copy internal buf to userbuf
|
||||||
userbuf.copy_from_slice(&self.buf);
|
userbuf.copy_from_slice(&self.buf);
|
||||||
let userbuf_sz = self.bufsz;
|
let userbuf_sz = self.bufsz;
|
||||||
|
|
||||||
// 2nd read directly into our internal buf
|
// 2nd read directly into our internal buf
|
||||||
let mut tmp = vec![0u8; self.capacity];
|
let mut tmp = Zeroizing::new(vec![0u8; self.capacity]);
|
||||||
let n2 = self.read_until_full(&mut tmp)?;
|
let n2 = self.read_until_full(&mut tmp)?;
|
||||||
self.buf = tmp;
|
self.buf = tmp;
|
||||||
self.bufsz = n2;
|
self.bufsz = n2;
|
||||||
if n2 == 0 {
|
if n2 == 0 {
|
||||||
return Ok(ReadInfo::LastChunk(userbuf_sz));
|
return Ok(ReadInfoChunk::Last(userbuf_sz));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(ReadInfo::NormalChunk(userbuf_sz))
|
Ok(ReadInfoChunk::Normal(userbuf_sz))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+302
@@ -0,0 +1,302 @@
|
|||||||
|
// SPDX-License-Identifier: MIT-0
|
||||||
|
|
||||||
|
//! Secret-handling primitives.
|
||||||
|
//!
|
||||||
|
//! Thin local adapters around the upstream `secrets` crate plus a
|
||||||
|
//! cross-platform passphrase reader:
|
||||||
|
//!
|
||||||
|
//! * [`SecretBytes32`] — heap-allocated 32-byte buffer protected by
|
||||||
|
//! `secrets::SecretBox`.
|
||||||
|
//! * [`SecretVec`] — fixed-allocation byte buffer protected by
|
||||||
|
//! `secrets::SecretVec`, with a separate logical length so tty input can be
|
||||||
|
//! appended without reallocations.
|
||||||
|
//! * [`read_passphrase_tty`] — direct tty reader (Linux/macOS termios,
|
||||||
|
//! Windows Console API). Reads into a pre-reserved `SecretVec` so no
|
||||||
|
//! reallocation can leave stale unzeroed copies on the heap.
|
||||||
|
|
||||||
|
use std::io;
|
||||||
|
|
||||||
|
use protected_secrets::{SecretBox as ProtectedSecretBox, SecretVec as ProtectedSecretVec};
|
||||||
|
|
||||||
|
/// Maximum passphrase length we accept on the tty.
|
||||||
|
/// Pre-reserved so the underlying Vec never reallocates while reading.
|
||||||
|
pub const MAX_PASSPHRASE_LEN: usize = 1024;
|
||||||
|
|
||||||
|
/// Heap-allocated 32-byte secret protected by the upstream `secrets` crate.
|
||||||
|
pub struct SecretBytes32 {
|
||||||
|
inner: ProtectedSecretBox<[u8; 32]>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SecretBytes32 {
|
||||||
|
pub fn zeroed() -> Self {
|
||||||
|
Self {
|
||||||
|
inner: ProtectedSecretBox::zero(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_array<R>(&self, f: impl FnOnce(&[u8; 32]) -> R) -> R {
|
||||||
|
let inner = self.inner.borrow();
|
||||||
|
f(&inner)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_mut_array<R>(&mut self, f: impl FnOnce(&mut [u8; 32]) -> R) -> R {
|
||||||
|
let mut inner = self.inner.borrow_mut();
|
||||||
|
f(&mut inner)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Heap-allocated byte buffer with **fixed capacity** protected by upstream
|
||||||
|
/// `secrets::SecretVec`.
|
||||||
|
///
|
||||||
|
/// Upstream `SecretVec` is fixed-length, so this adapter stores a separate
|
||||||
|
/// logical length. Bytes after `len` remain zero-filled padding and are never
|
||||||
|
/// exposed through [`SecretVec::with_slice`].
|
||||||
|
pub struct SecretVec {
|
||||||
|
inner: ProtectedSecretVec<u8>,
|
||||||
|
len: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SecretVec {
|
||||||
|
/// Allocate a protected buffer with fixed `capacity`.
|
||||||
|
pub fn with_capacity(capacity: usize) -> Self {
|
||||||
|
Self {
|
||||||
|
inner: ProtectedSecretVec::zero(capacity),
|
||||||
|
len: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Copy bytes from an already-allocated `Vec<u8>` into protected storage.
|
||||||
|
/// The upstream conversion zeroes the source bytes after copying; the
|
||||||
|
/// allocation itself is then released normally when the Vec is dropped.
|
||||||
|
pub fn from_vec(mut v: Vec<u8>) -> Self {
|
||||||
|
let len = v.len();
|
||||||
|
Self {
|
||||||
|
inner: ProtectedSecretVec::from(&mut v[..]),
|
||||||
|
len,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn push(&mut self, b: u8) -> io::Result<()> {
|
||||||
|
if self.len >= self.inner.len() {
|
||||||
|
return Err(io::Error::new(
|
||||||
|
io::ErrorKind::InvalidInput,
|
||||||
|
"secret buffer full",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let mut inner = self.inner.borrow_mut();
|
||||||
|
inner[self.len] = b;
|
||||||
|
}
|
||||||
|
self.len += 1;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_slice<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R {
|
||||||
|
let inner = self.inner.borrow();
|
||||||
|
f(&inner[..self.len])
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
self.len
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialEq for SecretVec {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
// Constant-time-ish: length still leaks, but contents do not early-out.
|
||||||
|
if self.len != other.len {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let a = self.inner.borrow();
|
||||||
|
let b = other.inner.borrow();
|
||||||
|
let mut diff: u8 = 0;
|
||||||
|
for (x, y) in a[..self.len].iter().zip(b[..other.len].iter()) {
|
||||||
|
diff |= x ^ y;
|
||||||
|
}
|
||||||
|
diff == 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// tty passphrase reader
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
/// Read a passphrase from the controlling terminal with echo disabled.
|
||||||
|
///
|
||||||
|
/// Bytes go directly into a pre-reserved `SecretVec` so no reallocation can
|
||||||
|
/// leave stale heap copies. CR is skipped, LF terminates the line.
|
||||||
|
/// Returns an error if the input exceeds `MAX_PASSPHRASE_LEN` bytes.
|
||||||
|
pub fn read_passphrase_tty(prompt: &str) -> io::Result<SecretVec> {
|
||||||
|
imp::read_passphrase_tty(prompt)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
mod imp {
|
||||||
|
use super::{MAX_PASSPHRASE_LEN, SecretVec};
|
||||||
|
use std::fs::OpenOptions;
|
||||||
|
use std::io::{self, Read, Write};
|
||||||
|
use std::os::unix::io::AsRawFd;
|
||||||
|
|
||||||
|
/// RAII guard that restores the original termios on drop.
|
||||||
|
struct TermiosGuard {
|
||||||
|
fd: i32,
|
||||||
|
orig: libc::termios,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for TermiosGuard {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
libc::tcsetattr(self.fd, libc::TCSANOW, &self.orig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_passphrase_tty(prompt: &str) -> io::Result<SecretVec> {
|
||||||
|
let mut tty = OpenOptions::new().read(true).write(true).open("/dev/tty")?;
|
||||||
|
let fd = tty.as_raw_fd();
|
||||||
|
|
||||||
|
let mut orig: libc::termios = unsafe { std::mem::zeroed() };
|
||||||
|
if unsafe { libc::tcgetattr(fd, &mut orig) } != 0 {
|
||||||
|
return Err(io::Error::last_os_error());
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut new = orig;
|
||||||
|
// Disable echo of typed characters; keep ECHONL so the final newline
|
||||||
|
// is shown when the user presses Enter (cosmetic).
|
||||||
|
new.c_lflag &= !libc::ECHO;
|
||||||
|
new.c_lflag |= libc::ECHONL;
|
||||||
|
if unsafe { libc::tcsetattr(fd, libc::TCSANOW, &new) } != 0 {
|
||||||
|
return Err(io::Error::last_os_error());
|
||||||
|
}
|
||||||
|
let _guard = TermiosGuard { fd, orig };
|
||||||
|
|
||||||
|
write!(tty, "{prompt}")?;
|
||||||
|
tty.flush()?;
|
||||||
|
|
||||||
|
let mut buf = SecretVec::with_capacity(MAX_PASSPHRASE_LEN);
|
||||||
|
let mut byte = [0u8; 1];
|
||||||
|
loop {
|
||||||
|
match tty.read(&mut byte) {
|
||||||
|
Ok(0) => break, // EOF
|
||||||
|
Ok(_) => match byte[0] {
|
||||||
|
b'\n' => break,
|
||||||
|
b'\r' => continue,
|
||||||
|
b => buf.push(b)?,
|
||||||
|
},
|
||||||
|
Err(e) if e.kind() == io::ErrorKind::Interrupted => continue,
|
||||||
|
Err(e) => return Err(e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
mod imp {
|
||||||
|
use super::{MAX_PASSPHRASE_LEN, SecretVec};
|
||||||
|
use std::fs::OpenOptions;
|
||||||
|
use std::io::{self, Write};
|
||||||
|
use std::os::windows::io::AsRawHandle;
|
||||||
|
use std::ptr;
|
||||||
|
use windows_sys::Win32::Foundation::HANDLE;
|
||||||
|
use windows_sys::Win32::System::Console::{
|
||||||
|
ENABLE_ECHO_INPUT, ENABLE_LINE_INPUT, ENABLE_PROCESSED_INPUT, GetConsoleMode, ReadConsoleW,
|
||||||
|
SetConsoleMode,
|
||||||
|
};
|
||||||
|
use zeroize::Zeroizing;
|
||||||
|
|
||||||
|
struct ConsoleModeGuard {
|
||||||
|
handle: HANDLE,
|
||||||
|
orig: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for ConsoleModeGuard {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
SetConsoleMode(self.handle, self.orig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_passphrase_tty(prompt: &str) -> io::Result<SecretVec> {
|
||||||
|
let tty_in = OpenOptions::new().read(true).write(true).open("CONIN$")?;
|
||||||
|
let mut tty_out = OpenOptions::new().write(true).open("CONOUT$")?;
|
||||||
|
|
||||||
|
let h_in = tty_in.as_raw_handle() as HANDLE;
|
||||||
|
let mut orig_mode: u32 = 0;
|
||||||
|
if unsafe { GetConsoleMode(h_in, &mut orig_mode) } == 0 {
|
||||||
|
return Err(io::Error::last_os_error());
|
||||||
|
}
|
||||||
|
|
||||||
|
let new_mode =
|
||||||
|
(orig_mode | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT) & !ENABLE_ECHO_INPUT;
|
||||||
|
if unsafe { SetConsoleMode(h_in, new_mode) } == 0 {
|
||||||
|
return Err(io::Error::last_os_error());
|
||||||
|
}
|
||||||
|
let _guard = ConsoleModeGuard {
|
||||||
|
handle: h_in,
|
||||||
|
orig: orig_mode,
|
||||||
|
};
|
||||||
|
|
||||||
|
write!(tty_out, "{prompt}")?;
|
||||||
|
tty_out.flush()?;
|
||||||
|
|
||||||
|
let mut wide = Zeroizing::new(Vec::<u16>::with_capacity(MAX_PASSPHRASE_LEN));
|
||||||
|
loop {
|
||||||
|
let mut unit = 0u16;
|
||||||
|
let mut read = 0u32;
|
||||||
|
let ok = unsafe {
|
||||||
|
ReadConsoleW(
|
||||||
|
h_in,
|
||||||
|
(&mut unit as *mut u16).cast(),
|
||||||
|
1,
|
||||||
|
&mut read,
|
||||||
|
ptr::null_mut(),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
if ok == 0 {
|
||||||
|
return Err(io::Error::last_os_error());
|
||||||
|
}
|
||||||
|
if read == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const LF: u16 = b'\n' as u16;
|
||||||
|
const CR: u16 = b'\r' as u16;
|
||||||
|
match unit {
|
||||||
|
LF | CR => break,
|
||||||
|
u => {
|
||||||
|
if wide.len() >= MAX_PASSPHRASE_LEN {
|
||||||
|
return Err(io::Error::new(
|
||||||
|
io::ErrorKind::InvalidInput,
|
||||||
|
"secret buffer full",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
wide.push(u);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Echo was off, so emit a newline so the next shell prompt is on a fresh line.
|
||||||
|
let _ = writeln!(tty_out);
|
||||||
|
let _ = tty_out.flush();
|
||||||
|
|
||||||
|
let utf8 = Zeroizing::new(String::from_utf16(&wide).map_err(|_| {
|
||||||
|
io::Error::new(
|
||||||
|
io::ErrorKind::InvalidData,
|
||||||
|
"console passphrase is not valid UTF-16",
|
||||||
|
)
|
||||||
|
})?);
|
||||||
|
if utf8.len() > MAX_PASSPHRASE_LEN {
|
||||||
|
return Err(io::Error::new(
|
||||||
|
io::ErrorKind::InvalidInput,
|
||||||
|
"secret buffer full",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let mut buf = SecretVec::with_capacity(MAX_PASSPHRASE_LEN);
|
||||||
|
for b in utf8.as_bytes() {
|
||||||
|
buf.push(*b)?;
|
||||||
|
}
|
||||||
|
Ok(buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
+279
-20
@@ -1,31 +1,290 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: MIT-0
|
||||||
|
|
||||||
use crate::reader::AheadReader;
|
use std::fs::{self, File, OpenOptions};
|
||||||
|
use std::io::{self, BufRead, BufReader, Seek, SeekFrom, Write};
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use std::io::BufReader;
|
use crate::policy;
|
||||||
use std::{
|
|
||||||
fs::File,
|
|
||||||
io::{self, Write},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const BUFSIZE: usize = 64 * 1024; // 64 KiB
|
/// Default plaintext chunk size: 1 MiB.
|
||||||
|
///
|
||||||
|
/// Stored in the header per file, so callers may override via CLI without
|
||||||
|
/// breaking older files (the decryptor reads the size from the header).
|
||||||
|
pub const DEFAULT_CHUNK_SIZE: u32 = policy::DEFAULT_CHUNK_SIZE;
|
||||||
|
|
||||||
pub(crate) fn read_from_file_or_stdin<S: AsRef<str>>(
|
/// Opened input.
|
||||||
input_file: Option<S>,
|
///
|
||||||
bufsz: usize,
|
/// `length` is `Some(n)` only when the source is a regular file (we stat the
|
||||||
) -> AheadReader {
|
/// open FD to avoid TOCTOU). For stdin, FIFOs, sockets, char devices, etc.
|
||||||
|
/// it is `None` — those paths cannot commit a length in the header.
|
||||||
|
pub(crate) struct Input {
|
||||||
|
pub reader: Box<dyn BufRead + Send>,
|
||||||
|
pub length: Option<u64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn open_input<S: AsRef<str>>(input_file: Option<S>) -> io::Result<Input> {
|
||||||
match input_file {
|
match input_file {
|
||||||
Some(f) => AheadReader::from(
|
Some(f) => {
|
||||||
Box::new(BufReader::new(File::open(f.as_ref()).unwrap())),
|
let file = File::open(f.as_ref())?;
|
||||||
bufsz,
|
// Stat the open FD (not the path) so we can't be raced between
|
||||||
),
|
// stat and open.
|
||||||
None => AheadReader::from(Box::new(io::stdin().lock()), bufsz),
|
let length = file
|
||||||
|
.metadata()
|
||||||
|
.ok()
|
||||||
|
.filter(|m| m.is_file())
|
||||||
|
.map(|m| m.len());
|
||||||
|
Ok(Input {
|
||||||
|
reader: Box::new(BufReader::new(file)),
|
||||||
|
length,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
None => Ok(Input {
|
||||||
|
// `Stdin` is `Send` (unlike `StdinLock`), so wrap it in a
|
||||||
|
// `BufReader` and box for cross-thread use in the parallel pipeline.
|
||||||
|
reader: Box::new(BufReader::new(io::stdin())),
|
||||||
|
length: None,
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn write_to_file_or_stdout<S: AsRef<str>>(output_file: Option<S>) -> Box<dyn Write> {
|
#[derive(Clone, Debug, Default)]
|
||||||
|
pub struct OutSinkOptions {
|
||||||
|
pub force: bool,
|
||||||
|
pub input_file: Option<PathBuf>,
|
||||||
|
pub temp_dir: Option<PathBuf>,
|
||||||
|
pub buffer_verify_stdout: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) struct SecureTempFile {
|
||||||
|
path: PathBuf,
|
||||||
|
file: Option<File>,
|
||||||
|
remove_on_drop: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SecureTempFile {
|
||||||
|
fn create(dir: &Path, prefix: &str) -> io::Result<Self> {
|
||||||
|
fs::create_dir_all(dir)?;
|
||||||
|
for _ in 0..128 {
|
||||||
|
let mut rand = [0u8; 16];
|
||||||
|
getrandom::fill(&mut rand).map_err(io::Error::other)?;
|
||||||
|
let name = format!("{prefix}.{}.tmp", hex(&rand));
|
||||||
|
let path = dir.join(name);
|
||||||
|
let mut opts = OpenOptions::new();
|
||||||
|
opts.read(true).write(true).create_new(true);
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
use std::os::unix::fs::OpenOptionsExt;
|
||||||
|
opts.mode(0o600);
|
||||||
|
}
|
||||||
|
match opts.open(&path) {
|
||||||
|
Ok(file) => {
|
||||||
|
return Ok(Self {
|
||||||
|
path,
|
||||||
|
file: Some(file),
|
||||||
|
remove_on_drop: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Err(e) if e.kind() == io::ErrorKind::AlreadyExists => continue,
|
||||||
|
Err(e) => return Err(e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(io::Error::new(
|
||||||
|
io::ErrorKind::AlreadyExists,
|
||||||
|
"could not create a unique temporary file after 128 attempts",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn file_mut(&mut self) -> &mut File {
|
||||||
|
self.file
|
||||||
|
.as_mut()
|
||||||
|
.expect("temporary file handle taken before commit")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sync_file(&mut self) -> io::Result<()> {
|
||||||
|
let file = self.file_mut();
|
||||||
|
file.flush()?;
|
||||||
|
file.sync_all()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn persist(mut self, final_path: &Path) -> io::Result<()> {
|
||||||
|
self.sync_file()?;
|
||||||
|
self.file.take();
|
||||||
|
#[cfg(windows)]
|
||||||
|
if final_path.exists() {
|
||||||
|
fs::remove_file(final_path)?;
|
||||||
|
}
|
||||||
|
fs::rename(&self.path, final_path)?;
|
||||||
|
self.remove_on_drop = false;
|
||||||
|
best_effort_fsync_parent(final_path);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn copy_to_stdout(mut self) -> io::Result<()> {
|
||||||
|
self.sync_file()?;
|
||||||
|
let mut file = self
|
||||||
|
.file
|
||||||
|
.take()
|
||||||
|
.expect("temporary file handle taken before stdout commit");
|
||||||
|
file.seek(SeekFrom::Start(0))?;
|
||||||
|
let mut stdout = io::stdout();
|
||||||
|
io::copy(&mut file, &mut stdout)?;
|
||||||
|
stdout.flush()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for SecureTempFile {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.file.take();
|
||||||
|
if self.remove_on_drop {
|
||||||
|
let _ = fs::remove_file(&self.path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hex(bytes: &[u8]) -> String {
|
||||||
|
const HEX: &[u8; 16] = b"0123456789abcdef";
|
||||||
|
let mut out = String::with_capacity(bytes.len() * 2);
|
||||||
|
for b in bytes {
|
||||||
|
out.push(HEX[(b >> 4) as usize] as char);
|
||||||
|
out.push(HEX[(b & 0x0f) as usize] as char);
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
fn best_effort_fsync_parent(path: &Path) {
|
||||||
|
let Some(parent) = path.parent() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
if let Ok(dir) = File::open(parent) {
|
||||||
|
let _ = dir.sync_all();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn temp_dir_for_target(final_path: &Path, explicit: Option<&Path>) -> PathBuf {
|
||||||
|
if let Some(dir) = explicit {
|
||||||
|
return dir.to_path_buf();
|
||||||
|
}
|
||||||
|
final_path
|
||||||
|
.parent()
|
||||||
|
.filter(|p| !p.as_os_str().is_empty())
|
||||||
|
.map(Path::to_path_buf)
|
||||||
|
.unwrap_or_else(|| PathBuf::from("."))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn temp_dir_for_stdout(explicit: Option<&Path>) -> PathBuf {
|
||||||
|
explicit
|
||||||
|
.map(Path::to_path_buf)
|
||||||
|
.unwrap_or_else(std::env::temp_dir)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn file_name_prefix(path: &Path) -> String {
|
||||||
|
path.file_name()
|
||||||
|
.and_then(|name| name.to_str())
|
||||||
|
.filter(|name| !name.is_empty())
|
||||||
|
.unwrap_or("fcry")
|
||||||
|
.to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn output_aliases_input(output: &Path, input: Option<&Path>) -> io::Result<bool> {
|
||||||
|
let Some(input) = input else {
|
||||||
|
return Ok(false);
|
||||||
|
};
|
||||||
|
match same_file::is_same_file(input, output) {
|
||||||
|
Ok(same) => Ok(same),
|
||||||
|
Err(e) if e.kind() == io::ErrorKind::NotFound => Ok(false),
|
||||||
|
Err(e) => Err(e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Output sink that supports atomic file replacement.
|
||||||
|
///
|
||||||
|
/// For file outputs: bytes are written to a private, randomly named temp file.
|
||||||
|
/// On `commit()`, the temp file is fsynced and renamed into place. If dropped
|
||||||
|
/// without commit (panic, error, process exit), the temp file is deleted so a
|
||||||
|
/// partial/garbage file does not replace any existing target.
|
||||||
|
///
|
||||||
|
/// For stdout: behaves as a passthrough; `commit()` is a no-op.
|
||||||
|
pub enum OutSink {
|
||||||
|
Stdout(io::Stdout),
|
||||||
|
BufferVerify {
|
||||||
|
temp: SecureTempFile,
|
||||||
|
},
|
||||||
|
File {
|
||||||
|
final_path: PathBuf,
|
||||||
|
temp: SecureTempFile,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OutSink {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn open<S: AsRef<str>>(output_file: Option<S>) -> io::Result<Self> {
|
||||||
|
Self::open_with_options(output_file, &OutSinkOptions::default())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn open_with_options<S: AsRef<str>>(
|
||||||
|
output_file: Option<S>,
|
||||||
|
options: &OutSinkOptions,
|
||||||
|
) -> io::Result<Self> {
|
||||||
match output_file {
|
match output_file {
|
||||||
Some(f) => Box::new(File::create(f.as_ref()).unwrap()),
|
None if options.buffer_verify_stdout => {
|
||||||
None => Box::new(io::stdout()),
|
let dir = temp_dir_for_stdout(options.temp_dir.as_deref());
|
||||||
|
Ok(Self::BufferVerify {
|
||||||
|
temp: SecureTempFile::create(&dir, "fcry-buffer")?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
None => Ok(Self::Stdout(io::stdout())),
|
||||||
|
Some(f) => {
|
||||||
|
let final_path = PathBuf::from(f.as_ref());
|
||||||
|
if final_path.exists()
|
||||||
|
&& !options.force
|
||||||
|
&& !output_aliases_input(&final_path, options.input_file.as_deref())?
|
||||||
|
{
|
||||||
|
return Err(io::Error::new(
|
||||||
|
io::ErrorKind::AlreadyExists,
|
||||||
|
format!(
|
||||||
|
"output file {} already exists (use --force to replace it)",
|
||||||
|
final_path.display()
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let dir = temp_dir_for_target(&final_path, options.temp_dir.as_deref());
|
||||||
|
let prefix = file_name_prefix(&final_path);
|
||||||
|
let temp = SecureTempFile::create(&dir, &prefix)?;
|
||||||
|
Ok(Self::File { final_path, temp })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn commit(mut self) -> io::Result<()> {
|
||||||
|
match &mut self {
|
||||||
|
Self::Stdout(s) => s.flush()?,
|
||||||
|
Self::BufferVerify { .. } => {}
|
||||||
|
Self::File { .. } => {}
|
||||||
|
}
|
||||||
|
match self {
|
||||||
|
Self::Stdout(_) => {}
|
||||||
|
Self::BufferVerify { temp } => temp.copy_to_stdout()?,
|
||||||
|
Self::File { final_path, temp } => temp.persist(&final_path)?,
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Write for OutSink {
|
||||||
|
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||||
|
match self {
|
||||||
|
Self::Stdout(s) => s.write(buf),
|
||||||
|
Self::BufferVerify { temp } => temp.file_mut().write(buf),
|
||||||
|
Self::File { temp, .. } => temp.file_mut().write(buf),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn flush(&mut self) -> io::Result<()> {
|
||||||
|
match self {
|
||||||
|
Self::Stdout(s) => s.flush(),
|
||||||
|
Self::BufferVerify { temp } => temp.file_mut().flush(),
|
||||||
|
Self::File { temp, .. } => temp.file_mut().flush(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1250
@@ -0,0 +1,1250 @@
|
|||||||
|
// SPDX-License-Identifier: MIT-0
|
||||||
|
//
|
||||||
|
// Integration tests for the `fcry` binary.
|
||||||
|
//
|
||||||
|
// These exercise the CLI as a black box: encrypt then decrypt and check that
|
||||||
|
// plaintext bytes are preserved, plus a handful of failure cases (tampering,
|
||||||
|
// wrong key, truncation, bad magic).
|
||||||
|
|
||||||
|
use std::fs;
|
||||||
|
use std::io::{ErrorKind, Write};
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
|
use assert_cmd::cargo::CommandCargoExt;
|
||||||
|
use tempfile::TempDir;
|
||||||
|
|
||||||
|
const KEY: &[u8; 32] = b"0123456789abcdef0123456789abcdef";
|
||||||
|
|
||||||
|
fn fcry() -> Command {
|
||||||
|
Command::cargo_bin("fcry").unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_key_file(dir: &std::path::Path) -> std::path::PathBuf {
|
||||||
|
let key = dir.join("key.bin");
|
||||||
|
fs::write(&key, KEY).unwrap();
|
||||||
|
key
|
||||||
|
}
|
||||||
|
|
||||||
|
fn key_file_near(path: &std::path::Path) -> std::path::PathBuf {
|
||||||
|
write_key_file(path.parent().unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Deterministic pseudo-random plaintext of `n` bytes (xorshift, seedable).
|
||||||
|
/// We avoid `/dev/urandom` so tests are reproducible on failure.
|
||||||
|
fn pseudo_random(seed: u64, n: usize) -> Vec<u8> {
|
||||||
|
let mut s = seed.wrapping_add(0x9E3779B97F4A7C15);
|
||||||
|
let mut out = Vec::with_capacity(n);
|
||||||
|
while out.len() < n {
|
||||||
|
s ^= s << 13;
|
||||||
|
s ^= s >> 7;
|
||||||
|
s ^= s << 17;
|
||||||
|
out.extend_from_slice(&s.to_le_bytes());
|
||||||
|
}
|
||||||
|
out.truncate(n);
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encrypt_file(plain: &std::path::Path, ct: &std::path::Path, chunk_size: Option<u32>) {
|
||||||
|
let mut cmd = fcry();
|
||||||
|
let key = key_file_near(ct);
|
||||||
|
cmd.arg("-i")
|
||||||
|
.arg(plain)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(ct)
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(key);
|
||||||
|
if let Some(cs) = chunk_size {
|
||||||
|
cmd.arg("--chunk-size").arg(cs.to_string());
|
||||||
|
}
|
||||||
|
let out = cmd.output().unwrap();
|
||||||
|
assert!(
|
||||||
|
out.status.success(),
|
||||||
|
"encrypt failed: {}",
|
||||||
|
String::from_utf8_lossy(&out.stderr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decrypt_file(ct: &std::path::Path, rt: &std::path::Path) {
|
||||||
|
let key = key_file_near(ct);
|
||||||
|
let out = fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("-i")
|
||||||
|
.arg(ct)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(rt)
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(key)
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
out.status.success(),
|
||||||
|
"decrypt failed: {}",
|
||||||
|
String::from_utf8_lossy(&out.stderr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn roundtrip_with_size(plaintext_size: usize, chunk_size: Option<u32>) {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("plain.bin");
|
||||||
|
let ct = dir.path().join("ct.bin");
|
||||||
|
let rt = dir.path().join("rt.bin");
|
||||||
|
|
||||||
|
let data = pseudo_random(plaintext_size as u64, plaintext_size);
|
||||||
|
fs::write(&plain, &data).unwrap();
|
||||||
|
|
||||||
|
encrypt_file(&plain, &ct, chunk_size);
|
||||||
|
decrypt_file(&ct, &rt);
|
||||||
|
|
||||||
|
let got = fs::read(&rt).unwrap();
|
||||||
|
assert_eq!(got, data, "roundtrip mismatch at size {plaintext_size}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn roundtrip_empty() {
|
||||||
|
roundtrip_with_size(0, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn roundtrip_one_byte() {
|
||||||
|
roundtrip_with_size(1, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn roundtrip_smaller_than_chunk() {
|
||||||
|
roundtrip_with_size(100, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn roundtrip_exactly_one_chunk() {
|
||||||
|
roundtrip_with_size(1024 * 1024, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn roundtrip_just_over_one_chunk() {
|
||||||
|
roundtrip_with_size(1024 * 1024 + 1, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn roundtrip_multi_chunk() {
|
||||||
|
roundtrip_with_size(5 * 1024 * 1024 + 12345, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn roundtrip_custom_small_chunk_size() {
|
||||||
|
// forces many chunks for a small input
|
||||||
|
roundtrip_with_size(50_000, Some(4096));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn roundtrip_chunk_size_one_byte() {
|
||||||
|
// pathological but should still work
|
||||||
|
roundtrip_with_size(257, Some(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn roundtrip_pipe_stdin_stdout() {
|
||||||
|
let data = pseudo_random(42, 200_000);
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let key = write_key_file(dir.path());
|
||||||
|
|
||||||
|
let mut enc = fcry()
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(&key)
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.stderr(Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
enc.stdin.as_mut().unwrap().write_all(&data).unwrap();
|
||||||
|
let enc_out = enc.wait_with_output().unwrap();
|
||||||
|
assert!(
|
||||||
|
enc_out.status.success(),
|
||||||
|
"pipe encrypt failed: {}",
|
||||||
|
String::from_utf8_lossy(&enc_out.stderr)
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut dec = fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(&key)
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.stderr(Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
dec.stdin
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.write_all(&enc_out.stdout)
|
||||||
|
.unwrap();
|
||||||
|
let dec_out = dec.wait_with_output().unwrap();
|
||||||
|
assert!(
|
||||||
|
dec_out.status.success(),
|
||||||
|
"pipe decrypt failed: {}",
|
||||||
|
String::from_utf8_lossy(&dec_out.stderr)
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(dec_out.stdout, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_wrong_key() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let ct = dir.path().join("c.bin");
|
||||||
|
fs::write(&plain, pseudo_random(1, 1000)).unwrap();
|
||||||
|
encrypt_file(&plain, &ct, None);
|
||||||
|
|
||||||
|
let wrong = dir.path().join("wrong.key");
|
||||||
|
fs::write(&wrong, b"ffffffffffffffffffffffffffffffff").unwrap();
|
||||||
|
let out = fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&ct)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(dir.path().join("rt.bin"))
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(wrong)
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(!out.status.success(), "decrypt with wrong key should fail");
|
||||||
|
assert!(
|
||||||
|
String::from_utf8_lossy(&out.stderr).contains("WrongKey"),
|
||||||
|
"expected distinct WrongKey error, got {}",
|
||||||
|
String::from_utf8_lossy(&out.stderr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_tampered_header() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let ct = dir.path().join("c.bin");
|
||||||
|
fs::write(&plain, pseudo_random(2, 1000)).unwrap();
|
||||||
|
encrypt_file(&plain, &ct, None);
|
||||||
|
|
||||||
|
// Flip a byte in the chunk_size field of the header (offset 8: 4 magic + 4 fixed).
|
||||||
|
let mut bytes = fs::read(&ct).unwrap();
|
||||||
|
bytes[8] ^= 0xff;
|
||||||
|
fs::write(&ct, &bytes).unwrap();
|
||||||
|
|
||||||
|
let out = fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&ct)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(dir.path().join("rt.bin"))
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(key_file_near(&ct))
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
!out.status.success(),
|
||||||
|
"decrypt with tampered header should fail"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_tampered_ciphertext() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let ct = dir.path().join("c.bin");
|
||||||
|
fs::write(&plain, pseudo_random(3, 5000)).unwrap();
|
||||||
|
encrypt_file(&plain, &ct, None);
|
||||||
|
|
||||||
|
// Flip a byte well past the header (in the first ciphertext chunk).
|
||||||
|
let mut bytes = fs::read(&ct).unwrap();
|
||||||
|
let off = bytes.len() / 2;
|
||||||
|
bytes[off] ^= 0x01;
|
||||||
|
fs::write(&ct, &bytes).unwrap();
|
||||||
|
|
||||||
|
let out = fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&ct)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(dir.path().join("rt.bin"))
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(key_file_near(&ct))
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
!out.status.success(),
|
||||||
|
"decrypt of tampered ciphertext should fail"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_truncated_ciphertext() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let ct = dir.path().join("c.bin");
|
||||||
|
fs::write(&plain, pseudo_random(4, 3 * 1024 * 1024)).unwrap();
|
||||||
|
encrypt_file(&plain, &ct, None);
|
||||||
|
|
||||||
|
// Drop the trailing 16-byte tag of the last chunk (and then some).
|
||||||
|
let mut bytes = fs::read(&ct).unwrap();
|
||||||
|
bytes.truncate(bytes.len() - 32);
|
||||||
|
fs::write(&ct, &bytes).unwrap();
|
||||||
|
|
||||||
|
let out = fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&ct)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(dir.path().join("rt.bin"))
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(key_file_near(&ct))
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
!out.status.success(),
|
||||||
|
"decrypt of truncated ciphertext should fail"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_bad_magic() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let bogus = dir.path().join("bogus.bin");
|
||||||
|
fs::write(&bogus, b"NOPE\x01\x01\x00\x00\x00\x10\x00\x00\x00").unwrap();
|
||||||
|
let out = fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&bogus)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(dir.path().join("rt.bin"))
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(write_key_file(dir.path()))
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
!out.status.success(),
|
||||||
|
"decrypt of file with bad magic should fail"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
String::from_utf8_lossy(&out.stderr).contains("magic"),
|
||||||
|
"expected 'magic' in stderr, got: {}",
|
||||||
|
String::from_utf8_lossy(&out.stderr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_short_key_file() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let key = dir.path().join("short.key");
|
||||||
|
fs::write(&plain, b"hello").unwrap();
|
||||||
|
fs::write(&key, b"tooshort").unwrap();
|
||||||
|
let out = fcry()
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&plain)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(dir.path().join("c.bin"))
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(&key)
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
!out.status.success(),
|
||||||
|
"encrypt with short key file should fail"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_long_key_file_and_trailing_newline() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let key = dir.path().join("long.key");
|
||||||
|
fs::write(&plain, b"hello").unwrap();
|
||||||
|
fs::write(&key, b"0123456789abcdef0123456789abcdef\n").unwrap();
|
||||||
|
let out = fcry()
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&plain)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(dir.path().join("c.bin"))
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(&key)
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(!out.status.success(), "long key file should fail");
|
||||||
|
assert!(
|
||||||
|
String::from_utf8_lossy(&out.stderr).contains("too long"),
|
||||||
|
"expected too-long error, got {}",
|
||||||
|
String::from_utf8_lossy(&out.stderr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn non_utf8_key_file_roundtrips() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let key = dir.path().join("key.bin");
|
||||||
|
let plain = dir.path().join("plain.bin");
|
||||||
|
let ct = dir.path().join("ct.bin");
|
||||||
|
let rt = dir.path().join("rt.bin");
|
||||||
|
let key_bytes: Vec<u8> = (0..32u8).map(|b| b ^ 0x80).collect();
|
||||||
|
let data = pseudo_random(31, 8192);
|
||||||
|
fs::write(&key, key_bytes).unwrap();
|
||||||
|
fs::write(&plain, &data).unwrap();
|
||||||
|
|
||||||
|
let enc = fcry()
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&plain)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(&ct)
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(&key)
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
enc.status.success(),
|
||||||
|
"non-UTF-8 key encrypt failed: {}",
|
||||||
|
String::from_utf8_lossy(&enc.stderr)
|
||||||
|
);
|
||||||
|
let dec = fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&ct)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(&rt)
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(&key)
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
dec.status.success(),
|
||||||
|
"non-UTF-8 key decrypt failed: {}",
|
||||||
|
String::from_utf8_lossy(&dec.stderr)
|
||||||
|
);
|
||||||
|
assert_eq!(fs::read(&rt).unwrap(), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
#[test]
|
||||||
|
fn split_fifo_key_file_read_roundtrips() {
|
||||||
|
use std::ffi::CString;
|
||||||
|
use std::fs::OpenOptions;
|
||||||
|
use std::os::unix::ffi::OsStrExt;
|
||||||
|
use std::thread;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let fifo = dir.path().join("key.fifo");
|
||||||
|
let fifo_c = CString::new(fifo.as_os_str().as_bytes()).unwrap();
|
||||||
|
let rc = unsafe { libc::mkfifo(fifo_c.as_ptr(), 0o600) };
|
||||||
|
assert_eq!(rc, 0, "mkfifo failed: {}", std::io::Error::last_os_error());
|
||||||
|
|
||||||
|
let plain = dir.path().join("plain.bin");
|
||||||
|
let ct = dir.path().join("ct.bin");
|
||||||
|
let rt = dir.path().join("rt.bin");
|
||||||
|
let data = pseudo_random(33, 8192);
|
||||||
|
fs::write(&plain, &data).unwrap();
|
||||||
|
|
||||||
|
let fifo_writer = fifo.clone();
|
||||||
|
let writer = thread::spawn(move || {
|
||||||
|
let mut file = OpenOptions::new().write(true).open(&fifo_writer).unwrap();
|
||||||
|
file.write_all(&KEY[..8]).unwrap();
|
||||||
|
file.flush().unwrap();
|
||||||
|
thread::sleep(Duration::from_millis(50));
|
||||||
|
file.write_all(&KEY[8..]).unwrap();
|
||||||
|
});
|
||||||
|
|
||||||
|
let enc = fcry()
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&plain)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(&ct)
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(&fifo)
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
writer.join().unwrap();
|
||||||
|
assert!(
|
||||||
|
enc.status.success(),
|
||||||
|
"split FIFO key encrypt failed: {}",
|
||||||
|
String::from_utf8_lossy(&enc.stderr)
|
||||||
|
);
|
||||||
|
|
||||||
|
decrypt_file(&ct, &rt);
|
||||||
|
assert_eq!(fs::read(&rt).unwrap(), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn roundtrip_passphrase_argon2id() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let ct = dir.path().join("c.bin");
|
||||||
|
let rt = dir.path().join("r.bin");
|
||||||
|
let data = pseudo_random(7, 100_000);
|
||||||
|
fs::write(&plain, &data).unwrap();
|
||||||
|
|
||||||
|
// Use cheap argon2 params so the test stays fast.
|
||||||
|
let enc = fcry()
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&plain)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(&ct)
|
||||||
|
.arg("--passphrase-env")
|
||||||
|
.arg("FCRY_TEST_PW")
|
||||||
|
.arg("--argon-memory")
|
||||||
|
.arg("8")
|
||||||
|
.arg("--argon-passes")
|
||||||
|
.arg("1")
|
||||||
|
.arg("--allow-weak-kdf")
|
||||||
|
.env("FCRY_TEST_PW", "correct horse battery staple")
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
enc.status.success(),
|
||||||
|
"passphrase encrypt failed: {}",
|
||||||
|
String::from_utf8_lossy(&enc.stderr)
|
||||||
|
);
|
||||||
|
|
||||||
|
let dec = fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&ct)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(&rt)
|
||||||
|
.arg("--passphrase-env")
|
||||||
|
.arg("FCRY_TEST_PW")
|
||||||
|
.env("FCRY_TEST_PW", "correct horse battery staple")
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
dec.status.success(),
|
||||||
|
"passphrase decrypt failed: {}",
|
||||||
|
String::from_utf8_lossy(&dec.stderr)
|
||||||
|
);
|
||||||
|
assert_eq!(fs::read(&rt).unwrap(), data);
|
||||||
|
|
||||||
|
// Wrong passphrase must fail.
|
||||||
|
let bad = fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&ct)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(dir.path().join("bad.bin"))
|
||||||
|
.arg("--passphrase-env")
|
||||||
|
.arg("FCRY_TEST_PW")
|
||||||
|
.env("FCRY_TEST_PW", "wrong passphrase")
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(!bad.status.success(), "wrong passphrase should fail");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn weak_passphrase_kdf_rejected_without_override() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
fs::write(&plain, b"hello").unwrap();
|
||||||
|
let enc = fcry()
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&plain)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(dir.path().join("c.bin"))
|
||||||
|
.arg("--passphrase-env")
|
||||||
|
.arg("FCRY_TEST_PW")
|
||||||
|
.arg("--argon-memory")
|
||||||
|
.arg("8")
|
||||||
|
.arg("--argon-passes")
|
||||||
|
.arg("1")
|
||||||
|
.env("FCRY_TEST_PW", "short")
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(!enc.status.success(), "weak KDF/passphrase should fail");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn decrypt_argon_memory_cap_rejects_hostile_header() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let ct = dir.path().join("c.bin");
|
||||||
|
fs::write(&plain, b"hello").unwrap();
|
||||||
|
let enc = fcry()
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&plain)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(&ct)
|
||||||
|
.arg("--passphrase-env")
|
||||||
|
.arg("FCRY_TEST_PW")
|
||||||
|
.arg("--argon-memory")
|
||||||
|
.arg("8")
|
||||||
|
.arg("--argon-passes")
|
||||||
|
.arg("1")
|
||||||
|
.arg("--allow-weak-kdf")
|
||||||
|
.env("FCRY_TEST_PW", "correct horse battery staple")
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(enc.status.success());
|
||||||
|
|
||||||
|
let dec = fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&ct)
|
||||||
|
.arg("--passphrase-env")
|
||||||
|
.arg("FCRY_TEST_PW")
|
||||||
|
.arg("--max-argon-memory-mib")
|
||||||
|
.arg("1")
|
||||||
|
.env("FCRY_TEST_PW", "correct horse battery staple")
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(!dec.status.success(), "low decrypt cap should reject file");
|
||||||
|
assert!(
|
||||||
|
String::from_utf8_lossy(&dec.stderr).contains("decrypt cap"),
|
||||||
|
"expected cap error, got {}",
|
||||||
|
String::from_utf8_lossy(&dec.stderr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn atomic_output_no_stale_tmp_on_failure() {
|
||||||
|
// A failed decrypt (wrong key) should not leave the output file behind.
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let ct = dir.path().join("c.bin");
|
||||||
|
let rt = dir.path().join("r.bin");
|
||||||
|
fs::write(&plain, b"hello world").unwrap();
|
||||||
|
encrypt_file(&plain, &ct, None);
|
||||||
|
|
||||||
|
let wrong = dir.path().join("wrong.key");
|
||||||
|
fs::write(&wrong, b"ffffffffffffffffffffffffffffffff").unwrap();
|
||||||
|
let out = fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&ct)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(&rt)
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(&wrong)
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(!out.status.success());
|
||||||
|
assert!(!rt.exists(), "final output must not exist after failure");
|
||||||
|
let mut tmp = rt.clone();
|
||||||
|
tmp.set_file_name("r.bin.tmp");
|
||||||
|
assert!(!tmp.exists(), "temp file must be cleaned up");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn existing_output_refuses_without_force() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let ct = dir.path().join("c.bin");
|
||||||
|
fs::write(&plain, b"hello").unwrap();
|
||||||
|
fs::write(&ct, b"existing").unwrap();
|
||||||
|
let out = fcry()
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&plain)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(&ct)
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(write_key_file(dir.path()))
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(!out.status.success(), "existing output should refuse");
|
||||||
|
assert_eq!(fs::read(&ct).unwrap(), b"existing");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn force_replaces_only_after_success() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let ct = dir.path().join("c.bin");
|
||||||
|
fs::write(&plain, b"hello").unwrap();
|
||||||
|
fs::write(&ct, b"existing").unwrap();
|
||||||
|
let out = fcry()
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&plain)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(&ct)
|
||||||
|
.arg("--force")
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(write_key_file(dir.path()))
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
out.status.success(),
|
||||||
|
"force encrypt failed: {}",
|
||||||
|
String::from_utf8_lossy(&out.stderr)
|
||||||
|
);
|
||||||
|
assert_ne!(fs::read(&ct).unwrap(), b"existing");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn in_place_replacement_roundtrips() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let path = dir.path().join("data.bin");
|
||||||
|
let original = pseudo_random(41, 50_000);
|
||||||
|
fs::write(&path, &original).unwrap();
|
||||||
|
|
||||||
|
let enc = fcry()
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&path)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(&path)
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(write_key_file(dir.path()))
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
enc.status.success(),
|
||||||
|
"in-place encrypt failed: {}",
|
||||||
|
String::from_utf8_lossy(&enc.stderr)
|
||||||
|
);
|
||||||
|
assert_ne!(fs::read(&path).unwrap(), original);
|
||||||
|
|
||||||
|
let dec = fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&path)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(&path)
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(write_key_file(dir.path()))
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
dec.status.success(),
|
||||||
|
"in-place decrypt failed: {}",
|
||||||
|
String::from_utf8_lossy(&dec.stderr)
|
||||||
|
);
|
||||||
|
assert_eq!(fs::read(&path).unwrap(), original);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn old_predictable_temp_name_input_is_not_truncated() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let input = dir.path().join("out.bin.tmp");
|
||||||
|
let output = dir.path().join("out.bin");
|
||||||
|
let original = pseudo_random(42, 1024);
|
||||||
|
fs::write(&input, &original).unwrap();
|
||||||
|
let out = fcry()
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&input)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(&output)
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(write_key_file(dir.path()))
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
out.status.success(),
|
||||||
|
"encrypt failed: {}",
|
||||||
|
String::from_utf8_lossy(&out.stderr)
|
||||||
|
);
|
||||||
|
assert_eq!(fs::read(&input).unwrap(), original);
|
||||||
|
assert!(output.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
#[test]
|
||||||
|
fn output_file_mode_is_0600() {
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let ct = dir.path().join("c.bin");
|
||||||
|
fs::write(&plain, b"hello").unwrap();
|
||||||
|
encrypt_file(&plain, &ct, None);
|
||||||
|
let mode = fs::metadata(&ct).unwrap().permissions().mode() & 0o777;
|
||||||
|
assert_eq!(mode, 0o600);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Multi-threaded pipeline + length-committed + random-access tests
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
fn encrypt_file_threads(
|
||||||
|
plain: &std::path::Path,
|
||||||
|
ct: &std::path::Path,
|
||||||
|
chunk_size: Option<u32>,
|
||||||
|
threads: usize,
|
||||||
|
) {
|
||||||
|
let mut cmd = fcry();
|
||||||
|
let key = key_file_near(ct);
|
||||||
|
cmd.arg("-i")
|
||||||
|
.arg(plain)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(ct)
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(key)
|
||||||
|
.arg("-j")
|
||||||
|
.arg(threads.to_string());
|
||||||
|
if let Some(cs) = chunk_size {
|
||||||
|
cmd.arg("--chunk-size").arg(cs.to_string());
|
||||||
|
}
|
||||||
|
let out = cmd.output().unwrap();
|
||||||
|
assert!(
|
||||||
|
out.status.success(),
|
||||||
|
"encrypt -j{threads} failed: {}",
|
||||||
|
String::from_utf8_lossy(&out.stderr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decrypt_file_threads(ct: &std::path::Path, rt: &std::path::Path, threads: usize) {
|
||||||
|
let key = key_file_near(ct);
|
||||||
|
let out = fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("-i")
|
||||||
|
.arg(ct)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(rt)
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(key)
|
||||||
|
.arg("-j")
|
||||||
|
.arg(threads.to_string())
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
out.status.success(),
|
||||||
|
"decrypt -j{threads} failed: {}",
|
||||||
|
String::from_utf8_lossy(&out.stderr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn roundtrip_multi_threaded() {
|
||||||
|
// Multi-chunk input. Encrypt+decrypt with -j 4 must round-trip.
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let ct = dir.path().join("c.bin");
|
||||||
|
let rt = dir.path().join("r.bin");
|
||||||
|
let data = pseudo_random(11, 5 * 1024 * 1024 + 12345);
|
||||||
|
fs::write(&plain, &data).unwrap();
|
||||||
|
|
||||||
|
encrypt_file_threads(&plain, &ct, Some(64 * 1024), 4);
|
||||||
|
decrypt_file_threads(&ct, &rt, 4);
|
||||||
|
assert_eq!(fs::read(&rt).unwrap(), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parallel_and_serial_outputs_round_trip() {
|
||||||
|
// Encrypt with -j 4 and decrypt serially (and vice-versa); both directions
|
||||||
|
// must yield the original plaintext.
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let data = pseudo_random(13, 256 * 1024 + 17);
|
||||||
|
fs::write(&plain, &data).unwrap();
|
||||||
|
|
||||||
|
let ct_par = dir.path().join("c_par.bin");
|
||||||
|
let ct_ser = dir.path().join("c_ser.bin");
|
||||||
|
encrypt_file_threads(&plain, &ct_par, Some(8192), 4);
|
||||||
|
encrypt_file_threads(&plain, &ct_ser, Some(8192), 1);
|
||||||
|
|
||||||
|
let rt1 = dir.path().join("r1.bin");
|
||||||
|
let rt2 = dir.path().join("r2.bin");
|
||||||
|
// par-encrypted, serial-decrypted
|
||||||
|
decrypt_file_threads(&ct_par, &rt1, 1);
|
||||||
|
// serial-encrypted, par-decrypted
|
||||||
|
decrypt_file_threads(&ct_ser, &rt2, 4);
|
||||||
|
assert_eq!(fs::read(&rt1).unwrap(), data);
|
||||||
|
assert_eq!(fs::read(&rt2).unwrap(), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn roundtrip_pipe_multi_threaded() {
|
||||||
|
// stdin/stdout mode with -j 4: length flag must NOT be set (no committed
|
||||||
|
// length when we don't know the input size), but encrypt/decrypt must still
|
||||||
|
// round-trip cleanly across the pipeline.
|
||||||
|
let data = pseudo_random(14, 200_000);
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let key = write_key_file(dir.path());
|
||||||
|
|
||||||
|
let mut enc = fcry()
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(&key)
|
||||||
|
.arg("-j")
|
||||||
|
.arg("4")
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.stderr(Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
enc.stdin.as_mut().unwrap().write_all(&data).unwrap();
|
||||||
|
let enc_out = enc.wait_with_output().unwrap();
|
||||||
|
assert!(
|
||||||
|
enc_out.status.success(),
|
||||||
|
"pipe encrypt -j4 failed: {}",
|
||||||
|
String::from_utf8_lossy(&enc_out.stderr)
|
||||||
|
);
|
||||||
|
|
||||||
|
// flags byte at offset 6 must not set length commitment for stdin input.
|
||||||
|
assert_eq!(
|
||||||
|
enc_out.stdout[6] & 0x01,
|
||||||
|
0,
|
||||||
|
"stdin-encrypted file unexpectedly committed length"
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut dec = fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(&key)
|
||||||
|
.arg("-j")
|
||||||
|
.arg("4")
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.stderr(Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
dec.stdin
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.write_all(&enc_out.stdout)
|
||||||
|
.unwrap();
|
||||||
|
let dec_out = dec.wait_with_output().unwrap();
|
||||||
|
assert!(
|
||||||
|
dec_out.status.success(),
|
||||||
|
"pipe decrypt -j4 failed: {}",
|
||||||
|
String::from_utf8_lossy(&dec_out.stderr)
|
||||||
|
);
|
||||||
|
assert_eq!(dec_out.stdout, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn stdin_chunk_size_zero_fails_but_empty_valid_chunk_succeeds() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let key = write_key_file(dir.path());
|
||||||
|
let mut bad = fcry()
|
||||||
|
.arg("--chunk-size")
|
||||||
|
.arg("0")
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(&key)
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.stderr(Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
// Invalid options can make the child exit before it drains stdin.
|
||||||
|
if let Err(err) = bad.stdin.as_mut().unwrap().write_all(b"x") {
|
||||||
|
assert_eq!(
|
||||||
|
err.kind(),
|
||||||
|
ErrorKind::BrokenPipe,
|
||||||
|
"unexpected stdin write error for failing chunk-size 0 process: {err}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let bad_out = bad.wait_with_output().unwrap();
|
||||||
|
assert!(!bad_out.status.success(), "chunk-size 0 should fail");
|
||||||
|
|
||||||
|
let mut good = fcry()
|
||||||
|
.arg("--chunk-size")
|
||||||
|
.arg("1")
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(&key)
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.stderr(Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
drop(good.stdin.take());
|
||||||
|
let good_out = good.wait_with_output().unwrap();
|
||||||
|
assert!(
|
||||||
|
good_out.status.success(),
|
||||||
|
"empty stdin with valid chunk should succeed: {}",
|
||||||
|
String::from_utf8_lossy(&good_out.stderr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn huge_thread_count_is_bounded() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let ct = dir.path().join("c.bin");
|
||||||
|
fs::write(&plain, b"hello").unwrap();
|
||||||
|
let out = fcry()
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&plain)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(&ct)
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(write_key_file(dir.path()))
|
||||||
|
.arg("-j")
|
||||||
|
.arg("1000000")
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
out.status.success(),
|
||||||
|
"huge -j should be capped, got {}",
|
||||||
|
String::from_utf8_lossy(&out.stderr)
|
||||||
|
);
|
||||||
|
assert!(String::from_utf8_lossy(&out.stderr).contains("capped"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn forged_huge_chunk_header_fails_before_allocation() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let forged = dir.path().join("forged.bin");
|
||||||
|
let mut bytes = Vec::new();
|
||||||
|
bytes.extend_from_slice(b"fcry");
|
||||||
|
bytes.push(3); // version
|
||||||
|
bytes.push(1); // alg
|
||||||
|
bytes.push(0x02); // key commitment flag
|
||||||
|
bytes.push(0); // reserved
|
||||||
|
bytes.extend_from_slice(&u32::MAX.to_le_bytes());
|
||||||
|
fs::write(&forged, bytes).unwrap();
|
||||||
|
|
||||||
|
let out = fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&forged)
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(write_key_file(dir.path()))
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(!out.status.success(), "huge chunk header should fail");
|
||||||
|
assert!(
|
||||||
|
String::from_utf8_lossy(&out.stderr).contains("chunk_size"),
|
||||||
|
"expected chunk_size error, got {}",
|
||||||
|
String::from_utf8_lossy(&out.stderr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn file_input_commits_length() {
|
||||||
|
// Encrypting from a regular file must auto-set FLAG_LENGTH_COMMITTED (bit 0
|
||||||
|
// of the flags byte at offset 6) and embed the length.
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let ct = dir.path().join("c.bin");
|
||||||
|
let data = pseudo_random(15, 50_000);
|
||||||
|
fs::write(&plain, &data).unwrap();
|
||||||
|
encrypt_file(&plain, &ct, Some(4096));
|
||||||
|
|
||||||
|
let bytes = fs::read(&ct).unwrap();
|
||||||
|
// Magic(4) + version(1) + alg(1) + flags(1) = byte 6
|
||||||
|
assert_eq!(bytes[4], 3, "version should be 3");
|
||||||
|
assert_eq!(bytes[6] & 0x01, 0x01, "length-committed flag should be set");
|
||||||
|
assert_eq!(bytes[6] & 0x02, 0x02, "key-committed flag should be set");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn v3_downgrade_or_commitment_stripping_fails_authentication() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let ct = dir.path().join("c.bin");
|
||||||
|
let rt = dir.path().join("r.bin");
|
||||||
|
fs::write(&plain, pseudo_random(51, 1000)).unwrap();
|
||||||
|
encrypt_file(&plain, &ct, None);
|
||||||
|
|
||||||
|
let mut bytes = fs::read(&ct).unwrap();
|
||||||
|
bytes[4] = 2;
|
||||||
|
bytes[6] &= !0x02;
|
||||||
|
fs::write(&ct, bytes).unwrap();
|
||||||
|
|
||||||
|
let out = fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&ct)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(&rt)
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(key_file_near(&ct))
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
!out.status.success(),
|
||||||
|
"downgraded/stripped v3 header must fail authentication"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encrypt_random_access_fixture(
|
||||||
|
dir: &std::path::Path,
|
||||||
|
data: &[u8],
|
||||||
|
chunk_size: u32,
|
||||||
|
) -> std::path::PathBuf {
|
||||||
|
let plain = dir.join("p.bin");
|
||||||
|
let ct = dir.join("c.bin");
|
||||||
|
fs::write(&plain, data).unwrap();
|
||||||
|
encrypt_file(&plain, &ct, Some(chunk_size));
|
||||||
|
ct
|
||||||
|
}
|
||||||
|
|
||||||
|
fn random_access_decrypt(
|
||||||
|
ct: &std::path::Path,
|
||||||
|
out: &std::path::Path,
|
||||||
|
offset: u64,
|
||||||
|
length: u64,
|
||||||
|
) -> std::process::Output {
|
||||||
|
fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("-i")
|
||||||
|
.arg(ct)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(out)
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(key_file_near(ct))
|
||||||
|
.arg("--offset")
|
||||||
|
.arg(offset.to_string())
|
||||||
|
.arg("--length")
|
||||||
|
.arg(length.to_string())
|
||||||
|
.output()
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn random_access_decrypt_slices() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let chunk = 4096u32;
|
||||||
|
let total = 5 * 1024 * 1024 + 12345;
|
||||||
|
let data = pseudo_random(16, total);
|
||||||
|
let ct = encrypt_random_access_fixture(dir.path(), &data, chunk);
|
||||||
|
|
||||||
|
// (offset, length) cases:
|
||||||
|
// - chunk-aligned start, mid-chunk end
|
||||||
|
// - mid-chunk start crossing several chunks
|
||||||
|
// - last partial chunk
|
||||||
|
// - last byte
|
||||||
|
// - entire file
|
||||||
|
let cases: &[(u64, u64)] = &[
|
||||||
|
(0, 1),
|
||||||
|
(chunk as u64, 7),
|
||||||
|
(chunk as u64 - 5, 100),
|
||||||
|
(10, chunk as u64 * 3 + 17),
|
||||||
|
(total as u64 - 1, 1),
|
||||||
|
(total as u64 - 100, 100),
|
||||||
|
(0, total as u64),
|
||||||
|
];
|
||||||
|
for (i, (offset, length)) in cases.iter().copied().enumerate() {
|
||||||
|
let out = dir.path().join(format!("slice_{i}.bin"));
|
||||||
|
let r = random_access_decrypt(&ct, &out, offset, length);
|
||||||
|
assert!(
|
||||||
|
r.status.success(),
|
||||||
|
"slice {i} ({offset}, {length}) failed: {}",
|
||||||
|
String::from_utf8_lossy(&r.stderr)
|
||||||
|
);
|
||||||
|
let got = fs::read(&out).unwrap();
|
||||||
|
let expected = &data[offset as usize..(offset + length) as usize];
|
||||||
|
assert_eq!(got, expected, "slice {i} mismatch");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn random_access_rejects_out_of_range() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let data = pseudo_random(17, 1000);
|
||||||
|
let ct = encrypt_random_access_fixture(dir.path(), &data, 256);
|
||||||
|
let out = dir.path().join("oob.bin");
|
||||||
|
let r = random_access_decrypt(&ct, &out, 900, 1000); // 900+1000 > 1000
|
||||||
|
assert!(!r.status.success(), "out-of-range slice should fail");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn random_access_rejects_stdin_encrypted() {
|
||||||
|
// Encrypt via stdin → no length committed → random access must refuse.
|
||||||
|
let data = pseudo_random(18, 2000);
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let ct = dir.path().join("c.bin");
|
||||||
|
let key = write_key_file(dir.path());
|
||||||
|
|
||||||
|
let mut enc = fcry()
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(&key)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(&ct)
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.stderr(Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
enc.stdin.as_mut().unwrap().write_all(&data).unwrap();
|
||||||
|
assert!(enc.wait().unwrap().success());
|
||||||
|
|
||||||
|
let out = dir.path().join("slice.bin");
|
||||||
|
let r = random_access_decrypt(&ct, &out, 0, 100);
|
||||||
|
assert!(
|
||||||
|
!r.status.success(),
|
||||||
|
"random access on stdin-encrypted file should fail"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn random_access_rejects_zero_length() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let data = pseudo_random(19, 1000);
|
||||||
|
let ct = encrypt_random_access_fixture(dir.path(), &data, 256);
|
||||||
|
let out = dir.path().join("empty.bin");
|
||||||
|
let r = random_access_decrypt(&ct, &out, 500, 0);
|
||||||
|
assert!(!r.status.success(), "zero-length slice should fail");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn random_access_tampered_length_fails() {
|
||||||
|
// Flip a byte inside the committed plaintext_length field. The header is
|
||||||
|
// AAD for every chunk, so the AEAD must reject decryption.
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let data = pseudo_random(20, 4000);
|
||||||
|
let ct = encrypt_random_access_fixture(dir.path(), &data, 1024);
|
||||||
|
let mut bytes = fs::read(&ct).unwrap();
|
||||||
|
// For raw-kdf header: magic(4)+ver(1)+alg(1)+flags(1)+rsv(1)+chunksize(4)+kdf_id(1)+nonce_prefix(19) = 32
|
||||||
|
// plaintext_length is at offset 32..40.
|
||||||
|
bytes[34] ^= 0xff;
|
||||||
|
fs::write(&ct, &bytes).unwrap();
|
||||||
|
let out = dir.path().join("bad.bin");
|
||||||
|
let r = random_access_decrypt(&ct, &out, 0, 100);
|
||||||
|
assert!(
|
||||||
|
!r.status.success(),
|
||||||
|
"tampered plaintext_length must fail authentication"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn buffer_verify_stdout_emits_nothing_on_truncated_ciphertext() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let ct = dir.path().join("c.bin");
|
||||||
|
fs::write(&plain, pseudo_random(61, 3 * 1024 * 1024)).unwrap();
|
||||||
|
encrypt_file(&plain, &ct, Some(64 * 1024));
|
||||||
|
let mut bytes = fs::read(&ct).unwrap();
|
||||||
|
bytes.truncate(bytes.len() - 32);
|
||||||
|
fs::write(&ct, bytes).unwrap();
|
||||||
|
|
||||||
|
let out = fcry()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&ct)
|
||||||
|
.arg("--buffer-verify")
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(key_file_near(&ct))
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(!out.status.success(), "truncated decrypt should fail");
|
||||||
|
assert!(
|
||||||
|
out.stdout.is_empty(),
|
||||||
|
"buffer-verify must suppress partial stdout"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_zero_threads() {
|
||||||
|
// -j 0 is almost certainly a user mistake. Clap should reject it before
|
||||||
|
// we ever reach the pipeline.
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
fs::write(&plain, b"hello").unwrap();
|
||||||
|
let out = fcry()
|
||||||
|
.arg("-i")
|
||||||
|
.arg(&plain)
|
||||||
|
.arg("-o")
|
||||||
|
.arg(dir.path().join("c.bin"))
|
||||||
|
.arg("--key-file")
|
||||||
|
.arg(write_key_file(dir.path()))
|
||||||
|
.arg("-j")
|
||||||
|
.arg("0")
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
assert!(!out.status.success(), "-j 0 should be rejected");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn header_chunk_size_is_authoritative_on_decrypt() {
|
||||||
|
// Encrypt with a non-default chunk size; decrypt without specifying one.
|
||||||
|
// The decryptor must read chunk_size from the header.
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let plain = dir.path().join("p.bin");
|
||||||
|
let ct = dir.path().join("c.bin");
|
||||||
|
let rt = dir.path().join("r.bin");
|
||||||
|
let data = pseudo_random(5, 100_000);
|
||||||
|
fs::write(&plain, &data).unwrap();
|
||||||
|
encrypt_file(&plain, &ct, Some(7919)); // prime, deliberately weird
|
||||||
|
decrypt_file(&ct, &rt);
|
||||||
|
assert_eq!(fs::read(&rt).unwrap(), data);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user