From 6065fa67d0910a051f8f4b09046e1924dacb71a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Thu, 8 Sep 2016 00:55:30 +0200 Subject: [PATCH] Add encrypted file upload for windows --- httpupload/httpupload.py | 32 ++++++++++++++++++++------------ httpupload/manifest.ini | 2 +- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/httpupload/httpupload.py b/httpupload/httpupload.py index a997be4..0c3446f 100644 --- a/httpupload/httpupload.py +++ b/httpupload/httpupload.py @@ -38,19 +38,21 @@ from .thumbnail import thumbnail log = logging.getLogger('gajim.plugin_system.httpupload') -if os.name != 'nt': - try: +try: + if os.name == 'nt': + from cryptography.hazmat.backends.openssl import backend + else: from cryptography.hazmat.backends import default_backend - from cryptography.hazmat.primitives.ciphers import Cipher - from cryptography.hazmat.primitives.ciphers import algorithms - from cryptography.hazmat.primitives.ciphers.modes import GCM - encryption_available = True - except Exception as e: - log.debug(e) - encryption_available = False -else: + from cryptography.hazmat.primitives.ciphers import Cipher + from cryptography.hazmat.primitives.ciphers import algorithms + from cryptography.hazmat.primitives.ciphers.modes import GCM + encryption_available = True +except Exception as e: + DEP_MSG = 'For encryption of files, ' \ + 'please install python-cryptography!' + log.debug('Cryptography Import Error: ' + str(e)) + log.info('Decryption/Encryption disabled due to errors') encryption_available = False - log.info('Cryptography not available on Windows for now') # XEP-0363 (http://xmpp.org/extensions/xep-0363.html) NS_HTTPUPLOAD = 'urn:xmpp:http:upload' @@ -65,6 +67,8 @@ class HttpuploadPlugin(GajimPlugin): @log_calls('HttpuploadPlugin') def init(self): + if not encryption_available: + self.available_text = DEP_MSG self.config_dialog = None # HttpuploadPluginConfigDialog(self) self.controls = [] self.events_handlers = {} @@ -466,10 +470,14 @@ class StreamFileWithProgress: self.encrypted_upload = encrypted_upload self.backing.seek(0, os.SEEK_END) if self.encrypted_upload: + if os.name == 'nt': + self.backend = backend + else: + self.backend = default_backend() self.encryptor = Cipher( algorithms.AES(key), GCM(iv), - backend=default_backend()).encryptor() + backend=self.backend).encryptor() self._total = self.backing.tell() + TAGSIZE else: self._total = self.backing.tell() diff --git a/httpupload/manifest.ini b/httpupload/manifest.ini index 2920829..0d2e319 100644 --- a/httpupload/manifest.ini +++ b/httpupload/manifest.ini @@ -1,7 +1,7 @@ [info] name: HttpUpload short_name: httpupload -version: 0.5.1 +version: 0.5.2 description: This plugin is designed to send a file to a contact or muc by using httpupload.
Your server must support XEP-0363: HTTP Upload.
Conversations supported this.