4
31
Fork
You've already forked simplematrixbotlib
21

Does encryption work at all? #100

Open
opened 2025年03月13日 10:45:53 +01:00 by zzzz · 5 comments

Describe the bug

That the library does not read chats in encrypted rooms.

To Reproduce
Steps to reproduce the behavior:

  1. Enable encryption
  2. Connect to the server
  3. Invite the chat bot user to an encrypted and unencrypted room
  4. Send a message in the unencrypted room
  5. message gets handled by the bot.
  6. Send a message in the encrypted room.
  7. Message does not get handled by the bot.

Expected behavior

That there is some indication that either encryption is not enabled anyway, if the library get the value to enable encryption.
Or that there is a error decrypting messages in encrypted rooms.

(It can send unencrypted messages in encrypted rooms. It can also say it joined encrypted rooms)

Also if the following is true, it might not connect to the homeserver at all.

config.ignore_unverified_devices = True

Desktop (please complete the following information):
Ubuntu
Python 3.12.3

Additional context

Its possible i did something wrong, to connect to the homeserver.
But i just followed the examples. Did install the matrix-nio[e2e]==0.25.2 library.
And non-encrypted chat rooms work.

Is there any matrix-nio based python library that handles encryption?

Since i did see the following issues.
#93
https://github.com/matrix-nio/matrix-nio/issues/430

Is there any python based library that connects to matrix that handles encryption?

I did find a node library where encryption just worked to make a bot with.
https://github.com/turt2live/matrix-bot-sdk
Which seems to be using a rust library for the encryption part.

Bindings for python with that rust library can get generated. But i haven't looked into it more than generating those bindings.

https://github.com/matrix-org/matrix-rust-sdk

sudo apt-get install libsqlite3-dev libssl-dev
cargo build --release
cd uniffi-bindgen
cargo run --features=uniffi/cli --bin uniffi-bindgen generate --library ../target/release/libmatrix_sdk_ffi.so --language python --out-dir out
**Describe the bug** That the library does not read chats in encrypted rooms. **To Reproduce** Steps to reproduce the behavior: 1. Enable encryption 2. Connect to the server 3. Invite the chat bot user to an encrypted and unencrypted room 4. Send a message in the unencrypted room 5. message gets handled by the bot. 6. Send a message in the encrypted room. 7. Message does **not** get handled by the bot. **Expected behavior** That there is some indication that either encryption is not enabled anyway, if the library get the value to enable encryption. Or that there is a error decrypting messages in encrypted rooms. (It can send unencrypted messages in encrypted rooms. It can also say it joined encrypted rooms) Also if the following is true, it might not connect to the homeserver at all. ``` config.ignore_unverified_devices = True ``` **Desktop (please complete the following information):** Ubuntu Python 3.12.3 **Additional context** Its possible i did something wrong, to connect to the homeserver. But i just followed the examples. Did install the matrix-nio[e2e]==0.25.2 library. And non-encrypted chat rooms work. Is there any matrix-nio based python library that handles encryption? Since i did see the following issues. https://codeberg.org/imbev/simplematrixbotlib/issues/93 https://github.com/matrix-nio/matrix-nio/issues/430 Is there any python based library that connects to matrix that handles encryption? I did find a node library where encryption just worked to make a bot with. https://github.com/turt2live/matrix-bot-sdk Which seems to be using a rust library for the encryption part. Bindings for python with that rust library can get generated. But i haven't looked into it more than generating those bindings. https://github.com/matrix-org/matrix-rust-sdk ``` sudo apt-get install libsqlite3-dev libssl-dev cargo build --release cd uniffi-bindgen cargo run --features=uniffi/cli --bin uniffi-bindgen generate --library ../target/release/libmatrix_sdk_ffi.so --language python --out-dir out ```
Owner
Copy link

Encryption in simplematrixbotlib is still broken, blocked by the linked matrix-nio issues.

Is there any python based library that connects to matrix that handles encryption?

Not as far as I am aware.

The design of simplematrixbotlib and matrix-nio means that fixes to encryption must be implemented upstream in matrix-nio.

Encryption in simplematrixbotlib is still broken, blocked by the linked matrix-nio issues. > Is there any python based library that connects to matrix that handles encryption? Not as far as I am aware. The design of simplematrixbotlib and matrix-nio means that fixes to encryption must be implemented upstream in matrix-nio.

It appears you can get verification by combining matrix-commander-rs in console and Ciny web client -> you get your credentials.json file and store folder that seems like working fine (verified matrix-commander --listen).

My problem though is that my code still doesn't work and I can't really troubleshoot it, as there is no way to see errors - could you please, help me?

I'm looking for the code that I can enable that will:

  • catch and show every message printed in the chat
  • catch and show every error that the simplematrixbot faces?

I'm trying to make my old code works, but can't figure out what is wrong - I can't see no errors / warnings / whatsoever after 'Connected to' message.

It appears you can get verification by combining matrix-commander-rs in console and Ciny web client -> you get your credentials.json file and store folder that seems like working fine (verified `matrix-commander --listen`). My problem though is that my code still doesn't work and I can't really troubleshoot it, as there is no way to see errors - could you please, help me? I'm looking for the code that I can enable that will: - catch and show every message printed in the chat - catch and show every error that the simplematrixbot faces? I'm trying to make my old code works, but can't figure out what is wrong - I can't see no errors / warnings / whatsoever after 'Connected to' message.

Apologies, here what I've tried to catch every event:

@bot.listener.on_message_event
async def everything(room, message):
 match = botlib.MessageMatch(room, message, bot)
 if match.is_not_from_this_bot(): print(message)

But the output maintain silence...

For the errors handling - I believe I didn't find anything to catch / register / etc.

Apologies, here what I've tried to catch every event: ```python @bot.listener.on_message_event async def everything(room, message): match = botlib.MessageMatch(room, message, bot) if match.is_not_from_this_bot(): print(message) ``` But the output maintain silence... For the errors handling - I believe I didn't find anything to catch / register / etc.
Author
Copy link

As an update.

I did find a different python library, that does handle encryption for matrix.

https://matrix.org/ecosystem/sdks/
https://github.com/mautrix/python

And a library that uses mautrix, to write plugins/bots with. Where there are are already bots written for it.
https://github.com/maubot/maubot

maubot is simpler. If you want to use mautrix, because that fits your requirements better, it might still be a good idea to get encryption working with maubot first.
(You can also open a extra unencrpyted chat room to test with that.)

You might need to use a new access token + device id combo for a bot with encryption.

As an update. I did find a different python library, that does handle encryption for matrix. https://matrix.org/ecosystem/sdks/ https://github.com/mautrix/python And a library that uses mautrix, to write plugins/bots with. Where there are are already bots written for it. https://github.com/maubot/maubot maubot is simpler. If you want to use mautrix, because that fits your requirements better, it might still be a good idea to get encryption working with maubot first. (You can also open a extra unencrpyted chat room to test with that.) You might need to use a new access token + device id combo for a bot with encryption.

@zzzz wrote in #100 (comment):

As an update.

I did find a different python library, that does handle encryption for matrix.

https://matrix.org/ecosystem/sdks/ https://github.com/mautrix/python

And a library that uses mautrix, to write plugins/bots with. Where there are are already bots written for it. https://github.com/maubot/maubot

maubot is simpler. If you want to use mautrix, because that fits your requirements better, it might still be a good idea to get encryption working with maubot first. (You can also open a extra unencrpyted chat room to test with that.)

You might need to use a new access token + device id combo for a bot with encryption.

Thank you. Last time I was implementing a bot (august 2023) encryption didn't work with maubot, at all - let me see if things changed this time!

@zzzz wrote in https://codeberg.org/imbev/simplematrixbotlib/issues/100#issuecomment-3680282: > As an update. > > I did find a different python library, that does handle encryption for matrix. > > https://matrix.org/ecosystem/sdks/ https://github.com/mautrix/python > > And a library that uses mautrix, to write plugins/bots with. Where there are are already bots written for it. https://github.com/maubot/maubot > > maubot is simpler. If you want to use mautrix, because that fits your requirements better, it might still be a good idea to get encryption working with maubot first. (You can also open a extra unencrpyted chat room to test with that.) > > You might need to use a new access token + device id combo for a bot with encryption. Thank you. Last time I was implementing a bot (august 2023) encryption didn't work with maubot, at all - let me see if things changed this time!
Sign in to join this conversation.
No Branch/Tag specified
master
v3
send_reaction
v2.13.1
v2.13.0
v2.12.2
v2.12.1
v2.12.0
v2.11.0
v2.10.3
v2.10.2
v2.10.1
v2.10.0
v2.9.1
v2.9.0
v2.7.4
v2.7.3
v2.7.2
v2.7.0
v2.6.4
v2.6.3
v2.6.2
v2.6.1
v2.6.0
v1.6.0
v2.5.1
v2.5.0
v2.4.1
v2.4.0
v2.3.0
v2.2.0
v2.1.0
v2.0.0
v1.6.1
v1.5.3
v1.5.2
v1.5.1
v1.5.0
v1.4.0
v1.3.3
v1.3.1
v1.3.0
v1.2.0
v1.3.2
v1.0.1
v1.0.0
v1.1.0
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
imbev/simplematrixbotlib#100
Reference in a new issue
imbev/simplematrixbotlib
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?