From b224467cffd61ecfea8f0ed2f319e1cf60083576 Mon Sep 17 00:00:00 2001 From: Kjell Braden <afflux.gajim@pentabarf.de> Date: Tue, 20 Mar 2012 18:55:41 +0100 Subject: [PATCH] merge gotr plugin with upstream repo --- gotr/manifest.ini | 2 +- gotr/otrmodule.py | 28 +++++++++++++++------------- gotr/ui.py | 8 +++++--- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/gotr/manifest.ini b/gotr/manifest.ini index 64246c54..31d474ae 100644 --- a/gotr/manifest.ini +++ b/gotr/manifest.ini @@ -1,7 +1,7 @@ [info] name: Off-The-Record Encryption short_name: gotr -version: 1.2 +version: 1.4 description: See http://www.cypherpunks.ca/otr/ authors: Kjell Braden <afflux.gajim@pentabarf.de> homepage: http://gajim-otr.pentabarf.de diff --git a/gotr/otrmodule.py b/gotr/otrmodule.py index 9823631e..21711c88 100644 --- a/gotr/otrmodule.py +++ b/gotr/otrmodule.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- ## otrmodule.py ## -## Copyright (C) 2008-2010 Kjell Braden <fnord@pentabarf.de> +## Copyright 2008-2012 Kjell Braden <afflux@pentabarf.de> ## ## This file is part of Gajim. ## @@ -29,7 +29,7 @@ Off-The-Record encryption plugin. :license: GPL ''' -MINVERSION = (1,0,0,'beta3') +MINVERSION = (1,0,0,'beta4') IGNORE = True PASS = False @@ -72,6 +72,8 @@ import pickle HAS_POTR = True try: import potr + if not hasattr(potr, 'VERSION') or potr.VERSION < MINVERSION: + raise ImportError('old / unsupported python-otr version') except ImportError: HAS_POTR = False @@ -152,7 +154,7 @@ class GajimOtrAccount(potr.context.Account): def dropPrivkey(self): try: - os.remove(self.keyFilePath + '.key2') + os.remove(self.keyFilePath + '.key3') except IOError, e: if e.errno != 2: log.exception('IOError occurred when removing key file for %s', @@ -161,8 +163,8 @@ class GajimOtrAccount(potr.context.Account): def loadPrivkey(self): try: - with open(self.keyFilePath + '.key2', 'r') as keyFile: - return pickle.load(keyFile) + with open(self.keyFilePath + '.key3', 'rb') as keyFile: + return potr.crypt.PK.parsePrivateKey(keyFile.read())[0] except IOError, e: if e.errno != 2: log.exception('IOError occurred when loading key file for %s', @@ -171,8 +173,8 @@ class GajimOtrAccount(potr.context.Account): def savePrivkey(self): try: - with open(self.keyFilePath + '.key2', 'w') as keyFile: - pickle.dump(self.getPrivkey(), keyFile) + with open(self.keyFilePath + '.key3', 'wb') as keyFile: + keyFile.write(self.getPrivkey().serializePrivateKey()) except IOError, e: log.exception('IOError occurred when loading key file for %s', self.name) @@ -489,6 +491,12 @@ class OtrPlugin(GajimPlugin): 'jid': event.fjid, 'error': e}, account, event.fjid) return IGNORE + + if ctx is not None: + ctx.smpWindow.handle_tlv(tlvs) + if not msgtxt: + return IGNORE + event.msgtxt = unicode(msgtxt) event.stanza.setBody(event.msgtxt) @@ -496,12 +504,6 @@ class OtrPlugin(GajimPlugin): if html_node: event.stanza.delChild(html_node) - if ctx is not None: - ctx.smpWindow.handle_tlv(tlvs) - - if not msgtxt: - return IGNORE - return PASS def handle_outgoing_msg(self, event): diff --git a/gotr/ui.py b/gotr/ui.py index 9c1a2d0b..17459714 100644 --- a/gotr/ui.py +++ b/gotr/ui.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- ## ui.py ## -## Copyright (C) 2008-2010 Kjell Braden <fnord@pentabarf.de> +## Copyright 2008-2012 Kjell Braden <afflux@pentabarf.de> ## ## This file is part of Gajim. ## @@ -214,6 +214,7 @@ class ContactOtrSmpWindow: def __init__(self, ctx): self.question = None + self.smp_running = False self.ctx = ctx self.account = ctx.user.accountname @@ -331,18 +332,19 @@ class ContactOtrSmpWindow: if tlvs: is1qtlv = self.get_tlv(tlvs, potr.proto.SMP1QTLV) # check for TLV_SMP_ABORT or state = CHEATED - if not self.ctx.smpIsValid(): - self._abort() + if self.smp_running and not self.ctx.smpIsValid(): self._finish(_('SMP verifying aborted')) # check for TLV_SMP1 elif self.get_tlv(tlvs, potr.proto.SMP1TLV): + self.smp_running = True self.question = None self.show(True) self.gw('progressbar').set_fraction(0.3) # check for TLV_SMP1Q elif is1qtlv: + self.smp_running = True self.question = is1qtlv.msg self.show(True) self.gw('progressbar').set_fraction(0.3) -- GitLab