From 2836a2886f0a02283dd6adc0178d8df3593d048a Mon Sep 17 00:00:00 2001 From: 8go <17750857+8go@users.noreply.github.com> Date: Sat, 14 Sep 2024 20:20:41 +0200 Subject: [PATCH] bug fixes - fixed bug in --log-level : now RUST_LOG is appropriately used as default - fixed bug --verify, --verify emoji improved, --verify emoji-req works on Element Web app but still does not work on Element Android app --- Cargo.lock | 166 +++++++++------- Cargo.toml | 22 ++- README.md | 39 ++-- VERSION | 2 +- help.help.txt | 10 +- help.manual.txt | 39 ++-- help.usage.txt | 1 + scripts/workflow.sh | 2 +- src/emoji_verify.rs | 447 +++++++++++++++++++++++++------------------- src/main.rs | 57 ++++-- src/mclient.rs | 5 +- 11 files changed, 472 insertions(+), 318 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2679780..7a389ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,19 +16,13 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.22.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" dependencies = [ "gimli", ] -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "adler2" version = "2.0.0" @@ -134,9 +128,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.86" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356" [[package]] name = "anymap2" @@ -258,17 +252,17 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.73" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ "addr2line", - "cc", "cfg-if", "libc", - "miniz_oxide 0.7.4", + "miniz_oxide", "object", "rustc-demangle", + "windows-targets 0.52.6", ] [[package]] @@ -382,9 +376,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.16" +version = "1.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9d013ecb737093c0e86b151a7b837993cf9ec6c502946cfb44bedc392421e0b" +checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476" dependencies = [ "shlex", ] @@ -546,9 +540,9 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ "libc", ] @@ -897,7 +891,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253" dependencies = [ "crc32fast", - "miniz_oxide 0.8.0", + "miniz_oxide", ] [[package]] @@ -1017,9 +1011,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.29.0" +version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" [[package]] name = "gloo-timers" @@ -1269,7 +1263,7 @@ dependencies = [ "http 1.1.0", "hyper 1.4.1", "hyper-util", - "rustls 0.23.12", + "rustls 0.23.13", "rustls-pki-types", "tokio", "tokio-rustls 0.26.0", @@ -1307,9 +1301,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9" +checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" dependencies = [ "bytes", "futures-channel", @@ -1429,9 +1423,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" [[package]] name = "is_terminal_polyfill" @@ -1623,9 +1617,18 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "matrix-commander" -version = "0.6.0" +version = "0.8.0" dependencies = [ "clap", "colored", @@ -1650,9 +1653,9 @@ dependencies = [ [[package]] name = "matrix-pickle" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb521190328c57a2051f70250beb874dc0fac6bcd22b615f7f9700b7b4fb826" +checksum = "4e2551de3bba2cc65b52dc6b268df6114011fe118ac24870fbcf1b35537bd721" dependencies = [ "matrix-pickle-derive", "thiserror", @@ -1660,12 +1663,12 @@ dependencies = [ [[package]] name = "matrix-pickle-derive" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6fb3c7231cbb7fbbc50871615edebf65183b382cdaa1fe21c5e88a12617de8e" +checksum = "f75de44c3120d78e978adbcf6d453b20ba011f3c46363e52d1dbbc72f545e9fb" dependencies = [ "proc-macro-crate 3.2.0", - "proc-macro-error", + "proc-macro-error2", "proc-macro2", "quote", "syn 2.0.77", @@ -1903,15 +1906,6 @@ dependencies = [ "unicase", ] -[[package]] -name = "miniz_oxide" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" -dependencies = [ - "adler", -] - [[package]] name = "miniz_oxide" version = "0.8.0" @@ -1990,9 +1984,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" [[package]] name = "opaque-debug" @@ -2058,9 +2052,9 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "parking" -version = "2.2.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" [[package]] name = "paste" @@ -2215,6 +2209,27 @@ dependencies = [ "version_check", ] +[[package]] +name = "proc-macro-error-attr2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] +name = "proc-macro-error2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11ec05c52be0a07b08061f7dd003e7d7092e0472bc731b4af7bb1ef876109802" +dependencies = [ + "proc-macro-error-attr2", + "proc-macro2", + "quote", +] + [[package]] name = "proc-macro2" version = "1.0.86" @@ -2331,8 +2346,17 @@ checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", - "regex-automata", - "regex-syntax", + "regex-automata 0.4.7", + "regex-syntax 0.8.4", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", ] [[package]] @@ -2343,9 +2367,15 @@ checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.8.4", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.8.4" @@ -2658,9 +2688,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.36" +version = "0.38.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f55e80d50763938498dd5ebb18647174e0c76dc38c5505294bb224624f30f36" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" dependencies = [ "bitflags 2.6.0", "errno", @@ -2683,15 +2713,15 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.12" +version = "0.23.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ "log", "once_cell", "ring", "rustls-pki-types", - "rustls-webpki 0.102.7", + "rustls-webpki 0.102.8", "subtle", "zeroize", ] @@ -2733,9 +2763,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.102.7" +version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84678086bd54edf2b415183ed7a94d0efb049f1b646a33e22a36f3794be6ae56" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ "ring", "rustls-pki-types", @@ -2750,11 +2780,11 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "schannel" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" +checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2798,9 +2828,9 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.209" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] @@ -2827,9 +2857,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.209" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", @@ -3170,7 +3200,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "rustls 0.23.12", + "rustls 0.23.13", "rustls-pki-types", "tokio", ] @@ -3332,10 +3362,14 @@ version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ + "matchers", "nu-ansi-term", + "once_cell", + "regex", "sharded-slab", "smallvec", "thread_local", + "tracing", "tracing-core", "tracing-log", ] @@ -3395,9 +3429,9 @@ checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-normalization" @@ -3454,7 +3488,7 @@ dependencies = [ "flate2", "log", "once_cell", - "rustls 0.23.12", + "rustls 0.23.13", "rustls-pki-types", "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 9480f4e..f7d0f59 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "matrix-commander" -version = "0.7.0" +version = "0.8.0" edition = "2021" description = "simple but convenient CLI-based Matrix client app for sending and receiving" documentation = "https://docs.rs/matrix-commander" @@ -18,13 +18,22 @@ publish = true [dependencies] -clap = { version = "4.5", features = ["derive", "color", "wrap_help", "unicode"] } +clap = { version = "4.5", features = [ + "derive", + "color", + "wrap_help", + "unicode", +] } colored = "2.1" directories = "5.0" futures-util = "0.3" json = "0.12" # matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk , features = ["markdown", "anyhow"] } -matrix-sdk = { version = "0.7", features = ["markdown", "anyhow", "bundled-sqlite"] } +matrix-sdk = { version = "0.7", features = [ + "markdown", + "anyhow", + "bundled-sqlite", +] } mime = "0.3" mime_guess = "2.0" regex = "1.10" @@ -33,9 +42,12 @@ rpassword = "7.3" serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } thiserror = "1.0" -tokio = { version = "1.40", default-features = false, features = ["rt-multi-thread", "macros",] } +tokio = { version = "1.40", default-features = false, features = [ + "rt-multi-thread", + "macros", +] } tracing = "0.1" -tracing-subscriber = "0.3" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } update-informer = "1.1" url = { version = "2.5", features = ["serde"] } diff --git a/README.md b/README.md index 94c5357..d5751fd 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,11 @@ Options: --log-level Set the log level by overwriting the default log level. Details:: If not used, then the default log level set with environment variable - 'RUST_LOG' will be used. See also '--debug' and '--verbose' + 'RUST_LOG' will be used. See also '--debug' and '--verbose'. An + example use of RUST_LOG is to use neither --log-level nor --debug, + and to set RUST_LOG="error,matrix_commander_rs=debug" which turns off + debugging on all lower level modules and turns debugging on only for + matrix-commander-rs [default: none] @@ -254,7 +258,15 @@ Options: --verify Perform account verification. Details:: By default, no verification is performed. Verification is currently offered via Manual-Device, - Manual-User, Emoji and Emoji-Req. Manual verification is simpler but + Manual-User, Emoji and Emoji-Req. Do verification in this order: 1) + bottstrap first with -bootstrap, 2) perform both manual + verifications, and 3) perform emoji verification. --verify emoji has + been tested against Element in Firefox browser and against Element + app on Android phone. Both has been working successfully in Sept + 2024. In Element web page it was important NOT to click the device in + the device list, but to click the underscored link "Verify" just + above the device list. In the Element on cell phone case, accept the + emojis first on the cell phone. Manual verification is simpler but does less. Try: '--bootstrap --password mypassword --verify manual-device' or '--bootstrap --password mypassword --verify manual-user'. Manual only verfies devices or users one-directionally. @@ -263,14 +275,16 @@ Options: and https://docs.rs/matrix-sdk/0.7/matrix_sdk/encryption/identities/struct.UserIdentity.html#method.verify for more info on Manual verification. manual-device can only verify - its own devices, notother users' devices. manual-user can trust other - users. So, with verify-user also use the --user option to specify one - or multiple users. One can first do 'manual-device' and 'manual-user' - verification and then 'emoji' or 'emoji-req' verification. Both - 'emoji' as well as 'emoji-req' perform emoji verification. With - 'emoji' we send a request to some other client to request - verification from their device. With 'emoji-req' we wait for some - other client to request verification from us. If verification is + its own devices, not other users' devices. manual-user can trust + other users. So, with manual-user also use the --user option to + specify one or multiple users. With manual-user first trust yourself, + by setting --user to yourself, or omitting -user in which case it + will default to itself. One should first do 'manual-device' and + 'manual-user' verification and then 'emoji' or 'emoji-req' + verification. Both 'emoji' as well as 'emoji-req' perform emoji + verification. With 'emoji' we send a request to some other client to + request verification from their device. With 'emoji-req' we wait for + some other client to request verification from us. If verification is desired, run this program in the foreground (not as a service) and without a pipe. While verification is optional it is highly recommended, and it is recommended to be done right after (or @@ -299,8 +313,9 @@ Options: similar. You must specify a user with --user and a device with --device to specify to which device you want to send the verification request. On the other device you get a pop up and you must accept the - verification request. 'emoji-req' seems to have problems, e.g. - 'emoji-req' does not seem to work with Element phone app + verification request. 'emoji-req' currently seems to have problems, + while it does work with Element web page in browser, 'emoji-req' does + not seem to work with Element phone app [default: none] diff --git a/VERSION b/VERSION index faef31a..a3df0a6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.7.0 +0.8.0 diff --git a/help.help.txt b/help.help.txt index 9c20daf..6ec50ce 100644 --- a/help.help.txt +++ b/help.help.txt @@ -1,10 +1,10 @@ Welcome to "matrix-commander-rs", a Matrix CLI client. ─── On the first run use --login to log in, to authenticate. On the second run we suggest to use --verify to get verified. Manual verification is built-in and can be used to -verify devices. Or combine both --login and --verify in the first run. On -further runs "matrix-commander-rs" implements a simple Matrix CLI client that -can send messages or files, listen to messages, operate on rooms, etc. ─── -─── This project is currently only a vision. The Python package +verify devices and users. Or combine both --login and --verify in the first +run. On further runs "matrix-commander-rs" implements a simple Matrix CLI +client that can send messages or files, listen to messages, operate on rooms, +etc. ─── ─── This project is currently only a vision. The Python package "matrix-commander" exists. The vision is to have a compatible program in Rust. I cannot do it myself, but I can coordinate and merge your pull requests. Have a look at the repo "https://github.com/8go/matrix-commander-rs/". Please help! @@ -163,5 +163,7 @@ Options: repository. --media-mxc-to-http [...] Convert URIs to HTTP URLs. + --get-masterkey + Get your own master key. PS: Also have a look at scripts/matrix-commander-rs-tui. Use --manual to get more detailed help information. diff --git a/help.manual.txt b/help.manual.txt index 7138313..681dde0 100644 --- a/help.manual.txt +++ b/help.manual.txt @@ -60,7 +60,11 @@ Options: --log-level Set the log level by overwriting the default log level. Details:: If not used, then the default log level set with environment variable - 'RUST_LOG' will be used. See also '--debug' and '--verbose' + 'RUST_LOG' will be used. See also '--debug' and '--verbose'. An + example use of RUST_LOG is to use neither --log-level nor --debug, + and to set RUST_LOG="error,matrix_commander_rs=debug" which turns off + debugging on all lower level modules and turns debugging on only for + matrix-commander-rs [default: none] @@ -144,7 +148,15 @@ Options: --verify Perform account verification. Details:: By default, no verification is performed. Verification is currently offered via Manual-Device, - Manual-User, Emoji and Emoji-Req. Manual verification is simpler but + Manual-User, Emoji and Emoji-Req. Do verification in this order: 1) + bottstrap first with -bootstrap, 2) perform both manual + verifications, and 3) perform emoji verification. --verify emoji has + been tested against Element in Firefox browser and against Element + app on Android phone. Both has been working successfully in Sept + 2024. In Element web page it was important NOT to click the device in + the device list, but to click the underscored link "Verify" just + above the device list. In the Element on cell phone case, accept the + emojis first on the cell phone. Manual verification is simpler but does less. Try: '--bootstrap --password mypassword --verify manual-device' or '--bootstrap --password mypassword --verify manual-user'. Manual only verfies devices or users one-directionally. @@ -153,14 +165,16 @@ Options: and https://docs.rs/matrix-sdk/0.7/matrix_sdk/encryption/identities/struct.UserIdentity.html#method.verify for more info on Manual verification. manual-device can only verify - its own devices, notother users' devices. manual-user can trust other - users. So, with verify-user also use the --user option to specify one - or multiple users. One can first do 'manual-device' and 'manual-user' - verification and then 'emoji' or 'emoji-req' verification. Both - 'emoji' as well as 'emoji-req' perform emoji verification. With - 'emoji' we send a request to some other client to request - verification from their device. With 'emoji-req' we wait for some - other client to request verification from us. If verification is + its own devices, not other users' devices. manual-user can trust + other users. So, with manual-user also use the --user option to + specify one or multiple users. With manual-user first trust yourself, + by setting --user to yourself, or omitting -user in which case it + will default to itself. One should first do 'manual-device' and + 'manual-user' verification and then 'emoji' or 'emoji-req' + verification. Both 'emoji' as well as 'emoji-req' perform emoji + verification. With 'emoji' we send a request to some other client to + request verification from their device. With 'emoji-req' we wait for + some other client to request verification from us. If verification is desired, run this program in the foreground (not as a service) and without a pipe. While verification is optional it is highly recommended, and it is recommended to be done right after (or @@ -189,8 +203,9 @@ Options: similar. You must specify a user with --user and a device with --device to specify to which device you want to send the verification request. On the other device you get a pop up and you must accept the - verification request. 'emoji-req' seems to have problems, e.g. - 'emoji-req' does not seem to work with Element phone app + verification request. 'emoji-req' currently seems to have problems, + while it does work with Element web page in browser, 'emoji-req' does + not seem to work with Element phone app [default: none] diff --git a/help.usage.txt b/help.usage.txt index c87f937..7cf0a2a 100644 --- a/help.usage.txt +++ b/help.usage.txt @@ -74,3 +74,4 @@ Options: --mime [...] --media-delete [...] --media-mxc-to-http [...] + --get-masterkey diff --git a/scripts/workflow.sh b/scripts/workflow.sh index da1721d..238c73e 100755 --- a/scripts/workflow.sh +++ b/scripts/workflow.sh @@ -133,7 +133,7 @@ done PS3='Please enter your choice: ' OPT1="git status # what is the current status" -OPT2="git add Cargo.lock Cargo.toml README.md VERSION help.manual.txt src/main.rs src/mclient.rs" +OPT2="git add Cargo.lock Cargo.toml README.md VERSION help.manual.txt help.help.txt help.usage.txt src/emoji_verify.rs src/main.rs src/mclient.rs" OPT3="cargo package --list # show files containing changes" OPTC="Continue" OPTQ="Quit" diff --git a/src/emoji_verify.rs b/src/emoji_verify.rs index a0802a0..67eca70 100644 --- a/src/emoji_verify.rs +++ b/src/emoji_verify.rs @@ -22,12 +22,18 @@ use matrix_sdk::{ ruma::{ events::{ key::verification::{ + accept::ToDeviceKeyVerificationAcceptEvent, + cancel::ToDeviceKeyVerificationCancelEvent, done::{OriginalSyncKeyVerificationDoneEvent, ToDeviceKeyVerificationDoneEvent}, key::{OriginalSyncKeyVerificationKeyEvent, ToDeviceKeyVerificationKeyEvent}, + // mac::{ToDeviceKeyVerificationMacEvent}, + ready::ToDeviceKeyVerificationReadyEvent, request::ToDeviceKeyVerificationRequestEvent, - start::{OriginalSyncKeyVerificationStartEvent, ToDeviceKeyVerificationStartEvent}, + start::OriginalSyncKeyVerificationStartEvent, + start::ToDeviceKeyVerificationStartEvent, + VerificationMethod, }, - room::message::{MessageType, OriginalSyncRoomMessageEvent}, + room::message::{MessageType, OriginalSyncRoomMessageEvent, SyncRoomMessageEvent}, }, OwnedDeviceId, OwnedUserId, UserId, }, @@ -55,11 +61,11 @@ async fn wait_for_confirmation(sas: SasVerification, emoji: [Emoji; 7]) { } /// Utility function to print confirmed verification results -fn print_result(sas: &SasVerification) { +fn print_success(sas: &SasVerification) { let device = sas.other_device(); println!( - "Successfully verified device {} {} {:?}", + "Successfully verified device {} {}, local trust state: {:?}", device.user_id(), device.device_id(), device.local_trust_state() @@ -80,7 +86,7 @@ async fn print_devices(user_id: &UserId, client: &Client) { .devices() { info!( - " {:<10} {:<30} {:<}", + " {:<10} {:<30} is_verified={:<}", device.device_id(), device.display_name().unwrap_or("-"), device.is_verified() @@ -100,11 +106,15 @@ async fn sas_verification_handler(client: Client, sas: SasVerification) { let mut stream = sas.changes(); while let Some(state) = stream.next().await { - match state { + match state.clone() { SasState::KeysExchanged { emojis, decimals: _, } => { + debug!( + "sas_verification_handler: state {:?} (SasState::KeysExchanged)", + state + ); tokio::spawn(wait_for_confirmation( sas.clone(), emojis @@ -113,17 +123,12 @@ async fn sas_verification_handler(client: Client, sas: SasVerification) { )); } SasState::Done { .. } => { - let device = sas.other_device(); - - println!( - "Successfully verified device {} {} {:?}", - device.user_id(), - device.device_id(), - device.local_trust_state() + debug!( + "sas_verification_handler: state {:?} (SasState::Done)", + state ); - + print_success(&sas); print_devices(sas.other_device().user_id(), &client).await; - break; } SasState::Cancelled(cancel_info) => { @@ -134,7 +139,9 @@ async fn sas_verification_handler(client: Client, sas: SasVerification) { break; } - SasState::Started { .. } | SasState::Accepted { .. } | SasState::Confirmed => (), + SasState::Started { .. } | SasState::Accepted { .. } | SasState::Confirmed => { + debug!("sas_verification_handler: state {:?} ignored", state); + } } } } @@ -152,18 +159,31 @@ async fn request_verification_handler(client: Client, request: VerificationReque let mut stream = request.changes(); while let Some(state) = stream.next().await { - match state { + match state.clone() { VerificationRequestState::Created { .. } | VerificationRequestState::Requested { .. } - | VerificationRequestState::Ready { .. } => (), + | VerificationRequestState::Ready { .. } => { + debug!("request_verification_handler: state {:?} ignored", state); + } VerificationRequestState::Transitioned { verification } => { // We only support SAS verification. + debug!( + "request_verification_handler: state {:?}, Verification state transitioned.", + state + ); if let Verification::SasV1(s) = verification { + debug!("request_verification_handler: Verification state transitioned to Emoji verification."); tokio::spawn(sas_verification_handler(client, s)); break; } } - VerificationRequestState::Done | VerificationRequestState::Cancelled(_) => break, + VerificationRequestState::Done | VerificationRequestState::Cancelled(_) => { + debug!( + "request_verification_handler: state {:?} forces us to stop", + state + ); + break; + } } } } @@ -176,7 +196,7 @@ async fn request_verification_handler(client: Client, request: VerificationReque pub async fn sync_wait_for_verification_request(client: &Client) -> matrix_sdk::Result<()> { client.add_event_handler( |ev: ToDeviceKeyVerificationRequestEvent, client: Client| async move { - debug!("ToDeviceKeyVerificationRequestEvent"); + debug!("ToDeviceKeyVerificationRequestEvent: entering"); let request = client .encryption() .get_verification_request(&ev.sender, &ev.content.transaction_id) @@ -185,16 +205,13 @@ pub async fn sync_wait_for_verification_request(client: &Client) -> matrix_sdk:: tokio::spawn(request_verification_handler(client, request)); - // request - // .accept() - // .await - // .expect("Can't accept verification request"); + debug!("ToDeviceKeyVerificationRequestEvent: leaving"); }, ); client.add_event_handler( |ev: OriginalSyncRoomMessageEvent, client: Client| async move { - debug!("OriginalSyncRoomMessageEvent"); + debug!("OriginalSyncRoomMessageEvent: entering"); if let MessageType::VerificationRequest(_) = &ev.content.msgtype { let request = client .encryption() @@ -204,109 +221,112 @@ pub async fn sync_wait_for_verification_request(client: &Client) -> matrix_sdk:: tokio::spawn(request_verification_handler(client, request)); - // request - // .accept() - // .await - // .expect("Can't accept verification request"); - } - }, - ); - - client.add_event_handler( - |ev: ToDeviceKeyVerificationStartEvent, client: Client| async move { - debug!("ToDeviceKeyVerificationStartEvent"); - if let Some(Verification::SasV1(sas)) = client - .encryption() - .get_verification(&ev.sender, ev.content.transaction_id.as_str()) - .await - { - info!( - "Starting verification with {} {}", - &sas.other_device().user_id(), - &sas.other_device().device_id() - ); - print_devices(&ev.sender, &client).await; - sas.accept().await.unwrap(); - } - }, - ); - - client.add_event_handler( - |ev: ToDeviceKeyVerificationKeyEvent, client: Client| async move { - debug!("ToDeviceKeyVerificationKeyEvent"); - if let Some(Verification::SasV1(sas)) = client - .encryption() - .get_verification(&ev.sender, ev.content.transaction_id.as_str()) - .await - { - tokio::spawn(sas_verification_handler(client, sas)); + debug!("OriginalSyncRoomMessageEvent: leaving"); } }, ); - client.add_event_handler( - |ev: ToDeviceKeyVerificationDoneEvent, client: Client| async move { - debug!("ToDeviceKeyVerificationDoneEvent"); - if let Some(Verification::SasV1(sas)) = client - .encryption() - .get_verification(&ev.sender, ev.content.transaction_id.as_str()) - .await - { - if sas.is_done() { - print_result(&sas); - print_devices(&ev.sender, &client).await; - } - } - }, - ); - - client.add_event_handler( - |ev: OriginalSyncKeyVerificationStartEvent, client: Client| async move { - debug!("OriginalSyncKeyVerificationStartEvent"); - if let Some(Verification::SasV1(sas)) = client - .encryption() - .get_verification(&ev.sender, ev.content.relates_to.event_id.as_str()) - .await - { - println!( - "Starting verification with {} {}", - &sas.other_device().user_id(), - &sas.other_device().device_id() - ); - print_devices(&ev.sender, &client).await; - sas.accept().await.unwrap(); - } - }, - ); - - client.add_event_handler( - |ev: OriginalSyncKeyVerificationKeyEvent, client: Client| async move { - debug!("OriginalSyncKeyVerificationKeyEvent"); - if let Some(Verification::SasV1(sas)) = client - .encryption() - .get_verification(&ev.sender, ev.content.relates_to.event_id.as_str()) - .await - { - tokio::spawn(sas_verification_handler(client, sas)); - } - }, - ); - - client.add_event_handler( - |ev: OriginalSyncKeyVerificationDoneEvent, client: Client| async move { - debug!("OriginalSyncKeyVerificationDoneEvent"); - if let Some(Verification::SasV1(sas)) = client - .encryption() - .get_verification(&ev.sender, ev.content.relates_to.event_id.as_str()) - .await - { - if sas.is_done() { - print_result(&sas); - print_devices(&ev.sender, &client).await; - } - } - }, - ); + // // removed Sept 2024, following matrix-rust-sdk/examples/emoji_verification + // client.add_event_handler( + // |ev: ToDeviceKeyVerificationStartEvent, client: Client| async move { + // debug!("ToDeviceKeyVerificationStartEvent"); + // if let Some(Verification::SasV1(sas)) = client + // .encryption() + // .get_verification(&ev.sender, ev.content.transaction_id.as_str()) + // .await + // { + // info!( + // "Starting verification with {} {}", + // &sas.other_device().user_id(), + // &sas.other_device().device_id() + // ); + // print_devices(&ev.sender, &client).await; + // sas.accept().await.unwrap(); + // } + // }, + // ); + + // // removed Sept 2024, following matrix-rust-sdk/examples/emoji_verification + // client.add_event_handler( + // |ev: ToDeviceKeyVerificationKeyEvent, client: Client| async move { + // debug!("ToDeviceKeyVerificationKeyEvent"); + // if let Some(Verification::SasV1(sas)) = client + // .encryption() + // .get_verification(&ev.sender, ev.content.transaction_id.as_str()) + // .await + // { + // tokio::spawn(sas_verification_handler(client, sas)); + // } + // }, + // ); + + // // removed Sept 2024, following matrix-rust-sdk/examples/emoji_verification + // client.add_event_handler( + // |ev: ToDeviceKeyVerificationDoneEvent, client: Client| async move { + // debug!("ToDeviceKeyVerificationDoneEvent"); + // if let Some(Verification::SasV1(sas)) = client + // .encryption() + // .get_verification(&ev.sender, ev.content.transaction_id.as_str()) + // .await + // { + // if sas.is_done() { + // print_success(&sas); + // print_devices(&ev.sender, &client).await; + // } + // } + // }, + // ); + + // // removed Sept 2024, following matrix-rust-sdk/examples/emoji_verification + // client.add_event_handler( + // |ev: OriginalSyncKeyVerificationStartEvent, client: Client| async move { + // debug!("OriginalSyncKeyVerificationStartEvent"); + // if let Some(Verification::SasV1(sas)) = client + // .encryption() + // .get_verification(&ev.sender, ev.content.relates_to.event_id.as_str()) + // .await + // { + // println!( + // "Starting verification with {} {}", + // &sas.other_device().user_id(), + // &sas.other_device().device_id() + // ); + // print_devices(&ev.sender, &client).await; + // sas.accept().await.unwrap(); + // } + // }, + // ); + + // // removed Sept 2024, following matrix-rust-sdk/examples/emoji_verification + // client.add_event_handler( + // |ev: OriginalSyncKeyVerificationKeyEvent, client: Client| async move { + // debug!("OriginalSyncKeyVerificationKeyEvent"); + // if let Some(Verification::SasV1(sas)) = client + // .encryption() + // .get_verification(&ev.sender, ev.content.relates_to.event_id.as_str()) + // .await + // { + // tokio::spawn(sas_verification_handler(client, sas)); + // } + // }, + // ); + + // // removed Sept 2024, following matrix-rust-sdk/examples/emoji_verification + // client.add_event_handler( + // |ev: OriginalSyncKeyVerificationDoneEvent, client: Client| async move { + // debug!("OriginalSyncKeyVerificationDoneEvent"); + // if let Some(Verification::SasV1(sas)) = client + // .encryption() + // .get_verification(&ev.sender, ev.content.relates_to.event_id.as_str()) + // .await + // { + // if sas.is_done() { + // print_success(&sas); + // print_devices(&ev.sender, &client).await; + // } + // } + // }, + // ); // go into event loop to sync and to execute verify protocol println!("Ready and waiting ..."); @@ -332,7 +352,7 @@ pub async fn sync_request_verification( ) -> matrix_sdk::Result<()> { client.add_event_handler( |ev: ToDeviceKeyVerificationRequestEvent, client: Client| async move { - debug!("ToDeviceKeyVerificationRequestEvent"); + debug!("ToDeviceKeyVerificationRequestEvent: entering"); let request = client .encryption() .get_verification_request(&ev.sender, &ev.content.transaction_id) @@ -340,17 +360,13 @@ pub async fn sync_request_verification( .expect("Request object wasn't created"); tokio::spawn(request_verification_handler(client, request)); - - // request - // .accept() - // .await - // .expect("Can't accept verification request"); + debug!("ToDeviceKeyVerificationRequestEvent: leaving"); }, ); client.add_event_handler( |ev: OriginalSyncRoomMessageEvent, client: Client| async move { - debug!("OriginalSyncRoomMessageEvent"); + debug!("OriginalSyncRoomMessageEvent: entering"); if let MessageType::VerificationRequest(_) = &ev.content.msgtype { let request = client .encryption() @@ -359,15 +375,16 @@ pub async fn sync_request_verification( .expect("Request object wasn't created"); tokio::spawn(request_verification_handler(client, request)); - - // request - // .accept() - // .await - // .expect("Can't accept verification request"); } + debug!("OriginalSyncRoomMessageEvent: leaving"); }, ); + client.add_event_handler(|_ev: SyncRoomMessageEvent, _client: Client| async move { + debug!("SyncRoomMessageEvent"); + }); + + // needed as of Sept 2024 client.add_event_handler( |ev: ToDeviceKeyVerificationStartEvent, client: Client| async move { debug!("ToDeviceKeyVerificationStartEvent"); @@ -376,91 +393,114 @@ pub async fn sync_request_verification( .get_verification(&ev.sender, ev.content.transaction_id.as_str()) .await { - info!( - "Starting verification with {} {}", - &sas.other_device().user_id(), - &sas.other_device().device_id() + debug!( + "ToDeviceKeyVerificationStartEvent: Verification state has Emoji verification." ); - print_devices(&ev.sender, &client).await; - sas.accept().await.unwrap(); + tokio::spawn(sas_verification_handler(client, sas)); } }, ); + // removed Sept 2024, following matrix-rust-sdk/examples/emoji_verification client.add_event_handler( - |ev: ToDeviceKeyVerificationKeyEvent, client: Client| async move { + |_ev: ToDeviceKeyVerificationReadyEvent, _client: Client| async move { + debug!("ToDeviceKeyVerificationReadyEvent"); + }, + ); + + // removed Sept 2024, following matrix-rust-sdk/examples/emoji_verification + client.add_event_handler( + |_ev: ToDeviceKeyVerificationAcceptEvent, _client: Client| async move { + debug!("ToDeviceKeyVerificationAcceptEvent"); + }, + ); + + // removed Sept 2024, following matrix-rust-sdk/examples/emoji_verification + client.add_event_handler( + |_ev: ToDeviceKeyVerificationCancelEvent, _client: Client| async move { + debug!("ToDeviceKeyVerificationCancelEvent"); + }, + ); + + // removed Sept 2024, following matrix-rust-sdk/examples/emoji_verification + client.add_event_handler( + |_ev: ToDeviceKeyVerificationKeyEvent, _client: Client| async move { debug!("ToDeviceKeyVerificationKeyEvent"); - if let Some(Verification::SasV1(sas)) = client - .encryption() - .get_verification(&ev.sender, ev.content.transaction_id.as_str()) - .await - { - tokio::spawn(sas_verification_handler(client, sas)); - } + // if let Some(Verification::SasV1(sas)) = client + // .encryption() + // .get_verification(&ev.sender, ev.content.transaction_id.as_str()) + // .await + // { + // tokio::spawn(sas_verification_handler(client, sas)); + // } }, ); + // removed Sept 2024, following matrix-rust-sdk/examples/emoji_verification client.add_event_handler( - |ev: ToDeviceKeyVerificationDoneEvent, client: Client| async move { + |_ev: ToDeviceKeyVerificationDoneEvent, _client: Client| async move { debug!("ToDeviceKeyVerificationDoneEvent"); - if let Some(Verification::SasV1(sas)) = client - .encryption() - .get_verification(&ev.sender, ev.content.transaction_id.as_str()) - .await - { - if sas.is_done() { - print_result(&sas); - print_devices(&ev.sender, &client).await; - } - } + // if let Some(Verification::SasV1(sas)) = client + // .encryption() + // .get_verification(&ev.sender, ev.content.transaction_id.as_str()) + // .await + // { + // if sas.is_done() { + // print_success(&sas); + // print_devices(&ev.sender, &client).await; + // } + // } }, ); + // removed Sept 2024, following matrix-rust-sdk/examples/emoji_verification client.add_event_handler( - |ev: OriginalSyncKeyVerificationStartEvent, client: Client| async move { + |_ev: OriginalSyncKeyVerificationStartEvent, _client: Client| async move { debug!("OriginalSyncKeyVerificationStartEvent"); - if let Some(Verification::SasV1(sas)) = client - .encryption() - .get_verification(&ev.sender, ev.content.relates_to.event_id.as_str()) - .await - { - println!( - "Starting verification with {} {}", - &sas.other_device().user_id(), - &sas.other_device().device_id() - ); - print_devices(&ev.sender, &client).await; - sas.accept().await.unwrap(); - } + // if let Some(Verification::SasV1(sas)) = client + // .encryption() + // .get_verification(&ev.sender, ev.content.relates_to.event_id.as_str()) + // .await + // { + // println!( + // "Starting verification with {} {}", + // &sas.other_device().user_id(), + // &sas.other_device().device_id() + // ); + // print_devices(&ev.sender, &client).await; + // sas.accept().await.unwrap(); + // } }, ); + // removed Sept 2024, following matrix-rust-sdk/examples/emoji_verification client.add_event_handler( - |ev: OriginalSyncKeyVerificationKeyEvent, client: Client| async move { + |_ev: OriginalSyncKeyVerificationKeyEvent, _client: Client| async move { debug!("OriginalSyncKeyVerificationKeyEvent"); - if let Some(Verification::SasV1(sas)) = client - .encryption() - .get_verification(&ev.sender, ev.content.relates_to.event_id.as_str()) - .await - { - tokio::spawn(sas_verification_handler(client, sas)); - } + // if let Some(Verification::SasV1(sas)) = client + // .encryption() + // .get_verification(&ev.sender, ev.content.relates_to.event_id.as_str()) + // .await + // { + // tokio::spawn(sas_verification_handler(client, sas)); + // } }, ); + // removed Sept 2024, following matrix-rust-sdk/examples/emoji_verification client.add_event_handler( - |ev: OriginalSyncKeyVerificationDoneEvent, client: Client| async move { + |_ev: OriginalSyncKeyVerificationDoneEvent, _client: Client| async move { debug!("OriginalSyncKeyVerificationDoneEvent"); - if let Some(Verification::SasV1(sas)) = client - .encryption() - .get_verification(&ev.sender, ev.content.relates_to.event_id.as_str()) - .await - { - if sas.is_done() { - print_result(&sas); - print_devices(&ev.sender, &client).await; - } - } + // if let Some(Verification::SasV1(sas)) = client + // .encryption() + // .get_verification(&ev.sender, ev.content.relates_to.event_id.as_str()) + // .await + // { + // if sas.is_done() { + // print_success(&sas); + // print_devices(&ev.sender, &client).await; + // } + // } }, ); @@ -470,7 +510,8 @@ pub async fn sync_request_verification( println!("verification with them. Best to have the other Matrix client ready and "); println!("waiting before you start {}.", get_prog_without_ext()); println!( - "\n ### THIS IS PARTIALLY BROKEN. DOES NOT SEEM TO WORK WITH ELEMENT ANDROID APP. ###\n" + "\n ### THIS IS PARTIALLY BROKEN. DOES NOT SEEM TO WORK WITH ELEMENT ANDROID APP. ###\ + \n ### BUT IT DOES WORK WITH ELEMENT WEB APP IN BROWSER. ###\n" ); println!( "Sending request to user's {:?} device {:?}.", @@ -483,14 +524,26 @@ pub async fn sync_request_verification( match encryption.get_device(&userid, &deviceid).await { Ok(Some(device)) => { // -> Result, CryptoStoreError> - debug!("already verified? {:?}", device.is_verified()); + debug!( + "Is device {} already verified? {:?}", + device.device_id(), + device.is_verified() + ); // if !device.is_verified() { - let verification = device.request_verification().await?; + // We don't want to support showing a QR code, we only support SAS + // verification + let methods = vec![VerificationMethod::SasV1]; + let verification = device.request_verification_with_methods(methods).await?; + // let verification = device.request_verification().await?; debug!( "verification: we_started is {:?}", verification.we_started() ); + debug!( + "verification with device {} was requested.", + device.device_id() + ); // } } Ok(None) => error!("Error: device not found: {:?}", deviceid), diff --git a/src/main.rs b/src/main.rs index 7c0e955..d111050 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,6 +54,7 @@ use std::path::{Path, PathBuf}; use std::str::FromStr; use thiserror::Error; use tracing::{debug, enabled, error, info, warn, Level}; +use tracing_subscriber::EnvFilter; use update_informer::{registry, Check}; use url::Url; @@ -784,6 +785,10 @@ pub struct Args { /// If not used, then the default /// log level set with environment variable 'RUST_LOG' will be used. /// See also '--debug' and '--verbose'. + /// An example use of RUST_LOG is to use neither --log-level nor --debug, + /// and to set RUST_LOG="error,matrix_commander_rs=debug" which turns + /// off debugging on all lower level modules and turns debugging on only + /// for matrix-commander-rs. // Possible values are // '{trace}', '{debug}', '{info}', '{warn}', and '{error}'. #[arg(long, value_enum, default_value_t = LogLevel::default(), ignore_case = true, )] @@ -885,6 +890,13 @@ pub struct Args { /// By default, no /// verification is performed. /// Verification is currently offered via Manual-Device, Manual-User, Emoji and Emoji-Req. + /// Do verification in this order: 1) bottstrap first with -bootstrap, + /// 2) perform both manual verifications, and 3) perform emoji verification. + /// --verify emoji has been tested against Element in Firefox browser and against + /// Element app on Android phone. Both has been working successfully in Sept 2024. + /// In Element web page it was important NOT to click the device in the device list, + /// but to click the underscored link "Verify" just above the device list. + /// In the Element on cell phone case, accept the emojis first on the cell phone. /// Manual verification is simpler but does less. /// Try: '--bootstrap --password mypassword --verify manual-device' or /// '--bootstrap --password mypassword --verify manual-user'. @@ -893,10 +905,11 @@ pub struct Args { /// and /// https://docs.rs/matrix-sdk/0.7/matrix_sdk/encryption/identities/struct.UserIdentity.html#method.verify /// for more info on Manual verification. - /// manual-device can only verify its own devices, notother users' devices. - /// manual-user can trust other users. So, with verify-user also use the --user option - /// to specify one or multiple users. - /// One can first do 'manual-device' and 'manual-user' verification and + /// manual-device can only verify its own devices, not other users' devices. + /// manual-user can trust other users. So, with manual-user also use the --user option + /// to specify one or multiple users. With manual-user first trust yourself, by + /// setting --user to yourself, or omitting -user in which case it will default to itself. + /// One should first do 'manual-device' and 'manual-user' verification and /// then 'emoji' or 'emoji-req' verification. /// Both 'emoji' as well as 'emoji-req' perform emoji verification. /// With 'emoji' we send a request to some other client to request verification from their device. @@ -936,7 +949,8 @@ pub struct Args { /// a device with --device to specify to which device you want to send the /// verification request. On the other device you get a pop up and you /// must accept the verification request. - /// 'emoji-req' seems to have problems, e.g. 'emoji-req' does not seem to + /// 'emoji-req' currently seems to have problems, while it does work with Element + /// web page in browser, 'emoji-req' does not seem to /// work with Element phone app. #[arg(long, value_enum, value_name = "VERIFICATION_METHOD", @@ -3315,20 +3329,19 @@ async fn main() -> Result<(), Error> { // -d overwrites --log-level ap.log_level = LogLevel::Debug } + // .with_env_filter("matrix_commander_rs=debug") // Todo : add 2nd --log-level arg for lower-level modules + // RUST_LOG="error,matrix_commander_rs=debug" .. This will only show matrix-comander-rs debug info, and erors for all other modules if ap.log_level.is_none() { - ap.log_level = LogLevel::from_str(&env_org_rust_log, true).unwrap_or(LogLevel::Error); - } - unsafe { - // overwrite environment variable, important because it might have been empty/unset - env::set_var("RUST_LOG", ap.log_level.to_string()); + tracing_subscriber::fmt() + .with_writer(io::stderr) + .with_env_filter(EnvFilter::from_default_env()) // support the standard RUST_LOG env variable + .init(); + } else { + tracing_subscriber::fmt() + .with_writer(io::stderr) + .with_max_level(Level::from_str(&ap.log_level.to_string()).unwrap_or(Level::ERROR)) + .init(); } - - // set log level e.g. via RUST_LOG=DEBUG cargo run, use newly set venv var value - // Send *all* output from Debug to Error to stderr - tracing_subscriber::fmt() - .with_writer(io::stderr) - .with_max_level(Level::from_str(&ap.log_level.to_string()).unwrap_or(Level::ERROR)) - .init(); debug!("Original RUST_LOG env var is {}", env_org_rust_log); debug!( "Final RUST_LOG env var is {}", @@ -3336,9 +3349,15 @@ async fn main() -> Result<(), Error> { ); debug!("Final log_level option is {:?}", ap.log_level); if enabled!(Level::TRACE) { - debug!("Log level is set to TRACE."); + debug!( + "Log level of module {} is set to TRACE.", + get_prog_without_ext() + ); } else if enabled!(Level::DEBUG) { - debug!("Log level is set to DEBUG."); + debug!( + "Log level of module {} is set to DEBUG.", + get_prog_without_ext() + ); } debug!("Version is {}", get_version()); debug!("Package name is {}", get_pkg_name()); diff --git a/src/mclient.rs b/src/mclient.rs index 12bfb41..a04b0bc 100644 --- a/src/mclient.rs +++ b/src/mclient.rs @@ -565,7 +565,10 @@ pub(crate) async fn verify(client: &Client, ap: &Args) -> Result<(), Error> { debug!("Client logged in: {}", client.logged_in()); debug!("Client user id: {}", userid); debug!("Client device id: {}", deviceid); - debug!("Client access token used: {:?}", client.access_token()); + debug!( + "Client access token used: {:?}", + obfuscate(&client.access_token().unwrap(), 4) + ); let css = client.encryption().cross_signing_status().await; debug!("Client cross signing status {:?}", css);