diff --git a/Cargo.lock b/Cargo.lock index 0b1b7b3..8fd087b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -132,6 +132,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 0.2.2", + "inout", +] + +[[package]] +name = "aes" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fc36d7440d015b45468ba08a21e80e056ebbd014c611c6298bb7503e04bd1" +dependencies = [ + "cipher", + "cpubits", + "cpufeatures 0.3.1", + "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.12" @@ -259,6 +296,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 0.3.1", + "password-hash", +] + [[package]] name = "arrayref" version = "0.3.9" @@ -466,6 +515,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" @@ -484,6 +539,17 @@ 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 0.11.1", +] + [[package]] name = "bincode" version = "2.0.1" @@ -539,6 +605,18 @@ name = "bitflags" version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" +dependencies = [ + "serde_core", +] + +[[package]] +name = "blake2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b5d4d889834ee8ecfc0f8426ad30faf7cdcb10f741a8e6d7224d95325479f6f" +dependencies = [ + "digest 0.11.3", +] [[package]] name = "block-buffer" @@ -546,7 +624,7 @@ version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ - "generic-array", + "generic-array 0.14.7", ] [[package]] @@ -554,6 +632,16 @@ 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", ] @@ -589,6 +677,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 = "borsh" version = "1.8.1" @@ -699,6 +797,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.2" @@ -748,8 +855,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" dependencies = [ "cfg-if", + "cipher", "cpufeatures 0.3.1", "rand_core 0.10.1", + "zeroize", ] [[package]] @@ -766,6 +875,18 @@ dependencies = [ "windows-link", ] +[[package]] +name = "cipher" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c" +dependencies = [ + "block-buffer 0.12.1", + "crypto-common 0.2.2", + "inout", + "zeroize", +] + [[package]] name = "clang-sys" version = "1.9.1" @@ -983,6 +1104,12 @@ dependencies = [ "windows-core", ] +[[package]] +name = "cpubits" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae" + [[package]] name = "cpufeatures" version = "0.2.17" @@ -1065,13 +1192,30 @@ 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 0.10.1", + "serdect", + "subtle", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" dependencies = [ - "generic-array", + "generic-array 0.14.7", "typenum", ] @@ -1081,7 +1225,19 @@ 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 0.10.1", +] + +[[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 0.10.1", ] [[package]] @@ -1093,6 +1249,15 @@ dependencies = [ "dtor", ] +[[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" @@ -1100,6 +1265,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "261af4dc7a06ea8a527a8717d8cbba3417530d6ea14e1edb3de6b67806be474f" dependencies = [ "cmov", + "subtle", ] [[package]] @@ -1108,6 +1274,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 0.3.1", + "curve25519-dalek-derive", + "digest 0.11.3", + "fiat-crypto", + "rand_core 0.10.1", + "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 = "dasp_sample" version = "0.11.0" @@ -1126,6 +1334,17 @@ 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.7.10" @@ -1135,7 +1354,18 @@ dependencies = [ "const-oid 0.9.6", "der_derive", "flagset", - "pem-rfc7468", + "pem-rfc7468 0.7.0", + "zeroize", +] + +[[package]] +name = "der" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a996a108feb8b427a6e12fcf6af4aa83409b79d72c15337d7741368131ee004" +dependencies = [ + "const-oid 0.10.3", + "pem-rfc7468 1.0.0", "zeroize", ] @@ -1179,6 +1409,15 @@ dependencies = [ "unicode-xid", ] +[[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.10.7" @@ -1200,6 +1439,7 @@ dependencies = [ "const-oid 0.10.3", "crypto-common 0.2.2", "ctutils", + "zeroize", ] [[package]] @@ -1305,12 +1545,75 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edf234dd1594d6dd434a8fb8cada51ddbbc593e40e4a01556a0b31c62da2775b" +[[package]] +name = "ecdsa" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0681a4fc24c767085329728d8dfba959af91228aa4610cca4f8ce317ba46ae0" +dependencies = [ + "der 0.8.3", + "digest 0.11.3", + "elliptic-curve", + "rfc6979", + "signature 3.0.0", + "spki 0.8.1", + "zeroize", +] + +[[package]] +name = "ed25519" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29fcf32e6c73d1079f83ab4d782de2d81620346a5f38c6237a86a22f8368980a" +dependencies = [ + "pkcs8 0.11.0", + "signature 3.0.0", +] + +[[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 0.10.1", + "serde", + "sha2 0.11.1", + "signature 3.0.0", + "subtle", + "zeroize", +] + [[package]] name = "either" 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 0.2.2", + "digest 0.11.3", + "ff", + "group", + "hkdf", + "hybrid-array", + "pem-rfc7468 1.0.0", + "pkcs8 0.11.0", + "rand_core 0.10.1", + "sec1", + "subtle", + "zeroize", +] + [[package]] name = "encoding_rs" version = "0.8.44" @@ -1331,6 +1634,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" @@ -1451,6 +1766,22 @@ dependencies = [ "web-sys", ] +[[package]] +name = "ff" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f686ab92a9fb0eaf188f6c6c87b89490baa6fdb0db4544ba4dc47f7942489f" +dependencies = [ + "rand_core 0.10.1", + "subtle", +] + +[[package]] +name = "fiat-crypto" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64cd1e32ddd350061ae6edb1b082d7c54915b5c672c389143b9a63403a109f24" + [[package]] name = "field-offset" version = "0.3.6" @@ -1745,6 +2076,16 @@ dependencies = [ "version_check", ] +[[package]] +name = "generic-array" +version = "1.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "337d46834ee672ab3e48caca2cb0c78cc174fb12b3a68d0d88f99a0519a5e36e" +dependencies = [ + "rustversion", + "typenum", +] + [[package]] name = "gethostname" version = "1.1.0" @@ -1785,9 +2126,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" dependencies = [ "cfg-if", + "js-sys", "libc", "r-efi 6.0.0", "rand_core 0.10.1", + "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]] @@ -1817,6 +2170,18 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b" +[[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.18.0" @@ -1909,6 +2274,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 0.10.1", + "subtle", +] + [[package]] name = "half" version = "2.7.1" @@ -1996,6 +2372,21 @@ 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" @@ -2033,7 +2424,10 @@ version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17" dependencies = [ + "ctutils", + "subtle", "typenum", + "zeroize", ] [[package]] @@ -2548,10 +2942,10 @@ dependencies = [ "plist", "plist-macro", "rand 0.10.4", - "rsa", + "rsa 0.9.10", "rustls", "serde", - "sha2", + "sha2 0.10.9", "thiserror 2.0.21", "tokio", "tokio-rustls", @@ -2652,6 +3046,16 @@ dependencies = [ "libc", ] +[[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 = "input" version = "0.10.0" @@ -2838,6 +3242,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 0.3.1", +] + +[[package]] +name = "kem" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01737161ba802849cfd486b5bd209d38ba4943494c249a8126005170c7621edd" +dependencies = [ + "crypto-common 0.2.2", + "rand_core 0.10.1", +] + [[package]] name = "keyboard-types" version = "0.8.3" @@ -3133,6 +3557,12 @@ dependencies = [ "digest 0.11.3", ] +[[package]] +name = "md5" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ebb8d8732c6a6df3d8f032a82911cfc747e00efb95cc46e8d0acd5b5b88570c" + [[package]] name = "memchr" version = "2.8.3" @@ -3211,6 +3641,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 0.11.0", + "rand_core 0.10.1", + "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" @@ -3381,6 +3837,18 @@ dependencies = [ "bitflags 2.13.2", ] +[[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 0.10.4", + "rand_core 0.10.1", +] + [[package]] name = "num-bigint-dig" version = "0.8.6" @@ -3938,6 +4406,67 @@ dependencies = [ "ttf-parser", ] +[[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 0.11.1", +] + +[[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 0.11.1", +] + +[[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 0.11.1", +] + +[[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 0.10.4", + "sha2 0.11.1", + "thiserror 2.0.21", + "tokio", + "windows", + "windows-strings", +] + [[package]] name = "parking" version = "2.2.1" @@ -4026,6 +4555,15 @@ dependencies = [ "skrifa 0.44.0", ] +[[package]] +name = "password-hash" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aab41826031698d6ffcd9cff78ef56ef998e39dc7e5067cdfebe373842d4723b" +dependencies = [ + "phc", +] + [[package]] name = "paste" version = "1.0.15" @@ -4038,6 +4576,16 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2ee67f1008b1ba2321834326597b8e186293b049a023cdef258527550b9935b4" +[[package]] +name = "pbkdf2" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112d82ceb8c5bf524d9af484d4e4970c9fd5a0cc15ba14ad93dccd28873b0629" +dependencies = [ + "digest 0.11.3", + "hmac", +] + [[package]] name = "pem-rfc7468" version = "0.7.0" @@ -4047,12 +4595,31 @@ dependencies = [ "base64ct", ] +[[package]] +name = "pem-rfc7468" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6305423e0e7738146434843d1694d621cce767262b2a86910beab705e4493d9" +dependencies = [ + "base64ct", +] + [[package]] name = "percent-encoding" version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" +[[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" @@ -4157,9 +4724,36 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" dependencies = [ - "der", - "pkcs8", - "spki", + "der 0.7.10", + "pkcs8 0.10.2", + "spki 0.7.3", +] + +[[package]] +name = "pkcs1" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6250dd7321adbe93d12b750aee0ced159fd13e77f625edcdf1cb6f83cd99f650" +dependencies = [ + "der 0.8.3", + "spki 0.8.1", +] + +[[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 0.8.3", + "pbkdf2", + "rand_core 0.10.1", + "scrypt", + "sha2 0.11.1", + "spki 0.8.1", ] [[package]] @@ -4168,8 +4762,20 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" dependencies = [ - "der", - "spki", + "der 0.7.10", + "spki 0.7.3", +] + +[[package]] +name = "pkcs8" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "451913da69c775a56034ea8d9003d27ee8948e12443eae7c038ba100a4f21cb7" +dependencies = [ + "der 0.8.3", + "pkcs5", + "rand_core 0.10.1", + "spki 0.8.1", ] [[package]] @@ -4233,6 +4839,17 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "poly1305" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e2d0073b297041425c7c3df6eb4792d598a15323fe63346852b092eca02904c" +dependencies = [ + "cpufeatures 0.3.1", + "universal-hash", + "zeroize", +] + [[package]] name = "polycool" version = "0.4.0" @@ -4242,6 +4859,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 0.3.1", + "universal-hash", + "zeroize", +] + [[package]] name = "portable-atomic" version = "1.15.0" @@ -4311,6 +4940,33 @@ dependencies = [ "num-integer", ] +[[package]] +name = "primefield" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c555a6e4eb7d4e158fcb028c835c3b8642206ddc279b5c6b202ef9a8bdb592f4" +dependencies = [ + "crypto-bigint", + "crypto-common 0.2.2", + "ff", + "rand_core 0.10.1", + "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" @@ -4619,6 +5275,16 @@ dependencies = [ "zune-jpeg", ] +[[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" @@ -4681,16 +5347,37 @@ dependencies = [ "num-bigint-dig", "num-integer", "num-traits", - "pkcs1", - "pkcs8", + "pkcs1 0.7.5", + "pkcs8 0.10.2", "rand_core 0.6.4", - "sha2", - "signature", - "spki", + "sha2 0.10.9", + "signature 2.2.0", + "spki 0.7.3", "subtle", "zeroize", ] +[[package]] +name = "rsa" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23e77fd77e0dea28b3011fd62d15445b7de7959333b0276d930e03be0f755699" +dependencies = [ + "const-oid 0.10.3", + "crypto-bigint", + "crypto-common 0.2.2", + "crypto-primes", + "digest 0.11.3", + "hmac", + "pkcs1 0.8.0", + "pkcs8 0.11.0", + "rand_core 0.10.1", + "sha2 0.11.1", + "signature 3.0.0", + "spki 0.8.1", + "zeroize", +] + [[package]] name = "rspolib" version = "0.1.2" @@ -4722,6 +5409,121 @@ dependencies = [ "realfft", ] +[[package]] +name = "russh" +version = "0.65.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78229f06e4d96d83bea5f5133ad3b6e4b5f0ce22d8e31c1ff7243ec8e18d5ba1" +dependencies = [ + "aes", + "bitflags 2.13.2", + "block-padding", + "byteorder", + "bytes", + "cbc", + "cipher", + "crypto-bigint", + "ctr", + "curve25519-dalek", + "data-encoding", + "delegate", + "der 0.8.3", + "digest 0.11.3", + "ecdsa", + "ed25519-dalek", + "elliptic-curve", + "enum_dispatch", + "flate2", + "futures", + "generic-array 1.4.5", + "getrandom 0.4.3", + "ghash", + "hex-literal", + "hmac", + "inout", + "keccak", + "log", + "md5", + "ml-kem", + "module-lattice", + "num-bigint", + "p256", + "p384", + "p521", + "pageant", + "pbkdf2", + "pkcs1 0.8.0", + "pkcs5", + "pkcs8 0.11.0", + "polyval", + "rand 0.10.4", + "rand_core 0.10.1", + "ring", + "rsa 0.10.0", + "russh-cryptovec", + "russh-util", + "salsa20", + "scrypt", + "sec1", + "sha1 0.11.0", + "sha2 0.11.1", + "sha3", + "signature 3.0.0", + "spki 0.8.1", + "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 = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb17f72aba4314656b359ffba72c68dcbd70ed9e97497898b75498fe7198042" +dependencies = [ + "bitflags 2.13.2", + "bytes", + "chrono", + "dashmap", + "gloo-timers", + "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" @@ -4824,6 +5626,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" @@ -4851,6 +5663,18 @@ 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 0.11.1", +] + [[package]] name = "sctk-adwaita" version = "0.10.1" @@ -4864,6 +5688,29 @@ dependencies = [ "tiny-skia 0.11.4", ] +[[package]] +name = "sec1" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d56d437c2f19203ce5f7122e507831de96f3d2d4d3be5af44a0b0a09d8a80e4d" +dependencies = [ + "base16ct", + "ctutils", + "der 0.8.3", + "hybrid-array", + "subtle", + "zeroize", +] + +[[package]] +name = "secrecy" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e891af845473308773346dc847b2c23ee78fe442e0472ac50e22a18a93d3ae5a" +dependencies = [ + "zeroize", +] + [[package]] name = "semver" version = "1.0.28" @@ -4880,6 +5727,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" @@ -4933,6 +5790,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.10.7" @@ -4966,6 +5833,39 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "sha2" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.1", + "digest 0.11.3", +] + +[[package]] +name = "sha3" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc9bad02c26382724b2d2692c6f179285e4b54eeecd7968f52a50059c3c11759" +dependencies = [ + "digest 0.11.3", + "keccak", + "sponge-cursor", +] + +[[package]] +name = "shake" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09057cb2149ad4cbd2da1e26b351f9a4c354219421229c69c3063e6f61947c4a" +dependencies = [ + "digest 0.11.3", + "keccak", + "sponge-cursor", +] + [[package]] name = "shlex" version = "2.0.1" @@ -4992,6 +5892,16 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "signature" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d567dcbaf0049cb8ac2608a76cd95ff9e4412e1899d389ee400918ca7537f5" +dependencies = [ + "digest 0.11.3", + "rand_core 0.10.1", +] + [[package]] name = "simd-adler32" version = "0.3.10" @@ -5322,7 +6232,82 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" dependencies = [ "base64ct", - "der", + "der 0.7.10", +] + +[[package]] +name = "spki" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef958a98b9d5da290cfc78946e9f3e61e1e62a18db0d92cac0b83cc161491a9" +dependencies = [ + "base64ct", + "der 0.8.3", +] + +[[package]] +name = "sponge-cursor" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a0219bd7d979d58245a4f41f695e1ac9f8befdffadd7f61f1bae9e39abc6620" + +[[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 0.11.3", + "pem-rfc7468 1.0.0", + "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 0.10.1", + "rsa 0.10.0", + "sec1", + "sha1 0.11.0", + "sha2 0.11.1", + "signature 3.0.0", + "ssh-cipher", + "ssh-encoding", + "zeroize", ] [[package]] @@ -5863,9 +6848,21 @@ dependencies = [ "mio", "pin-project-lite", "socket2", + "tokio-macros", "windows-sys 0.61.2", ] +[[package]] +name = "tokio-macros" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + [[package]] name = "tokio-rustls" version = "0.26.6" @@ -5876,6 +6873,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" @@ -5991,6 +7002,7 @@ dependencies = [ "tunal-devices", "tunal-dirmeta", "tunal-elevate", + "tunal-player", "tunal-tags", "tunal-theme", "tunal-thumbs", @@ -6037,7 +7049,13 @@ version = "0.1.0" dependencies = [ "base64 0.23.1", "hmac", + "russh", + "russh-sftp", + "secrecy", "sha1 0.11.0", + "tokio", + "tunal-core", + "zeroize", ] [[package]] @@ -6173,6 +7191,16 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" +[[package]] +name = "universal-hash" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4987bdc12753382e0bec4a65c50738ffaabc998b9cdd1f952fb5f39b0048a96" +dependencies = [ + "crypto-common 0.2.2", + "ctutils", +] + [[package]] name = "untrusted" version = "0.9.0" @@ -7098,6 +8126,18 @@ version = "0.57.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" +[[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 = "write-fonts" version = "0.50.0" @@ -7156,10 +8196,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1301e935010a701ae5f8655edc0ad17c44bad3ac5ce8c39185f75453b720ae94" dependencies = [ "const-oid 0.9.6", - "der", + "der 0.7.10", "sha1 0.10.7", - "signature", - "spki", + "signature 2.2.0", + "spki 0.7.3", "tls_codec", ] diff --git a/Cargo.toml b/Cargo.toml index eae3d15..bd6cd29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,4 +35,8 @@ hmac = "0.13" sha1 = "0.11" futures-lite = "2" idevice = { version = "0.1.68", default-features = false, features = ["ring", "usbmuxd", "afc", "pair"] } -tokio = { version = "1", features = ["rt-multi-thread", "net", "time"] } +tokio = { version = "1", features = ["rt-multi-thread", "net", "time", "sync"] } +russh = { version = "0.65", default-features = false, features = ["ring", "flate2", "rsa"] } +russh-sftp = "3" +secrecy = "0.10" +zeroize = "1" diff --git a/Plans/10 Network/S028-sftp-location.md b/Plans/10 Network/S028-sftp-location.md index bd1330a..da7bc59 100644 --- a/Plans/10 Network/S028-sftp-location.md +++ b/Plans/10 Network/S028-sftp-location.md @@ -10,13 +10,13 @@ docs/DECISIONS.md D-019, D-020; CLAUDE.md §3 (secrets); crates/tunal-core trait; russh/russh-sftp docs in ~/.cargo/registry. ## Steps -- [ ] Own tokio runtime on a background thread inside `tunal-net`; blocking `Location` API on top; russh crypto features on ring (D-019), not aws-lc-rs. -- [ ] Connection manager per (user, host, port): reuse, keepalive, reconnect, idle close. -- [ ] Auth chain: agent (`SSH_AUTH_SOCK`) → identity files (passphrase callback) → password / keyboard-interactive callback; secrets in `secrecy`/`zeroize` types only. -- [ ] Host key via known_hosts: Unknown → callback (SHA256 fingerprint), Mismatch → hard error. -- [ ] Location ops: readdir, stat/lstat, readlink, pipelined read/write, mkdir, rename (posix-rename extension when offered), delete; trash Unsupported (permanent delete with confirm). -- [ ] Example `--example sftp-ls -- ` (only against a server the user names; otherwise build-only). -- [ ] PROGRESS entry, INDEX line, commit `S028: …` +- [x] Own tokio runtime on a background thread inside `tunal-net`; blocking `Location` API on top; russh crypto features on ring (D-019), not aws-lc-rs. +- [x] Connection manager per (user, host, port): reuse, keepalive, reconnect, idle close. +- [x] Auth chain: agent (`SSH_AUTH_SOCK`) → identity files (passphrase callback) → password / keyboard-interactive callback; secrets in `secrecy`/`zeroize` types only. +- [x] Host key via known_hosts: Unknown → callback (SHA256 fingerprint), Mismatch → hard error. +- [x] Location ops: readdir, stat/lstat, readlink, pipelined read/write, mkdir, rename (posix-rename extension when offered), delete; trash Unsupported (permanent delete with confirm). +- [x] Example `--example sftp-ls -- ` (only against a server the user names; otherwise build-only). +- [x] PROGRESS entry, INDEX line, commit `S028: …` ## End criteria - `cargo build --workspace`, `cargo clippy --workspace --all-targets -- -D warnings` and `cargo fmt --check` pass. diff --git a/Plans/INDEX.md b/Plans/INDEX.md index 70193d4..aeb4e2f 100644 --- a/Plans/INDEX.md +++ b/Plans/INDEX.md @@ -62,7 +62,7 @@ Tracker: https://claude.ai/artifact/4X8YCk3cQjUGyuyCqGuU7v ## 10 Network - [x] [S027 — ssh config and known_hosts](10%20Network/S027-ssh-config-known-hosts.md) · Sonnet high -- [ ] [S028 — SFTP location](10%20Network/S028-sftp-location.md) · Opus high +- [x] [S028 — SFTP location](10%20Network/S028-sftp-location.md) · Opus high - [ ] [S029 — SFTP connections in the UI](10%20Network/S029-sftp-ui.md) · Opus high ## 11 Native drag and drop diff --git a/crates/tunal-net/Cargo.toml b/crates/tunal-net/Cargo.toml index 6d675a8..8e68fb1 100644 --- a/crates/tunal-net/Cargo.toml +++ b/crates/tunal-net/Cargo.toml @@ -9,3 +9,9 @@ publish.workspace = true base64.workspace = true hmac.workspace = true sha1.workspace = true +tunal-core = { path = "../tunal-core" } +tokio.workspace = true +russh.workspace = true +russh-sftp.workspace = true +secrecy.workspace = true +zeroize.workspace = true diff --git a/crates/tunal-net/examples/sftp-ls.rs b/crates/tunal-net/examples/sftp-ls.rs new file mode 100644 index 0000000..951507f --- /dev/null +++ b/crates/tunal-net/examples/sftp-ls.rs @@ -0,0 +1,72 @@ +//! `cargo run -p tunal-net --example sftp-ls -- sftp://[user@]host[:port]/path` +//! Lists a remote folder. Only run it against a server you name; asks on the terminal. + +use std::io::{self, BufRead, Write}; +use std::path::Path; +use std::sync::Arc; + +use secrecy::SecretString; +use tunal_core::{Location, Uri}; +use tunal_net::auth::{HostKeyInfo, InteractiveRequest, Prompts}; +use tunal_net::sftp::SftpLocation; + +struct Terminal; + +fn line(prompt: &str, hidden: bool) -> Option { + eprint!("{prompt} "); + let _ = io::stderr().flush(); + if hidden { + let _ = std::process::Command::new("stty").arg("-echo").status(); + } + let mut s = String::new(); + let ok = io::stdin().lock().read_line(&mut s).is_ok_and(|n| n > 0); + if hidden { + let _ = std::process::Command::new("stty").arg("echo").status(); + eprintln!(); + } + ok.then(|| SecretString::from(s.trim_end().to_owned())) +} + +impl Prompts for Terminal { + fn confirm_host_key(&self, i: &HostKeyInfo) -> bool { + use secrecy::ExposeSecret; + let q = format!( + "Unknown host {}:{} {} {}. Accept? [y/N]", + i.host, i.port, i.key_type, i.fingerprint + ); + line(&q, false).is_some_and(|a| a.expose_secret().eq_ignore_ascii_case("y")) + } + + fn password(&self, user: &str, host: &str) -> Option { + line(&format!("Password for {user}@{host}:"), true) + } + + fn passphrase(&self, key: &Path) -> Option { + line(&format!("Passphrase for {}:", key.display()), true) + } + + fn interactive(&self, req: &InteractiveRequest) -> Option> { + req.prompts.iter().map(|p| line(&p.text, !p.echo)).collect() + } +} + +fn main() { + let arg = std::env::args() + .nth(1) + .expect("usage: sftp-ls sftp://[user@]host[:port]/path"); + let uri = Uri::parse(&arg).expect("not a URI"); + let sftp = SftpLocation::new(Arc::new(Terminal)); + let result = sftp.list(&uri, &mut |entries| { + for e in entries { + println!( + "{:>10} {:o} {} {:?}", + e.size, e.mode, e.display_name, e.kind + ); + } + std::ops::ControlFlow::Continue(()) + }); + if let Err(e) = result { + eprintln!("error: {e}"); + std::process::exit(1); + } +} diff --git a/crates/tunal-net/src/auth.rs b/crates/tunal-net/src/auth.rs new file mode 100644 index 0000000..869ee8e --- /dev/null +++ b/crates/tunal-net/src/auth.rs @@ -0,0 +1,274 @@ +//! Authentication chain (agent, identity files, password / keyboard-interactive) and the +//! prompt callbacks the UI implements. Secrets live in `secrecy` types and are never logged. + +use std::path::{Path, PathBuf}; +use std::sync::Arc; + +use russh::MethodKind; +use russh::client::{Handle, Handler, KeyboardInteractiveAuthResponse}; +use russh::keys::agent::AgentIdentity; +use russh::keys::agent::client::AgentClient; +use russh::keys::{self, HashAlg, PrivateKeyWithHashAlg}; +use secrecy::{ExposeSecret, SecretString}; +use tunal_core::Error; + +use crate::ssh_config::{Resolved, ssh_dir}; + +const MAX_TRIES: usize = 3; + +/// A host key not seen before, shown to the user to accept or refuse. +#[derive(Debug, Clone)] +pub struct HostKeyInfo { + pub host: String, + pub port: u16, + /// e.g. `ssh-ed25519`. + pub key_type: String, + /// `SHA256:…`, as `ssh-keygen -l` prints it. + pub fingerprint: String, +} + +/// One keyboard-interactive question. +#[derive(Debug, Clone)] +pub struct InteractivePrompt { + pub text: String, + /// False for secrets: the answer must not be shown while typing. + pub echo: bool, +} + +/// A keyboard-interactive round. +#[derive(Debug, Clone)] +pub struct InteractiveRequest { + pub name: String, + pub instructions: String, + pub prompts: Vec, +} + +/// Questions the connection layer asks the user. Called on a worker thread and may block +/// until the user answers; `None` / `false` means the user cancelled. Defaults refuse. +pub trait Prompts: Send + Sync { + /// Unknown host key: accept (and remember in Tunal's known_hosts) or refuse. + fn confirm_host_key(&self, _info: &HostKeyInfo) -> bool { + false + } + + /// Account password for `user@host`. + fn password(&self, _user: &str, _host: &str) -> Option { + None + } + + /// Passphrase for the encrypted private key file `key`. + fn passphrase(&self, _key: &Path) -> Option { + None + } + + /// Answers for a keyboard-interactive round, one per prompt. + fn interactive(&self, _req: &InteractiveRequest) -> Option> { + None + } +} + +/// Refuses every question: only agent and unencrypted keys work. +pub struct NoPrompts; + +impl Prompts for NoPrompts {} + +/// Runs a blocking prompt callback off the async worker. +async fn ask( + prompts: &Arc, + f: impl FnOnce(&dyn Prompts) -> T + Send + 'static, +) -> Option { + let prompts = prompts.clone(); + tokio::task::spawn_blocking(move || f(&*prompts)).await.ok() +} + +pub(crate) async fn authenticate( + handle: &mut Handle, + user: &str, + host: &str, + resolved: &Resolved, + prompts: &Arc, +) -> Result<(), Error> { + let files = identity_files(resolved); + let rsa_hash = handle + .best_supported_rsa_hash() + .await + .ok() + .flatten() + .flatten(); + + if try_agent(handle, user, resolved, &files, rsa_hash).await { + return Ok(()); + } + for file in &files { + if try_key_file(handle, user, file, rsa_hash, prompts).await { + return Ok(()); + } + } + + let methods = match handle.authenticate_none(user).await { + Ok(result) if result.success() => return Ok(()), + Ok(russh::client::AuthResult::Failure { + remaining_methods, .. + }) => remaining_methods, + _ => return Err(denied()), + }; + if methods.contains(&MethodKind::Password) { + for _ in 0..MAX_TRIES { + let (u, h) = (user.to_owned(), host.to_owned()); + let Some(Some(password)) = ask(prompts, move |p| p.password(&u, &h)).await else { + break; + }; + match handle + .authenticate_password(user, password.expose_secret()) + .await + { + Ok(r) if r.success() => return Ok(()), + Ok(_) => {} + Err(e) => return Err(Error::Remote(e.to_string())), + } + } + } + if methods.contains(&MethodKind::KeyboardInteractive) + && try_interactive(handle, user, prompts).await + { + return Ok(()); + } + Err(denied()) +} + +fn denied() -> Error { + Error::Remote("authentication failed".into()) +} + +/// Identity files to try: the configured ones, else the usual defaults that exist. +fn identity_files(resolved: &Resolved) -> Vec { + if !resolved.identity_files.is_empty() { + return resolved + .identity_files + .iter() + .filter(|f| f.is_file()) + .cloned() + .collect(); + } + let Some(dir) = ssh_dir() else { + return Vec::new(); + }; + ["id_ed25519", "id_ecdsa", "id_rsa"] + .iter() + .map(|n| dir.join(n)) + .filter(|f| f.is_file()) + .collect() +} + +/// Agent keys; with `IdentitiesOnly` only those matching a `.pub` file. +async fn try_agent( + handle: &mut Handle, + user: &str, + resolved: &Resolved, + files: &[PathBuf], + rsa_hash: Option, +) -> bool { + let Ok(mut agent) = AgentClient::connect_env().await else { + return false; + }; + let Ok(identities) = agent.request_identities().await else { + return false; + }; + let allowed: Vec<_> = files + .iter() + .filter_map(|f| keys::load_public_key(f.with_extension("pub")).ok()) + .map(|k| k.fingerprint(HashAlg::Sha256)) + .collect(); + for identity in identities { + let AgentIdentity::PublicKey { key, .. } = identity else { + continue; + }; + if resolved.identities_only && !allowed.contains(&key.fingerprint(HashAlg::Sha256)) { + continue; + } + let hash = key.algorithm().is_rsa().then_some(rsa_hash).flatten(); + if let Ok(r) = handle + .authenticate_publickey_with(user, key, hash, &mut agent) + .await + && r.success() + { + return true; + } + } + false +} + +async fn try_key_file( + handle: &mut Handle, + user: &str, + file: &Path, + rsa_hash: Option, + prompts: &Arc, +) -> bool { + let mut key = keys::load_secret_key(file, None); + for _ in 0..MAX_TRIES { + if !matches!(key, Err(keys::Error::KeyIsEncrypted)) { + break; + } + let path = file.to_path_buf(); + let Some(Some(pass)) = ask(prompts, move |p| p.passphrase(&path)).await else { + return false; + }; + key = keys::load_secret_key(file, Some(pass.expose_secret())); + } + let Ok(key) = key else { return false }; + let key = PrivateKeyWithHashAlg::new(Arc::new(key), rsa_hash); + matches!(handle.authenticate_publickey(user, key).await, Ok(r) if r.success()) +} + +async fn try_interactive( + handle: &mut Handle, + user: &str, + prompts: &Arc, +) -> bool { + let Ok(mut response) = handle + .authenticate_keyboard_interactive_start(user, None) + .await + else { + return false; + }; + for _ in 0..MAX_TRIES * 2 { + match response { + KeyboardInteractiveAuthResponse::Success => return true, + KeyboardInteractiveAuthResponse::Failure { .. } => return false, + KeyboardInteractiveAuthResponse::InfoRequest { + name, + instructions, + prompts: qs, + } => { + let req = InteractiveRequest { + name, + instructions, + prompts: qs + .into_iter() + .map(|q| InteractivePrompt { + text: q.prompt, + echo: q.echo, + }) + .collect(), + }; + let answers = if req.prompts.is_empty() { + Vec::new() + } else { + let Some(Some(a)) = ask(prompts, move |p| p.interactive(&req)).await else { + return false; + }; + a.iter().map(|s| s.expose_secret().to_owned()).collect() + }; + match handle + .authenticate_keyboard_interactive_respond(answers) + .await + { + Ok(next) => response = next, + Err(_) => return false, + } + } + } + } + false +} diff --git a/crates/tunal-net/src/lib.rs b/crates/tunal-net/src/lib.rs index 530ee99..17065c0 100644 --- a/crates/tunal-net/src/lib.rs +++ b/crates/tunal-net/src/lib.rs @@ -1,6 +1,9 @@ //! SFTP locations, ssh config hosts and known_hosts. +pub mod auth; pub mod known_hosts; +mod session; +pub mod sftp; pub mod ssh_config; /// Shell-style glob match (`*`, `?`) on bytes, as used by ssh patterns. diff --git a/crates/tunal-net/src/session.rs b/crates/tunal-net/src/session.rs new file mode 100644 index 0000000..789569a --- /dev/null +++ b/crates/tunal-net/src/session.rs @@ -0,0 +1,263 @@ +//! Background tokio runtime and the connection manager: one SFTP session per +//! (user, host, port), reused, kept alive, reconnected after a drop and closed when idle. + +use std::collections::HashMap; +use std::future::Future; +use std::sync::{Arc, Mutex, OnceLock}; +use std::time::{Duration, Instant}; + +use russh::client::{self, Handle}; +use russh::keys::{HashAlg, PublicKeyOrCertificate}; +use russh_sftp::client::SftpSession; +use tokio::runtime::Runtime; +use tunal_core::{Error, Result}; + +use crate::auth::{HostKeyInfo, Prompts, authenticate}; +use crate::known_hosts::{self, HostCheck, KnownHosts}; +use crate::ssh_config::Resolved; + +const CONNECT_TIMEOUT: Duration = Duration::from_secs(15); +const KEEPALIVE: Duration = Duration::from_secs(30); +const IDLE_CLOSE: Duration = Duration::from_secs(300); +const SWEEP: Duration = Duration::from_secs(30); + +fn runtime() -> &'static Runtime { + static RT: OnceLock = OnceLock::new(); + RT.get_or_init(|| { + tokio::runtime::Builder::new_multi_thread() + .worker_threads(2) + .thread_name("tunal-net") + .enable_all() + .build() + .expect("tokio runtime") + }) +} + +/// Runs `fut` on the network runtime and blocks the calling (non-runtime) thread. +pub(crate) fn block_on(fut: impl Future) -> T { + runtime().block_on(fut) +} + +/// Where a connection goes. +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub(crate) struct ConnKey { + pub user: String, + pub host: String, + pub port: u16, +} + +/// A live SSH connection with its SFTP session. +pub(crate) struct Conn { + handle: Handle, + pub sftp: SftpSession, + last_used: Mutex, +} + +impl Conn { + fn touch(&self) { + *self.last_used.lock().unwrap() = Instant::now(); + } + + fn alive(&self) -> bool { + !self.handle.is_closed() + } + + async fn close(&self) { + let _ = self.sftp.close().await; + let _ = self + .handle + .disconnect(russh::Disconnect::ByApplication, "", "en") + .await; + } +} + +/// Connection pool. Cheap to clone via `Arc`. +pub(crate) struct Pool { + conns: Mutex>>, + prompts: Arc, +} + +impl Pool { + pub fn new(prompts: Arc) -> Arc { + let pool = Arc::new(Self { + conns: Mutex::default(), + prompts, + }); + let weak = Arc::downgrade(&pool); + runtime().spawn(async move { + loop { + tokio::time::sleep(SWEEP).await; + let Some(pool) = weak.upgrade() else { return }; + pool.close_idle().await; + } + }); + pool + } + + /// A live connection for `key`, connecting (and authenticating) when needed. + pub fn get(&self, key: &ConnKey, resolved: &Resolved) -> Result> { + if let Some(c) = self.conns.lock().unwrap().get(key).filter(|c| c.alive()) { + c.touch(); + return Ok(c.clone()); + } + let conn = block_on(connect(key, resolved, &self.prompts))?; + self.conns.lock().unwrap().insert(key.clone(), conn.clone()); + Ok(conn) + } + + /// Forgets a connection that failed mid-operation so the next `get` reconnects. + pub fn drop_conn(&self, key: &ConnKey, conn: &Arc) { + let mut conns = self.conns.lock().unwrap(); + if conns.get(key).is_some_and(|c| Arc::ptr_eq(c, conn)) { + conns.remove(key); + } + } + + /// Closes connections unused for `IDLE_CLOSE` that nothing else holds (open streams do). + async fn close_idle(&self) { + let stale: Vec> = { + let mut conns = self.conns.lock().unwrap(); + let mut out = Vec::new(); + conns.retain(|_, c| { + let idle = c.last_used.lock().unwrap().elapsed() > IDLE_CLOSE; + let drop_it = !c.alive() || (idle && Arc::strong_count(c) == 1); + if drop_it { + out.push(c.clone()); + } + !drop_it + }); + out + }; + for c in stale { + c.close().await; + } + } +} + +async fn connect( + key: &ConnKey, + resolved: &Resolved, + prompts: &Arc, +) -> Result> { + if resolved.unsupported_proxy { + return Err(Error::Remote( + "hosts behind ProxyJump / ProxyCommand are not supported".into(), + )); + } + let config = Arc::new(client::Config { + keepalive_interval: Some(KEEPALIVE), + keepalive_max: 3, + ..Default::default() + }); + let failure = Arc::new(Mutex::new(None)); + let client = Client { + host: key.host.clone(), + port: key.port, + known: KnownHosts::load_default(), + prompts: prompts.clone(), + failure: failure.clone(), + }; + let connecting = client::connect(config, (key.host.as_str(), key.port), client); + let mut handle = match tokio::time::timeout(CONNECT_TIMEOUT, connecting).await { + Err(_) => { + return Err(Error::Remote(format!( + "connecting to {} timed out", + key.host + ))); + } + Ok(Err(e)) => { + let reason = failure.lock().unwrap().take(); + return Err(Error::Remote(reason.unwrap_or_else(|| e.to_string()))); + } + Ok(Ok(h)) => h, + }; + authenticate(&mut handle, &key.user, &key.host, resolved, prompts).await?; + let remote = |e: &dyn std::fmt::Display| Error::Remote(e.to_string()); + let channel = handle + .channel_open_session() + .await + .map_err(|e| remote(&e))?; + channel + .request_subsystem(true, "sftp") + .await + .map_err(|e| remote(&e))?; + let sftp = SftpSession::new(channel.into_stream()) + .await + .map_err(|e| remote(&e))?; + Ok(Arc::new(Conn { + handle, + sftp, + last_used: Mutex::new(Instant::now()), + })) +} + +/// russh handler: checks the server key against known_hosts. +struct Client { + host: String, + port: u16, + known: KnownHosts, + prompts: Arc, + /// Why the key was refused, for a readable error. + failure: Arc>>, +} + +impl client::Handler for Client { + type Error = russh::Error; + + async fn check_server_key( + &mut self, + key: &PublicKeyOrCertificate, + ) -> std::result::Result { + // Certificate hosts are not supported: the CA lines are ignored (S027). + let PublicKeyOrCertificate::PublicKey { key, .. } = key else { + *self.failure.lock().unwrap() = Some("host certificates are not supported".into()); + return Ok(false); + }; + let fingerprint = key.fingerprint(HashAlg::Sha256).to_string(); + let key_type = key.algorithm().to_string(); + let blob = key + .to_openssh() + .ok() + .and_then(|l| l.split_whitespace().nth(1).map(str::to_owned)); + let Some(blob) = blob else { return Ok(false) }; + let fail = |msg: String| *self.failure.lock().unwrap() = Some(msg); + match self.known.check(&self.host, self.port, &key_type, &blob) { + HostCheck::Match => Ok(true), + HostCheck::Mismatch => { + fail(format!( + "host key of {} changed ({fingerprint}); someone may be intercepting the connection", + self.host + )); + Ok(false) + } + HostCheck::Revoked => { + fail(format!( + "host key of {} is revoked ({fingerprint})", + self.host + )); + Ok(false) + } + HostCheck::Unknown => { + let info = HostKeyInfo { + host: self.host.clone(), + port: self.port, + key_type: key_type.clone(), + fingerprint, + }; + let prompts = self.prompts.clone(); + let ask = info.clone(); + let accepted = tokio::task::spawn_blocking(move || prompts.confirm_host_key(&ask)) + .await + .unwrap_or(false); + if !accepted { + fail(format!("host key of {} was not accepted", self.host)); + return Ok(false); + } + if let Some(own) = known_hosts::own_file() { + let _ = known_hosts::accept_key(&own, &self.host, self.port, &key_type, &blob); + } + Ok(true) + } + } + } +} diff --git a/crates/tunal-net/src/sftp.rs b/crates/tunal-net/src/sftp.rs new file mode 100644 index 0000000..aa2c96e --- /dev/null +++ b/crates/tunal-net/src/sftp.rs @@ -0,0 +1,374 @@ +//! `sftp://[user@]host[:port]/path` as a `Location` (russh + russh-sftp). + +use std::io::{self, Read, Write}; +use std::sync::Arc; +use std::time::{Duration, SystemTime}; + +use russh_sftp::client::error::Error as SftpError; +use russh_sftp::client::fs::{File, Metadata}; +use russh_sftp::protocol::{FileType as WireType, OpenFlags, StatusCode}; +use tokio::io::{AsyncReadExt, AsyncWriteExt}; +use tunal_core::mime::mime_type; +use tunal_core::{ + Capabilities, Entry, Error, FileType, Kind, ListSink, Location, Result, Uri, WriteMode, + display_name, +}; + +use crate::auth::Prompts; +use crate::session::{Conn, ConnKey, Pool, block_on}; +use crate::ssh_config::SshConfig; + +/// Scheme of SFTP locations. +pub const SCHEME: &str = "sftp"; + +const CHUNK: usize = 256; + +pub struct SftpLocation { + pool: Arc, + config: SshConfig, +} + +impl SftpLocation { + /// Reads `~/.ssh/config` once; `prompts` answers host key, password and passphrase questions. + pub fn new(prompts: Arc) -> Self { + Self::with_config(SshConfig::load_default(), prompts) + } + + pub fn with_config(config: SshConfig, prompts: Arc) -> Self { + Self { + pool: Pool::new(prompts), + config, + } + } + + /// The remote home folder of `uri`'s host (what a relative path starts from). + pub fn home(&self, uri: &Uri) -> Result { + let home = self.op(uri, |c| block_on(c.sftp.canonicalize(".")))?; + Ok(Uri::new(SCHEME, uri.authority(), home.into_bytes())) + } + + fn conn(&self, uri: &Uri) -> Result<(ConnKey, Arc)> { + if uri.scheme() != SCHEME { + return Err(Error::Unsupported); + } + let (user, host, port) = parse_authority(uri.authority()).ok_or(Error::Unsupported)?; + let resolved = self.config.resolve(host); + let user = user + .map(str::to_owned) + .or_else(|| resolved.user.clone()) + .or_else(|| std::env::var("USER").ok()) + .ok_or_else(|| Error::Remote("no user name for the connection".into()))?; + let key = ConnKey { + user, + host: resolved.host_name.clone(), + port: port.unwrap_or(resolved.port), + }; + let conn = self.pool.get(&key, &resolved)?; + Ok((key, conn)) + } + + /// Runs `f` on a live connection; a connection-level failure drops the connection and + /// retries once on a fresh one. + fn op( + &self, + uri: &Uri, + f: impl Fn(&Conn) -> std::result::Result, + ) -> Result { + for attempt in 0..2 { + let (key, conn) = self.conn(uri)?; + match f(&conn) { + Ok(v) => return Ok(v), + Err(e) if is_connection_error(&e) => { + self.pool.drop_conn(&key, &conn); + if attempt == 1 { + return Err(map_error(e)); + } + } + Err(e) => return Err(map_error(e)), + } + } + unreachable!() + } +} + +/// `[user@]host[:port]`. +fn parse_authority(a: &str) -> Option<(Option<&str>, &str, Option)> { + let (user, hostport) = match a.rsplit_once('@') { + Some((u, h)) => (Some(u).filter(|u| !u.is_empty()), h), + None => (None, a), + }; + let (host, port) = match hostport.rsplit_once(':') { + Some((h, p)) if !h.ends_with(']') || h.starts_with('[') => (h, Some(p.parse().ok()?)), + _ => (hostport, None), + }; + let host = host.trim_start_matches('[').trim_end_matches(']'); + (!host.is_empty()).then_some((user, host, port)) +} + +fn remote_path(uri: &Uri) -> Result { + String::from_utf8(uri.path().to_vec()).map_err(|_| Error::Unsupported) +} + +fn is_connection_error(e: &SftpError) -> bool { + match e { + SftpError::IO(_) | SftpError::Timeout => true, + SftpError::Status(s) => matches!( + s.status_code, + StatusCode::NoConnection | StatusCode::ConnectionLost + ), + _ => false, + } +} + +fn map_error(e: SftpError) -> Error { + match &e { + SftpError::Status(s) => match s.status_code { + StatusCode::NoSuchFile => Error::NotFound, + StatusCode::PermissionDenied => Error::PermissionDenied, + StatusCode::OpUnsupported => Error::Unsupported, + _ => Error::Remote(e.to_string()), + }, + _ => Error::Remote(e.to_string()), + } +} + +fn wire_kind(m: &Metadata) -> FileType { + match m.file_type() { + WireType::Dir => FileType::Dir, + WireType::File => FileType::File, + _ => FileType::Special, + } +} + +fn entry(name: Vec, m: &Metadata, link: Option<(Vec, Option)>) -> Entry { + let kind = match (link, m.file_type()) { + (Some((target, target_type)), _) => Kind::Symlink { + target, + target_type, + }, + (None, WireType::Dir) => Kind::Dir, + (None, WireType::File) => Kind::File, + (None, _) => Kind::Special, + }; + Entry { + display_name: display_name(&name), + hidden: name.first() == Some(&b'.'), + mime: mime_type(&name, &kind), + kind, + size: m.size.unwrap_or(0), + mtime: m + .mtime + .map(|t| SystemTime::UNIX_EPOCH + Duration::from_secs(t.into())), + mode: m.permissions.unwrap_or(0) & 0o7777, + uid: m.uid.unwrap_or(0), + gid: m.gid.unwrap_or(0), + name, + } +} + +/// Link target and target type for a symlink at `path`. +async fn link_info(conn: &Conn, path: &str) -> (Vec, Option) { + let target = conn + .sftp + .read_link(path) + .await + .map(String::into_bytes) + .unwrap_or_default(); + let target_type = conn.sftp.metadata(path).await.ok().map(|m| wire_kind(&m)); + (target, target_type) +} + +async fn lstat_entry( + conn: &Conn, + path: &str, + name: Vec, +) -> std::result::Result { + let m = conn.sftp.symlink_metadata(path).await?; + let link = if m.file_type() == WireType::Symlink { + Some(link_info(conn, path).await) + } else { + None + }; + Ok(entry(name, &m, link)) +} + +impl Location for SftpLocation { + fn scheme(&self) -> &str { + SCHEME + } + + fn capabilities(&self) -> Capabilities { + Capabilities { + write: true, + trash: false, + symlink: true, + watch: false, + permissions: true, + } + } + + fn list(&self, dir: &Uri, sink: &mut ListSink<'_>) -> Result<()> { + let path = remote_path(dir)?; + let entries = self.op(dir, |c| { + block_on(async { + let mut out = Vec::new(); + for e in c.sftp.read_dir(path.as_str()).await? { + let name = e.file_name(); + if name == "." || name == ".." { + continue; + } + let m = e.metadata(); + let link = if m.file_type() == WireType::Symlink { + Some(link_info(c, &e.path()).await) + } else { + None + }; + out.push(entry(name.into_bytes(), &m, link)); + } + Ok(out) + }) + })?; + let mut entries = entries.into_iter().peekable(); + while entries.peek().is_some() { + let chunk: Vec = entries.by_ref().take(CHUNK).collect(); + if sink(chunk).is_break() { + return Err(Error::Cancelled); + } + } + Ok(()) + } + + fn stat(&self, uri: &Uri) -> Result { + let path = remote_path(uri)?; + let name = uri.file_name().unwrap_or(b"/").to_vec(); + self.op(uri, |c| block_on(lstat_entry(c, &path, name.clone()))) + } + + fn open_read(&self, uri: &Uri) -> Result> { + let path = remote_path(uri)?; + let (key, conn) = self.conn(uri)?; + let file = block_on(conn.sftp.open(path)).map_err(|e| { + if is_connection_error(&e) { + self.pool.drop_conn(&key, &conn); + } + map_error(e) + })?; + Ok(Box::new(Remote { + _conn: conn, + file: Some(file), + })) + } + + fn open_write(&self, uri: &Uri, mode: WriteMode) -> Result> { + let path = remote_path(uri)?; + let flags = match mode { + WriteMode::CreateNew => OpenFlags::CREATE | OpenFlags::WRITE | OpenFlags::EXCLUDE, + WriteMode::Overwrite => OpenFlags::CREATE | OpenFlags::WRITE | OpenFlags::TRUNCATE, + }; + let (key, conn) = self.conn(uri)?; + let file = block_on(conn.sftp.open_with_flags(path, flags)).map_err(|e| { + if is_connection_error(&e) { + self.pool.drop_conn(&key, &conn); + } + match (&e, mode) { + // The server answers a failed O_EXCL open with a plain failure. + (SftpError::Status(s), WriteMode::CreateNew) + if s.status_code == StatusCode::Failure => + { + Error::Exists + } + _ => map_error(e), + } + })?; + Ok(Box::new(Remote { + _conn: conn, + file: Some(file), + })) + } + + fn mkdir(&self, uri: &Uri) -> Result<()> { + let path = remote_path(uri)?; + if self.op(uri, |c| block_on(c.sftp.try_exists(path.as_str())))? { + return Err(Error::Exists); + } + self.op(uri, |c| block_on(c.sftp.create_dir(path.as_str()))) + } + + fn rename(&self, from: &Uri, to: &Uri) -> Result<()> { + if from.authority() != to.authority() || to.scheme() != SCHEME { + return Err(Error::Unsupported); + } + let (a, b) = (remote_path(from)?, remote_path(to)?); + // Plain SFTP rename may replace or fail depending on the server: check first. + if self + .op(to, |c| block_on(c.sftp.symlink_metadata(b.as_str()))) + .is_ok() + { + return Err(Error::Exists); + } + self.op(from, |c| block_on(c.sftp.rename(a.as_str(), b.as_str()))) + } + + fn delete(&self, uri: &Uri) -> Result<()> { + let path = remote_path(uri)?; + self.op(uri, |c| { + block_on(async { + if c.sftp.symlink_metadata(path.as_str()).await?.file_type() == WireType::Dir { + c.sftp.remove_dir(path.as_str()).await + } else { + c.sftp.remove_file(path.as_str()).await + } + }) + }) + } + + fn symlink(&self, link: &Uri, target: &[u8]) -> Result<()> { + let path = remote_path(link)?; + let target = String::from_utf8(target.to_vec()).map_err(|_| Error::Unsupported)?; + // OpenSSH's sftp-server reads the two names in swapped order (unlike the spec). + self.op(link, |c| { + block_on(c.sftp.symlink(target.as_str(), path.as_str())) + }) + } +} + +/// A remote file as blocking `Read` / `Write`. Holds the connection open while in use. +struct Remote { + _conn: Arc, + file: Option, +} + +impl Remote { + fn file(&mut self) -> io::Result<&mut File> { + self.file + .as_mut() + .ok_or_else(|| io::Error::from(io::ErrorKind::BrokenPipe)) + } +} + +impl Read for Remote { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + let file = self.file()?; + block_on(file.read(buf)) + } +} + +impl Write for Remote { + fn write(&mut self, buf: &[u8]) -> io::Result { + let file = self.file()?; + block_on(file.write(buf)) + } + + fn flush(&mut self) -> io::Result<()> { + let file = self.file()?; + block_on(file.flush()) + } +} + +impl Drop for Remote { + fn drop(&mut self) { + if let Some(mut file) = self.file.take() { + let _ = block_on(file.shutdown()); + } + } +} diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md index bf21037..845e625 100644 --- a/docs/PROGRESS.md +++ b/docs/PROGRESS.md @@ -210,6 +210,14 @@ One entry per session, newest last, ≤ 15 lines: done, verified how, not done, - Not done: no iPhone (D-009, S036): pairing, Trust prompt, AFC ops, eject, names all unchecked live. Symlinks shown with unknown target type. main.rs still names the backends `mtp` (left to avoid S021's file). - Later: eject for MTP phones; device name in breadcrumb; free space via AFC device info; a "Connecting…" entry shows the default name "iPhone" until lockdown answers. +## S028 — SFTP location +- Done: `tunal-net` `sftp::SftpLocation::new(Arc)` (`with_config`, `home(uri)`), scheme `sftp`, authority `[user@]host[:port]` (host may be an ssh_config alias; user falls back to config, then $USER). Register it with `Locations::register`. Caps: write, symlink, permissions; no trash/watch. `session.rs`: own 2-thread tokio runtime (`tunal-net` threads), pool per (user, host, port): reuse, keepalive 30 s (3 misses), dead connection replaced on next use, one retry on a connection error, idle close after 5 min when nothing holds it. `auth.rs`: agent (IdentitiesOnly filters by `.pub`) → identity files (config, else id_ed25519/ecdsa/rsa; passphrase prompt, 3 tries) → password (3 tries) → keyboard-interactive. Host key via S027 `check`; Unknown → `Prompts::confirm_host_key` then `accept_key` to own file; Mismatch/Revoked/certificate → `Error::Remote` message. Reads and writes are pipelined by russh-sftp (16 in flight); `Remote` is blocking `Read`/`Write` (flush before drop to see write errors). +- Prompt API (`auth::Prompts`, all blocking, called on a worker thread, defaults refuse): `confirm_host_key(&HostKeyInfo{host,port,key_type,fingerprint})`, `password(user, host)`, `passphrase(&Path)`, `interactive(&InteractiveRequest{name,instructions,prompts[{text,echo}]})`; answers are `secrecy::SecretString`. `NoPrompts` refuses all. +- Deps (workspace): russh 0.65 (ring, no aws-lc-rs), russh-sftp 3, secrecy 0.10, zeroize 1, tokio +sync. Example `sftp-ls -- ` (terminal prompts). +- Verified: tunal-net build, clippy -D warnings, fmt --check; `cargo tree -i aws-lc-rs` empty; secret grep empty; against a local sshd (port 2299, scratch HOME, key auth): list + symlink entries, accept then silent reuse, changed key = hard error, refuse = error, mkdir/exists, create-new/overwrite, 3 MB write+read roundtrip equal, rename (Exists on clash), delete, symlink, home. Workspace clippy fails only on S023's unfinished `player_bridge` module. +- Not done: password and keyboard-interactive paths (local sshd had keys only), agent auth, passphrase keys, ProxyJump (reported unsupported); `posix-rename` not used (library hides offered extensions; rename pre-checks the target instead, so overwriting needs delete first); non-UTF-8 remote paths give `Unsupported`; `NotEmpty` not reported (server says failure); russh keeps its own copy of the password string, not zeroized. Real host check is S036. +- Later: posix-rename via the raw session; watch by polling. + ## Later - (orchestrator) Breadcrumb: a long path is hard-clipped at the bar's left edge with no elision mark, and the root crumb elides at 960 px — for S034. -