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

[omemo] Make encrypt_file() method better available

Now we dont need to supply the account
parent 6974e704
......@@ -45,6 +45,7 @@ try:
from cryptography.hazmat.primitives.ciphers import algorithms
from cryptography.hazmat.primitives.ciphers.modes import GCM
from cryptography.hazmat.backends import default_backend
from omemo.omemo.aes_gcm_native import aes_encrypt
except ImportError:
ERROR = True
......@@ -59,6 +60,15 @@ except Exception:
def encrypt_file(data):
key = os.urandom(32)
iv = os.urandom(16)
payload, tag = aes_encrypt(key, iv, data)
encrypted_data = payload + tag
return (encrypted_data, key, iv)
class File:
def __init__(self, url):
self.url, self.fragment = urldefrag(url)
......@@ -217,14 +217,6 @@ 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)
......@@ -45,7 +45,7 @@ ERROR_MSG = ''
log = logging.getLogger('gajim.plugin_system.omemo')
from omemo.file_decryption import FileDecryption
from omemo import file_crypto
except Exception as error:
......@@ -188,17 +188,19 @@ class OmemoPlugin(GajimPlugin):
self.connections[].encrypt_message(conn, obj, callback)
def _file_decryption(self, url, kind, instance, window):
FileDecryption(self).hyperlink_handler(url, kind, instance, window)
url, kind, instance, window)
def encrypt_file(self, file, account, callback):
def encrypt_file(self, file, callback):
thread = threading.Thread(target=self._encrypt_file_thread,
args=(file, account, callback))
args=(file, callback))
thread.daemon = True
def _encrypt_file_thread(self, file, account, callback):
omemo = self.get_omemo(account)
encrypted_data, key, iv = omemo.encrypt_file(file.get_data(full=True))
def _encrypt_file_thread(file, callback):
encrypted_data, key, iv = file_decryption.encrypt_file(
file.encrypted = True
file.size = len(encrypted_data)
file.user_data = binascii.hexlify(iv + key).decode('utf-8')
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