Commit b4927cd3 authored by Kjell Braden's avatar Kjell Braden

updated gotr to version 1.5

parent 38efc8c3
name: Off-The-Record Encryption
short_name: gotr
version: 1.4
version: 1.5
description: See
authors: Kjell Braden <>
......@@ -24,12 +24,12 @@
Off-The-Record encryption plugin.
:author: Kjell self.Braden <>
:since: 20 May 2011
:copyright: Copyright (2011) Kjell Braden <>
:since: 2008
:copyright: Copyright 2008-2012 Kjell Braden <>
:license: GPL
MINVERSION = (1,0,0,'beta4')
MINVERSION = (1,0,0,'beta5')
PASS = False
......@@ -77,11 +77,18 @@ try:
except ImportError:
HAS_POTR = False
def get_jid_from_fjid(fjid):
return gajim.get_room_and_nick_from_fjid(fjid)[0]
class GajimContext(potr.context.Context):
__slots__ = ['smpWindow']
# self.peer is fjid
# self.jid does not contain resource
__slots__ = ['smpWindow', 'jid']
def __init__(self, account, peer):
super(GajimContext, self).__init__(account, peer)
self.jid = get_jid_from_fjid(peer)
self.trustName = self.jid
self.smpWindow = ui.ContactOtrSmpWindow(self)
def inject(self, msg, appdata=None):
......@@ -137,8 +144,7 @@ class GajimContext(potr.context.Context):
def getPolicy(self, key):
jid = gajim.get_room_and_nick_from_fjid(self.peer)[0]
ret = self.user.plugin.get_flags(self.user.accountname, jid)[key]
ret = self.user.plugin.get_flags(self.user.accountname, self.jid)[key]
log.debug('getPolicy(key=%s) = %s', key, ret)
return ret
......@@ -191,7 +197,8 @@ class GajimOtrAccount(potr.context.Account):
if acc != or proto != PROTOCOL:
self.getContext(ctx, newCtxCb).setTrust(fpr, trust)
jid = get_jid_from_fjid(ctx)
self.setTrust(jid, fpr, trust)
except IOError, e:
if e.errno != 2:
log.exception('IOError occurred when loading fpr file for %s',
......@@ -200,10 +207,10 @@ class GajimOtrAccount(potr.context.Account):
def saveTrusts(self):
with open(self.keyFilePath + '.fpr', 'w') as fprFile:
for uid, ctx in self.ctxs.iteritems():
for fpr, trust in
for uid, trusts in self.trusts.iteritems():
for fpr, trustVal in trusts.iteritems():
(uid,, PROTOCOL, fpr, trust)))
(uid,, PROTOCOL, fpr, trustVal)))
except IOError, e:
log.exception('IOError occurred when loading fpr file for %s',
......@@ -237,6 +244,7 @@ class OtrPlugin(GajimPlugin):
acc = str(acc)
if acc not in self.config or None not in self.config[acc]:
self.config[acc] = {None:DEFAULTFLAGS.copy()}
def activate(self):
......@@ -370,27 +378,42 @@ class OtrPlugin(GajimPlugin):
def update_context_list(self):
for us in
for uid, ctx in us.ctxs.iteritems():
for fpr, trust in
trust = False
if ctx.state == potr.context.STATE_ENCRYPTED:
if ctx.getCurrentKey().cfingerprint() == fpr:
state = "encrypted"
tip = enc_tip
trust = bool(ctx.getCurrentTrust())
state = "unused"
tip = unused_tip
elif ctx.state == potr.context.STATE_FINISHED:
state = "finished"
tip = ended_tip
state = 'inactive'
tip = inactive_tip
usedFpr = set()
for fjid, ctx in us.ctxs.iteritems():
# get active contexts first
key = ctx.getCurrentKey()
if not key:
fpr = key.cfingerprint()
human_hash = potr.human_hash(fpr)
trust = bool(us.getTrust(ctx.trustName, fpr))
if ctx.state == potr.context.STATE_ENCRYPTED:
state = "encrypted"
tip = enc_tip
elif ctx.state == potr.context.STATE_FINISHED:
state = "finished"
tip = ended_tip
state = 'inactive'
tip = inactive_tip
self.config_dialog.fpr_model.append((fjid, state, trust,
'<tt>%s</tt>' % human_hash,, tip, fpr))
for uid, trusts in us.trusts.iteritems():
for fpr, trust in trusts.iteritems():
if fpr in usedFpr:
state = 'inactive'
tip = inactive_tip
human_hash = potr.human_hash(fpr)
self.config_dialog.fpr_model.append((uid, state, trust,
self.config_dialog.fpr_model.append((uid, state, bool(trust),
'<tt>%s</tt>' % human_hash,, tip, fpr))
......@@ -470,22 +493,31 @@ class OtrPlugin(GajimPlugin):
ctx =[account].getContext(event.fjid)
msgtxt, tlvs = ctx.receiveMessage(event.msgtxt,
except potr.context.NotOTRMessage, e:
# received message was not OTR - pass it on
return PASS
except potr.context.UnencryptedMessage, e:
# we are encrypted but got some plaintext
# display it with a warning
tlvs = []
msgtxt = _('The following message received from %(jid)s was '
'*not encrypted*: [%(error)s]') % {'jid': event.fjid,
'error': e.args[0]}
except potr.context.NotEncryptedError, e:
# we got some encrypted data
# but we don't have an encrypted session
self.gajim_log(_('The encrypted message received from %s is '
'unreadable, as you are not currently communicating '
'privately') % event.fjid, account, event.fjid)
return IGNORE
except potr.context.ErrorReceived, e:
# got a protocol error
self.gajim_log(_('We received the following OTR error '
'message from %(jid)s: [%(error)s]') % {'jid': event.fjid,
'error': e.args[0].error})
return IGNORE
except RuntimeError, e:
# generic library bug?
self.gajim_log(_('The following error occurred when trying to '
'decrypt a message from %(jid)s: [%(error)s]') % {
'jid': event.fjid, 'error': e},
......@@ -494,12 +526,12 @@ class OtrPlugin(GajimPlugin):
if ctx is not None:
if not msgtxt:
return IGNORE
event.msgtxt = unicode(msgtxt)
event.msgtxt = unicode(msgtxt or '')
# every message that went through OTR (ie. was OTR-related) gets
# stripped from html. I don't like html.
html_node = event.stanza.getTag('html')
if html_node:
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