General Upgrade, NEW: WebServers, Better Docs
Some checks failed
CI / checks (push) Failing after 4m5s

This commit is contained in:
Alex Emmet 2026-07-18 03:08:03 +02:00
commit f3b6393849
120 changed files with 10036 additions and 4887 deletions

447
example/Cargo.lock generated
View file

@ -51,6 +51,17 @@ dependencies = [
"syn",
]
[[package]]
name = "async-trait"
version = "0.1.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "autocfg"
version = "1.5.1"
@ -156,6 +167,12 @@ dependencies = [
"shlex",
]
[[package]]
name = "cesu8"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
[[package]]
name = "cfg-if"
version = "1.0.4"
@ -205,7 +222,7 @@ dependencies = [
[[package]]
name = "client"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"mtp",
"rand 0.8.6",
@ -227,6 +244,16 @@ version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a"
[[package]]
name = "combine"
version = "4.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd"
dependencies = [
"bytes",
"memchr",
]
[[package]]
name = "const-oid"
version = "0.9.6"
@ -457,6 +484,24 @@ dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "fastbloom"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7f34442dbe69c60fe8eaf58a8cafff81a1f278816d8ab4db255b3bef4ac3c4"
dependencies = [
"getrandom 0.3.4",
"libm",
"rand 0.9.4",
"siphasher",
]
[[package]]
name = "fastrand"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6"
[[package]]
name = "fiat-crypto"
version = "0.2.9"
@ -484,12 +529,71 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
[[package]]
name = "futures"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
name = "futures-core"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d"
[[package]]
name = "futures-executor"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf29c38818342a3b26b5b923639e7b1f4a61fc5e76102d4b1981c6dc7a7579d"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-io"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718"
[[package]]
name = "futures-macro"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "futures-sink"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893"
[[package]]
name = "futures-task"
version = "0.3.32"
@ -502,8 +606,13 @@ version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-macro",
"futures-sink",
"futures-task",
"memchr",
"pin-project-lite",
"slab",
]
@ -557,6 +666,62 @@ dependencies = [
"rand_core 0.10.1",
]
[[package]]
name = "h3"
version = "0.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10872b55cfb02a821b69dc7cf8dc6a71d6af25eb9a79662bec4a9d016056b3be"
dependencies = [
"bytes",
"fastrand",
"futures-util",
"http",
"pin-project-lite",
"tokio",
]
[[package]]
name = "h3-datagram"
version = "0.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d2c9f77921668673721ae40f17c729fc48b9e38a663858097cea547484fdf0f"
dependencies = [
"bytes",
"h3",
"pin-project-lite",
]
[[package]]
name = "h3-quinn"
version = "0.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b2e732c8d91a74731663ac8479ab505042fbf547b9a207213ab7fbcbfc4f8b4"
dependencies = [
"bytes",
"futures",
"h3",
"h3-datagram",
"quinn",
"tokio",
"tokio-util",
]
[[package]]
name = "h3-webtransport"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d91a50fd582a5d67b1f756fba3cd9c66367ff4f23e1017c882f664d63b350a7"
dependencies = [
"bytes",
"futures-util",
"h3",
"h3-datagram",
"http",
"pin-project-lite",
"tokio",
"tracing",
]
[[package]]
name = "hashbrown"
version = "0.17.1"
@ -593,6 +758,16 @@ version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a9fcbcc408c5526c3ab80d534e5c86e7967c1fb7aa0a8c76abd1edc27deb877"
[[package]]
name = "http"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6970f50e31d6fc17d3fa27329444bfa74e196cf62e95052a3f6fee181dba6425"
dependencies = [
"bytes",
"itoa",
]
[[package]]
name = "hybrid-array"
version = "0.4.13"
@ -731,6 +906,50 @@ version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
[[package]]
name = "jni"
version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97"
dependencies = [
"cesu8",
"cfg-if",
"combine",
"jni-sys 0.3.1",
"log",
"thiserror 1.0.69",
"walkdir",
"windows-sys 0.45.0",
]
[[package]]
name = "jni-sys"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41a652e1f9b6e0275df1f15b32661cf0d4b78d4d87ddec5e0c3c20f097433258"
dependencies = [
"jni-sys 0.4.1",
]
[[package]]
name = "jni-sys"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6377a88cb3910bee9b0fa88d4f42e1d2da8e79915598f65fb0c7ee14c878af2"
dependencies = [
"jni-sys-macros",
]
[[package]]
name = "jni-sys-macros"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264"
dependencies = [
"quote",
"syn",
]
[[package]]
name = "jobserver"
version = "0.1.34"
@ -773,7 +992,7 @@ dependencies = [
[[package]]
name = "keygen"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"mtp",
]
@ -790,6 +1009,12 @@ version = "0.2.186"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
[[package]]
name = "libm"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
[[package]]
name = "litemap"
version = "0.8.2"
@ -895,7 +1120,7 @@ dependencies = [
[[package]]
name = "mtp"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"mtp-client",
"mtp-codec",
@ -905,11 +1130,12 @@ dependencies = [
"mtp-host",
"mtp-transport",
"mtp-type-map",
"mtp-webserver",
]
[[package]]
name = "mtp-client"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"mtp-codec",
"mtp-common",
@ -922,7 +1148,7 @@ dependencies = [
[[package]]
name = "mtp-codec"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"base64",
"byteorder",
@ -934,7 +1160,7 @@ dependencies = [
[[package]]
name = "mtp-common"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"quinn",
"rustls",
@ -944,7 +1170,7 @@ dependencies = [
[[package]]
name = "mtp-crypto"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"base64",
"chacha20poly1305",
@ -954,23 +1180,27 @@ dependencies = [
"ml-dsa",
"mlkem-tls",
"rand_core 0.6.4",
"rcgen",
"serde",
"sha2 0.11.0",
"thiserror 1.0.69",
"time",
"zeroize",
]
[[package]]
name = "mtp-files"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"mtp-crypto",
"rand_core 0.6.4",
"thiserror 1.0.69",
"zeroize",
]
[[package]]
name = "mtp-host"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"mtp-codec",
"mtp-common",
@ -978,18 +1208,20 @@ dependencies = [
"mtp-transport",
"rand 0.8.6",
"tokio",
"tracing",
]
[[package]]
name = "mtp-transport"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"log",
"async-trait",
"mtp-codec",
"mtp-common",
"rcgen",
"rustls",
"rustls-native-certs",
"sha2 0.11.0",
"tokio",
"tracing",
"wtransport",
@ -997,12 +1229,42 @@ dependencies = [
[[package]]
name = "mtp-type-map"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"serde",
"serde_yaml",
]
[[package]]
name = "mtp-webserver"
version = "0.2.0"
dependencies = [
"async-trait",
"bytes",
"h3",
"h3-quinn",
"h3-webtransport",
"http",
"mtp-codec",
"mtp-common",
"mtp-host",
"mtp-transport",
"quinn",
"rustls",
"thiserror 2.0.18",
"tokio",
"tracing",
]
[[package]]
name = "mtp-webserver-example"
version = "0.2.0"
dependencies = [
"http",
"mtp",
"tokio",
]
[[package]]
name = "nom"
version = "7.1.3"
@ -1212,6 +1474,7 @@ checksum = "0c1a41e437b6bbd489372cd4971de128e85c855f56c57f283d20ff016cf7c0a8"
dependencies = [
"bytes",
"cfg_aliases",
"futures-io",
"pin-project-lite",
"quinn-proto",
"quinn-udp",
@ -1232,6 +1495,7 @@ checksum = "4fcb935c5bec503c2f0e306bdd3e58bb9029dcb14fa8d9ac76e3a5256ac0763e"
dependencies = [
"aws-lc-rs",
"bytes",
"fastbloom",
"getrandom 0.3.4",
"lru-slab",
"rand 0.9.4",
@ -1239,6 +1503,7 @@ dependencies = [
"rustc-hash",
"rustls",
"rustls-pki-types",
"rustls-platform-verifier",
"slab",
"thiserror 2.0.18",
"tinyvec",
@ -1446,6 +1711,33 @@ dependencies = [
"zeroize",
]
[[package]]
name = "rustls-platform-verifier"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d99feebc72bae7ab76ba994bb5e121b8d83d910ca40b36e0921f53becc41784"
dependencies = [
"core-foundation",
"core-foundation-sys",
"jni",
"log",
"once_cell",
"rustls",
"rustls-native-certs",
"rustls-platform-verifier-android",
"rustls-webpki",
"security-framework",
"security-framework-sys",
"webpki-root-certs",
"windows-sys 0.61.2",
]
[[package]]
name = "rustls-platform-verifier-android"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f"
[[package]]
name = "rustls-webpki"
version = "0.103.13"
@ -1470,6 +1762,15 @@ version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]]
name = "schannel"
version = "0.1.29"
@ -1572,14 +1873,12 @@ dependencies = [
[[package]]
name = "server"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"base64",
"hex",
"mtp",
"rcgen",
"serde_json",
"time",
"tokio",
]
@ -1617,7 +1916,7 @@ dependencies = [
[[package]]
name = "shake"
version = "0.1.0"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09057cb2149ad4cbd2da1e26b351f9a4c354219421229c69c3063e6f61947c4a"
dependencies = [
@ -1661,6 +1960,12 @@ dependencies = [
"rand_core 0.10.1",
]
[[package]]
name = "siphasher"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
[[package]]
name = "slab"
version = "0.4.12"
@ -1705,7 +2010,7 @@ dependencies = [
[[package]]
name = "sponge-cursor"
version = "0.1.0"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a0219bd7d979d58245a4f41f695e1ac9f8befdffadd7f61f1bae9e39abc6620"
@ -1866,12 +2171,26 @@ dependencies = [
"syn",
]
[[package]]
name = "tokio-util"
version = "0.7.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098"
dependencies = [
"bytes",
"futures-core",
"futures-sink",
"pin-project-lite",
"tokio",
]
[[package]]
name = "tracing"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
dependencies = [
"log",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
@ -1961,6 +2280,16 @@ version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "walkdir"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
dependencies = [
"same-file",
"winapi-util",
]
[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
@ -2031,12 +2360,39 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "webpki-root-certs"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d46a5a140e6f7afeccd8eae97eff335163939eac8b929834875168b29b3d267"
dependencies = [
"rustls-pki-types",
]
[[package]]
name = "winapi-util"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-sys"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [
"windows-targets 0.42.2",
]
[[package]]
name = "windows-sys"
version = "0.52.0"
@ -2064,6 +2420,21 @@ dependencies = [
"windows-link",
]
[[package]]
name = "windows-targets"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
dependencies = [
"windows_aarch64_gnullvm 0.42.2",
"windows_aarch64_msvc 0.42.2",
"windows_i686_gnu 0.42.2",
"windows_i686_msvc 0.42.2",
"windows_x86_64_gnu 0.42.2",
"windows_x86_64_gnullvm 0.42.2",
"windows_x86_64_msvc 0.42.2",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
@ -2097,6 +2468,12 @@ dependencies = [
"windows_x86_64_msvc 0.53.1",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
@ -2109,6 +2486,12 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
@ -2121,6 +2504,12 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006"
[[package]]
name = "windows_i686_gnu"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
@ -2145,6 +2534,12 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c"
[[package]]
name = "windows_i686_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
@ -2157,6 +2552,12 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
@ -2169,6 +2570,12 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
@ -2181,6 +2588,12 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"

View file

@ -1,6 +1,6 @@
[workspace]
members = [
"server",
"client", "keygen",
"client", "keygen", "webserver",
]
resolver = "3"

View file

@ -1,6 +1,6 @@
[package]
name = "client"
version = "0.1.0"
version = "0.2.0"
edition = "2024"
[[bin]]
@ -8,6 +8,6 @@ name = "client"
path = "src/main.rs"
[dependencies]
mtp = { version = "0.1.0", path = "../../", features = ["client", "crypto", "files", "pipes"] }
mtp = { version = "0.2.0", path = "../../", features = ["client", "crypto", "files", "pipes"] }
tokio = { version = "1", features = ["full"] }
rand = "0.8"

View file

@ -4,7 +4,7 @@ use mtp::client::{ClientConfig, MTPClient, MTPConnection};
use mtp::crypto::{
Ed25519Signer, KemPrivateKey, KemPublicKey, Keyring, MlDsaSigner, PublicKeyBundle,
};
use mtp::files::{load_keyring, save_keyring};
use mtp::files::{load_keyring_raw, save_keyring_raw};
pub async fn connect_or_register(
mut config: ClientConfig,
@ -14,7 +14,10 @@ pub async fn connect_or_register(
let keyring_path = format!("{key_prefix}.mk");
let id_path = format!("{key_prefix}.id");
if let (Ok(keyring), Ok(id)) = (load_keyring(&keyring_path), fs::read_to_string(&id_path)) {
if let (Ok(keyring), Ok(id)) = (
load_keyring_raw(&keyring_path),
fs::read_to_string(&id_path),
) {
let client_id: u64 = id.trim().parse()?;
println!("Loaded client keys (ID: {client_id})");
@ -41,7 +44,7 @@ pub async fn connect_or_register(
let conn = MTPClient::auth_register(config, &keyring, &host_public_key).await?;
println!("Registered with ID: {}", conn.client_id);
save_keyring(&keyring, &keyring_path)?;
save_keyring_raw(&keyring, &keyring_path)?;
fs::write(&id_path, conn.client_id.to_string())?;
println!("Saved client keys -> {keyring_path}");

View file

@ -13,33 +13,33 @@ pub fn build_demo_message(
let signer = Ed25519Signer::new(&keyring.sig_cl_secret_key)?;
let tm = TypeMap::latest();
let version_id = DataType::Version
.try_to_id(&tm)
.ok_or_else(|| std::io::Error::other("Version is absent from the type map"))?;
let id_id = DataType::Id
.try_to_id(&tm)
.ok_or_else(|| std::io::Error::other("Id is absent from the type map"))?;
let inner_enc = DataValue::Container(vec![
(
DataType::Version.to_id(&tm),
DataValue::Str("secret inner data".into()),
),
(DataType::Id.to_id(&tm), DataValue::UnsignedNumber(42)),
(version_id, DataValue::Str("secret inner data".into())),
(id_id, DataValue::UnsignedNumber(42)),
]);
let mut dv_enc = inner_enc;
dv_enc.encrypt_container(enc_type, server_bundle, b"demo-aad");
let inner_sig = DataValue::Container(vec![
(
DataType::Version.to_id(&tm),
DataValue::Str("signed by client".into()),
),
(DataType::Id.to_id(&tm), DataValue::UnsignedNumber(99)),
(version_id, DataValue::Str("signed by client".into())),
(id_id, DataValue::UnsignedNumber(99)),
]);
let mut dv_sig = inner_sig;
dv_sig.sign_container(SigAlgorithm::ED25519, &signer);
let inner_sec = DataValue::Container(vec![
(
DataType::Version.to_id(&tm),
version_id,
DataValue::Str("signed+encrypted payload".into()),
),
(DataType::Id.to_id(&tm), DataValue::UnsignedNumber(7)),
(id_id, DataValue::UnsignedNumber(7)),
]);
let mut dv_sec = inner_sec;
dv_sec.sign_and_encrypt_container(
@ -65,7 +65,7 @@ pub fn build_demo_message(
)
.add_typed_default(DataType::Data, DataValue::Str("Hello, MTP!".into()))
.add_typed_default(DataType::Flags, DataValue::BoolTrue)
.add_typed_default(DataType::Value, DataValue::Float(2, 12345))
.add_typed_default(DataType::Value, DataValue::Float(1_234_500.0))
.add_typed_default(
DataType::BinaryData,
DataValue::Bytes(vec![0xDE, 0xAD, 0xBE, 0xEF, 0x42]),

View file

@ -1,7 +1,7 @@
[package]
name = "keygen"
version = "0.1.0"
version = "0.2.0"
edition = "2024"
[dependencies]
mtp = { version = "0.1.0", path = "../../", features = ["files"] }
mtp = { version = "0.2.0", path = "../../", features = ["files"] }

View file

@ -2,8 +2,8 @@ use std::path::PathBuf;
use mtp::crypto::Keyring;
use mtp::files::{
self, BUNDLE_EXTENSION, KEYRING_EXTENSION, load_keyring, load_public_key_bundle, save_keyring,
save_public_key_bundle,
self, BUNDLE_EXTENSION, KEYRING_EXTENSION, load_keyring_raw, load_public_key_bundle,
save_keyring_raw, save_public_key_bundle,
};
fn main() -> Result<(), files::FileError> {
@ -11,11 +11,11 @@ fn main() -> Result<(), files::FileError> {
let bundle_path = PathBuf::from(format!("bundle.{BUNDLE_EXTENSION}"));
let keyring = Keyring::generate();
save_keyring(&keyring, &keyring_path)?;
save_keyring_raw(&keyring, &keyring_path)?;
save_public_key_bundle(&keyring.public_key_bundle(), &bundle_path)?;
/* Read both back to confirm the files round-trip through the on-disk format. */
let loaded_keyring = load_keyring(&keyring_path)?;
let loaded_keyring = load_keyring_raw(&keyring_path)?;
let loaded_bundle = load_public_key_bundle(&bundle_path)?;
assert_eq!(keyring.to_bytes(), loaded_keyring.to_bytes());
assert_eq!(

View file

@ -1,6 +1,6 @@
[package]
name = "server"
version = "0.1.0"
version = "0.2.0"
edition = "2024"
[[bin]]
@ -8,10 +8,8 @@ name = "server"
path = "src/main.rs"
[dependencies]
mtp = { version = "0.1.0", path = "../../", features = ["crypto", "host", "files", "pipes"] }
rcgen = "0.14"
mtp = { version = "0.2.0", path = "../../", features = ["crypto", "tls", "host", "files", "pipes"] }
tokio = { version = "1", features = ["full"] }
serde_json = { version = "1" }
hex = "0.4"
base64 = "0.22"
time = "0.3"

View file

@ -1,7 +1,7 @@
use std::fs;
use mtp::crypto::Keyring;
use mtp::files::{load_keyring, save_keyring, save_public_key_bundle};
use mtp::files::{load_keyring_raw, save_keyring_raw, save_public_key_bundle};
/* Host id is fixed for the example; only the keyring itself is persisted. */
const HOST_ID: u64 = 1;
@ -9,13 +9,13 @@ const HOST_ID: u64 = 1;
pub fn load_or_generate_host_keys(
keyring_path: &str,
) -> Result<(u64, Keyring), Box<dyn std::error::Error>> {
if let Ok(keyring) = load_keyring(keyring_path) {
if let Ok(keyring) = load_keyring_raw(keyring_path) {
println!("Loaded host keyring from {keyring_path}");
return Ok((HOST_ID, keyring));
}
let keyring = Keyring::generate();
save_keyring(&keyring, keyring_path)?;
save_keyring_raw(&keyring, keyring_path)?;
println!("Generated host keyring -> {keyring_path}");
Ok((HOST_ID, keyring))
}

View file

@ -86,13 +86,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (_host_id, host_keyring) = keys::load_or_generate_host_keys("host.mk")?;
keys::export_host_public_keys(&host_keyring)?;
let decrypt_keyring = Arc::new(match mtp::crypto::Keyring::from_bytes(&host_keyring.to_bytes())
{
Ok(keyring) => keyring,
Err(e) => {
return Err(format!("failed to re-load host keyring for decryption: {e}").into());
}
});
let decrypt_keyring = Arc::new(
match mtp::crypto::Keyring::from_bytes(&host_keyring.to_bytes()) {
Ok(keyring) => keyring,
Err(e) => {
return Err(format!("failed to re-load host keyring for decryption: {e}").into());
}
},
);
let (clients, next_id) = clients::load_client_db("clients.json")?;
@ -100,7 +101,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let get_existing_user = move |id: u64, _description: Option<String>| {
let clients = clients_for_get.clone();
Box::pin(async move {
let result = clients.lock()?.get(&id).cloned();
let result = clients.lock().unwrap().get(&id).cloned();
if result.is_some() {
println!("Auth lookup: client ID {id} found");
} else {
@ -119,8 +120,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let nid_arc = next_id_for_register.clone();
let path = clients_path.clone();
Box::pin(async move {
let mut db = db_arc.lock()?;
let mut nid = nid_arc.lock()?;
let mut db = db_arc.lock().unwrap();
let mut nid = nid_arc.lock().unwrap();
let id = *nid;
*nid += 1;
db.insert(id, bundle);
@ -166,7 +167,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
);
println!("Client ID: {}", conn.client_id);
let tm: &TypeMap = conn.codec.registry().get(&conn.version)?;
let tm: &TypeMap = conn.codec.registry().get(&conn.version).unwrap();
println!("Waiting for messages / pipe requests ...");
loop {

View file

@ -1,9 +1,6 @@
use base64::Engine;
use rcgen::{CertificateParams, ExtendedKeyUsagePurpose, IsCa, KeyPair, KeyUsagePurpose, SanType};
use std::fs;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::path::Path;
use time::{Duration, OffsetDateTime};
pub fn load_or_generate_tls(
cert_path: &str,
@ -22,35 +19,13 @@ pub fn load_or_generate_tls(
fs::create_dir_all(parent)?;
}
let key_pair = KeyPair::generate_for(&rcgen::PKCS_ECDSA_P256_SHA256)?;
let (cert_pem, key_pem) = mtp::crypto::tls::generate_self_signed_cert("localhost")?;
let mut params = CertificateParams::new(vec!["localhost".into()])?;
params.not_before = OffsetDateTime::now_utc() - Duration::minutes(5);
params.not_after = OffsetDateTime::now_utc() + Duration::days(13);
params
.subject_alt_names
.push(SanType::IpAddress(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))));
params
.subject_alt_names
.push(SanType::IpAddress(IpAddr::V6(Ipv6Addr::new(
0, 0, 0, 0, 0, 0, 0, 1,
))));
params.key_usages = vec![KeyUsagePurpose::DigitalSignature];
params.extended_key_usages = vec![ExtendedKeyUsagePurpose::ServerAuth];
params.is_ca = IsCa::NoCa;
let cert = params.self_signed(&key_pair)?;
let cert_str = cert.pem();
let key_str = key_pair.serialize_pem();
fs::write(cert_path, cert_str.as_bytes())?;
fs::write(key_path, key_str.as_bytes())?;
fs::write(cert_path, &cert_pem)?;
fs::write(key_path, &key_pem)?;
println!("Wrote {cert_path} and {key_path}");
Ok((cert_str.into_bytes(), key_str.into_bytes()))
Ok((cert_pem, key_pem))
}
pub fn certificate_sha256_hex(cert: &[u8]) -> Result<String, Box<dyn std::error::Error>> {

View file

@ -1,7 +1,7 @@
{
"name": "mtp-web-client",
"private": true,
"version": "0.1.0",
"version": "0.2.0",
"type": "module",
"packageManager": "pnpm@11.8.0",
"scripts": {

View file

@ -0,0 +1,10 @@
[package]
name = "mtp-webserver-example"
version = "0.2.0"
edition = "2024"
publish = false
[dependencies]
http = "1"
mtp = { path = "../..", features = ["web-server"] }
tokio = { version = "1", features = ["full"] }

View file

@ -0,0 +1,38 @@
use http::StatusCode;
use mtp::{
host::HostConfig,
webserver::{Http3Request, Http3Response, MTPWebServer, WebServerConfig},
};
async fn health(_request: Http3Request, response: Http3Response) -> Http3Response {
response
.status(StatusCode::OK)
.header("content-type", "application/json")
.body(r#"{"status":"ok"}"#)
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = HostConfig::new(
"0.0.0.0".parse()?,
4433,
std::fs::read("cert.pem")?,
std::fs::read("key.pem")?,
);
let web = WebServerConfig::new().route("/health", health)?.mtp_path("/mtp");
let mut server = MTPWebServer::new(config, web).await?;
println!("listening on {}", server.local_addr());
while let Some(connection) = server.accept().await? {
println!(
"MTP client connected: path={}, version={}, description={:?}",
connection.path, connection.version, connection.description
);
tokio::spawn(async move {
while let Ok(message) = connection.receiver.receive().await {
println!("received MTP message {}", message.get_id());
}
});
}
Ok(())
}