From 695a4ca4dad3548b7b34747a0da034a8b44941ab Mon Sep 17 00:00:00 2001 From: astar76 Date: Wed, 25 Nov 2026 07:45:25 -0600 Subject: [PATCH] S011: FTP, FTPS, SFTP and folder listings Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 1155 +++++++++++++++++++++++++++++- Plans/02 Engine/S011-ftp-sftp.md | 14 +- Plans/INDEX.md | 2 +- crates/core/Cargo.toml | 12 +- crates/core/lang/en.json | 10 + crates/core/src/error.rs | 9 +- crates/core/src/ftp.rs | 388 ++++++++++ crates/core/src/http/mod.rs | 65 +- crates/core/src/http/parts.rs | 4 +- crates/core/src/lib.rs | 4 + crates/core/src/listing.rs | 238 ++++++ crates/core/src/paths.rs | 5 + crates/core/src/proxy.rs | 17 +- crates/core/src/sftp/known.rs | 165 +++++ crates/core/src/sftp/mod.rs | 351 +++++++++ crates/core/src/site.rs | 50 +- crates/core/src/tls.rs | 7 +- crates/core/src/transport.rs | 365 ++++++++++ crates/core/tests/ftp/ftpd.rs | 221 ++++++ crates/core/tests/ftp/main.rs | 435 +++++++++++ crates/core/tests/ftp/sshd.rs | 233 ++++++ docs/DECISIONS.md | 3 + docs/PROGRESS.md | 9 + 23 files changed, 3720 insertions(+), 42 deletions(-) create mode 100644 crates/core/src/ftp.rs create mode 100644 crates/core/src/listing.rs create mode 100644 crates/core/src/sftp/known.rs create mode 100644 crates/core/src/sftp/mod.rs create mode 100644 crates/core/src/transport.rs create mode 100644 crates/core/tests/ftp/ftpd.rs create mode 100644 crates/core/tests/ftp/main.rs create mode 100644 crates/core/tests/ftp/sshd.rs diff --git a/Cargo.lock b/Cargo.lock index b25d0ad..d43965f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -118,6 +118,43 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" +[[package]] +name = "aead" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1973cfbc1a2daf9cf550e74e1f088c28e7f7d8c1e1418fb6c9dc5184b7e84c99" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] +name = "aes" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fc36d7440d015b45468ba08a21e80e056ebbd014c611c6298bb7503e04bd1" +dependencies = [ + "cipher", + "cpubits", + "cpufeatures", + "zeroize", +] + +[[package]] +name = "aes-gcm" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f2b8006a0c83f52b62ba44a97b58bf76fe2f70a329e588f67f89691d93d498f" +dependencies = [ + "aead", + "aes", + "cipher", + "ctr", + "ctutils", + "ghash", + "zeroize", +] + [[package]] name = "ahash" version = "0.8.13" @@ -211,6 +248,18 @@ dependencies = [ "rustversion", ] +[[package]] +name = "argon2" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "134c52ddac6d63c576bef8168db10c83c49c26444ecbc68060fef078925a901c" +dependencies = [ + "base64ct", + "blake2", + "cpufeatures", + "password-hash", +] + [[package]] name = "arrayref" version = "0.3.9" @@ -457,6 +506,12 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" +[[package]] +name = "base16ct" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd307490d624467aa6f74b0eabb77633d1f758a7b25f12bceb0b22e08d9726f6" + [[package]] name = "base64" version = "0.22.1" @@ -469,6 +524,23 @@ version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" +[[package]] +name = "base64ct" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" + +[[package]] +name = "bcrypt-pbkdf" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "144e573728da132683b9488acd528274c790e07fc06ff81ee29f9d8f8b1041e0" +dependencies = [ + "blowfish", + "pbkdf2", + "sha2", +] + [[package]] name = "bit-set" version = "0.10.0" @@ -502,11 +574,30 @@ dependencies = [ "serde_core", ] +[[package]] +name = "blake2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b5d4d889834ee8ecfc0f8426ad30faf7cdcb10f741a8e6d7224d95325479f6f" +dependencies = [ + "digest", +] + [[package]] name = "block-buffer" version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa" +dependencies = [ + "hybrid-array", + "zeroize", +] + +[[package]] +name = "block-padding" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "710f1dd022ef4e93f8a438b4ba958de7f64308434fa6a87104481645cc30068b" dependencies = [ "hybrid-array", ] @@ -542,6 +633,16 @@ dependencies = [ "piper", ] +[[package]] +name = "blowfish" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62ce3946557b35e71d1bbe07ec385073ce9eda05043f95de134eb578fcf1a298" +dependencies = [ + "byteorder", + "cipher", +] + [[package]] name = "bumpalo" version = "3.20.4" @@ -568,6 +669,12 @@ dependencies = [ "syn 3.0.10", ] +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "byteorder-lite" version = "0.1.0" @@ -606,6 +713,15 @@ dependencies = [ "wayland-client", ] +[[package]] +name = "cbc" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce2dc9ee5f88d11e0beb842c88b33c8a5cf0d1329c4b19494af42b07dbfe8896" +dependencies = [ + "cipher", +] + [[package]] name = "cc" version = "1.11.3" @@ -639,6 +755,19 @@ dependencies = [ "libc", ] +[[package]] +name = "chacha20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", + "rand_core", + "zeroize", +] + [[package]] name = "chrono" version = "0.4.45" @@ -646,10 +775,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" dependencies = [ "iana-time-zone", + "js-sys", "num-traits", + "wasm-bindgen", "windows-link", ] +[[package]] +name = "cipher" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c" +dependencies = [ + "block-buffer", + "crypto-common", + "inout", + "zeroize", +] + [[package]] name = "clipboard-win" version = "5.4.3" @@ -659,6 +802,12 @@ dependencies = [ "error-code", ] +[[package]] +name = "cmov" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a" + [[package]] name = "codespan-reporting" version = "0.13.1" @@ -754,6 +903,12 @@ dependencies = [ "libc", ] +[[package]] +name = "cpubits" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae" + [[package]] name = "cpufeatures" version = "0.3.1" @@ -784,13 +939,61 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" +[[package]] +name = "crypto-bigint" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "914c195c4d7fbc5ed7f88d14cbf85914d5c664967658d43404b263913a477e82" +dependencies = [ + "cpubits", + "ctutils", + "getrandom 0.4.3", + "hybrid-array", + "num-traits", + "rand_core", + "serdect", + "subtle", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" dependencies = [ + "getrandom 0.4.3", "hybrid-array", + "rand_core", +] + +[[package]] +name = "crypto-primes" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3633a51a39c69ebbaa4feaa694bd83d241e4093901c84a0963b19d9bb3f0cf8f" +dependencies = [ + "crypto-bigint", + "rand_core", +] + +[[package]] +name = "ctr" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baaca1c4b237092596f64d571e9db6ce4109c4ef9742e27590f1709594461f21" +dependencies = [ + "cipher", +] + +[[package]] +name = "ctutils" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261af4dc7a06ea8a527a8717d8cbba3417530d6ea14e1edb3de6b67806be474f" +dependencies = [ + "cmov", + "subtle", ] [[package]] @@ -799,6 +1002,48 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f27ae1dd37df86211c42e150270f82743308803d90a6f6e6651cd730d5e1732f" +[[package]] +name = "curve25519-dalek" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5eed333089e2e1c1ac8c6c0398e5e2497b4c9926ca6d0365ed1e099afa5bc23" +dependencies = [ + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest", + "fiat-crypto", + "rand_core", + "rustc_version", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "dashmap" +version = "6.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6361d5c062261c78a176addb82d4c821ae42bed6089de0e12603cd25de2059c" +dependencies = [ + "cfg-if", + "crossbeam-utils", + "hashbrown 0.14.5", + "lock_api", + "once_cell", + "parking_lot_core", +] + [[package]] name = "data-encoding" version = "2.11.1" @@ -811,6 +1056,28 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be1e0bca6c3637f992fc1cc7cbc52a78c1ef6db076dbf1059c4323d6a2048376" +[[package]] +name = "delegate" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "780eb241654bf097afb00fc5f054a09b687dad862e485fdcf8399bb056565370" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "der" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a996a108feb8b427a6e12fcf6af4aa83409b79d72c15337d7741368131ee004" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + [[package]] name = "der-parser" version = "10.0.0" @@ -820,7 +1087,7 @@ dependencies = [ "asn1-rs", "displaydoc", "nom 7.1.3", - "num-bigint", + "num-bigint 0.4.8", "num-traits", "rusticata-macros", ] @@ -831,6 +1098,15 @@ version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e9de72ce2ad1f90dc62fa25f0f430ef85eb4b0d8fa0be4f30373bc40a21d28e" +[[package]] +name = "des" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "916a94e407b54f9034d71dd748234cd1e516ced6284009906ae246f177eafe5a" +dependencies = [ + "cipher", +] + [[package]] name = "digest" version = "0.11.3" @@ -840,6 +1116,8 @@ dependencies = [ "block-buffer", "const-oid", "crypto-common", + "ctutils", + "zeroize", ] [[package]] @@ -920,6 +1198,21 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76" +[[package]] +name = "ecdsa" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0681a4fc24c767085329728d8dfba959af91228aa4610cca4f8ce317ba46ae0" +dependencies = [ + "der", + "digest", + "elliptic-curve", + "rfc6979", + "signature", + "spki", + "zeroize", +] + [[package]] name = "ecolor" version = "0.37.0" @@ -931,6 +1224,32 @@ dependencies = [ "serde", ] +[[package]] +name = "ed25519" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29fcf32e6c73d1079f83ab4d782de2d81620346a5f38c6237a86a22f8368980a" +dependencies = [ + "pkcs8", + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ebaa1a2bf1290ab3bfe5a7b771d050ebffab2711c19a81691c683a5144a25de" +dependencies = [ + "curve25519-dalek", + "ed25519", + "rand_core", + "serde", + "sha2", + "signature", + "subtle", + "zeroize", +] + [[package]] name = "eframe" version = "0.37.0" @@ -1090,6 +1409,28 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be" +[[package]] +name = "elliptic-curve" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900f37e7e18d74a2347389af6cd69e3a30d5cc9e697f40004865679aa75e9c7c" +dependencies = [ + "base16ct", + "crypto-bigint", + "crypto-common", + "digest", + "ff", + "group", + "hkdf", + "hybrid-array", + "pem-rfc7468", + "pkcs8", + "rand_core", + "sec1", + "subtle", + "zeroize", +] + [[package]] name = "emath" version = "0.37.0" @@ -1106,6 +1447,18 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "66b7e2430c6dff6a955451e2cfc438f09cea1965a9d6f87f7e3b90decc014099" +[[package]] +name = "enum_dispatch" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa18ce2bc66555b3218614519ac839ddb759a7d6720732f979ef8d13be147ecd" +dependencies = [ + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "enumflags2" version = "0.7.12" @@ -1261,6 +1614,22 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b97b65636e5b9ef369943878ac74335ba1c55c1cb6adbf1e2c293c624248d693" +[[package]] +name = "ff" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f686ab92a9fb0eaf188f6c6c87b89490baa6fdb0db4544ba4dc47f7942489f" +dependencies = [ + "rand_core", + "subtle", +] + +[[package]] +name = "fiat-crypto" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64cd1e32ddd350061ae6edb1b082d7c54915b5c672c389143b9a63403a109f24" + [[package]] name = "find-msvc-tools" version = "0.1.15" @@ -1370,6 +1739,21 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a31d2a3fbaaeb2af2368bbdd904aa8e812d3c04a1ee10d3171f52d556e5d0a3" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.34" @@ -1377,6 +1761,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -1385,6 +1770,17 @@ version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" +[[package]] +name = "futures-executor" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031b47cf1a3c6cc8bc2fc76cd437f521619387907d469316e7c0bc278f1f5432" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + [[package]] name = "futures-io" version = "0.3.34" @@ -1415,6 +1811,12 @@ dependencies = [ "syn 3.0.10", ] +[[package]] +name = "futures-sink" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" + [[package]] name = "futures-task" version = "0.3.34" @@ -1427,9 +1829,13 @@ version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" dependencies = [ + "futures-channel", "futures-core", + "futures-io", "futures-macro", + "futures-sink", "futures-task", + "memchr", "pin-project-lite", "slab", ] @@ -1465,9 +1871,20 @@ dependencies = [ "js-sys", "libc", "r-efi", + "rand_core", "wasm-bindgen", ] +[[package]] +name = "ghash" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eecf2d5dc9b66b732b97707a0210906b1d30523eb773193ab777c0c84b3e8d5" +dependencies = [ + "polyval", + "zeroize", +] + [[package]] name = "gl_generator" version = "0.14.0" @@ -1496,6 +1913,18 @@ dependencies = [ "vello_common", ] +[[package]] +name = "gloo-timers" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4460540da666acdb5722b2a62ac47d18f627fcfc0c728d04dc7226b3f6d40a7" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "glow" version = "0.17.0" @@ -1588,6 +2017,17 @@ dependencies = [ "windows", ] +[[package]] +name = "group" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fd1a1c7a5206c5b7a3f5a0d7ccd3ff85d0c8f5133d62a02680255b0004af5f4" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + [[package]] name = "guillotiere" version = "0.7.0" @@ -1621,6 +2061,12 @@ dependencies = [ "smallvec", ] +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + [[package]] name = "hashbrown" version = "0.15.5" @@ -1671,6 +2117,30 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hex-literal" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e712f64ec3850b98572bffac52e2c6f282b29fe6c5fa6d42334b30be438d95c1" + +[[package]] +name = "hkdf" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4aaa26c720c68b866f2c96ef5c1264b3e6f473fe5d4ce61cd44bbe913e553018" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f" +dependencies = [ + "digest", +] + [[package]] name = "http" version = "1.5.0" @@ -1716,7 +2186,10 @@ version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17" dependencies = [ + "ctutils", + "subtle", "typenum", + "zeroize", ] [[package]] @@ -1935,6 +2408,16 @@ dependencies = [ "hashbrown 0.17.2", ] +[[package]] +name = "inout" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a580c13f0ffc335ef42dd3f6b1a41b726051c5e1656d9a3aa6fddb3c5dfbbf9" +dependencies = [ + "block-padding", + "hybrid-array", +] + [[package]] name = "ipnet" version = "2.12.2" @@ -1956,6 +2439,43 @@ version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" +[[package]] +name = "jiff" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "107f2e89536b6818514025f6787b0d94d819e54fe3b40365275fc753de485b3f" +dependencies = [ + "jiff-core", + "jiff-static", + "js-sys", + "log", + "portable-atomic", + "portable-atomic-util", + "serde_core", + "wasm-bindgen", +] + +[[package]] +name = "jiff-core" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d44c923edf2bf456a982253f1a9ee1f6e89e421dffd0065d9b9a581da0def58f" +dependencies = [ + "log", +] + +[[package]] +name = "jiff-static" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4996f71e569e3a3e32b925c28ef8f0027dc30bb1d594b33eeda409eea185f5c8" +dependencies = [ + "jiff-core", + "proc-macro2", + "quote", + "syn 3.0.10", +] + [[package]] name = "jni" version = "0.22.4" @@ -2035,6 +2555,26 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "keccak" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8f198d1db720e4940b5a493201d199d9f24f568f8f746bd13706243a2f71598" +dependencies = [ + "cfg-if", + "cpufeatures", +] + +[[package]] +name = "kem" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01737161ba802849cfd486b5bd209d38ba4943494c249a8126005170c7621edd" +dependencies = [ + "crypto-common", + "rand_core", +] + [[package]] name = "khronos-egl" version = "6.0.0" @@ -2191,6 +2731,12 @@ dependencies = [ "digest", ] +[[package]] +name = "md5" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ebb8d8732c6a6df3d8f032a82911cfc747e00efb95cc46e8d0acd5b5b88570c" + [[package]] name = "medlar" version = "0.1.0" @@ -2223,18 +2769,25 @@ name = "medlar-core" version = "0.1.0" dependencies = [ "arc-swap", + "base64 0.23.1", "bytes", "chrono", "dirs", "fastrand", "futures-lite", + "http", + "http-body", + "hyper-util", "log", "md-5", "medlar-testserver", "percent-encoding", + "rcgen", "regex", "reqwest", "rusqlite", + "russh", + "russh-sftp", "rustix 1.1.6", "rustls", "rustls-platform-verifier", @@ -2243,6 +2796,8 @@ dependencies = [ "sha2", "tempfile", "tokio", + "tokio-rustls", + "tower-service", "url", "zbus", ] @@ -2321,6 +2876,32 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "ml-kem" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84ca78b66f46050d49fa21693ae8adab2081d8101b65d8067316b6b70b64a0d1" +dependencies = [ + "hybrid-array", + "kem", + "module-lattice", + "pkcs8", + "rand_core", + "sha3", + "shake", +] + +[[package]] +name = "module-lattice" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e412c8ee83a1c678f427806219c49c96b2511b9f07497514f0e43fb26155" +dependencies = [ + "ctutils", + "hybrid-array", + "num-traits", +] + [[package]] name = "moxcms" version = "0.8.1" @@ -2399,6 +2980,18 @@ dependencies = [ "jni-sys 0.3.1", ] +[[package]] +name = "nix" +version = "0.31.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bc81ce8148d3b4f3274da811f11cdd824ae661ee4ef732cdb229825cf5be7f7" +dependencies = [ + "bitflags 2.13.2", + "cfg-if", + "cfg_aliases", + "libc", +] + [[package]] name = "nohash-hasher" version = "0.2.0" @@ -2434,6 +3027,18 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-bigint" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93e7820bc0a80a0238e650327316f929ba18d5be054b647490a3a6a339f3e7c0" +dependencies = [ + "num-integer", + "num-traits", + "rand", + "rand_core", +] + [[package]] name = "num-conv" version = "0.2.2" @@ -2868,6 +3473,67 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "p256" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2c9239b2dbc807adbbe147e8cf72ea7450c3a0aabe62cb8e75ff4ec22e1f72a" +dependencies = [ + "ecdsa", + "elliptic-curve", + "primefield", + "primeorder", + "sha2", +] + +[[package]] +name = "p384" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d17b851e6b3e378ab4ecb07fa2ed23f4d15f075735f8fec9fa1e7bdce5f8301f" +dependencies = [ + "ecdsa", + "elliptic-curve", + "fiat-crypto", + "primefield", + "primeorder", + "sha2", +] + +[[package]] +name = "p521" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ad64cc32c2dc466317c12ee5853e61f159f9eab1fe7efade0395dc2e7b43449" +dependencies = [ + "base16ct", + "ecdsa", + "elliptic-curve", + "primefield", + "primeorder", + "sha2", +] + +[[package]] +name = "pageant" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0bc922d9aa8cfcf598de27b3c6122cb2eeda9d6fe71527a22ebcb7f633540ff" +dependencies = [ + "base16ct", + "byteorder", + "bytes", + "delegate", + "futures", + "log", + "rand", + "sha2", + "thiserror 2.0.21", + "tokio", + "windows", + "windows-strings", +] + [[package]] name = "parking" version = "2.2.1" @@ -2903,6 +3569,25 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73072a9470554c8e794778acece2312661218aaabb635600957d952cf01c716e" +[[package]] +name = "password-hash" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aab41826031698d6ffcd9cff78ef56ef998e39dc7e5067cdfebe373842d4723b" +dependencies = [ + "phc", +] + +[[package]] +name = "pbkdf2" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112d82ceb8c5bf524d9af484d4e4970c9fd5a0cc15ba14ad93dccd28873b0629" +dependencies = [ + "digest", + "hmac", +] + [[package]] name = "pem" version = "4.0.0" @@ -2913,6 +3598,15 @@ dependencies = [ "serde_core", ] +[[package]] +name = "pem-rfc7468" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6305423e0e7738146434843d1694d621cce767262b2a86910beab705e4493d9" +dependencies = [ + "base64ct", +] + [[package]] name = "peniko" version = "0.6.1" @@ -2943,6 +3637,16 @@ dependencies = [ "indexmap", ] +[[package]] +name = "phc" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44dc769b75f93afdddd8c7fa12d685292ddeff1e66f7f0f3a234cf1818afe892" +dependencies = [ + "base64ct", + "ctutils", +] + [[package]] name = "phf" version = "0.14.0" @@ -3029,6 +3733,45 @@ dependencies = [ "futures-io", ] +[[package]] +name = "pkcs1" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6250dd7321adbe93d12b750aee0ced159fd13e77f625edcdf1cb6f83cd99f650" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkcs5" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63d440a804ec8d6fafbb6b84471e013286658d373248927692ab3366686220ca" +dependencies = [ + "aes", + "aes-gcm", + "cbc", + "der", + "pbkdf2", + "rand_core", + "scrypt", + "sha2", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "451913da69c775a56034ea8d9003d27ee8948e12443eae7c038ba100a4f21cb7" +dependencies = [ + "der", + "pkcs5", + "rand_core", + "spki", +] + [[package]] name = "pkg-config" version = "0.3.34" @@ -3097,6 +3840,17 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e9b9cf600136f5b976fbc5727d58c26e1ecab8ee23088d44ef1c7af793550ab" +[[package]] +name = "poly1305" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e2d0073b297041425c7c3df6eb4792d598a15323fe63346852b092eca02904c" +dependencies = [ + "cpufeatures", + "universal-hash", + "zeroize", +] + [[package]] name = "polycool" version = "0.4.0" @@ -3106,6 +3860,18 @@ dependencies = [ "arrayvec", ] +[[package]] +name = "polyval" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0fa31d631f2b2cb2a544d0aa321ce847a94764d701ca2becc411138b93d49cd" +dependencies = [ + "cpubits", + "cpufeatures", + "universal-hash", + "zeroize", +] + [[package]] name = "portable-atomic" version = "1.15.0" @@ -3142,6 +3908,33 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa" +[[package]] +name = "primefield" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c555a6e4eb7d4e158fcb028c835c3b8642206ddc279b5c6b202ef9a8bdb592f4" +dependencies = [ + "crypto-bigint", + "crypto-common", + "ff", + "rand_core", + "subtle", + "zeroize", +] + +[[package]] +name = "primeorder" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c9f42978c78a00e3d68f69fc03e57a234debae69da4020a4fb588fcdcd07b06" +dependencies = [ + "elliptic-curve", + "once_cell", + "primefield", + "serdect", + "wnaf", +] + [[package]] name = "proc-macro-crate" version = "3.5.0" @@ -3202,6 +3995,23 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" +[[package]] +name = "rand" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f6fa277c67e6ea590466f04c3fe82cb509f0864fe470643e5570de9514a9b11" +dependencies = [ + "chacha20", + "getrandom 0.4.3", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + [[package]] name = "range-alloc" version = "0.1.5" @@ -3371,6 +4181,16 @@ dependencies = [ "usvg", ] +[[package]] +name = "rfc6979" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4a459cddafb3fe76b31fd8f1108007566c40301feb64dc7b54656eb7388172b" +dependencies = [ + "crypto-bigint", + "hmac", +] + [[package]] name = "rgb" version = "0.8.53" @@ -3422,6 +4242,27 @@ dependencies = [ "memchr", ] +[[package]] +name = "rsa" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23e77fd77e0dea28b3011fd62d15445b7de7959333b0276d930e03be0f755699" +dependencies = [ + "const-oid", + "crypto-bigint", + "crypto-common", + "crypto-primes", + "digest", + "hmac", + "pkcs1", + "pkcs8", + "rand_core", + "sha2", + "signature", + "spki", + "zeroize", +] + [[package]] name = "rsqlite-vfs" version = "0.2.0" @@ -3446,6 +4287,119 @@ dependencies = [ "sqlite-wasm-rs", ] +[[package]] +name = "russh" +version = "0.65.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "569d8c45e20c123af2fc5ecb4803fde0a98572449ba4c24ed97741d7b02fedf7" +dependencies = [ + "aes", + "bitflags 2.13.2", + "block-padding", + "byteorder", + "bytes", + "cbc", + "cipher", + "crypto-bigint", + "ctr", + "curve25519-dalek", + "data-encoding", + "delegate", + "der", + "digest", + "ecdsa", + "ed25519-dalek", + "elliptic-curve", + "enum_dispatch", + "futures", + "getrandom 0.4.3", + "ghash", + "hex-literal", + "hmac", + "inout", + "keccak", + "log", + "md5", + "ml-kem", + "module-lattice", + "num-bigint 0.5.1", + "p256", + "p384", + "p521", + "pageant", + "pbkdf2", + "pkcs1", + "pkcs5", + "pkcs8", + "polyval", + "rand", + "rand_core", + "ring", + "rsa", + "russh-cryptovec", + "russh-util", + "salsa20", + "scrypt", + "sec1", + "sha1", + "sha2", + "sha3", + "signature", + "spki", + "ssh-encoding", + "ssh-key", + "subtle", + "thiserror 2.0.21", + "tokio", + "typenum", + "universal-hash", + "zeroize", +] + +[[package]] +name = "russh-cryptovec" +version = "0.62.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3aec6cb630dbe85d72ffd7bcd95f07e1bd69f9f270ee8adfa1afe443a6331438" +dependencies = [ + "log", + "nix", + "ssh-encoding", + "windows-sys 0.61.2", +] + +[[package]] +name = "russh-sftp" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8067d56cde438de09db20be974be92118b85d671c7f50ea3b37cf9011760f0" +dependencies = [ + "bitflags 2.13.2", + "bytes", + "dashmap", + "gloo-timers", + "jiff", + "log", + "serde", + "serde_bytes", + "thiserror 2.0.21", + "tokio", + "tokio-util", + "wasm-bindgen-futures", +] + +[[package]] +name = "russh-util" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "668424a5dde0bcb45b55ba7de8476b93831b4aa2fa6947e145f3b053e22c60b6" +dependencies = [ + "chrono", + "tokio", + "wasm-bindgen", + "wasm-bindgen-futures", +] + [[package]] name = "rustc-hash" version = "1.1.0" @@ -3581,6 +4535,16 @@ version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" +[[package]] +name = "salsa20" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f874456e72520ff1375a06c588eaf074b0f01f9e9e1aada45bd9b7954a6e42c" +dependencies = [ + "cfg-if", + "cipher", +] + [[package]] name = "same-file" version = "1.0.6" @@ -3611,6 +4575,32 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "scrypt" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d87af57419b594aa23fa95f09f0e06d80d84ba01c26148c43844cad6ff4485f0" +dependencies = [ + "cfg-if", + "pbkdf2", + "salsa20", + "sha2", +] + +[[package]] +name = "sec1" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d56d437c2f19203ce5f7122e507831de96f3d2d4d3be5af44a0b0a09d8a80e4d" +dependencies = [ + "base16ct", + "ctutils", + "der", + "hybrid-array", + "subtle", + "zeroize", +] + [[package]] name = "security-framework" version = "3.7.0" @@ -3662,6 +4652,16 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde_bytes" +version = "0.11.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5d440709e79d88e51ac01c4b72fc6cb7314017bb7da9eeff678aa94c10e3ea8" +dependencies = [ + "serde", + "serde_core", +] + [[package]] name = "serde_core" version = "1.0.229" @@ -3715,6 +4715,16 @@ dependencies = [ "serde_core", ] +[[package]] +name = "serdect" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66cf8fedced2fcf12406bcb34223dffb92eaf34908ede12fed414c82b7f00b3e" +dependencies = [ + "base16ct", + "serde", +] + [[package]] name = "sha1" version = "0.11.0" @@ -3737,6 +4747,28 @@ dependencies = [ "digest", ] +[[package]] +name = "sha3" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc9bad02c26382724b2d2692c6f179285e4b54eeecd7968f52a50059c3c11759" +dependencies = [ + "digest", + "keccak", + "sponge-cursor", +] + +[[package]] +name = "shake" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09057cb2149ad4cbd2da1e26b351f9a4c354219421229c69c3063e6f61947c4a" +dependencies = [ + "digest", + "keccak", + "sponge-cursor", +] + [[package]] name = "shlex" version = "2.0.1" @@ -3753,6 +4785,16 @@ dependencies = [ "libc", ] +[[package]] +name = "signature" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d567dcbaf0049cb8ac2608a76cd95ff9e4412e1899d389ee400918ca7537f5" +dependencies = [ + "digest", + "rand_core", +] + [[package]] name = "simd-adler32" version = "0.3.10" @@ -3877,6 +4919,22 @@ dependencies = [ "bitflags 2.13.2", ] +[[package]] +name = "spki" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef958a98b9d5da290cfc78946e9f3e61e1e62a18db0d92cac0b83cc161491a9" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "sponge-cursor" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a0219bd7d979d58245a4f41f695e1ac9f8befdffadd7f61f1bae9e39abc6620" + [[package]] name = "sqlite-wasm-rs" version = "0.6.3" @@ -3887,6 +4945,65 @@ dependencies = [ "rsqlite-vfs", ] +[[package]] +name = "ssh-cipher" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d801accda99469cde6d73da741422610fdf6508a72d9a69d1b55cb241c720597" +dependencies = [ + "aead", + "aes", + "aes-gcm", + "chacha20", + "cipher", + "ctutils", + "des", + "poly1305", + "ssh-encoding", + "zeroize", +] + +[[package]] +name = "ssh-encoding" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b54d0ed0498daf3f78d82e00e28c8eec9d75a067c4cfbcc7a0f7d0f4077749e" +dependencies = [ + "base64ct", + "bytes", + "crypto-bigint", + "ctutils", + "digest", + "pem-rfc7468", + "zeroize", +] + +[[package]] +name = "ssh-key" +version = "0.7.0-rc.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0701b552e6bd8f13a6e07bde25307c32d7daad80a79b65832d110c0416e7b638" +dependencies = [ + "argon2", + "bcrypt-pbkdf", + "ctutils", + "ed25519-dalek", + "hex", + "hmac", + "p256", + "p384", + "p521", + "rand_core", + "rsa", + "sec1", + "sha1", + "sha2", + "signature", + "ssh-cipher", + "ssh-encoding", + "zeroize", +] + [[package]] name = "stable_deref_trait" version = "1.2.1" @@ -4165,6 +5282,20 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-util" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e464cf451ba96ebfc6f9b6542f17ee8b8956e33f1e40d9690624e59d7a7f8a4b" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "futures-util", + "pin-project-lite", + "tokio", +] + [[package]] name = "toml" version = "1.2.1+spec-1.1.0" @@ -4369,6 +5500,16 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca718471876992059f251e33aafc334346ada08042b7661dd1fe313a9bced557" +[[package]] +name = "universal-hash" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4987bdc12753382e0bec4a65c50738ffaabc998b9cdd1f952fb5f39b0048a96" +dependencies = [ + "crypto-common", + "ctutils", +] + [[package]] name = "untrusted" version = "0.9.0" @@ -5162,6 +6303,18 @@ dependencies = [ "wayland-protocols-wlr", ] +[[package]] +name = "wnaf" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "795ca18b3fdb5e62bf982199278341ddcf7ebf7d32e25e212ad05d496e95f6fa" +dependencies = [ + "ff", + "group", + "hybrid-array", + "primefield", +] + [[package]] name = "writeable" version = "0.6.4" diff --git a/Plans/02 Engine/S011-ftp-sftp.md b/Plans/02 Engine/S011-ftp-sftp.md index 84f03f5..569b8cd 100644 --- a/Plans/02 Engine/S011-ftp-sftp.md +++ b/Plans/02 Engine/S011-ftp-sftp.md @@ -11,13 +11,13 @@ FEATURES 1.9, plus directory listing used by the site explorer. - suppaftp and russh docs for the pinned versions ## Steps -- [ ] A transport trait drawn from the HTTP path, only as wide as needed -- [ ] FTP and FTPS: passive and extended passive, REST resume, SIZE, MDTM, segments when the server allows several logins -- [ ] SFTP: password and key logins, host key prompt and known_hosts style store, positioned reads in parallel -- [ ] Directory listing (MLSD, LIST variants, SFTP) as one type -- [ ] Errors mapped to S007's kinds if it is merged, else to the model's placeholder kinds -- [ ] In-process FTP and SFTP test servers on loopback (dev-dependency or small own stub) -- [ ] `docs/PROGRESS.md` entry, tick `Plans/INDEX.md`, commit `S011: …`, push +- [x] A transport trait drawn from the HTTP path, only as wide as needed +- [x] FTP and FTPS: passive and extended passive, REST resume, SIZE, MDTM, segments when the server allows several logins +- [x] SFTP: password and key logins, host key prompt and known_hosts style store, positioned reads in parallel +- [x] Directory listing (MLSD, LIST variants, SFTP) as one type +- [x] Errors mapped to S007's kinds if it is merged, else to the model's placeholder kinds +- [x] In-process FTP and SFTP test servers on loopback (dev-dependency or small own stub) +- [x] `docs/PROGRESS.md` entry, tick `Plans/INDEX.md`, commit `S011: …`, push ## End criteria - `nice cargo test -j 2 -p medlar-core --test ftp` green: resume, cut, wrong login, changed host key refused diff --git a/Plans/INDEX.md b/Plans/INDEX.md index de30a75..442997a 100644 --- a/Plans/INDEX.md +++ b/Plans/INDEX.md @@ -19,7 +19,7 @@ Tracker: https://claude.ai/artifact/XouimfVJS6FYVKskGJ8s7H - [x] [S008](02%20Engine/S008-continue-links.md) Continue from a new link - [ ] [S009](02%20Engine/S009-mirrors-checksums.md) Mirrors, Metalink and checksums - [x] [S010](02%20Engine/S010-logins-proxies.md) Logins, cookies and proxies -- [ ] [S011](02%20Engine/S011-ftp-sftp.md) FTP, FTPS and SFTP +- [x] [S011](02%20Engine/S011-ftp-sftp.md) FTP, FTPS and SFTP - [ ] [S012](02%20Engine/S012-streams.md) HLS, DASH, RTSP and MMS ## 03 Interface diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 08b063f..99fdc61 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -7,16 +7,23 @@ description = "Medlar's engine, store and settings" [dependencies] arc-swap = "1.9.5" +base64 = "0.23" bytes = "1.10" chrono = { version = "0.4", default-features = false, features = ["clock", "std"] } dirs = "6" futures-lite = "2.6" +http = "1.5" +http-body = "1.1" +hyper-util = { version = "0.1.21", default-features = false, features = ["client-legacy", "client-proxy", "http1", "tokio"] } log = { workspace = true, features = ["std"] } md-5 = "0.11.0" percent-encoding = "2.3.2" regex = { version = "1", default-features = false, features = ["std", "unicode-case", "unicode-perl"] } # Pinned: D-017. reqwest = { version = "=0.13.5", default-features = false, features = ["rustls-no-provider", "socks"] } +# ring, as everywhere else: aws-lc-rs would be a second one. +russh = { version = "=0.65.4", default-features = false, features = ["ring", "rsa"] } +russh-sftp = { version = "4", features = ["raw-string"] } rusqlite = { version = "0.43", features = ["bundled", "fallible_uint"] } rustix = { version = "1.1.6", features = ["fs", "process"] } rustls = { version = "0.23.46", default-features = false, features = ["ring", "std", "tls12"] } @@ -25,7 +32,9 @@ rustls-platform-verifier = "0.7.1" serde.workspace = true serde_json.workspace = true sha2 = "0.11.1" -tokio = { version = "1.54.1", features = ["rt-multi-thread", "macros", "sync", "time"] } +tokio = { version = "1.54.1", features = ["rt-multi-thread", "macros", "sync", "time", "net", "io-util"] } +tokio-rustls = { version = "0.26", default-features = false } +tower-service = "0.3" url = "2" # Without its tokio feature: the window's accessibility and tray share this build and run outside of tokio. zbus = "5.19" @@ -33,4 +42,5 @@ zbus = "5.19" [dev-dependencies] fastrand = "2.5.0" medlar-testserver.workspace = true +rcgen = { version = "0.14.10", default-features = false, features = ["crypto", "ring", "pem"] } tempfile = "3" diff --git a/crates/core/lang/en.json b/crates/core/lang/en.json index 32d032e..bffeada 100644 --- a/crates/core/lang/en.json +++ b/crates/core/lang/en.json @@ -227,6 +227,10 @@ "error.tls.not_yet": "The certificate of {server} is not valid yet, so nothing was downloaded from it. This computer's clock may be wrong.", "error.tls.unknown": "Nobody this computer trusts vouches for {server}, so nothing was downloaded from it.", "error.tls.name": "The certificate belongs to another server than {server}, so nothing was downloaded from it.", + "error.host_key.changed": "{server} has another key than before. Someone may be intercepting the connection. Accept the new key only if you know why it changed.", + "error.host_key.new": "Medlar has not seen the key of {server} before. Compare it with one you trust, then accept it.", + "error.tls.old": "{server} and Medlar have no way in common to secure the connection.", + "error.tls.none": "{server} offers no secure connection, so nothing was downloaded from it.", "error.tls.revoked": "The certificate of {server} was withdrawn, so nothing was downloaded from it.", "error.proxy": "No connection through the proxy", "error.proxy.why": "The proxy for {server} did not answer, or could not reach it.", @@ -234,21 +238,27 @@ "error.login": "Login needed", "error.login.why": "{server} wants a user name and password.", "error.forbidden": "Access denied", + "error.forbidden.plain": "{server} refused to give out the file. Another login may be allowed to have it.", "error.forbidden.why": "{server} refused to give out the file (status {code}). The link may need the page it came from.", "error.link": "Waiting for a new link", "error.link.why": "Start the download again on the page it came from. Medlar continues this one with the new link.", "error.expired": "Link expired", "error.expired.why": "{server} gave out the file before but refuses now (status {code}). A new link for the same file continues the download.", "error.not_found": "File not found", + "error.not_found.plain": "{server} has no file at this link, or does not show it to you.", "error.not_found.why": "{server} has no file at this link (status {code}).", + "error.login.key": "The key file for {server} can't be read, or its passphrase is wrong.", "error.login.proxy": "The proxy for {server} wants a user name and password, or the ones it got are wrong.", "secret.memory": "No keyring answered, so logins are only remembered until Medlar closes.", "secret.label": "Medlar login for {host}", "error.rejected": "Request rejected", + "error.rejected.plain": "{server} did not accept the request.", "error.rejected.why": "{server} did not accept the request (status {code}).", "error.busy": "Server is busy", + "error.busy.connections": "{server} allows no more connections right now.", "error.busy.why": "{server} has too many requests right now (status {code}).", "error.server": "Server error", + "error.server.plain": "{server} had a problem of its own.", "error.server.why": "{server} had a problem of its own (status {code}).", "error.bad_reply": "Wrong answer from the server", "error.bad_reply.why": "{server} contradicted itself about the file, so nothing from that answer was used.", diff --git a/crates/core/src/error.rs b/crates/core/src/error.rs index 4c607c2..ed066d8 100644 --- a/crates/core/src/error.rs +++ b/crates/core/src/error.rs @@ -188,6 +188,7 @@ impl Failure { E::Net(e) => of_net(e), E::Idle => ErrorKind::Timeout, E::Tls(_) => ErrorKind::Tls, + E::Conn { kind, why } => return Failure::because(*kind, *why, place), E::Proxy(None) => return Failure::because(ErrorKind::Proxy, Some("error.proxy.setting"), place), E::Proxy(Some(e)) if proxy_login(e) => return Failure::because(ErrorKind::Login, Some("error.login.proxy"), place), E::Proxy(Some(_)) => ErrorKind::Proxy, @@ -231,7 +232,7 @@ pub(crate) fn tls_error(e: &reqwest::Error) -> Option<&rustls::Error> { } /// The plain reason a certificate was refused. -fn tls_why(e: Option<&rustls::Error>) -> Option<&'static str> { +pub(crate) fn tls_why(e: Option<&rustls::Error>) -> Option<&'static str> { use rustls::CertificateError::*; let Some(rustls::Error::InvalidCertificate(e)) = e else { return None }; Some(match e { @@ -248,8 +249,12 @@ fn tls_why(e: Option<&rustls::Error>) -> Option<&'static str> { /// hyper's types for it are private. fn proxy_login(e: &reqwest::Error) -> bool { + causes(e).any(|e| proxy_wants_login(&e.to_string())) +} + +pub(crate) fn proxy_wants_login(text: &str) -> bool { let known = ["proxy authorization required", "credentials not accepted", "does not support user/pass", "implements authentication incorrectly"]; - causes(e).any(|e| known.iter().any(|k| e.to_string().contains(k))) + known.iter().any(|k| text.contains(k)) } /// The error and all that led to it. diff --git a/crates/core/src/ftp.rs b/crates/core/src/ftp.rs new file mode 100644 index 0000000..7b243c9 --- /dev/null +++ b/crates/core/src/ftp.rs @@ -0,0 +1,388 @@ +//! FTP and FTPS: passive only, binary only. Links: `ftp` is plain, `ftps` has TLS from the start, `ftpes` asks for it (AUTH TLS). +//! A path counts from the login's own folder; one that starts with `%2F` counts from the root. (D-049) + +use crate::auth::Login; +use crate::http::{Error, Result}; +use crate::listing::{self, Found, stamp}; +use crate::model::ErrorKind; +use crate::transport::{Stat, Transport, Way, dial, host}; +use bytes::{Bytes, BytesMut}; +use chrono::Utc; +use rustls::pki_types::ServerName; +use std::io; +use std::sync::Arc; +use tokio::io::{AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, BufReader}; +use tokio_rustls::TlsConnector; +use url::Url; + +/// Bytes read at once. +const PIECE: usize = 64 * 1024; +/// More than any honest server sends. +const MAX_REPLY: usize = 256 * 1024; +const MAX_LIST: u64 = 32 * 1024 * 1024; + +trait Wire: AsyncRead + AsyncWrite + Send + Sync + Unpin {} +impl Wire for T {} + +pub(crate) struct Ftp { + control: BufReader>, + way: Way, + /// For data connections. + host: String, + tls: Option<(TlsConnector, ServerName<'static>)>, + /// Extended passive mode works, as far as is known. + extended: bool, + mlsd: bool, + resumes: Option, + data: Option>, + /// Bytes to read, if not to the end. + left: Option, + /// Stopped in the middle of a file. + spent: bool, +} + +struct Answer { + code: u16, + text: String, +} + +impl Answer { + fn expect(self, codes: &[u16]) -> Result { + if codes.contains(&self.code) { Ok(self) } else { Err(self.error()) } + } + + fn says(&self, words: &[&str]) -> bool { + let text = self.text.to_ascii_lowercase(); + words.iter().any(|w| text.contains(w)) + } + + /// No room for another connection, whatever the code. + fn full(&self) -> bool { + self.says(&["too many", "maximum", "max number", "limit", "already logged"]) + } + + fn error(&self) -> Error { + match self.code { + 421 => Error::because(ErrorKind::Busy, "error.busy.connections"), + 425 | 426 | 451 => Error::conn(ErrorKind::Cut), + 430 | 530 | 532 if self.full() => Error::because(ErrorKind::Busy, "error.busy.connections"), + 332 | 430 | 530 | 532 => Error::conn(ErrorKind::Login), + 522 | 533 | 534 | 535 => Error::because(ErrorKind::Tls, "error.tls.none"), + 450 | 550 | 553 if self.says(&["denied", "permission", "not allowed", "forbidden"]) => { + Error::because(ErrorKind::Forbidden, "error.forbidden.plain") + } + 450 | 550 | 553 => Error::because(ErrorKind::NotFound, "error.not_found.plain"), + 400..=499 => Error::because(ErrorKind::Server, "error.server.plain"), + _ => Error::because(ErrorKind::Rejected, "error.rejected.plain"), + } + } +} + +impl Transport for Ftp { + async fn connect(way: Way, url: &Url, known: bool) -> Result { + let implicit = url.scheme() == "ftps"; + let name = host(url)?; + let (stream, host) = dial(&way, &name, url.port().unwrap_or(if implicit { 990 } else { 21 })).await?; + let tls = match url.scheme() { + "ftp" => None, + _ => { + let mut config = way.client.trust().config(Arc::new(rustls::crypto::ring::default_provider()))?; + config.alpn_protocols.clear(); + Some((TlsConnector::from(Arc::new(config)), ServerName::try_from(name).map_err(|_| Error::Link)?)) + } + }; + let mut ftp = Ftp { + control: BufReader::new(Box::new(stream)), + way, + host, + tls, + extended: true, + mlsd: false, + resumes: None, + data: None, + left: None, + spent: false, + }; + if implicit { + ftp.secure_control().await?; + } + let mut hello = ftp.answer().await?; + while hello.code < 200 { + hello = ftp.answer().await?; + } + hello.expect(&[220])?; + if url.scheme() == "ftpes" { + if ftp.command("AUTH", b"TLS").await?.code != 234 { + return Err(Error::because(ErrorKind::Tls, "error.tls.none")); + } + // Whatever came before the handshake could be anyone's. + if !ftp.control.buffer().is_empty() { + return Err(Error::conn(ErrorKind::Tls)); + } + ftp.secure_control().await?; + } + if ftp.tls.is_some() { + ftp.command("PBSZ", b"0").await?; + ftp.command("PROT", b"P").await?.expect(&[200])?; + } + ftp.login(known).await?; + let features = ftp.command("FEAT", b"").await?; + if features.code == 211 { + ftp.mlsd = features.says(&["mlst"]); + if features.says(&["utf8"]) { + // Those who refuse speak it anyway. + ftp.command("OPTS", b"UTF8 ON").await?; + } + } + ftp.command("TYPE", b"I").await?.expect(&[200])?; + Ok(ftp) + } + + fn path(url: &Url) -> Result> { + let path = url.path(); + let path = path.strip_prefix('/').unwrap_or(path); + let path = match path.rsplit_once(";type=") { + Some((path, kind)) if kind.len() == 1 => path, + _ => path, + }; + let path: Vec = percent_encoding::percent_decode_str(path).collect(); + // Each line is a command of its own. + if path.iter().any(|b| matches!(b, b'\r' | b'\n' | 0)) { Err(Error::Link) } else { Ok(path) } + } + + async fn stat(&mut self, path: &[u8]) -> Result { + let fine = |a: Answer| match a.code { + 213 => Ok(Some(a.text)), + 421 | 530 => Err(a.error()), + // Unknown here, or for this file: the download itself will tell. + _ => Ok(None), + }; + let size = fine(self.command("SIZE", path).await?)?; + let modified = fine(self.command("MDTM", path).await?)?; + let size = size.and_then(|s| s.split_whitespace().next()?.parse().ok()); + Ok(Stat { size, modified: modified.and_then(|m| stamp(&m)) }) + } + + async fn resumes(&mut self) -> Result { + if self.resumes.is_none() { + let can = self.command("REST", b"1").await?.code == 350 && self.command("REST", b"0").await?.code == 350; + self.resumes = Some(can); + } + Ok(self.resumes == Some(true)) + } + + async fn open(&mut self, path: &[u8], first: u64, len: Option) -> Result<()> { + // A folder has no bytes. + if path.is_empty() { + return Err(Error::because(ErrorKind::NotFound, "error.not_found.plain")); + } + let rest = (first > 0).then_some(first); + self.transfer("RETR", path, rest).await?; + self.left = len; + Ok(()) + } + + async fn next(&mut self) -> Result> { + let Some(data) = &mut self.data else { return Ok(None) }; + if self.left == Some(0) { + // The rest of the file is on its way already. + (self.data, self.spent) = (None, true); + return Ok(None); + } + let most = self.left.map_or(PIECE, |left| left.min(PIECE as u64) as usize); + let mut piece = BytesMut::with_capacity(most); + let mut data = data.take(most as u64); + // Without a timeout: nobody reads on while limits hold the bytes back, and whoever waits has one. + match data.read_buf(&mut piece).await { + Ok(0) => {} + // TLS without its proper end, as many do. What the server says next counts. + Err(e) if e.kind() == io::ErrorKind::UnexpectedEof => {} + Err(e) => return Err(e.into()), + Ok(n) => { + self.left = self.left.map(|left| left - n as u64); + return Ok(Some(piece.freeze())); + } + } + self.data = None; + let end = self.answer().await?; + if matches!(end.code, 226 | 250) { Ok(None) } else { Err(Error::conn(ErrorKind::Cut)) } + } + + fn reusable(&self) -> bool { + !self.spent && self.data.is_none() + } + + async fn list(&mut self, path: &[u8]) -> Result> { + // Names with blanks or a dash in front go wrong as an argument of LIST. + if !path.is_empty() { + self.command("CWD", path).await?.expect(&[200, 250])?; + } + let begun = self.transfer(if self.mlsd { "MLSD" } else { "LIST" }, b"", None).await; + match begun { + // How some put it that the folder is empty. + Err(Error::Conn { kind: ErrorKind::NotFound, .. }) => return Ok(vec![]), + begun => begun?, + } + let mut text = vec![]; + while let Some(piece) = self.way.client.clone().wait(self.next()).await? { + text.extend_from_slice(&piece); + if text.len() as u64 > MAX_LIST { + return Err(Error::BadReply("a listing without end".into())); + } + } + Ok(if self.mlsd { listing::mlsd(&text) } else { listing::plain(&text, Utc::now()) }) + } +} + +impl Ftp { + async fn login(&mut self, known: bool) -> Result<()> { + let anonymous = || Login { user: "anonymous".into(), password: "anonymous".into() }; + let Login { user, password } = self.way.login.clone().unwrap_or_else(anonymous); + let mut answer = self.command("USER", user.as_bytes()).await?; + if answer.code == 331 { + answer = self.command("PASS", password.as_bytes()).await?; + } + match answer.code { + 200 | 202 | 230 => Ok(()), + 430 | 530 if known => Err(Error::because(ErrorKind::Busy, "error.busy.connections")), + _ => Err(answer.error()), + } + } + + /// Asks for data. They can be read when it returns. + async fn transfer(&mut self, command: &str, argument: &[u8], rest: Option) -> Result<()> { + let port = self.passive().await?; + let (stream, _) = dial(&self.way, &self.host, port).await?; + if let Some(rest) = rest + && self.command("REST", rest.to_string().as_bytes()).await?.code != 350 + { + return Err(Error::RangeIgnored); + } + self.command(command, argument).await?.expect(&[125, 150])?; + (self.left, self.spent) = (None, false); + self.data = Some(self.secured(Box::new(stream)).await?); + Ok(()) + } + + /// The port for the next data connection. Always at the same host: an address in the answer could be anyone's. + async fn passive(&mut self) -> Result { + if self.extended { + let answer = self.command("EPSV", b"").await?; + if answer.code == 229 { + return extended_port(&answer.text).ok_or_else(|| Error::BadReply("no port to connect to".into())); + } + if answer.code < 500 { + return Err(answer.error()); + } + self.extended = false; + } + let answer = self.command("PASV", b"").await?.expect(&[227])?; + passive_port(&answer.text).ok_or_else(|| Error::BadReply("no port to connect to".into())) + } + + async fn secure_control(&mut self) -> Result<()> { + // Stays for an instant only. + let plain = std::mem::replace(&mut self.control, BufReader::new(Box::new(tokio::io::empty()))); + self.control = BufReader::new(self.secured(plain.into_inner()).await?); + Ok(()) + } + + async fn secured(&self, wire: Box) -> Result> { + let Some((connector, name)) = &self.tls else { return Ok(wire) }; + let wire = self.way.client.wait(connector.connect(name.clone(), wire)).await?; + Ok(Box::new(wire)) + } + + async fn command(&mut self, verb: &str, argument: &[u8]) -> Result { + if argument.iter().any(|b| matches!(b, b'\r' | b'\n' | 0)) { + return Err(Error::Link); + } + let mut line = verb.as_bytes().to_vec(); + if !argument.is_empty() { + line.push(b' '); + line.extend_from_slice(argument); + } + line.extend_from_slice(b"\r\n"); + let client = self.way.client.clone(); + client.wait(self.control.write_all(&line)).await?; + client.wait(self.control.flush()).await?; + self.answer().await + } + + async fn answer(&mut self) -> Result { + let client = self.way.client.clone(); + client.wait(self.read_answer()).await + } + + async fn read_answer(&mut self) -> Result { + let mut text = vec![]; + let mut room = MAX_REPLY; + let mut code = None; + loop { + let mut line = vec![]; + let n = (&mut self.control).take(room as u64).read_until(b'\n', &mut line).await?; + room -= n; + if n == 0 { + return Err(if room == 0 { Error::BadReply("an answer without end".into()) } else { Error::conn(ErrorKind::Cut) }); + } + let number = line.get(..3).and_then(|n| std::str::from_utf8(n).ok()?.parse::().ok()).filter(|n| (100..600).contains(n)); + // The first line has the code; with a dash the last one begins with it too. + let last = line.get(3) != Some(&b'-'); + match code { + None => code = Some(number.ok_or_else(|| Error::BadReply("no FTP server".into()))?), + Some(_) if number != code => { + text.extend_from_slice(&line); + continue; + } + Some(_) => {} + } + text.extend_from_slice(line.get(4..).unwrap_or_default()); + if let Some(code) = code.filter(|_| last) { + return Ok(Answer { code, text: String::from_utf8_lossy(&text).trim().into() }); + } + } + } +} + +/// `(|||port|)`, with any sign in place of the bar. +fn extended_port(text: &str) -> Option { + let inner = text.split_once('(')?.1.split_once(')')?.0; + let bar = inner.chars().next()?; + inner.split(bar).nth(3)?.parse().ok() +} + +/// Six numbers: the address and the port. +fn passive_port(text: &str) -> Option { + let from = text.find('(').map_or_else(|| text.find(|c: char| c.is_ascii_digit()), |i| Some(i + 1))?; + let inner = text[from..].split(')').next()?; + let numbers: Vec = inner.split(',').map(|n| n.trim().parse().ok()).collect::>()?; + let [_, _, _, _, high, low] = numbers[..] else { return None }; + Some(u16::from_be_bytes([high, low])) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn ports() { + assert_eq!(extended_port("Entering Extended Passive Mode (|||6446|)"), Some(6446)); + assert_eq!(extended_port("ok (!!!21!)"), Some(21)); + assert_eq!(passive_port("Entering Passive Mode (10,0,0,1,19,137)."), Some(5001)); + assert_eq!(passive_port("Entering Passive Mode 10,0,0,1,19,137"), Some(5001)); + for bad in ["", "(", "()", "(|||x|)", "(1,2,3)", "(1,2,3,4,5,600)", "(|||70000|)"] { + assert_eq!((extended_port(bad), passive_port(bad)), (None, None), "{bad}"); + } + } + + #[test] + fn paths() { + let path = |url: &str| Ftp::path(&Url::parse(url).unwrap()).ok(); + assert_eq!(path("ftp://h/a%20b/c.iso").unwrap(), b"a b/c.iso"); + assert_eq!(path("ftps://h/%2Fetc/x;type=i").unwrap(), b"/etc/x"); + assert_eq!(path("ftp://h").unwrap(), b""); + for command in ["ftp://h/a%0D%0ADELE%20x", "ftp://h/a%0a", "ftp://h/%00"] { + assert_eq!(path(command), None); + } + } +} diff --git a/crates/core/src/http/mod.rs b/crates/core/src/http/mod.rs index 6dd2582..953c736 100644 --- a/crates/core/src/http/mod.rs +++ b/crates/core/src/http/mod.rs @@ -15,12 +15,16 @@ pub use monitor::{Monitor, PartEvent, PartId, PartState, PartView, Snapshot}; pub use name::safe as safe_name; pub use probe::{Probe, probe}; +use crate::model::ErrorKind; +use crate::sftp::HostKeys; use crate::site::{Access, same_site}; use crate::tls::Trust; +use crate::transport::{Remote, Way}; use crate::{disk, redact, store}; use reqwest::header::{self, HeaderMap, HeaderName, HeaderValue}; pub(crate) use reqwest::Response; use reqwest::{RequestBuilder, StatusCode, redirect}; +use std::path::PathBuf; use std::sync::{Arc, Once}; use std::time::Duration; use tokio::sync::watch; @@ -39,6 +43,8 @@ pub enum Error { Idle, /// The proxy can't be reached or refuses. None: its setting makes no sense. Proxy(Option), + /// A connection that isn't HTTP failed. `why` is the text, if it isn't the usual one. + Conn { kind: ErrorKind, why: Option<&'static str> }, /// TLS can't be set up here. Tls(rustls::Error), Status { code: u16, retry_after: Option }, @@ -62,6 +68,16 @@ pub enum Error { Store(store::Error), } +impl Error { + pub(crate) fn conn(kind: ErrorKind) -> Error { + Error::Conn { kind, why: None } + } + + pub(crate) fn because(kind: ErrorKind, why: &'static str) -> Error { + Error::Conn { kind, why: Some(why) } + } +} + pub type Result = std::result::Result; impl From for Error { @@ -98,11 +114,13 @@ pub struct ClientOptions { pub idle_timeout: Duration, /// DER certificates to trust instead of the system's (tests). pub only_certs: Vec>, + /// Where the keys of SSH servers are kept: `Paths::known_hosts`. None forgets them at the end. + pub known_hosts: Option, } impl Default for ClientOptions { fn default() -> Self { - ClientOptions { connect_timeout: Duration::from_secs(20), idle_timeout: Duration::from_secs(30), only_certs: vec![] } + ClientOptions { connect_timeout: Duration::from_secs(20), idle_timeout: Duration::from_secs(30), only_certs: vec![], known_hosts: None } } } @@ -110,7 +128,9 @@ impl Default for ClientOptions { #[derive(Debug, Clone)] pub struct Client { inner: reqwest::Client, + connect: Duration, idle: Duration, + trust: Arc, } impl Client { @@ -118,6 +138,18 @@ impl Client { self.inner.get(url) } + pub(crate) fn connect_timeout(&self) -> Duration { + self.connect + } + + pub(crate) fn idle_timeout(&self) -> Duration { + self.idle + } + + pub(crate) fn trust(&self) -> &Arc { + &self.trust + } + /// The time counts while it is waited for only: limits may hold back what came before for longer. reqwest's own timeout goes /// on meanwhile. pub(crate) async fn wait>(&self, what: impl Future>) -> Result { @@ -134,7 +166,8 @@ pub fn client(options: &ClientOptions) -> Result { /// Reads the system's certificates. pub(crate) fn trust(options: &ClientOptions) -> Result> { - Ok(Arc::new(Trust::new(Arc::new(rustls::crypto::ring::default_provider()), &options.only_certs)?)) + let host_keys = HostKeys::new(options.known_hosts.clone()); + Ok(Arc::new(Trust::new(Arc::new(rustls::crypto::ring::default_provider()), &options.only_certs, host_keys)?)) } pub(crate) fn client_with(options: &ClientOptions, trust: &Arc, proxy: Option) -> Result { @@ -156,7 +189,7 @@ pub(crate) fn client_with(options: &ClientOptions, trust: &Arc, proxy: Op if let Some(proxy) = proxy { builder = builder.proxy(reqwest::Proxy::all(proxy)?); } - Ok(Client { inner: builder.build()?, idle: options.idle_timeout }) + Ok(Client { inner: builder.build()?, connect: options.connect_timeout, idle: options.idle_timeout, trust: trust.clone() }) } /// A link and the headers that go with it. @@ -165,6 +198,8 @@ pub struct Source { pub url: Url, pub headers: HeaderMap, access: Option>, + /// For a link that isn't HTTP. + remote: Option>, } /// Redirects followed. @@ -173,10 +208,11 @@ const HOPS: usize = 10; impl Source { pub fn new(url: &str) -> Result { let url = Url::parse(url).map_err(|_| Error::Link)?; - if !matches!(url.scheme(), "http" | "https") || !url.has_host() { + let remote = Remote::of(&url).map(Arc::new); + if !(remote.is_some() || matches!(url.scheme(), "http" | "https")) || url.host_str().is_none_or(str::is_empty) { return Err(Error::Link); } - Ok(Source { url, headers: HeaderMap::new(), access: None }) + Ok(Source { url, headers: HeaderMap::new(), access: None, remote }) } /// Adds headers, skipping what isn't valid and what the engine sets itself. @@ -208,7 +244,19 @@ impl Source { let harmless = [header::USER_AGENT, header::ACCEPT, header::ACCEPT_LANGUAGE, header::REFERER]; headers = headers.into_iter().filter_map(|(name, value)| Some((name.filter(|n| harmless.contains(n))?, value))).collect(); } - Source { url: url.clone(), headers, access: self.access.clone() } + Source { url: url.clone(), headers, access: self.access.clone(), remote: self.remote.clone() } + } + + pub(crate) fn remote(&self) -> Option<&Remote> { + self.remote.as_deref() + } + + /// For a link that isn't HTTP. + pub(crate) async fn way(&self, client: &Client) -> Result { + match &self.access { + Some(access) => access.way(&self.url).await, + None => Ok(Way { client: client.clone(), proxy: None, login: None, key: None }), + } } async fn get(&self, client: &Client, range: Option, if_range: Option<&HeaderValue>, stop: &mut Stop) -> Result { @@ -219,6 +267,9 @@ impl Source { } async fn follow(&self, client: &Client, range: Option<&str>, if_range: Option<&HeaderValue>) -> Result { + if let Some(remote) = &self.remote { + return remote.respond(client, self, range).await; + } let mut here = self.clone(); for _ in 0..=HOPS { let request = |client: &Client, headers: &HeaderMap| -> RequestBuilder { @@ -426,7 +477,7 @@ mod tests { assert_eq!(moved.len(), 1, "{other}"); assert!(moved.contains_key(header::REFERER)); } - for bad in ["ftp://h/f", "file:///etc/passwd", "no link", "http:///"] { + for bad in ["gopher://h/f", "sftp:///f", "file:///etc/passwd", "no link", "http:///"] { assert!(matches!(Source::new(bad), Err(Error::Link)), "{bad}"); } } diff --git a/crates/core/src/http/parts.rs b/crates/core/src/http/parts.rs index f7d3766..df5ccd2 100644 --- a/crates/core/src/http/parts.rs +++ b/crates/core/src/http/parts.rs @@ -7,7 +7,7 @@ use super::*; use crate::adapt::Adapt; use crate::disk::PartialFile; use crate::host::{Hosts, Member, Permit}; -use crate::model::Part; +use crate::model::{ErrorKind, Part}; use crate::part::LivePart; use crate::segment::{self, Pick, View}; use std::hash::{BuildHasher, RandomState}; @@ -102,6 +102,8 @@ fn weigh(e: &Error) -> Weight { Error::Status { .. } | Error::RangeIgnored => Weight::Refused { again: false }, Error::Net(e) if e.is_redirect() || e.is_builder() => Weight::Fatal, Error::Proxy(Some(_)) => Weight::Broken, + Error::Conn { kind: ErrorKind::Busy | ErrorKind::Refused, .. } => Weight::Refused { again: true }, + Error::Conn { kind, .. } if kind.of_network() || *kind == ErrorKind::Server => Weight::Broken, Error::Net(e) if e.is_connect() => Weight::Refused { again: true }, Error::Net(_) => Weight::Broken, _ => Weight::Fatal, diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 400d949..6aaae21 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -7,9 +7,11 @@ pub mod cookie; pub mod disk; pub mod error; pub mod events; +mod ftp; pub mod host; pub mod http; pub mod limit; +pub mod listing; pub mod logging; pub mod manager; pub mod model; @@ -23,11 +25,13 @@ pub mod relink; pub mod secret; pub mod segment; pub mod settings; +pub mod sftp; pub mod site; pub mod snapshot; pub mod speed; pub mod store; pub mod strings; pub mod tls; +mod transport; pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/crates/core/src/listing.rs b/crates/core/src/listing.rs new file mode 100644 index 0000000..1f31d4d --- /dev/null +++ b/crates/core/src/listing.rs @@ -0,0 +1,238 @@ +//! What a folder on a server holds, whichever way it was asked for. (D-050) + +use crate::http::{Client, Result, Source, Stop}; +use crate::model::Time; +use crate::transport; +use chrono::{DateTime, Datelike, Duration, NaiveDate, NaiveDateTime, NaiveTime, Utc}; +use percent_encoding::{AsciiSet, NON_ALPHANUMERIC, percent_encode}; +use regex::bytes::{Captures, Regex}; +use std::sync::LazyLock; +use url::Url; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Kind { + File, + Folder, + /// To a file or a folder: which one shows when it is opened. + Link, + /// Nothing that can be downloaded. + Other, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Entry { + /// For the eye: not safe as a file name. + pub name: String, + pub kind: Kind, + pub size: Option, + /// As good as the server tells: some give no year or no time zone. + pub modified: Option