New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attachments in encrypted rooms are not automatically decrypted #1991
Comments
After an intense search in other projects, I have found the solution to my problem. When a file is uploaded to a private room, the content of that file is encrypted. Once downloaded, it is necessary to decrypt it using external libraries. Here I show an example code to decrypt files from Matrix: @match_event(File)
async def file_skill(self, event):
try:
data_in_bytes = await event.get_file_bytes()
content = event.raw_event['content']
if ('file' in content):
# The file is encoded
file_data = event.raw_event['content']['file']
data_in_bytes = crypto.attachments.decrypt_attachment(
data_in_bytes,
file_data["key"]["k"],
file_data["hashes"]["sha256"],
file_data["iv"],
)
return data_in_bytes.decode('utf-8')
except BaseException as e:
logging.error(e)
return None In my opinion, this information should be added to the connectors documentation. If anyone has any comments, fell free to post it. Otherwise, this issue can be closed. |
Thanks for figuring this one out and providing the code to decrypt the attachment. We should definitely add this to the connector so it's transparent to the skills. |
Hi there, was wondering if this has been done and if not if I could be assigned to it? I am a first time contributor so I might ask a few questions about it if I get stuck. Thanks and looking forward to hearing back! |
@Cadair just in case I needed to mention you :) |
Description
When I try to read a file uploaded to a private room, the byte representation appears encrypted. However, when I run it on a public room, I don't have that problem and I can read the file without problems.
Steps to Reproduce
Upload a txt file with any content (in this case, only one line with the text 'hola') to a private room. A skill with match_event(File) decorator will receive the event. When the method "get_file_bytes()" is called, it returns the content encrypted
Expected Functionality
The method get_file_bytes() should return the bytes representation of the file.
This method should return the data b'hola'
Experienced Functionality
The method get_file_bytes() returns the bytes representation of the file encrypted.
This method returns b'\xc6p\xa09'
Versions
Configuration File
Please include your version of the configuration file below.
Example Code
The text was updated successfully, but these errors were encountered: