diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..051d09d --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +eval "$(lorri direnv)" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9061fd3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +config.dhall +var/* diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..92f4af2 --- /dev/null +++ b/shell.nix @@ -0,0 +1,24 @@ +{ pkgs ? import { } }: + +pkgs.mkShell { + buildInputs = with pkgs; [ + # rust + cargo + cargo-watch + rustc + rust-analyzer + rustfmt + + # system + pkg-config + openssl + cmake + + # dhall + dhall + dhall-json + ]; + + RUST_LOG = "info"; + RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; +} diff --git a/src/main.rs b/src/main.rs index 4b715d3..e0cc52b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,8 @@ use matrix_sdk::{ config::{ClientConfig, SyncSettings}, room::Room, ruma::{ + api::client::r0::uiaa, + assign, events::{ room::message::{MessageType, RoomMessageEventContent, TextMessageEventContent}, SyncMessageEvent, @@ -43,21 +45,12 @@ async fn main() -> Result<()> { // First we need to log in. client - .login( - cfg.username.localpart(), - &cfg.password, - Some(&cfg.client_id), - Some(APPLICATION_NAME), - ) + .login(cfg.username.localpart(), &cfg.password, None, None) .await?; // Ignore old messages client.sync_once(SyncSettings::default()).await?; - if cfg.key_path.exists() { - client.import_keys(cfg.key_path, "").await?; - } - client.register_event_handler(on_room_message).await; // Syncing is important to synchronize the client state with the server. @@ -67,6 +60,24 @@ async fn main() -> Result<()> { Ok(()) } +async fn unfuck_crypto(client: Client, cfg: &Config) { + if let Err(e) = client.bootstrap_cross_signing(None).await { + if let Some(response) = e.uiaa_response() { + let auth_data = uiaa::AuthData::Password(assign!( + uiaa::Password::new(uiaa::UserIdentifier::MatrixId(&*cfg.username.as_str()), &cfg.password), + { session: response.session.as_deref() } + )); + + client + .bootstrap_cross_signing(Some(auth_data)) + .await + .expect("Couldn't bootstrap cross signing") + } else { + panic!("Error durign cross signing bootstrap {:#?}", e); + } + } +} + async fn on_room_message(event: SyncMessageEvent, room: Room) { if let Room::Joined(room) = room { let msg_body = match event.content.msgtype {