diff --git a/.github/workflows/mod-registry.yml b/.github/workflows/mod-registry.yml new file mode 100644 index 000000000..0f252bb68 --- /dev/null +++ b/.github/workflows/mod-registry.yml @@ -0,0 +1,34 @@ +name: mod-registry +# The submission service is its own workspace (crates/horizon-mod-registry), so the checks job doesn't build +# it: this one does, when it or horizon-mods (the checks it shares with the launcher and the game) changes. +on: + push: + branches: [main] + paths: + - 'crates/horizon-mods/**' + - 'crates/horizon-mod-registry/**' + - '.github/workflows/mod-registry.yml' + pull_request: + paths: + - 'crates/horizon-mods/**' + - 'crates/horizon-mod-registry/**' + - '.github/workflows/mod-registry.yml' +permissions: + contents: read +jobs: + check: + runs-on: ubuntu-latest + timeout-minutes: 20 + defaults: + run: + working-directory: crates/horizon-mod-registry + steps: + - uses: actions/checkout@v4 + - run: rustup toolchain install stable --profile minimal --component rustfmt --component clippy + - uses: Swatinem/rust-cache@v2 + with: + workspaces: crates/horizon-mod-registry + save-if: ${{ github.ref == 'refs/heads/main' }} + - run: cargo +stable fmt --check + - run: cargo +stable clippy --all-targets --locked -- -D warnings + - run: cargo +stable test --locked diff --git a/Cargo.toml b/Cargo.toml index f197c34fe..6271b9673 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -exclude = ["launcher", "crates/horizon-telemetry-server", "third_party/wgpu-hal"] +exclude = ["launcher", "crates/horizon-telemetry-server", "crates/horizon-mod-registry", "third_party/wgpu-hal"] members = ["crates/horizon-core", "crates/horizon-dualsense", "crates/horizon-threads", "crates/horizon-world", "crates/horizon-client", "crates/horizon-server-files", "crates/horizon-server", "crates/horizon-bots", "crates/horizon-assets", "crates/horizon-protocol", "crates/horizon-theme", "crates/horizon-prepare", "crates/horizon-telemetry", "crates/horizon-bench", "crates/horizon-friends", "crates/horizon-relay", "crates/horizon-mod-sdk", "crates/horizon-mods", "crates/horizon-mods/tests/guest", "crates/cargo-horizon-mod", "crates/horizon-port-pack", "crates/horizon-release-sign", "crates/horizon-mod-sdk/examples/coords-hud", "xtask"] resolver = "2" diff --git a/crates/horizon-mod-registry/Cargo.lock b/crates/horizon-mod-registry/Cargo.lock new file mode 100644 index 000000000..44ef1e078 --- /dev/null +++ b/crates/horizon-mod-registry/Cargo.lock @@ -0,0 +1,1352 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "arbitrary" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bc62ac97cc33321f50863d514c3bc38a453947a8f9e781137e47c7401020aed" +dependencies = [ + "derive_arbitrary", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "axum" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31b698c5f9a010f6573133b09e0de5408834d0c82f8d7475a89fc1867a71cd90" +dependencies = [ + "axum-core", + "bytes", + "form_urlencoded", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "multer", + "percent-encoding", + "pin-project-lite", + "serde_core", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "sync_wrapper", + "tower-layer", + "tower-service", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + +[[package]] +name = "cc" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86e055fa6e3e40ad6187ba25b6855eeb635d5271f8e0f0e1e9a5826b8d75bea0" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "core_detect" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ba106e844045ddc02c20768ac4b0b7cb45f2cc2ecbd833ac9f5dacb183c2055" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6" + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "derive_arbitrary" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b034bd7d5f032402a2479444dcc6f74e36a03f31854d41680fb240ef682a1ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", + "subtle", +] + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "encoding_rs" +version = "0.8.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e985e0451871ad22fb8d2b6b076e2028a502a0d3950998c2c5c0a4f9b5d9679" +dependencies = [ + "cfg-if", + "core_detect", + "multiversion_no_op", + "rustversion", + "scopeguard", + "simdutf8", +] + +[[package]] +name = "equivalent" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" + +[[package]] +name = "flate2" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e634e2e0ebac1ee034020da1ca582e17ffe4e0f5e985823721e168928136dcb" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasip2", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "horizon-mod-registry" +version = "0.1.0" +dependencies = [ + "axum", + "base64", + "getrandom 0.3.4", + "hmac", + "horizon-mods", + "http-body-util", + "serde", + "serde_json", + "sha2", + "tokio", + "toml", + "tower", + "ureq", +] + +[[package]] +name = "horizon-mods" +version = "0.1.0" +dependencies = [ + "log", + "minisign-verify", + "serde", + "serde_json", + "sha2", + "toml", + "zip", +] + +[[package]] +name = "http" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c3e324da4c95177d6291d4c8730197c0d1822f8a9766814a4a44fa5ab797c9c" +dependencies = [ + "atomic-waker", + "bytes", + "futures-core", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", +] + +[[package]] +name = "hyper-util" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddc03d96684f9226b8a787cdb71488417b53ab5ea8fdb1dac946cb9431cc8bff" +dependencies = [ + "bytes", + "http", + "http-body", + "hyper", + "pin-project-lite", + "tokio", + "tower-service", +] + +[[package]] +name = "icu_collections" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe090a42a0d3140fed8c63263ed1fecc02422cb2f4bfe55cd8de2de1b8e105dd" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25d29b57c17c6528d0dc4c2141cfa2d08200465acb537a3909c8b9b8a4a984c0" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "404a3b8c486f205c87fe7f23ab6894d84a4ad76d6e4671ae1981ba7def87c599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20f0088bfb7441f7a37fa0c9e20cb1e9cba1cac6b9ce8cd2a6dc44294f8e8cbc" + +[[package]] +name = "icu_properties" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ea83d991c56158f7cf898bf86436c1dfe7c07ee82fe88951f2695c9f37a379f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98f29af82d02b163fe50161388350e743bb3107cc8e8c2f7314cb505faddfcf" + +[[package]] +name = "icu_provider" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413099315636c588ee8f011190b329b971a09a8fae9d157e01dcae8379468514" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "libc" +version = "0.2.191" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" + +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + +[[package]] +name = "log" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" + +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "minisign-verify" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "871285dc19d8d0ebe0eef3d0e99a205f2a71363b122632cbbfa4a6c370a960ce" + +[[package]] +name = "miniz_oxide" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "mio" +version = "1.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1788edb87fdc09c7e26304471e2f5be8cdefb1b6930d6e3985fc02ff53bf86ee" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "multer" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83e87776546dc87511aa5ee218730c92b666d7264ab6ed41f9d215af9cd5224b" +dependencies = [ + "bytes", + "encoding_rs", + "futures-util", + "http", + "httparse", + "memchr", + "mime", + "spin", + "version_check", +] + +[[package]] +name = "multiversion_no_op" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "743fb55ba31b18fb1ecef6bdc9aa2743314978ac084044301a7eee33fb99a20d" + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "zerovec", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf" +dependencies = [ + "log", + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" +dependencies = [ + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + +[[package]] +name = "serde_spanned" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7523beb55eece201a2356bee0bbca0d1ab466c14c07703b2e0ee6d42cb0c2c" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "simd-adler32" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" + +[[package]] +name = "simdutf8" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.16.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0d5d4b1981b8bbbb7aed204cae5726d683d5d6ac7e74ec54122ea28f315e7c8" + +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "spin" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3763264f6b73151db08c50ff20d7d8a0b8796e021cdea7ceedad07b80155fa0e" + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "3.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" + +[[package]] +name = "synstructure" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinystr" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abc840c238154d58f9e86b2792261edfde565a17696e1cda1a449de27979801a" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tokio" +version = "1.54.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b52fd3255258d26fac7264ab5a76b53c13367136dc011d3d6ad4f8ed070396a3" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "signal-hook-registry", + "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", +] + +[[package]] +name = "toml" +version = "1.1.8+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20489e00e4d8741d6be680764cc12e270655e375a20d1011e844a9c3379e678d" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow", +] + +[[package]] +name = "toml_datetime" +version = "1.1.2+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b86d767906c6c42421dcba507eb9d203e779497710a47782a224bb871653053" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_parser" +version = "1.1.5+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baa693a8032d7e1cada7d0041e96126df243179ff061456783ac7f12bda4744c" +dependencies = [ + "winnow", +] + +[[package]] +name = "toml_writer" +version = "1.1.3+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06bdbd8cfc056b8d2e2e85f29b56a3bdbecb527cef81eb39e3e7b98af4652770" + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "ureq" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d" +dependencies = [ + "base64", + "log", + "once_cell", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "url", + "webpki-roots 0.26.11", +] + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.4+wasi-0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "0.26.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" +dependencies = [ + "webpki-roots 1.0.11", +] + +[[package]] +name = "webpki-roots" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5f280bbb2b287bc8e7de7e3852945a0ff50d1bbcb5ed42b6c7a568c546df171" +dependencies = [ + "rustls-pki-types", +] + +[[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.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81" + +[[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + +[[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + +[[package]] +name = "yoke" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "417ef3fcf6c300b7dbd25c85531a746931c02ad536f3cf4786ed1e88223340b3" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8ebde2db3681e8c9980cc27822030e68752690ddfa9473e739aeb4dbde6d71" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" + +[[package]] +name = "zerotrie" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f58a2799cfe9a1670c7ea8edbd52ef8edb93cb37a7f83bf31ba9e35d9dae6a40" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3743ddbf47738d929cd1ae2e199d40d0162979dfe31aef8ae646d2bf00bf97a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zip" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dcb24d0152526ae49b9b96c1dcf71850ca1e0b882e4e28ed898a93c41334744" +dependencies = [ + "arbitrary", + "crc32fast", + "crossbeam-utils", + "flate2", + "indexmap", + "memchr", + "zopfli", +] + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" + +[[package]] +name = "zopfli" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaf7fc5d30c28483d93805c4a5e12b05bbb52407fa67c5f8bd552374cd01fb11" +dependencies = [ + "bumpalo", + "crc32fast", + "log", + "simd-adler32", +] diff --git a/crates/horizon-mod-registry/Cargo.toml b/crates/horizon-mod-registry/Cargo.toml new file mode 100644 index 000000000..affc08f62 --- /dev/null +++ b/crates/horizon-mod-registry/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "horizon-mod-registry" +version = "0.1.0" +edition = "2024" +license = "MIT" +rust-version = "1.90" +publish = false +description = "The registry's submission service: GitHub sign-in, the file's checks, staging, and a pull request (docs/api/mod-index.md)" + +# Its own workspace, as the telemetry server's: the game's workspace never builds a web server. +[workspace] + +[dependencies] +horizon-mods = { path = "../horizon-mods", default-features = false, features = ["index"] } +axum = { version = "0.8", default-features = false, features = ["http1", "tokio", "json", "query", "multipart"] } +tokio = { version = "1", features = ["rt-multi-thread", "macros", "net", "signal", "fs", "io-util"] } +serde = { version = "1", features = ["derive"] } +serde_json = "1" +toml = "1" +# GitHub's API, blocking, on tokio's blocking pool: the launcher's HTTP client. +ureq = { version = "2", default-features = false, features = ["json", "tls"] } +hmac = "0.12" +sha2 = "0.10" +base64 = "0.22" +getrandom = "0.3" + +[dev-dependencies] +tower = { version = "0.5", features = ["util"] } +http-body-util = "0.1" + +[profile.release] +strip = true +lto = "thin" diff --git a/crates/horizon-mod-registry/Dockerfile b/crates/horizon-mod-registry/Dockerfile new file mode 100644 index 000000000..13522165a --- /dev/null +++ b/crates/horizon-mod-registry/Dockerfile @@ -0,0 +1,14 @@ +# Built from the repository root: docker build -f crates/horizon-mod-registry/Dockerfile . +FROM rust:1-slim AS build +WORKDIR /src +# The root manifest only for the shared crate's workspace settings (edition, lints). +COPY Cargo.toml Cargo.toml +COPY crates/horizon-mods crates/horizon-mods +COPY crates/horizon-mod-registry crates/horizon-mod-registry +RUN cargo build --release --locked --manifest-path crates/horizon-mod-registry/Cargo.toml + +FROM debian:stable-slim +RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/* +COPY --from=build /src/crates/horizon-mod-registry/target/release/horizon-mod-registry /usr/local/bin/ +USER nobody +CMD ["horizon-mod-registry"] diff --git a/crates/horizon-mod-registry/README.md b/crates/horizon-mod-registry/README.md new file mode 100644 index 000000000..936fe5acf --- /dev/null +++ b/crates/horizon-mod-registry/README.md @@ -0,0 +1,44 @@ +# horizon-mod-registry + +The service behind the registry's submission form (`playhorizon.dev/mods/submit`). A creator signs in with GitHub and +sends a file with its page; the service runs the file's own checks (`horizon_mods::index::inspect`, the signature, the +entry's fields), uploads it to the `staging` release of +[ludovic111/horizon-mods](https://github.com/ludovic111/horizon-mods) as `.`, and opens a pull +request adding or updating `mods/.toml`. That repository's CI checks it again, with a trial run of a mod in the +sandbox; reviewers decide, and merging publishes. Formats and rules: [docs/api/mod-index.md](../../docs/api/mod-index.md). + +It keeps no data: a session is a signed cookie holding the GitHub login, and the user's OAuth token is used once, to +read that login, and dropped. The sign-in asks for no scope. + +| Route | | +| --- | --- | +| `GET /api/mods/auth/login` | Starts the GitHub sign-in | +| `GET /api/mods/auth/callback` | GitHub's redirect: sets the session, back to `/mods/submit` | +| `POST /api/mods/auth/logout` | Ends it | +| `GET /api/mods/me` | `{login, csrf}`, or 401 | +| `POST /api/mods/submit` | Multipart: `entry` (JSON: `id kind name summary description authors license source icon key signature version game changelog`) and `file`; `{pull_request}` or `{error}` | +| `GET /healthz` | `ok` | + +A submission must come from `REGISTRY_PUBLIC_URL`'s origin with the session's `X-CSRF-Token`. Six per account and sixty +in all per hour. Only an entry's `owners` publish its updates; a key change, an icon in the repository or anything else +is a pull request by hand. + +## Running it + +```sh +cargo test # against a mock GitHub (tests/submit.rs) +REGISTRY_PUBLIC_URL=http://localhost:4173 REGISTRY_SESSION_KEY=... GITHUB_CLIENT_ID=... GITHUB_CLIENT_SECRET=... \ + GITHUB_BOT_TOKEN=... REGISTRY_REPO=you/horizon-mods-test cargo run +``` + +| Variable | | +| --- | --- | +| `REGISTRY_PUBLIC_URL` | The site, `https://playhorizon.dev`: the OAuth callback is `/api/mods/auth/callback` | +| `REGISTRY_SESSION_KEY` | 32 characters or more, random: signs sessions | +| `GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET` | The OAuth app | +| `GITHUB_BOT_TOKEN` | Fine-grained, the registry repository only: Contents and Pull requests read and write | +| `REGISTRY_REPO` | Default `ludovic111/horizon-mods` | +| `PORT` | Default 8080 | + +On Railway it is its own service (`railway.json`, built with the `Dockerfile` from the repository root); the website's +Caddy sends `/api/mods/*` to it over Railway's private network. diff --git a/crates/horizon-mod-registry/railway.json b/crates/horizon-mod-registry/railway.json new file mode 100644 index 000000000..cfafe4367 --- /dev/null +++ b/crates/horizon-mod-registry/railway.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://railway.com/railway.schema.json", + "build": { + "builder": "DOCKERFILE", + "dockerfilePath": "crates/horizon-mod-registry/Dockerfile", + "watchPatterns": [ + "/crates/horizon-mods/**", + "/crates/horizon-mod-registry/**", + "/Cargo.toml" + ] + }, + "deploy": { + "healthcheckPath": "/healthz", + "healthcheckTimeout": 60, + "restartPolicyType": "ON_FAILURE", + "restartPolicyMaxRetries": 5, + "multiRegionConfig": { + "europe-west4-drams3a": { "numReplicas": 1 } + } + } +} diff --git a/crates/horizon-mod-registry/src/github.rs b/crates/horizon-mod-registry/src/github.rs new file mode 100644 index 000000000..01a1b1bdb --- /dev/null +++ b/crates/horizon-mod-registry/src/github.rs @@ -0,0 +1,276 @@ +//! What the service asks of GitHub: the sign-in (OAuth, no scope: only the +//! public profile), and with the bot's token on the registry repository +//! alone, an entry, the `staging` release, a branch, a file, a pull request. +//! Blocking (ureq): called from tokio's blocking pool. +use base64::{Engine, engine::general_purpose::STANDARD}; +use horizon_mods::index::registry::Entry; +use serde_json::{Value, json}; +use std::{path::Path, time::Duration}; + +/// Where GitHub is: the real one, or a test's mock. +#[derive(Clone, Debug)] +pub struct Endpoints { + /// `https://github.com`: OAuth. + pub web: String, + /// `https://api.github.com`. + pub api: String, + /// `https://uploads.github.com`: release assets. + pub uploads: String, +} + +impl Default for Endpoints { + fn default() -> Self { + Endpoints { + web: "https://github.com".into(), + api: "https://api.github.com".into(), + uploads: "https://uploads.github.com".into(), + } + } +} + +#[derive(Clone)] +pub struct GitHub { + pub at: Endpoints, + /// `owner/name` of the registry repository. + pub repo: String, + pub client_id: String, + pub client_secret: String, + /// Fine-grained, this repository only: contents and pull requests. + pub bot_token: String, + agent: ureq::Agent, +} + +/// A failed call: `status` is GitHub's, 0 when it wasn't reached. +#[derive(Debug)] +pub struct Failure { + pub status: u16, + pub message: String, +} + +type Result = std::result::Result; + +fn failure(e: ureq::Error) -> Failure { + match e { + ureq::Error::Status(status, response) => Failure { + status, + message: response + .into_string() + .unwrap_or_default() + .chars() + .take(300) + .collect(), + }, + other => Failure { + status: 0, + message: other.to_string(), + }, + } +} + +fn read(response: ureq::Response) -> Result { + response.into_json().map_err(|e| Failure { + status: 0, + message: e.to_string(), + }) +} + +impl GitHub { + pub fn new( + at: Endpoints, + repo: String, + client_id: String, + client_secret: String, + bot_token: String, + ) -> GitHub { + let agent = ureq::AgentBuilder::new() + .timeout(Duration::from_secs(60)) + .user_agent("horizon-mod-registry") + .build(); + GitHub { + at, + repo, + client_id, + client_secret, + bot_token, + agent, + } + } + + /// Where the sign-in starts. + pub fn authorize_url(&self, redirect: &str, state: &str) -> String { + format!( + "{}/login/oauth/authorize?client_id={}&redirect_uri={}&state={state}&allow_signup=true", + self.at.web, + self.client_id, + encode(redirect) + ) + } + + /// The signed-in account (login, id) for an OAuth `code`. Its token is + /// used once and dropped. + pub fn sign_in(&self, code: &str, redirect: &str) -> Result<(String, u64)> { + let token = self + .agent + .post(&format!("{}/login/oauth/access_token", self.at.web)) + .set("Accept", "application/json") + .send_json(json!({ + "client_id": self.client_id, + "client_secret": self.client_secret, + "code": code, + "redirect_uri": redirect, + })) + .map_err(failure) + .and_then(read)?; + let Some(token) = token["access_token"].as_str() else { + return Err(Failure { + status: 401, + message: "GitHub refused the sign-in".into(), + }); + }; + let user = self + .agent + .get(&format!("{}/user", self.at.api)) + .set("Authorization", &format!("Bearer {token}")) + .set("Accept", "application/vnd.github+json") + .call() + .map_err(failure) + .and_then(read)?; + match (user["login"].as_str(), user["id"].as_u64()) { + (Some(login), Some(id)) => Ok((login.to_owned(), id)), + _ => Err(Failure { + status: 0, + message: "GitHub sent no login".into(), + }), + } + } + + fn call(&self, method: &str, path: &str) -> ureq::Request { + self.agent + .request( + method, + &format!("{}/repos/{}{path}", self.at.api, self.repo), + ) + .set("Authorization", &format!("Bearer {}", self.bot_token)) + .set("Accept", "application/vnd.github+json") + .set("X-GitHub-Api-Version", "2022-11-28") + } + + /// `mods/.toml` on main, with its blob sha; None when it isn't there. + pub fn entry(&self, id: &str) -> Result> { + let response = self + .call("GET", &format!("/contents/mods/{id}.toml")) + .query("ref", "main") + .call(); + let file = match response { + Ok(r) => read(r)?, + Err(ureq::Error::Status(404, _)) => return Ok(None), + Err(e) => return Err(failure(e)), + }; + let bytes = file["content"] + .as_str() + .map(|c| c.replace('\n', "")) + .and_then(|c| STANDARD.decode(c).ok()) + .unwrap_or_default(); + let entry = toml::from_str(&String::from_utf8_lossy(&bytes)).map_err(|e| Failure { + status: 0, + message: format!("mods/{id}.toml on main: {e}"), + })?; + Ok(Some((entry, file["sha"].as_str().unwrap_or("").to_owned()))) + } + + /// Uploads `path` as asset `name` of the `staging` prerelease, unless it + /// is already there (the same file submitted again). + pub fn stage(&self, name: &str, path: &Path) -> Result<()> { + let release = self + .call("GET", "/releases/tags/staging") + .call() + .map_err(failure) + .and_then(read)?; + let there = release["assets"] + .as_array() + .is_some_and(|a| a.iter().any(|x| x["name"] == name)); + if there { + return Ok(()); + } + let id = release["id"].as_u64().unwrap_or(0); + let bytes = std::fs::read(path).map_err(|e| Failure { + status: 0, + message: e.to_string(), + })?; + self.agent + .post(&format!( + "{}/repos/{}/releases/{id}/assets", + self.at.uploads, self.repo + )) + .query("name", name) + .set("Authorization", &format!("Bearer {}", self.bot_token)) + .set("Accept", "application/vnd.github+json") + .set("Content-Type", "application/octet-stream") + .send_bytes(&bytes) + .map_err(failure)?; + Ok(()) + } + + /// Makes branch `name` from main; false when it already exists. + pub fn branch(&self, name: &str) -> Result { + let main = self + .call("GET", "/git/ref/heads/main") + .call() + .map_err(failure) + .and_then(read)?; + let sha = main["object"]["sha"].as_str().unwrap_or(""); + match self + .call("POST", "/git/refs") + .send_json(json!({"ref": format!("refs/heads/{name}"), "sha": sha})) + { + Ok(_) => Ok(true), + Err(ureq::Error::Status(422, _)) => Ok(false), + Err(e) => Err(failure(e)), + } + } + + /// Writes `path` on `branch` in one commit; `sha` is the blob it replaces. + pub fn put( + &self, + path: &str, + text: &str, + branch: &str, + sha: Option<&str>, + message: &str, + ) -> Result<()> { + let mut body = json!({ + "message": message, + "content": STANDARD.encode(text), + "branch": branch, + }); + if let Some(sha) = sha { + body["sha"] = json!(sha); + } + self.call("PUT", &format!("/contents/{path}")) + .send_json(body) + .map_err(failure)?; + Ok(()) + } + + /// Opens the pull request; its address. + pub fn pull(&self, title: &str, head: &str, body: &str) -> Result { + let pr = self + .call("POST", "/pulls") + .send_json(json!({"title": title, "head": head, "base": "main", "body": body})) + .map_err(failure) + .and_then(read)?; + Ok(pr["html_url"].as_str().unwrap_or("").to_owned()) + } +} + +/// Percent-encodes a query value. +fn encode(s: &str) -> String { + s.bytes() + .map(|b| match b { + b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'.' | b'_' | b'~' => { + (b as char).to_string() + } + _ => format!("%{b:02X}"), + }) + .collect() +} diff --git a/crates/horizon-mod-registry/src/lib.rs b/crates/horizon-mod-registry/src/lib.rs new file mode 100644 index 000000000..9799bace8 --- /dev/null +++ b/crates/horizon-mod-registry/src/lib.rs @@ -0,0 +1,675 @@ +//! `horizon-mod-registry`: the submission form's service at +//! `playhorizon.dev/api/mods/*` (docs/api/mod-index.md). A creator signs in +//! with GitHub, sends a file and its page; the service runs the file's own +//! checks, uploads it to the registry's `staging` release and opens a pull +//! request with the entry. Reviewers decide; merging publishes. It keeps no +//! data: sessions are signed cookies, and GitHub holds everything else. +pub mod github; + +use axum::{ + Json, Router, + extract::{DefaultBodyLimit, Multipart, Query, State}, + http::{HeaderMap, StatusCode, header}, + response::{IntoResponse, Redirect, Response}, + routing::{get, post}, +}; +use base64::{Engine, engine::general_purpose::URL_SAFE_NO_PAD}; +use github::GitHub; +use hmac::{Hmac, Mac}; +use horizon_mods::index::{ + self, Kind, + registry::{self, Entry, EntryVersion, Sources}, +}; +use serde::Deserialize; +use serde_json::json; +use sha2::Sha256; +use std::{ + collections::{HashMap, VecDeque}, + path::{Path, PathBuf}, + sync::{Arc, Mutex}, + time::{Duration, Instant, SystemTime, UNIX_EPOCH}, +}; + +/// How long a sign-in lasts. +const SESSION: u64 = 12 * 3600; +/// Submissions per account per hour, and from everyone. +const PER_ACCOUNT: usize = 6; +const PER_HOUR: usize = 60; +/// The page's JSON. +const MAX_FORM: usize = 64 << 10; + +pub struct Config { + /// `https://playhorizon.dev`: where the form is, and the only origin it + /// takes submissions from. + pub public_url: String, + /// At least 32 bytes: signs sessions. + pub session_key: Vec, + pub github: GitHub, + /// Where files wait during a submission. + pub scratch: PathBuf, +} + +impl Config { + /// `REGISTRY_PUBLIC_URL`, `REGISTRY_SESSION_KEY`, `REGISTRY_REPO`, + /// `GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET`, `GITHUB_BOT_TOKEN`. + pub fn from_env() -> Result { + let var = |name: &str| std::env::var(name).map_err(|_| format!("{name} is not set")); + let key = var("REGISTRY_SESSION_KEY")?; + if key.len() < 32 { + return Err("REGISTRY_SESSION_KEY needs at least 32 characters".into()); + } + Ok(Config { + public_url: var("REGISTRY_PUBLIC_URL")?.trim_end_matches('/').to_owned(), + session_key: key.into_bytes(), + github: GitHub::new( + github::Endpoints::default(), + std::env::var("REGISTRY_REPO").unwrap_or_else(|_| "ludovic111/horizon-mods".into()), + var("GITHUB_CLIENT_ID")?, + var("GITHUB_CLIENT_SECRET")?, + var("GITHUB_BOT_TOKEN")?, + ), + scratch: std::env::temp_dir().join("horizon-mod-registry"), + }) + } + + fn callback(&self) -> String { + format!("{}/api/mods/auth/callback", self.public_url) + } +} + +#[derive(Clone)] +pub struct App(Arc); + +struct Inner { + config: Config, + recent: Mutex>>, +} + +impl App { + pub fn new(config: Config) -> App { + App(Arc::new(Inner { + config, + recent: Mutex::new(HashMap::new()), + })) + } +} + +pub fn router(app: App) -> Router { + Router::new() + .route("/healthz", get(|| async { "ok" })) + .route("/api/mods/auth/login", get(login)) + .route("/api/mods/auth/callback", get(callback)) + .route("/api/mods/auth/logout", post(logout)) + .route("/api/mods/me", get(me)) + .route( + "/api/mods/submit", + post(submit).layer(DefaultBodyLimit::max( + index::MAX_FILE as usize + MAX_FORM * 2, + )), + ) + .with_state(app) +} + +/// An error players read in the form. +#[derive(Debug)] +pub struct Refusal(StatusCode, String); + +impl Refusal { + fn new(status: StatusCode, message: impl Into) -> Refusal { + Refusal(status, message.into()) + } +} + +impl IntoResponse for Refusal { + fn into_response(self) -> Response { + (self.0, Json(json!({"error": self.1}))).into_response() + } +} + +fn bad(message: impl Into) -> Refusal { + Refusal::new(StatusCode::BAD_REQUEST, message) +} + +fn github_down(e: github::Failure) -> Refusal { + eprintln!("horizon-mod-registry: GitHub {}: {}", e.status, e.message); + Refusal::new( + StatusCode::BAD_GATEWAY, + "GitHub didn't answer as expected: try again in a minute", + ) +} + +// Signed values: `.`, both base64url. + +fn sign(key: &[u8], payload: &str) -> String { + let mut mac = Hmac::::new_from_slice(key).expect("any key length"); + mac.update(payload.as_bytes()); + format!( + "{}.{}", + URL_SAFE_NO_PAD.encode(payload), + URL_SAFE_NO_PAD.encode(mac.finalize().into_bytes()) + ) +} + +fn unsign(key: &[u8], value: &str) -> Option { + let (payload, tag) = value.split_once('.')?; + let payload = String::from_utf8(URL_SAFE_NO_PAD.decode(payload).ok()?).ok()?; + let mut mac = Hmac::::new_from_slice(key).ok()?; + mac.update(payload.as_bytes()); + mac.verify_slice(&URL_SAFE_NO_PAD.decode(tag).ok()?).ok()?; + Some(payload) +} + +fn now() -> u64 { + SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap_or_default() + .as_secs() +} + +fn random_hex() -> String { + let mut bytes = [0u8; 16]; + getrandom::fill(&mut bytes).expect("the system's random numbers"); + bytes.iter().map(|b| format!("{b:02x}")).collect() +} + +fn cookie(headers: &HeaderMap, name: &str) -> Option { + headers + .get_all(header::COOKIE) + .iter() + .filter_map(|v| v.to_str().ok()) + .flat_map(|v| v.split(';')) + .filter_map(|c| c.trim().split_once('=')) + .find(|(k, _)| *k == name) + .map(|(_, v)| v.to_owned()) +} + +fn set_cookie(name: &str, value: &str, max_age: u64) -> String { + format!("{name}={value}; Path=/api/mods; HttpOnly; Secure; SameSite=Lax; Max-Age={max_age}") +} + +/// The signed-in account: (login, id). +fn session(app: &Inner, headers: &HeaderMap) -> Option<(String, u64)> { + let payload = unsign(&app.config.session_key, &cookie(headers, "hm_session")?)?; + let mut parts = payload.split('\n'); + let (login, id, until) = (parts.next()?, parts.next()?, parts.next()?); + (until.parse::().ok()? > now()).then(|| (login.to_owned(), id.parse().unwrap_or(0))) +} + +/// The form sends this with each submission: a page on another site can't +/// read it, so it can't submit in a signed-in creator's name. +fn csrf(app: &Inner, headers: &HeaderMap) -> Option { + let session = cookie(headers, "hm_session")?; + let signed = sign(&app.config.session_key, &format!("csrf\n{session}")); + Some(signed.rsplit('.').next()?.chars().take(32).collect()) +} + +async fn login(State(app): State) -> Response { + let state = random_hex(); + let signed = sign(&app.0.config.session_key, &state); + let url = app + .0 + .config + .github + .authorize_url(&app.0.config.callback(), &state); + ( + [(header::SET_COOKIE, set_cookie("hm_state", &signed, 600))], + Redirect::to(&url), + ) + .into_response() +} + +#[derive(Deserialize)] +struct Callback { + code: String, + state: String, +} + +async fn callback( + State(app): State, + headers: HeaderMap, + Query(q): Query, +) -> Result { + let expected = cookie(&headers, "hm_state").and_then(|v| unsign(&app.0.config.session_key, &v)); + if expected.as_deref() != Some(q.state.as_str()) { + return Err(Refusal::new( + StatusCode::FORBIDDEN, + "the sign-in expired or didn't start here: try again", + )); + } + let inner = app.0.clone(); + let (login, id) = tokio::task::spawn_blocking(move || { + inner + .config + .github + .sign_in(&q.code, &inner.config.callback()) + }) + .await + .map_err(|_| Refusal::new(StatusCode::INTERNAL_SERVER_ERROR, "sign-in failed"))? + .map_err(github_down)?; + let value = sign( + &app.0.config.session_key, + &format!("{login}\n{id}\n{}", now() + SESSION), + ); + let back = format!("{}/mods/submit", app.0.config.public_url); + let mut response = Redirect::to(&back).into_response(); + let headers = response.headers_mut(); + headers.append( + header::SET_COOKIE, + set_cookie("hm_session", &value, SESSION).parse().unwrap(), + ); + headers.append( + header::SET_COOKIE, + set_cookie("hm_state", "", 0).parse().unwrap(), + ); + Ok(response) +} + +async fn logout() -> Response { + ( + [(header::SET_COOKIE, set_cookie("hm_session", "", 0))], + StatusCode::NO_CONTENT, + ) + .into_response() +} + +async fn me( + State(app): State, + headers: HeaderMap, +) -> Result, Refusal> { + let (login, _) = session(&app.0, &headers) + .ok_or_else(|| Refusal::new(StatusCode::UNAUTHORIZED, "not signed in"))?; + Ok(Json( + json!({"login": login, "csrf": csrf(&app.0, &headers)}), + )) +} + +/// The page a submission fills in: a project's fields, and the version's. +#[derive(Clone, Debug, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Form { + pub id: String, + pub kind: String, + pub name: String, + pub summary: String, + #[serde(default)] + pub description: String, + #[serde(default)] + pub authors: Vec, + pub license: String, + pub source: String, + /// `https://` only; an icon in the repository is a pull request by hand. + #[serde(default)] + pub icon: Option, + /// A new project's minisign public key. + #[serde(default)] + pub key: Option, + /// The `.minisig` text. + #[serde(default)] + pub signature: Option, + pub version: String, + pub game: String, + #[serde(default)] + pub changelog: String, +} + +fn take(window: &mut VecDeque, max: usize) -> bool { + while window + .front() + .is_some_and(|t| t.elapsed() > Duration::from_secs(3600)) + { + window.pop_front(); + } + window.len() < max +} + +async fn submit( + State(app): State, + headers: HeaderMap, + mut multipart: Multipart, +) -> Result, Refusal> { + let inner = app.0.clone(); + let origin = headers.get(header::ORIGIN).and_then(|v| v.to_str().ok()); + if origin != Some(inner.config.public_url.as_str()) { + return Err(Refusal::new( + StatusCode::FORBIDDEN, + "submit from the registry's form", + )); + } + let (login, user_id) = session(&inner, &headers) + .ok_or_else(|| Refusal::new(StatusCode::UNAUTHORIZED, "sign in with GitHub first"))?; + let sent = headers.get("x-csrf-token").and_then(|v| v.to_str().ok()); + if sent.is_none() || sent.map(str::to_owned) != csrf(&inner, &headers) { + return Err(Refusal::new( + StatusCode::FORBIDDEN, + "reload the form and try again", + )); + } + { + let mut recent = inner.recent.lock().unwrap(); + let ok = take(recent.entry(String::new()).or_default(), PER_HOUR) + && take(recent.entry(login.to_lowercase()).or_default(), PER_ACCOUNT); + if !ok { + return Err(Refusal::new( + StatusCode::TOO_MANY_REQUESTS, + "too many submissions this hour: try again later", + )); + } + let at = Instant::now(); + recent.entry(String::new()).or_default().push_back(at); + recent + .entry(login.to_lowercase()) + .or_default() + .push_back(at); + } + let dir = inner.config.scratch.join(random_hex()); + std::fs::create_dir_all(&dir) + .map_err(|e| Refusal::new(StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; + let result = receive(&mut multipart, &dir).await; + let result = match result { + Ok((form, file)) => { + let inner = inner.clone(); + tokio::task::spawn_blocking(move || { + publish(&inner.config, &login, user_id, &form, &file) + }) + .await + .unwrap_or_else(|_| { + Err(Refusal::new( + StatusCode::INTERNAL_SERVER_ERROR, + "the check crashed", + )) + }) + } + Err(e) => Err(e), + }; + let _ = std::fs::remove_dir_all(&dir); + result.map(|url| Json(json!({"pull_request": url}))) +} + +/// Reads the form's two parts: `entry` (JSON) and `file`, streamed to `dir`. +async fn receive(multipart: &mut Multipart, dir: &Path) -> Result<(Form, PathBuf), Refusal> { + use tokio::io::AsyncWriteExt; + let (mut form, mut file) = (None, None); + while let Some(mut field) = multipart + .next_field() + .await + .map_err(|e| bad(e.body_text()))? + { + match field.name() { + Some("entry") => { + let text = field.text().await.map_err(|e| bad(e.body_text()))?; + if text.len() > MAX_FORM { + return Err(bad("the page's text is too long")); + } + form = Some(serde_json::from_str::
(&text).map_err(|e| bad(e.to_string()))?); + } + Some("file") => { + let path = dir.join("upload"); + let mut out = tokio::fs::File::create(&path) + .await + .map_err(|e| Refusal::new(StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; + let mut size = 0u64; + while let Some(chunk) = field.chunk().await.map_err(|e| bad(e.body_text()))? { + size += chunk.len() as u64; + if size > index::MAX_FILE { + return Err(bad(format!( + "the file is over {} MiB", + index::MAX_FILE >> 20 + ))); + } + out.write_all(&chunk).await.map_err(|e| { + Refusal::new(StatusCode::INTERNAL_SERVER_ERROR, e.to_string()) + })?; + } + out.flush().await.ok(); + file = Some(path); + } + _ => {} + } + } + match (form, file) { + (Some(form), Some(file)) => Ok((form, file)), + _ => Err(bad("send the page and the file")), + } +} + +/// `YYYY-MM-DD` of a Unix time (UTC). +fn date(secs: u64) -> String { + // Howard Hinnant's days-to-civil. + let z = (secs / 86400) as i64 + 719_468; + let era = z.div_euclid(146_097); + let doe = z - era * 146_097; + let yoe = (doe - doe / 1460 + doe / 36524 - doe / 146_096) / 365; + let doy = doe - (365 * yoe + yoe / 4 - yoe / 100); + let mp = (5 * doy + 2) / 153; + let d = doy - (153 * mp + 2) / 5 + 1; + let m = if mp < 10 { mp + 3 } else { mp - 9 }; + let y = yoe + era * 400 + i64::from(m <= 2); + format!("{y:04}-{m:02}-{d:02}") +} + +/// The submission, past its checks: the entry written on a new branch and a +/// pull request opened. Returns the pull request's address. +pub fn publish( + config: &Config, + login: &str, + user_id: u64, + form: &Form, + file: &Path, +) -> Result { + let gh = &config.github; + let kind = Kind::from(form.kind.clone()); + registry::open(&kind).map_err(bad)?; + if !index::valid_id(&form.id) { + return Err(bad("an id is 1 to 64 of a-z, 0-9 and _")); + } + if form + .icon + .as_ref() + .is_some_and(|i| !i.starts_with("https://")) + { + return Err(bad("the icon must be an https:// address")); + } + if !form.source.trim().starts_with("https://") { + return Err(bad("the source must be an https:// address of the code")); + } + if form.name.trim().is_empty() || form.license.trim().is_empty() { + return Err(bad("a project needs a name and a licence")); + } + // The file's own checks first: a wrong file never reaches GitHub. + let facts = index::inspect(&kind, file).map_err(bad)?; + if let Some(id) = facts.id.as_ref().filter(|id| **id != form.id) { + return Err(bad(format!("the file's id is {id:?}, not {:?}", form.id))); + } + if let Some(v) = facts + .version + .as_ref() + .filter(|v| **v != form.version.trim()) + { + return Err(bad(format!( + "the file says version {v:?}, not {:?}", + form.version.trim() + ))); + } + let sha256 = index::sha256_file(file).map_err(bad)?; + let extension = kind.extension().unwrap_or("zip"); + let version = EntryVersion { + version: form.version.trim().to_owned(), + published: date(now()), + game: form.game.trim().to_owned(), + file: format!("{}-{}.{extension}", form.id, form.version.trim()), + sha256: sha256.clone(), + signature: form.signature.clone().filter(|s| !s.trim().is_empty()), + changelog: form.changelog.clone(), + }; + let existing = gh.entry(&form.id).map_err(github_down)?; + let is_new = existing.is_none(); + let (entry, blob) = match existing { + None => ( + Entry { + id: form.id.clone(), + kind: kind.clone(), + name: form.name.trim().to_owned(), + summary: form.summary.trim().to_owned(), + description: form.description.clone(), + authors: form.authors.clone(), + owners: vec![login.to_owned()], + license: form.license.trim().to_owned(), + source: form.source.trim().to_owned(), + icon: form.icon.clone(), + key: form.key.clone().filter(|k| !k.trim().is_empty()), + versions: vec![version.clone()], + }, + None, + ), + Some((mut entry, blob)) => { + if !entry.owners.iter().any(|o| o.eq_ignore_ascii_case(login)) { + return Err(Refusal::new( + StatusCode::FORBIDDEN, + format!( + "{} is {}'s: only its owners publish its updates", + form.id, + entry.owners.join(", ") + ), + )); + } + if entry.kind != kind { + return Err(bad(format!("{} is a {}", form.id, entry.kind.name()))); + } + if entry.versions.iter().any(|v| v.version == version.version) { + return Err(Refusal::new( + StatusCode::CONFLICT, + format!( + "{} {} is already published: give this file a new version", + form.id, version.version + ), + )); + } + let key = form.key.clone().filter(|k| !k.trim().is_empty()); + if key.is_some() && key != entry.key { + return Err(bad( + "changing a project's key is a pull request by hand, reviewed on its own", + )); + } + entry.name = form.name.trim().to_owned(); + entry.summary = form.summary.trim().to_owned(); + entry.description = form.description.clone(); + entry.authors = form.authors.clone(); + entry.license = form.license.trim().to_owned(); + entry.source = form.source.trim().to_owned(); + if form.icon.is_some() { + entry.icon = form.icon.clone(); + } + entry.versions.insert(0, version.clone()); + (entry, Some(blob)) + } + }; + // Every check CI runs but the trial run: the file as its kind, its id and + // version, its signature, the entry's fields. CI runs it all again. + let files = file.parent().unwrap_or(Path::new(".")); + std::fs::copy(file, files.join(&sha256)).map_err(|e| bad(e.to_string()))?; + let mut checked = entry.clone(); + checked.versions.truncate(1); + if checked + .icon + .as_ref() + .is_some_and(|i| !i.starts_with("https://")) + { + checked.icon = None; + } + let project = registry::project( + &checked, + &Sources { + registry: files, + files, + release: index::FILE_HOST, + site: "https://example.invalid/", + generated: String::new(), + }, + ) + .map_err(|errors| bad(errors.join("; ")))?; + let text = entry.to_toml().map_err(bad)?; + gh.stage(&format!("{sha256}.{extension}"), file) + .map_err(github_down)?; + let branch = format!("submit/{}-{}", form.id, version.version); + if !gh.branch(&branch).map_err(github_down)? { + return Err(Refusal::new( + StatusCode::CONFLICT, + format!( + "{} {} was already submitted: its pull request is open", + form.id, version.version + ), + )); + } + let what = if is_new { "Add" } else { "Update" }; + let message = format!( + "{what} {} {}\n\nSubmitted by @{login} through the form.\n\nCo-authored-by: {login} <{user_id}+{login}@users.noreply.github.com>", + form.id, version.version + ); + gh.put( + &format!("mods/{}.toml", form.id), + &text, + &branch, + blob.as_deref(), + &message, + ) + .map_err(github_down)?; + let v = &project.versions[0]; + let capabilities: Vec = v + .capabilities + .iter() + .map(|c| format!("- may {}", c.describe())) + .collect(); + let requires: Vec = v + .requires + .iter() + .map(|r| format!("- needs {} {}", r.id, r.version)) + .collect(); + let body = format!( + "\nSubmitted by @{login} through [the form]({public}/mods/submit).\n\n\ + | | |\n|---|---|\n| Project | `{id}` ({kind}, {new}) |\n| Version | {version} for {game} |\n| File | `{file}`, {size} bytes, SHA-256 `{sha256}` |\n| Signed | {signed} |\n| Source | {source} |\n\n{lists}\n\n\ + The checks below run the file's own checks again and, for a mod, a trial run in the sandbox. \ + Reviewers: read the source and the checks' report before you approve.", + public = config.public_url, + id = form.id, + kind = kind.name(), + new = if is_new { "new" } else { "update" }, + version = v.version, + game = v.game, + file = v.file.name, + size = v.file.size, + signed = if entry.key.is_some() { + "yes, with the project's key" + } else { + "no" + }, + source = entry.source, + lists = [capabilities, requires].concat().join("\n"), + ); + gh.pull( + &format!("{what} {} {}", form.id, version.version), + &branch, + &body, + ) + .map_err(github_down) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn dates_and_signatures() { + assert_eq!(date(0), "1970-01-01"); + assert_eq!(date(1_792_800_000), "2026-10-24"); + let key = b"0123456789abcdef0123456789abcdef"; + let signed = sign(key, "alice\n7\n99"); + assert_eq!(unsign(key, &signed).as_deref(), Some("alice\n7\n99")); + assert_eq!(unsign(b"another key, another key, another", &signed), None); + let forged = format!( + "{}.{}", + URL_SAFE_NO_PAD.encode("mallory\n8\n99"), + signed.split_once('.').unwrap().1 + ); + assert_eq!(unsign(key, &forged), None); + } +} diff --git a/crates/horizon-mod-registry/src/main.rs b/crates/horizon-mod-registry/src/main.rs new file mode 100644 index 000000000..81fe1b7b6 --- /dev/null +++ b/crates/horizon-mod-registry/src/main.rs @@ -0,0 +1,25 @@ +//! `horizon-mod-registry`: serves on `PORT` (default 8080). Configured by the +//! environment (see `Config::from_env`); keeps no data. +use std::net::SocketAddr; + +use horizon_mod_registry::{App, Config, router}; + +#[tokio::main(flavor = "multi_thread", worker_threads = 2)] +async fn main() { + let port: u16 = std::env::var("PORT") + .ok() + .and_then(|p| p.parse().ok()) + .unwrap_or(8080); + let config = Config::from_env().unwrap_or_else(|e| panic!("horizon-mod-registry: {e}")); + let repo = config.github.repo.clone(); + let listener = tokio::net::TcpListener::bind(SocketAddr::from(([0, 0, 0, 0], port))) + .await + .unwrap_or_else(|e| panic!("port {port}: {e}")); + eprintln!("horizon-mod-registry: listening on {port}, submitting to {repo}"); + axum::serve(listener, router(App::new(config))) + .with_graceful_shutdown(async { + let _ = tokio::signal::ctrl_c().await; + }) + .await + .unwrap_or_else(|e| panic!("{e}")); +} diff --git a/crates/horizon-mod-registry/tests/submit.rs b/crates/horizon-mod-registry/tests/submit.rs new file mode 100644 index 000000000..77487089d --- /dev/null +++ b/crates/horizon-mod-registry/tests/submit.rs @@ -0,0 +1,373 @@ +//! The whole submission against a mock GitHub: sign in, submit the sample +//! signed mod (`crates/horizon-mods/tests/index`), and what lands on GitHub; +//! then what is refused. +use axum::{ + Json, Router, + body::{Body, Bytes}, + extract::{Path as UrlPath, Query, State}, + http::{Request, StatusCode, header}, + routing::{get, post}, +}; +use base64::{Engine, engine::general_purpose::STANDARD}; +use horizon_mod_registry::{App, Config, github, router}; +use horizon_mods::index::registry::Entry; +use http_body_util::BodyExt; +use serde_json::{Value, json}; +use std::{ + collections::HashMap, + path::PathBuf, + sync::{Arc, Mutex}, +}; +use tower::ServiceExt; + +const PUBLIC: &str = "https://playhorizon.test"; +const HMOD_SHA: &str = "e1135345692f6dd8fd4c51920151944b82333e17049c9bb7d756f27b8deefc53"; + +#[derive(Default)] +struct Mock { + /// Path -> text on main. + main: HashMap, + assets: Vec<(String, usize)>, + branches: Vec, + /// (branch, path) -> (text, message, replaced blob). + commits: HashMap<(String, String), (String, String, Option)>, + pulls: Vec, + /// The account the next sign-in gets. + login: String, +} + +type Shared = Arc>; + +async fn mock_github() -> (String, Shared) { + let state: Shared = Arc::default(); + state.lock().unwrap().login = "alice".into(); + let app = Router::new() + .route( + "/login/oauth/access_token", + post(|Json(body): Json| async move { + Json(if body["code"] == "good" { + json!({"access_token": "gho_user"}) + } else { + json!({"error": "bad_verification_code"}) + }) + }), + ) + .route( + "/user", + get(|State(s): State| async move { + Json(json!({"login": s.lock().unwrap().login, "id": 7})) + }), + ) + .route( + "/repos/o/r/contents/mods/{file}", + get( + |State(s): State, UrlPath(file): UrlPath| async move { + let s = s.lock().unwrap(); + match s.main.get(&format!("mods/{file}")) { + Some(text) => Ok(Json(json!({"content": STANDARD.encode(text), "sha": "blob1"}))), + None => Err(StatusCode::NOT_FOUND), + } + }, + ) + .put( + |State(s): State, UrlPath(file): UrlPath, Json(b): Json| async move { + let text = String::from_utf8(STANDARD.decode(b["content"].as_str().unwrap()).unwrap()).unwrap(); + let key = (b["branch"].as_str().unwrap().to_owned(), format!("mods/{file}")); + let value = (text, b["message"].as_str().unwrap().to_owned(), b["sha"].as_str().map(str::to_owned)); + s.lock().unwrap().commits.insert(key, value); + Json(json!({})) + }, + ), + ) + .route( + "/repos/o/r/releases/tags/staging", + get(|State(s): State| async move { + let names: Vec = s.lock().unwrap().assets.iter().map(|(n, _)| json!({"name": n})).collect(); + Json(json!({"id": 42, "assets": names})) + }), + ) + .route( + "/repos/o/r/releases/42/assets", + post( + |State(s): State, Query(q): Query>, body: Bytes| async move { + s.lock().unwrap().assets.push((q["name"].clone(), body.len())); + Json(json!({})) + }, + ), + ) + .route( + "/repos/o/r/git/ref/heads/main", + get(|| async { Json(json!({"object": {"sha": "abc123"}})) }), + ) + .route( + "/repos/o/r/git/refs", + post(|State(s): State, Json(b): Json| async move { + assert_eq!(b["sha"], "abc123"); + let name = b["ref"].as_str().unwrap().trim_start_matches("refs/heads/").to_owned(); + let mut s = s.lock().unwrap(); + if s.branches.contains(&name) { + return Err(StatusCode::UNPROCESSABLE_ENTITY); + } + s.branches.push(name); + Ok(Json(json!({}))) + }), + ) + .route( + "/repos/o/r/pulls", + post(|State(s): State, Json(b): Json| async move { + let mut s = s.lock().unwrap(); + s.pulls.push(b); + Json(json!({"html_url": format!("https://github.com/o/r/pull/{}", s.pulls.len())})) + }), + ) + .with_state(state.clone()); + let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); + let base = format!("http://{}", listener.local_addr().unwrap()); + tokio::spawn(async move { axum::serve(listener, app).await.unwrap() }); + (base, state) +} + +fn fixtures() -> PathBuf { + PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../horizon-mods/tests/index") +} + +struct Client { + app: Router, + cookies: HashMap, +} + +impl Client { + async fn send(&mut self, request: Request) -> (StatusCode, Value, Option) { + let response = self.app.clone().oneshot(request).await.unwrap(); + let status = response.status(); + for c in response.headers().get_all(header::SET_COOKIE) { + let (pair, _) = c.to_str().unwrap().split_once(';').unwrap(); + let (k, v) = pair.split_once('=').unwrap(); + self.cookies.insert(k.into(), v.into()); + } + let location = response + .headers() + .get(header::LOCATION) + .map(|l| l.to_str().unwrap().to_owned()); + let bytes = response.into_body().collect().await.unwrap().to_bytes(); + ( + status, + serde_json::from_slice(&bytes).unwrap_or(Value::Null), + location, + ) + } + + fn cookie_header(&self) -> String { + self.cookies + .iter() + .filter(|(_, v)| !v.is_empty()) + .map(|(k, v)| format!("{k}={v}")) + .collect::>() + .join("; ") + } + + fn get(&self, uri: &str) -> Request { + Request::get(uri) + .header(header::COOKIE, self.cookie_header()) + .body(Body::empty()) + .unwrap() + } + + async fn sign_in(&mut self) -> String { + let (status, _, location) = self.send(self.get("/api/mods/auth/login")).await; + assert_eq!(status, StatusCode::SEE_OTHER); + let location = location.unwrap(); + assert!(location.contains( + "redirect_uri=https%3A%2F%2Fplayhorizon.test%2Fapi%2Fmods%2Fauth%2Fcallback" + )); + let state = location + .split("state=") + .nth(1) + .unwrap() + .split('&') + .next() + .unwrap() + .to_owned(); + // Another state than the one this browser started with is refused. + let (status, ..) = self + .send(self.get("/api/mods/auth/callback?code=good&state=other")) + .await; + assert_eq!(status, StatusCode::FORBIDDEN); + let (status, _, location) = self + .send(self.get(&format!("/api/mods/auth/callback?code=good&state={state}"))) + .await; + assert_eq!(status, StatusCode::SEE_OTHER); + assert_eq!( + location.as_deref(), + Some("https://playhorizon.test/mods/submit") + ); + let (status, me, _) = self.send(self.get("/api/mods/me")).await; + assert_eq!(status, StatusCode::OK); + me["csrf"].as_str().unwrap().to_owned() + } + + async fn submit(&mut self, csrf: &str, form: &Value, file: &[u8]) -> (StatusCode, Value) { + let boundary = "XhorizonX"; + let mut body = format!( + "--{boundary}\r\nContent-Disposition: form-data; name=\"entry\"\r\n\r\n{form}\r\n--{boundary}\r\nContent-Disposition: form-data; name=\"file\"; filename=\"f\"\r\nContent-Type: application/octet-stream\r\n\r\n" + ) + .into_bytes(); + body.extend_from_slice(file); + body.extend_from_slice(format!("\r\n--{boundary}--\r\n").as_bytes()); + let request = Request::post("/api/mods/submit") + .header(header::COOKIE, self.cookie_header()) + .header(header::ORIGIN, PUBLIC) + .header("x-csrf-token", csrf) + .header( + header::CONTENT_TYPE, + format!("multipart/form-data; boundary={boundary}"), + ) + .body(Body::from(body)) + .unwrap(); + let (status, json, _) = self.send(request).await; + (status, json) + } +} + +fn form() -> Value { + let key = std::fs::read_to_string(fixtures().join("test.pub")).unwrap(); + json!({ + "id": "coords_hud", + "kind": "mod", + "name": "Coordinates HUD", + "summary": "Your coordinates in a corner.", + "authors": ["Alice"], + "license": "MIT", + "source": "https://github.com/alice/coords", + "key": key.lines().last().unwrap(), + "signature": std::fs::read_to_string(fixtures().join("coords_hud-0.1.0.hmod.minisig")).unwrap(), + "version": "0.1.0", + "game": "26.3", + }) +} + +async fn setup() -> (Client, Shared) { + let (base, mock) = mock_github().await; + let scratch = + std::env::temp_dir().join(format!("horizon-mod-registry-test-{}", std::process::id())); + let config = Config { + public_url: PUBLIC.into(), + session_key: b"a test key of at least thirty-two bytes".to_vec(), + github: github::GitHub::new( + github::Endpoints { + web: base.clone(), + api: base.clone(), + uploads: base, + }, + "o/r".into(), + "client".into(), + "secret".into(), + "bot".into(), + ), + scratch, + }; + let client = Client { + app: router(App::new(config)), + cookies: HashMap::new(), + }; + (client, mock) +} + +#[tokio::test(flavor = "multi_thread")] +async fn a_submission_becomes_a_pull_request() { + let (mut client, mock) = setup().await; + let file = std::fs::read(fixtures().join("coords_hud-0.1.0.hmod")).unwrap(); + // Not signed in. + let (status, _) = client.submit("x", &form(), &file).await; + assert_eq!(status, StatusCode::UNAUTHORIZED); + let csrf = client.sign_in().await; + let (status, _) = client.submit("wrong", &form(), &file).await; + assert_eq!(status, StatusCode::FORBIDDEN); + + let (status, json) = client.submit(&csrf, &form(), &file).await; + assert_eq!(status, StatusCode::OK, "{json}"); + assert_eq!(json["pull_request"], "https://github.com/o/r/pull/1"); + { + let m = mock.lock().unwrap(); + assert_eq!(m.assets, [(format!("{HMOD_SHA}.hmod"), file.len())]); + assert_eq!(m.branches, ["submit/coords_hud-0.1.0"]); + let (text, message, replaced) = &m.commits[&( + "submit/coords_hud-0.1.0".into(), + "mods/coords_hud.toml".into(), + )]; + let entry: Entry = toml::from_str(text).unwrap(); + assert_eq!(entry.owners, ["alice"]); + assert_eq!(entry.versions[0].sha256, HMOD_SHA); + assert_eq!(entry.versions[0].file, "coords_hud-0.1.0.hmod"); + assert!(entry.versions[0].signature.is_some() && entry.key.is_some()); + assert!(message.contains("Co-authored-by: alice <7+alice@users.noreply.github.com>")); + assert_eq!(replaced, &None); + let body = m.pulls[0]["body"].as_str().unwrap(); + assert!(body.starts_with(""), "{body}"); + assert!(body.contains("may draw text on your screen"), "{body}"); + } + // The same version again: its branch is there. + let (status, json) = client.submit(&csrf, &form(), &file).await; + assert_eq!(status, StatusCode::CONFLICT, "{json}"); + assert_eq!(mock.lock().unwrap().assets.len(), 1, "uploaded once"); +} + +#[tokio::test(flavor = "multi_thread")] +async fn what_the_form_refuses() { + let (mut client, mock) = setup().await; + let file = std::fs::read(fixtures().join("coords_hud-0.1.0.hmod")).unwrap(); + let csrf = client.sign_in().await; + let refused = |status: StatusCode, json: &Value, part: &str| { + assert!( + json["error"].as_str().unwrap_or("").contains(part), + "{status} {json}" + ); + }; + // A file that isn't what the page says. + let mut f = form(); + f["id"] = json!("other_mod"); + let (status, json) = client.submit(&csrf, &f, &file).await; + assert_eq!(status, StatusCode::BAD_REQUEST); + refused(status, &json, "the file's id is \"coords_hud\""); + // A broken signature. + let mut f = form(); + f["signature"] = json!( + std::fs::read_to_string(fixtures().join("coords_hud-0.1.0.hmod.minisig")) + .unwrap() + .replace("RUTV", "RUTW") + ); + let (status, json) = client.submit(&csrf, &f, &file).await; + assert_eq!(status, StatusCode::BAD_REQUEST, "{json}"); + // Shader packs aren't open. + let mut f = form(); + f["kind"] = json!("shader"); + let (status, json) = client.submit(&csrf, &f, &file).await; + refused(status, &json, "shader packs open"); + // An update by someone who isn't an owner. + let owned = "id = \"coords_hud\"\nkind = \"mod\"\nname = \"C\"\nsummary = \"s\"\nowners = [\"bob\"]\nlicense = \"MIT\"\nsource = \"https://x.test\"\n\n[[versions]]\nversion = \"0.0.1\"\npublished = \"2026-01-01\"\ngame = \"26.3\"\nfile = \"coords_hud-0.0.1.hmod\"\nsha256 = \"0000000000000000000000000000000000000000000000000000000000000000\"\n"; + mock.lock() + .unwrap() + .main + .insert("mods/coords_hud.toml".into(), owned.into()); + let (status, json) = client.submit(&csrf, &form(), &file).await; + assert_eq!(status, StatusCode::FORBIDDEN); + refused(status, &json, "bob's"); + // From another site. + let mut request = Request::post("/api/mods/submit") + .header(header::COOKIE, client.cookie_header()) + .header(header::ORIGIN, "https://evil.test") + .header("x-csrf-token", &csrf) + .body(Body::empty()) + .unwrap(); + request.headers_mut().insert( + header::CONTENT_TYPE, + "multipart/form-data; boundary=x".parse().unwrap(), + ); + let (status, ..) = client.send(request).await; + assert_eq!(status, StatusCode::FORBIDDEN); + let m = mock.lock().unwrap(); + assert!( + m.assets.is_empty() && m.pulls.is_empty(), + "nothing reached GitHub" + ); +} diff --git a/docs/api/mod-index.md b/docs/api/mod-index.md index afa6e8944..beb6ec2c8 100644 --- a/docs/api/mod-index.md +++ b/docs/api/mod-index.md @@ -129,6 +129,8 @@ reason = "Sent chat messages it didn't declare." date = "2026-10-24" ``` +The submission form's service (`crates/horizon-mod-registry`) writes these entries: it signs the creator in with GitHub, runs the file's checks, uploads the file to the repository's `staging` release as `.` and opens the pull request. Only an entry's `owners` publish updates through it. + Unknown keys are refused. Its CI runs `cargo-horizon-mod` (`crates/cargo-horizon-mod`): | Command | What it does |