feat: enable encryption

This commit is contained in:
Jan Christian Grünhage 2020-10-26 23:12:25 +01:00
parent 48a5972aaf
commit 12e947bd8b
5 changed files with 363 additions and 8 deletions

358
Cargo.lock generated
View File

@ -1,5 +1,14 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[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 +33,39 @@ version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1fd36ffbb1fb7c834eac128ea8d0e310c5aeb635548f9d58861e1308d46e71c"
[[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 +77,12 @@ dependencies = [
"syn",
]
[[package]]
name = "atomic"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64f46ca51dca4837f1520754d1c8c36636356b81553d928dc9c177025369a06e"
[[package]]
name = "atty"
version = "0.2.14"
@ -70,6 +118,12 @@ 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 +155,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 +182,26 @@ dependencies = [
"vec_map",
]
[[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 +218,45 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac"
[[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 = "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 = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]]
name = "dtoa"
version = "0.4.6"
@ -209,6 +334,21 @@ version = "0.1.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c7e4c2612746b0df8fed4ce0c69156021b704c9aefa360311c04e6e9e002eed"
[[package]]
name = "futures"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d8e3078b7b2a8a671cb7a3d17b4760e4181ea243227776ba83fd043b4ca034e"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.6"
@ -216,6 +356,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7a4d35f7401e948629c9c3d6638fb9bf94e0b2121e96c3b428cc4e631f3eb74"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
@ -224,13 +365,30 @@ version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d674eaa0056896d5ada519900dbf97ead2e46a7b6621e8160d79e2f2e1e2784b"
[[package]]
name = "futures-executor"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
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.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4297dd1d9d6268237e4f93aeb9c90fc1bf0d8cec7e1cef22798939e4c43a251"
dependencies = [
"futures",
"futures 0.1.30",
]
[[package]]
@ -244,6 +402,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 +422,15 @@ version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a894a0acddba51a2d49a6f4263b1e64b8c579ece8af50fa86503d52cd1eea34"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-sink",
"futures-task",
"memchr",
"pin-project",
"pin-utils",
"slab",
]
[[package]]
@ -279,6 +445,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 +512,12 @@ dependencies = [
"libc",
]
[[package]]
name = "hex"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35"
[[package]]
name = "http"
version = "0.2.1"
@ -500,6 +683,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 +703,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"
@ -541,6 +741,7 @@ checksum = "55109f3f4c3f6becf39e17b2827415c74eee378f4538fba36e695af2658361fa"
dependencies = [
"async-trait",
"matrix-sdk-common",
"matrix-sdk-crypto",
"serde",
"serde_json",
"thiserror",
@ -565,6 +766,28 @@ dependencies = [
"uuid",
]
[[package]]
name = "matrix-sdk-crypto"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "510016e90136a28de947ad9102ca865ae8c68f09d160e1092f1cb9912fffa0d7"
dependencies = [
"async-trait",
"atomic",
"cjson",
"dashmap",
"matrix-sdk-common",
"olm-rs",
"serde",
"serde_json",
"sqlx",
"thiserror",
"tracing",
"tracing-futures",
"url",
"zeroize",
]
[[package]]
name = "matrix-wol"
version = "0.1.0"
@ -585,6 +808,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 +925,31 @@ dependencies = [
"libc",
]
[[package]]
name = "olm-rs"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "033e81431ecd7c359ab02e4c3f08ebe803acbcccf92765ae56252e95561038c9"
dependencies = [
"getrandom 0.1.15",
"olm-sys",
"serde",
"serde_json",
"zeroize",
]
[[package]]
name = "olm-sys"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d77deffdae89bf5b2ff17a9c54fab4b3b92c5440e9e4645e8bb08d7c6ace8fc"
[[package]]
name = "once_cell"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad"
[[package]]
name = "openssl"
version = "0.10.30"
@ -779,6 +1033,12 @@ version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20"
[[package]]
name = "proc-macro-hack"
version = "0.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598"
[[package]]
name = "proc-macro2"
version = "1.0.24"
@ -803,7 +1063,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 +1086,7 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
dependencies = [
"getrandom",
"getrandom 0.1.15",
]
[[package]]
@ -1118,6 +1378,71 @@ 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 0.3.6",
"heck",
"lazy_static",
"proc-macro2",
"quote",
"sqlx-core",
"syn",
"tokio",
"url",
]
[[package]]
name = "strsim"
version = "0.8.0"
@ -1156,6 +1481,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"
@ -1584,3 +1921,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",
]

View File

@ -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 = "0.1.0"
fern = "0.6.0"
chrono = "0.4.19"
tracing = { version = "0.1.21", features = ["log"] }

View File

@ -1,6 +1,7 @@
hs_url = "https://example.org"
username = "wol"
password = "s3cr3t"
store_path = "./store"
[[ hosts ]]
name = "example"

View File

@ -10,6 +10,7 @@ pub(crate) struct Config {
pub(crate) username: String,
pub(crate) password: String,
pub(crate) hosts: HashMap<String, Host>,
pub(crate) store_path: String,
}
#[derive(Deserialize)]

View File

@ -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,10 +27,9 @@ 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(SyncSettings::default()).await?;
client
.add_event_emitter(Box::new(WakeOnLanBot::new(client.clone(), config.hosts)))
.await;