[httpupload] Refactor encryption_activated()
This commit is contained in:
@@ -43,13 +43,13 @@ try:
|
|||||||
from cryptography.hazmat.primitives.ciphers import Cipher
|
from cryptography.hazmat.primitives.ciphers import Cipher
|
||||||
from cryptography.hazmat.primitives.ciphers import algorithms
|
from cryptography.hazmat.primitives.ciphers import algorithms
|
||||||
from cryptography.hazmat.primitives.ciphers.modes import GCM
|
from cryptography.hazmat.primitives.ciphers.modes import GCM
|
||||||
encryption_available = True
|
ENCRYPTION_AVAILABLE = True
|
||||||
except Exception as e:
|
except Exception as exc:
|
||||||
DEP_MSG = 'For encryption of files, ' \
|
DEP_MSG = 'For encryption of files, ' \
|
||||||
'please install python-cryptography!'
|
'please install python-cryptography!'
|
||||||
log.debug('Cryptography Import Error: ' + str(e))
|
log.debug('Cryptography Import Error: %s', exc)
|
||||||
log.info('Decryption/Encryption disabled due to errors')
|
log.info('Decryption/Encryption disabled due to errors')
|
||||||
encryption_available = False
|
ENCRYPTION_AVAILABLE = False
|
||||||
|
|
||||||
# XEP-0363 (http://xmpp.org/extensions/xep-0363.html)
|
# XEP-0363 (http://xmpp.org/extensions/xep-0363.html)
|
||||||
IQ_CALLBACK = {}
|
IQ_CALLBACK = {}
|
||||||
@@ -59,7 +59,7 @@ TAGSIZE = 16
|
|||||||
|
|
||||||
class HttpuploadPlugin(GajimPlugin):
|
class HttpuploadPlugin(GajimPlugin):
|
||||||
def init(self):
|
def init(self):
|
||||||
if not encryption_available:
|
if not ENCRYPTION_AVAILABLE:
|
||||||
self.available_text = DEP_MSG
|
self.available_text = DEP_MSG
|
||||||
self.config_dialog = None # HttpuploadPluginConfigDialog(self)
|
self.config_dialog = None # HttpuploadPluginConfigDialog(self)
|
||||||
self.events_handlers = {}
|
self.events_handlers = {}
|
||||||
@@ -116,13 +116,14 @@ class HttpuploadPlugin(GajimPlugin):
|
|||||||
try:
|
try:
|
||||||
return self.gui_interfaces[account]
|
return self.gui_interfaces[account]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.gui_interfaces[account] = Base(self)
|
self.gui_interfaces[account] = Base(self, account)
|
||||||
return self.gui_interfaces[account]
|
return self.gui_interfaces[account]
|
||||||
|
|
||||||
|
|
||||||
class Base(object):
|
class Base(object):
|
||||||
def __init__(self, plugin):
|
def __init__(self, plugin, account):
|
||||||
self.plugin = plugin
|
self.plugin = plugin
|
||||||
|
self.account = account
|
||||||
self.encrypted_upload = False
|
self.encrypted_upload = False
|
||||||
self.enabled = False
|
self.enabled = False
|
||||||
self.component = None
|
self.component = None
|
||||||
@@ -164,40 +165,29 @@ class Base(object):
|
|||||||
for jid in self.controls:
|
for jid in self.controls:
|
||||||
self.set_button_state(state, self.controls[jid])
|
self.set_button_state(state, self.controls[jid])
|
||||||
|
|
||||||
def encryption_activated(self):
|
def encryption_activated(self, jid):
|
||||||
if not encryption_available:
|
if not ENCRYPTION_AVAILABLE:
|
||||||
return False
|
return False
|
||||||
jid = self.chat_control.contact.jid
|
|
||||||
account = self.chat_control.account
|
|
||||||
for plugin in gajim.plugin_manager.active_plugins:
|
for plugin in gajim.plugin_manager.active_plugins:
|
||||||
if type(plugin).__name__ == 'OmemoPlugin':
|
if type(plugin).__name__ == 'OmemoPlugin':
|
||||||
omemo = plugin
|
state = plugin.get_omemo_state(self.account)
|
||||||
break
|
encryption = state.encryption.is_active(jid)
|
||||||
if omemo:
|
log.info('Encryption is: %s', encryption)
|
||||||
state = omemo.get_omemo_state(account)
|
return encryption
|
||||||
log.info('Encryption is: ' +
|
log.info('OMEMO not found, encryption disabled')
|
||||||
str(state.encryption.is_active(jid)))
|
|
||||||
return state.encryption.is_active(jid)
|
|
||||||
log.info('Encryption is: False / OMEMO not found')
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def on_file_dialog_ok(self, widget, jid, chat_control):
|
def on_file_dialog_ok(self, widget, jid, chat_control):
|
||||||
path_to_file = widget.get_filename()
|
path_to_file = widget.get_filename()
|
||||||
widget.destroy()
|
widget.destroy()
|
||||||
|
|
||||||
try:
|
|
||||||
self.encrypted_upload = self.encryption_activated()
|
|
||||||
except Exception as e:
|
|
||||||
log.debug(e)
|
|
||||||
self.encrypted_upload = False
|
|
||||||
|
|
||||||
if not path_to_file or not os.path.exists(path_to_file):
|
if not path_to_file or not os.path.exists(path_to_file):
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.encrypted_upload:
|
encrypted = self.encryption_activated(jid)
|
||||||
filesize = os.path.getsize(path_to_file) + TAGSIZE # in bytes
|
filesize = os.path.getsize(path_to_file)
|
||||||
else:
|
if encrypted:
|
||||||
filesize = os.path.getsize(path_to_file)
|
filesize += TAGSIZE
|
||||||
|
|
||||||
invalid_file = False
|
invalid_file = False
|
||||||
if os.path.isfile(path_to_file):
|
if os.path.isfile(path_to_file):
|
||||||
|
|||||||
Reference in New Issue
Block a user