xmtp / libxmtp

LibXMTP is a shared library encapsulating the core functionality of the XMTP messaging protocol, such as cryptography, networking, and language bindings.
MIT License
42 stars 18 forks source link

Bug: InvalidMac on self-fanout #199

Closed jazzz closed 11 months ago

jazzz commented 1 year ago

Describe the bug

$ ./xli.sh --db a2.db3 list-conversations                                       
    Finished dev [unoptimized + debuginfo] target(s) in 0.26s
     Running `/Users/jazz/dev/libxmtp/target/debug/cli-client --db a1.db3 list-conversations`
[2023-08-16T02:09:59Z INFO  cli_client] Starting CLI Client....
[2023-08-16T02:09:59Z INFO  cli_client] List Conversations
[2023-08-16T02:09:59Z INFO  cli_client] Using persistent storage: a1.db3 
[2023-08-16T02:09:59Z WARN  xmtp::conversations] 0
[2023-08-16T02:10:00Z INFO  xmtp::conversations] Messages Downloaded:1
[2023-08-16T02:10:00Z ERROR xmtp::conversations] Error processing msg: Session(Decrypt(InvalidMAC(MacError)))
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: MessageStore(Unknown("Session: decrypt error"))', examples/cli/cli-client.rs:163:33
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected behavior

Messages sent from A1 need to be replicated to A2

Steps to reproduce the bug

A1:Register A2:Register B1:Register A1: Send B A2: list-conversations -> InvalidMAC

jazzz commented 1 year ago

Looks like the two peer accounts are deriving two different sessions for each other.

To fix this the contact bundle will need to be included with the PreKey messages to ensure they same keypairs are being used.

Beyond this we'll need a strategy for when two clients message eachother at the same time. This will lead to the same issue, where each peer believes it started the session.

A1:

image

A2:

image