From 163a409b8d6ffbcd6724a53e9c1794f986c52d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Christian=20Gr=C3=BCnhage?= Date: Mon, 26 Oct 2020 23:12:25 +0100 Subject: [PATCH] feat: enable encryption --- .gitignore | 1 + Cargo.lock | 754 ++++++++++++++++++++++++++++++++++++++++++--- Cargo.toml | 2 +- config.sample.toml | 1 + src/bot.rs | 68 +++- src/config.rs | 1 + src/main.rs | 14 +- 7 files changed, 771 insertions(+), 70 deletions(-) diff --git a/.gitignore b/.gitignore index 4a3b37d..1822450 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target +/store config.toml diff --git a/Cargo.lock b/Cargo.lock index 17cbc3b..4c6d7c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,48 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "aes-ctr" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64c3b03608ea1c077228520a167cca2514dc7cd8100a81b30a2b38be985234e5" +dependencies = [ + "aes-soft", + "aesni", + "ctr", + "stream-cipher", +] + +[[package]] +name = "aes-soft" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63dd91889c49327ad7ef3b500fd1109dbd3c509a03db0d4a9ce413b79f575cb6" +dependencies = [ + "block-cipher", + "byteorder", + "opaque-debug", +] + +[[package]] +name = "aesni" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6a4d655ae633a96d0acaf0fd7e76aafb8ca5732739bba37aac6f882c8fce656" +dependencies = [ + "block-cipher", + "opaque-debug", + "stream-cipher", +] + +[[package]] +name = "ahash" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" +dependencies = [ + "const-random", +] + [[package]] name = "aho-corasick" version = "0.7.14" @@ -24,6 +67,45 @@ version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1fd36ffbb1fb7c834eac128ea8d0e310c5aeb635548f9d58861e1308d46e71c" +[[package]] +name = "assign" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4af5687fe33aec5e70ef14caac5e0d363e335e5e5d6385fb75978d0c241b1d67" + +[[package]] +name = "async-native-tls" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e9e7a929bd34c68a82d58a4de7f86fffdaf97fb2af850162a7bb19dd7269b33" +dependencies = [ + "native-tls", + "thiserror", + "tokio", + "url", +] + +[[package]] +name = "async-stream" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22068c0c19514942eefcfd4daf8976ef1aad84e61539f95cd200c35202f80af5" +dependencies = [ + "async-stream-impl", + "futures-core", +] + +[[package]] +name = "async-stream-impl" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25f9db3b38af870bf7e5cc649167533b493928e50744e2c30ae350230b414670" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "async-trait" version = "0.1.41" @@ -35,6 +117,15 @@ dependencies = [ "syn", ] +[[package]] +name = "atomic" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3410529e8288c463bedb5930f82833bc0c90e5d2fe639a56582a4d09220b281" +dependencies = [ + "autocfg", +] + [[package]] name = "atty" version = "0.2.14" @@ -58,18 +149,48 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-cipher" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f337a3e6da609650eb74e02bc9fac7b735049f7623ab12f2e4c719316fcc7e80" +dependencies = [ + "generic-array", +] + [[package]] name = "bumpalo" version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" +[[package]] +name = "byteorder" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" + [[package]] name = "bytes" version = "0.5.6" @@ -101,6 +222,18 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "cjson" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2b601fb350e2fdbbd2ffb19aef2141fa90864d8fdca83d64466cb9bdb5694a7" +dependencies = [ + "itoa", + "serde", + "serde_derive", + "serde_json", +] + [[package]] name = "clap" version = "2.33.3" @@ -116,6 +249,35 @@ dependencies = [ "vec_map", ] +[[package]] +name = "cmake" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e56268c17a6248366d66d4a47a3381369d068cce8409bb1716ed77ea32163bb" +dependencies = [ + "cc", +] + +[[package]] +name = "const-random" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02dc82c12dc2ee6e1ded861cf7d582b46f66f796d1b6c93fa28b911ead95da02" +dependencies = [ + "const-random-macro", + "proc-macro-hack", +] + +[[package]] +name = "const-random-macro" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc757bbb9544aa296c2ae00c679e81f886b37e28e59097defe0cf524306f6685" +dependencies = [ + "getrandom 0.2.0", + "proc-macro-hack", +] + [[package]] name = "core-foundation" version = "0.7.0" @@ -132,6 +294,79 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" +[[package]] +name = "cpuid-bool" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" + +[[package]] +name = "crossbeam-queue" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" +dependencies = [ + "cfg-if", + "crossbeam-utils", + "maybe-uninit", +] + +[[package]] +name = "crossbeam-utils" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +dependencies = [ + "autocfg", + "cfg-if", + "lazy_static", +] + +[[package]] +name = "crypto-mac" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58bcd97a54c7ca5ce2f6eb16f6bede5b0ab5f0055fedc17d2f0b4466e21671ca" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "ctr" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc03dee3a2843ac6eb4b5fb39cfcf4cb034d078555d1f4a0afbed418b822f3c2" +dependencies = [ + "stream-cipher", +] + +[[package]] +name = "dashmap" +version = "3.11.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f260e2fc850179ef410018660006951c1b55b79e8087e87111a2c388994b9b5" +dependencies = [ + "ahash", + "cfg-if", + "num_cpus", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "dtoa" version = "0.4.6" @@ -205,9 +440,18 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" [[package]] name = "futures" -version = "0.1.30" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7e4c2612746b0df8fed4ce0c69156021b704c9aefa360311c04e6e9e002eed" +checksum = "5d8e3078b7b2a8a671cb7a3d17b4760e4181ea243227776ba83fd043b4ca034e" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] [[package]] name = "futures-channel" @@ -216,6 +460,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a4d35f7401e948629c9c3d6638fb9bf94e0b2121e96c3b428cc4e631f3eb74" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -225,14 +470,43 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d674eaa0056896d5ada519900dbf97ead2e46a7b6621e8160d79e2f2e1e2784b" [[package]] -name = "futures-locks" -version = "0.5.0" +name = "futures-executor" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4297dd1d9d6268237e4f93aeb9c90fc1bf0d8cec7e1cef22798939e4c43a251" +checksum = "cc709ca1da6f66143b8c9bec8e6260181869893714e9b5a490b169b0414144ab" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1798854a4727ff944a7b12aa999f58ce7aa81db80d2dfaaf2ba06f065ddd2b" + +[[package]] +name = "futures-locks" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50c4e684ddb2d8a4db5ca8a02b35156da129674ba4412b6f528698d58c594954" dependencies = [ "futures", ] +[[package]] +name = "futures-macro" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e36fccf3fc58563b4a14d265027c627c3b665d7fed489427e88e7cc929559efe" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "futures-sink" version = "0.3.6" @@ -244,6 +518,9 @@ name = "futures-task" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dd26820a9f3637f1302da8bceba3ff33adbe53464b54ca24d4e2d4f1db30f94" +dependencies = [ + "once_cell", +] [[package]] name = "futures-timer" @@ -261,10 +538,28 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a894a0acddba51a2d49a6f4263b1e64b8c579ece8af50fa86503d52cd1eea34" dependencies = [ + "futures-channel", "futures-core", + "futures-io", + "futures-macro", + "futures-sink", "futures-task", + "memchr", "pin-project", "pin-utils", + "proc-macro-hack", + "proc-macro-nested", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +dependencies = [ + "typenum", + "version_check", ] [[package]] @@ -279,6 +574,17 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "getrandom" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee8025cf36f917e6a52cce185b7c7177689b838b7ec138364e50cc2277a56cf4" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + [[package]] name = "gloo-timers" version = "0.2.1" @@ -335,6 +641,22 @@ dependencies = [ "libc", ] +[[package]] +name = "hex" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" + +[[package]] +name = "hmac" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "deae6d9dbb35ec2c502d62b8f7b1c000a0822c3b0794ba36b3149c0a1c840dff" +dependencies = [ + "crypto-mac", + "digest", +] + [[package]] name = "http" version = "0.2.1" @@ -500,6 +822,17 @@ version = "0.2.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743" +[[package]] +name = "libsqlite3-sys" +version = "0.17.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56d90181c2904c287e5390186be820e5ef311a3c62edebb7d6ca3d6a48ce041d" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + [[package]] name = "log" version = "0.4.11" @@ -509,6 +842,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + [[package]] name = "matches" version = "0.1.8" @@ -518,53 +857,95 @@ checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" [[package]] name = "matrix-sdk" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59d9ccbfce4bffc992f0677095e57c37b23f99479c4425fcbca61166b6ebec7f" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=8f99180c99ccd74803565fb36098389198091ded#8f99180c99ccd74803565fb36098389198091ded" dependencies = [ + "async-trait", + "dashmap", "futures-timer", "http", "matrix-sdk-base", "matrix-sdk-common", + "matrix-sdk-common-macros", + "mime", "reqwest", "serde_json", "thiserror", + "tokio", "tracing", "tracing-futures", "url", + "zeroize", ] [[package]] name = "matrix-sdk-base" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55109f3f4c3f6becf39e17b2827415c74eee378f4538fba36e695af2658361fa" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=8f99180c99ccd74803565fb36098389198091ded#8f99180c99ccd74803565fb36098389198091ded" dependencies = [ "async-trait", "matrix-sdk-common", + "matrix-sdk-common-macros", + "matrix-sdk-crypto", "serde", "serde_json", "thiserror", "tokio", + "tracing", "zeroize", ] [[package]] name = "matrix-sdk-common" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f84c944b357af4f81b14bf434ead2fdeaaa143dd9d8202a8b7ee0b4380370f76" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=8f99180c99ccd74803565fb36098389198091ded#8f99180c99ccd74803565fb36098389198091ded" dependencies = [ + "assign", "futures-locks", "instant", "js_int", - "ruma-api", - "ruma-client-api", - "ruma-events", - "ruma-identifiers", + "ruma", "tokio", "uuid", ] +[[package]] +name = "matrix-sdk-common-macros" +version = "0.1.0" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=8f99180c99ccd74803565fb36098389198091ded#8f99180c99ccd74803565fb36098389198091ded" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "matrix-sdk-crypto" +version = "0.1.0" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=8f99180c99ccd74803565fb36098389198091ded#8f99180c99ccd74803565fb36098389198091ded" +dependencies = [ + "aes-ctr", + "async-trait", + "atomic", + "base64 0.13.0", + "byteorder", + "cjson", + "dashmap", + "getrandom 0.2.0", + "hmac", + "matrix-sdk-common", + "matrix-sdk-common-macros", + "olm-rs", + "pbkdf2", + "serde", + "serde_json", + "sha2", + "sqlx", + "thiserror", + "tracing", + "tracing-futures", + "url", + "zeroize", +] + [[package]] name = "matrix-wol" version = "0.1.0" @@ -585,6 +966,12 @@ dependencies = [ "url", ] +[[package]] +name = "maybe-uninit" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" + [[package]] name = "memchr" version = "2.3.3" @@ -696,6 +1083,40 @@ dependencies = [ "libc", ] +[[package]] +name = "olm-rs" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daab4abdd728e5e77ec15888fc12688c0b821c81fca621f1bb28dbe489cbc404" +dependencies = [ + "getrandom 0.2.0", + "olm-sys", + "serde", + "serde_json", + "zeroize", +] + +[[package]] +name = "olm-sys" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf083a66a6b86db09dac0e31bd5dc20ffe3d5677375bb4133ae3d0fd813354f" +dependencies = [ + "cmake", +] + +[[package]] +name = "once_cell" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + [[package]] name = "openssl" version = "0.10.30" @@ -729,6 +1150,15 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "pbkdf2" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7170d73bf11f39b4ce1809aabc95bf5c33564cdc16fc3200ddda17a5f6e5e48b" +dependencies = [ + "crypto-mac", +] + [[package]] name = "percent-encoding" version = "2.1.0" @@ -779,6 +1209,27 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" +[[package]] +name = "proc-macro-crate" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" +dependencies = [ + "toml", +] + +[[package]] +name = "proc-macro-hack" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598" + +[[package]] +name = "proc-macro-nested" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" + [[package]] name = "proc-macro2" version = "1.0.24" @@ -803,7 +1254,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom", + "getrandom 0.1.15", "libc", "rand_chacha", "rand_core", @@ -826,7 +1277,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom", + "getrandom 0.1.15", ] [[package]] @@ -877,7 +1328,7 @@ version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9eaa17ac5d7b838b7503d118fa16ad88f440498bf9ffe5424e621f93190d61e" dependencies = [ - "base64", + "base64 0.12.3", "bytes", "encoding_rs", "futures-core", @@ -906,41 +1357,74 @@ dependencies = [ "winreg", ] +[[package]] +name = "ruma" +version = "0.0.1" +source = "git+https://github.com/ruma/ruma?rev=50eb700571480d1440e15a387d10f98be8abab59#50eb700571480d1440e15a387d10f98be8abab59" +dependencies = [ + "assign", + "js_int", + "ruma-api", + "ruma-appservice-api", + "ruma-client-api", + "ruma-common", + "ruma-events", + "ruma-federation-api", + "ruma-identifiers", + "ruma-serde", +] + [[package]] name = "ruma-api" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82ffdb7fb9cf6af2b1d0d8254d922560ecb70081d7e70931c9b996b6b4839db5" +version = "0.17.0-alpha.1" +source = "git+https://github.com/ruma/ruma?rev=50eb700571480d1440e15a387d10f98be8abab59#50eb700571480d1440e15a387d10f98be8abab59" dependencies = [ "http", "percent-encoding", "ruma-api-macros", + "ruma-common", "ruma-identifiers", "ruma-serde", "serde", "serde_json", "strum", + "thiserror", ] [[package]] name = "ruma-api-macros" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52b82b4567b9af9b40a86f7778821c016ea961f55e4fee255f8f24bb28ee7452" +version = "0.17.0-alpha.1" +source = "git+https://github.com/ruma/ruma?rev=50eb700571480d1440e15a387d10f98be8abab59#50eb700571480d1440e15a387d10f98be8abab59" dependencies = [ + "proc-macro-crate", "proc-macro2", "quote", "syn", ] [[package]] -name = "ruma-client-api" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "082913ad135ca55ee06a55d295bea954982f2ac5e0150adc09024f5cbb8cb6cf" +name = "ruma-appservice-api" +version = "0.2.0-alpha.1" +source = "git+https://github.com/ruma/ruma?rev=50eb700571480d1440e15a387d10f98be8abab59#50eb700571480d1440e15a387d10f98be8abab59" dependencies = [ + "ruma-api", + "ruma-common", + "ruma-events", + "ruma-identifiers", + "serde", + "serde_json", +] + +[[package]] +name = "ruma-client-api" +version = "0.10.0-alpha.1" +source = "git+https://github.com/ruma/ruma?rev=50eb700571480d1440e15a387d10f98be8abab59#50eb700571480d1440e15a387d10f98be8abab59" +dependencies = [ + "assign", "http", "js_int", + "maplit", + "percent-encoding", "ruma-api", "ruma-common", "ruma-events", @@ -953,22 +1437,33 @@ dependencies = [ [[package]] name = "ruma-common" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cb49e83277e82c69cc258cedc7e68b3d72ba378f1cb6105cbfcc8831e422b4d" +version = "0.2.0" +source = "git+https://github.com/ruma/ruma?rev=50eb700571480d1440e15a387d10f98be8abab59#50eb700571480d1440e15a387d10f98be8abab59" dependencies = [ - "matches", + "js_int", + "ruma-common-macros", + "ruma-identifiers", "ruma-serde", "serde", "serde_json", "strum", ] +[[package]] +name = "ruma-common-macros" +version = "0.2.0" +source = "git+https://github.com/ruma/ruma?rev=50eb700571480d1440e15a387d10f98be8abab59#50eb700571480d1440e15a387d10f98be8abab59" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "ruma-events" -version = "0.21.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ddf82c2231e4c53443424df34e868e4b09c20de7a76780d47a133a3b3f8ad9c" +version = "0.22.0-alpha.1" +source = "git+https://github.com/ruma/ruma?rev=50eb700571480d1440e15a387d10f98be8abab59#50eb700571480d1440e15a387d10f98be8abab59" dependencies = [ "js_int", "ruma-common", @@ -977,33 +1472,70 @@ dependencies = [ "ruma-serde", "serde", "serde_json", + "strum", ] [[package]] name = "ruma-events-macros" -version = "0.21.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88e5c5b242fe4ee0cc56879057353621196d0988dd359579cad8f43471e483b7" +version = "0.22.0-alpha.1" +source = "git+https://github.com/ruma/ruma?rev=50eb700571480d1440e15a387d10f98be8abab59#50eb700571480d1440e15a387d10f98be8abab59" dependencies = [ + "proc-macro-crate", "proc-macro2", "quote", "syn", ] +[[package]] +name = "ruma-federation-api" +version = "0.0.3" +source = "git+https://github.com/ruma/ruma?rev=50eb700571480d1440e15a387d10f98be8abab59#50eb700571480d1440e15a387d10f98be8abab59" +dependencies = [ + "js_int", + "ruma-api", + "ruma-common", + "ruma-events", + "ruma-identifiers", + "ruma-serde", + "serde", + "serde_json", +] + [[package]] name = "ruma-identifiers" -version = "0.16.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6316cb248e3e0323a5a269b8eaed571404fb4f65c81848549e9ba99fd9b8e9de" +version = "0.17.4" +source = "git+https://github.com/ruma/ruma?rev=50eb700571480d1440e15a387d10f98be8abab59#50eb700571480d1440e15a387d10f98be8abab59" +dependencies = [ + "ruma-identifiers-macros", + "ruma-identifiers-validation", + "serde", + "strum", +] + +[[package]] +name = "ruma-identifiers-macros" +version = "0.17.4" +source = "git+https://github.com/ruma/ruma?rev=50eb700571480d1440e15a387d10f98be8abab59#50eb700571480d1440e15a387d10f98be8abab59" +dependencies = [ + "proc-macro2", + "quote", + "ruma-identifiers-validation", + "syn", +] + +[[package]] +name = "ruma-identifiers-validation" +version = "0.1.1" +source = "git+https://github.com/ruma/ruma?rev=50eb700571480d1440e15a387d10f98be8abab59#50eb700571480d1440e15a387d10f98be8abab59" dependencies = [ "serde", + "strum", ] [[package]] name = "ruma-serde" version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a50045b7e93329085488c88aee95e109c32d53c89d0f4882791e2cc81eb10ce" +source = "git+https://github.com/ruma/ruma?rev=50eb700571480d1440e15a387d10f98be8abab59#50eb700571480d1440e15a387d10f98be8abab59" dependencies = [ "form_urlencoded", "itoa", @@ -1100,6 +1632,19 @@ dependencies = [ "url", ] +[[package]] +name = "sha2" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2933378ddfeda7ea26f48c555bdad8bb446bf8a3d17832dc83e380d444cfb8c1" +dependencies = [ + "block-buffer", + "cfg-if", + "cpuid-bool", + "digest", + "opaque-debug", +] + [[package]] name = "slab" version = "0.4.2" @@ -1118,6 +1663,81 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "sqlformat" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f699301eec598ffd6c39832cca1416381ea459ac73c506f6ca74c8750fb52969" +dependencies = [ + "lazy_static", + "maplit", + "regex", +] + +[[package]] +name = "sqlx" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8974cacd80085fbe49e778708d660dec6fb351604dc34c3905b26efb2803b038" +dependencies = [ + "sqlx-core", + "sqlx-macros", +] + +[[package]] +name = "sqlx-core" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ac5a436f941c42eac509471a730df5c3c58e1450e68cd39afedbd948206273" +dependencies = [ + "async-native-tls", + "async-stream", + "bitflags", + "byteorder", + "crossbeam-queue", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-util", + "hex", + "libc", + "libsqlite3-sys", + "log", + "memchr", + "percent-encoding", + "sqlformat", + "tokio", + "url", +] + +[[package]] +name = "sqlx-macros" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de2ae78b783af5922d811b14665a5a3755e531c3087bb805cf24cf71f15e6780" +dependencies = [ + "dotenv", + "futures", + "heck", + "lazy_static", + "proc-macro2", + "quote", + "sqlx-core", + "syn", + "tokio", + "url", +] + +[[package]] +name = "stream-cipher" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c80e15f898d8d8f25db24c253ea615cc14acf418ff307822995814e7d42cfa89" +dependencies = [ + "block-cipher", + "generic-array", +] + [[package]] name = "strsim" version = "0.8.0" @@ -1126,18 +1746,18 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "strum" -version = "0.18.0" +version = "0.19.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57bd81eb48f4c437cadc685403cad539345bf703d78e63707418431cecd4522b" +checksum = "b89a286a7e3b5720b9a477b23253bc50debac207c8d21505f8e70b36792f11b5" dependencies = [ "strum_macros", ] [[package]] name = "strum_macros" -version = "0.18.0" +version = "0.19.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87c85aa3f8ea653bfd3ddf25f7ee357ee4d204731f6aa9ad04002306f6e2774c" +checksum = "e61bb0be289045cb80bfce000512e32d09f8337e54c186725da381377ad1f8d5" dependencies = [ "heck", "proc-macro2", @@ -1145,6 +1765,12 @@ dependencies = [ "syn", ] +[[package]] +name = "subtle" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "343f3f510c2915908f155e94f17220b19ccfacf2a64a2a5d8004f2c3e311e7fd" + [[package]] name = "syn" version = "1.0.44" @@ -1156,6 +1782,18 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "synstructure" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "unicode-xid", +] + [[package]] name = "tempfile" version = "3.1.0" @@ -1343,6 +1981,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" +[[package]] +name = "typenum" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" + [[package]] name = "unicase" version = "2.6.0" @@ -1406,6 +2050,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11" dependencies = [ "rand", + "serde", ] [[package]] @@ -1584,3 +2229,18 @@ name = "zeroize" version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05f33972566adbd2d3588b0491eb94b98b43695c4ef897903470ede4f3f5a28a" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3f369ddb18862aba61aa49bf31e74d29f0f162dec753063200e1dc084345d16" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] diff --git a/Cargo.toml b/Cargo.toml index 9373398..aa5f932 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ license = "AGPL-3.0-only" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -matrix-sdk = { version = "0.1.0", default_features = false, features = ["messages"] } +matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "8f99180c99ccd74803565fb36098389198091ded" } fern = "0.6.0" chrono = "0.4.19" tracing = { version = "0.1.21", features = ["log"] } diff --git a/config.sample.toml b/config.sample.toml index 860fcf0..6fe9ddb 100644 --- a/config.sample.toml +++ b/config.sample.toml @@ -1,6 +1,7 @@ hs_url = "https://example.org" username = "wol" password = "s3cr3t" +store_path = "./store" [ hosts.example ] mac_addr = [0x70,0x8b,0xcd,0x54,0xe2,0x32] diff --git a/src/bot.rs b/src/bot.rs index cca9705..a6bf943 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -7,14 +7,17 @@ use tracing::{error, info}; use async_trait::async_trait; use matrix_sdk::{ self, - identifiers::RoomId, events::{ room::{ member::MemberEventContent, - message::{MessageEvent, MessageEventContent, TextMessageEventContent, NoticeMessageEventContent}, + message::{ + MessageEvent, MessageEventContent, NoticeMessageEventContent, + TextMessageEventContent, + }, }, - stripped::StrippedStateEvent, + AnyMessageEventContent, StrippedStateEvent, SyncMessageEvent, }, + identifiers::RoomId, Client, EventEmitter, SyncRoom, }; @@ -68,10 +71,10 @@ impl EventEmitter for WakeOnLanBot { _ => {} } } - async fn on_room_message(&self, room: SyncRoom, event: &MessageEvent) { + async fn on_room_message(&self, room: SyncRoom, event: &SyncMessageEvent) { match room { SyncRoom::Joined(room) => { - let msg_body = if let MessageEvent { + let msg_body = if let SyncMessageEvent { content: MessageEventContent::Text(TextMessageEventContent { body: msg_body, .. }), .. @@ -83,7 +86,15 @@ impl EventEmitter for WakeOnLanBot { }; if let Ok(command) = Command::from_str(&msg_body) { - handle_command(command, &self.client, &self.hosts, event, &room.read().await.room_id.clone()).await; + let room_id = room.read().await.room_id.clone(); + handle_command( + command, + &self.client, + &self.hosts, + event, + &room_id, + ) + .await; } else { //TODO: give help text } @@ -93,7 +104,13 @@ impl EventEmitter for WakeOnLanBot { } } -async fn handle_command(command: Command, client: &Client, hosts: &HashMap, event: &MessageEvent, room: &RoomId) { +async fn handle_command( + command: Command, + client: &Client, + hosts: &HashMap, + event: &SyncMessageEvent, + room: &RoomId, +) { match command { Command::Wake { host } => { if let Some(host_conf) = hosts.get(&host) { @@ -102,15 +119,26 @@ async fn handle_command(command: Command, client: &Client, hosts: &HashMap { info!("Magic packet sent to {} successfully", host); - send_message(client, &format!("Successfully send magic packet to {}", host), room).await; + send_message( + client, + &format!("Successfully send magic packet to {}", host), + room, + ) + .await; } Err(e) => { error!("Couldn't send magic packet to {}, error: {}", host, e); - send_message(client, &format!("Failed to send magic packet to {}", host), room).await; + send_message( + client, + &format!("Failed to send magic packet to {}", host), + room, + ) + .await; } } } else { - send_message(client, &format!("No permission to wake up {}!", host), room).await; + send_message(client, &format!("No permission to wake up {}!", host), room) + .await; } } else { send_message(client, &format!("Host {} not found!", host), room).await; @@ -120,12 +148,20 @@ async fn handle_command(command: Command, client: &Client, hosts: &HashMap, + pub(crate) store_path: String, } #[derive(Deserialize)] diff --git a/src/main.rs b/src/main.rs index 6e69d5c..1926b4e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,12 +10,14 @@ use anyhow::{Context, Result}; use tracing::info; -use matrix_sdk::{self, Client, SyncSettings}; +use matrix_sdk::{self, Client, ClientConfig, JsonStore, SyncSettings}; use url::Url; async fn login_and_sync(config: Config) -> Result<()> { let homeserver_url = Url::parse(&config.hs_url).expect("Couldn't parse the homeserver URL"); - let mut client = Client::new(homeserver_url).unwrap(); + let store = JsonStore::open(config.store_path)?; + let client_config = ClientConfig::new().state_store(Box::new(store)); + let mut client = Client::new_with_config(homeserver_url, client_config)?; client .login( @@ -25,16 +27,15 @@ async fn login_and_sync(config: Config) -> Result<()> { Some(&"command bot".to_string()), ) .await?; - info!("logged in as {}", config.username); - client.sync(SyncSettings::default()).await.unwrap(); + client.sync_once(SyncSettings::default()).await?; client .add_event_emitter(Box::new(WakeOnLanBot::new(client.clone(), config.hosts))) .await; let settings = SyncSettings::default().token(client.sync_token().await.unwrap()); - client.sync_forever(settings, |_| async {}).await; + client.sync(settings).await; Ok(()) } @@ -43,7 +44,8 @@ async fn login_and_sync(config: Config) -> Result<()> { async fn main() -> Result<()> { let matches = config::setup_clap(); config::setup_logging(matches.occurrences_of("v")); - let config = config::read_config(matches.value_of("config").unwrap()).context("Couldn't load config")?; + let config = + config::read_config(matches.value_of("config").unwrap()).context("Couldn't load config")?; login_and_sync(config).await?; Ok(()) }