Commit 3e287d2a authored by Philipp Hörist's avatar Philipp Hörist
Browse files

[omemo] Add encrypt_file method

The HTTPUploadPlugin calls that if encryption is enabled
parent c4f2c658
......@@ -19,6 +19,7 @@
import logging
import time
import os
from base64 import b64encode
from axolotl.ecc.djbec import DjbECPublicKey
......@@ -216,6 +217,14 @@ class OmemoState:
log.debug("Decrypted Message => " + result)
return result
def encrypt_file(self, data):
key = os.urandom(32)
iv = os.urandom(16)
payload, tag = encrypt(key, iv, data)
encrypted_data = payload + tag
return (encrypted_data, key, iv)
def create_msg(self, from_jid, jid, plaintext):
key = get_random_bytes(16)
iv = get_random_bytes(16)
......@@ -25,7 +25,10 @@ import os
import sqlite3
import shutil
import nbxmpp
import binascii
import threading
from gi.repository import GLib
from nbxmpp.simplexml import Node
from nbxmpp import NS_ADDRESS
......@@ -201,6 +204,23 @@ class OmemoPlugin(GajimPlugin):
def file_decryption(self, url, kind, instance, window):
FileDecryption(self).hyperlink_handler(url, kind, instance, window)
def encrypt_file(self, file, account, callback):
thread = threading.Thread(target=self._encrypt_file_thread,
args=(file, account, callback))
thread.daemon = True
def _encrypt_file_thread(self, file, account, callback):
state = self.get_omemo_state(account)
encrypted_data, key, iv = state.encrypt_file(file.get_data(full=True))
file.encrypted = True
file.size = len(encrypted_data)
file.user_data = binascii.hexlify(iv + key).decode('utf-8') = encrypted_data
if file.event.isSet():
GLib.idle_add(callback, file)
def signed_in(self, event):
""" Method called on SignIn
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment