annotate src/plugins/plugin_sec_otr.py @ 1055:abcac1ac27a7

plugin otr: first draft
author Goffi <goffi@goffi.org>
date Sat, 07 Jun 2014 16:39:08 +0200
parents
children ef7b7dd5c5db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1055
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin for OTR encryption
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 # XXX: thanks to Darrik L Mazey for his documentation (https://blog.darmasoft.net/2013/06/30/using-pure-python-otr.html)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21 # this implentation is based on it
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat.core.i18n import _
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat.core.log import getLogger
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat.core import exceptions
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 log = getLogger(__name__)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.words.protocols.jabber import jid
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from twisted.python import failure
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 import potr
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 DEFAULT_POLICY_FLAGS = {
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 'ALLOW_V1':False,
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 'ALLOW_V2':True,
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 'REQUIRE_ENCRYPTION':True,
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 }
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 PLUGIN_INFO = {
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 "name": "OTR",
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 "import_name": "OTR",
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 "type": "SEC",
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 "protocols": [],
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 "dependencies": [],
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 "main": "OTR",
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 "handler": "no",
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 "description": _("""Implementation of OTR""")
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 }
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 PROTOCOL='xmpp'
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 MMS=1024
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 class Context(potr.context.Context):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 def __init__(self, host, account, peer):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 super(Context, self).__init__(account, peer)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.host = host
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 def getPolicy(self, key):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 if key in DEFAULT_POLICY_FLAGS:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 return DEFAULT_POLICY_FLAGS[key]
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 else:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 return False
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 def inject(self, msg, appdata=None):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 to_jid, profile = appdata
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 assert isinstance(to_jid, jid.JID)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 client = self.host.getClient(profile)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 log.debug('inject(%s, appdata=%s, to=%s)' % (msg, appdata, to_jid))
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 mess_data = {'message': msg,
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71 'type': 'chat',
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 'from': client.jid,
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 'to': to_jid,
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 'subject': None,
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 }
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 self.host.generateMessageXML(mess_data)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 client.xmlstream.send(mess_data['xml'])
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 def setState(self, state):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80 super(Context, self).setState(state)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 log.debug("setState: %s (self = %s)" % (state, self))
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 # TODO: send signal to frontends, maybe a message feedback too
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 class Account(potr.context.Account):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 def __init__(self, account_jid):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88 global PROTOCOL, MMS
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89 assert isinstance(account_jid, jid.JID)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90 log.debug("new account: %s" % account_jid)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 super(Account, self).__init__(account_jid, PROTOCOL, MMS)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93 def loadPrivkey(self):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94 # TODO
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95 log.debug("loadPrivkey")
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96 return None
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
98 def savePrivkey(self):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
99 # TODO
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
100 log.debug("savePrivkey")
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
101
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
102
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103 class ContextManager(object):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
105 def __init__(self, host, client):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
106 self.host = host
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107 self.account = Account(client.jid)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
108 self.contexts = {}
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
109
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
110 def startContext(self, other):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
111 assert isinstance(other, jid.JID)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
112 if not other in self.contexts:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
113 self.contexts[other] = Context(self.host, self.account, other)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
114 return self.contexts[other]
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
115
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
116 def getContextForUser(self, other):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117 log.debug("getContextForUser [%s]" % other)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118 return self.startContext(other)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
119
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
120
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
121 class OTR(object):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
122
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
123 def __init__(self, host):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
124 log.info(_("OTR plugin initialization"))
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
125 self.host = host
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
126 self.context_managers = {}
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
127 host.trigger.add("MessageReceived", self.MessageReceivedTrigger, priority=100000)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
128 host.trigger.add("sendMessage", self.sendMessageTrigger, priority=100000)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
129
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130 def profileConnected(self, profile):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
131 client = self.host.getClient(profile)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
132 self.context_managers[profile] = ContextManager(self.host, client)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
133
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
134 def _receivedTreatment(self, data, profile):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
135 from_jid = jid.JID(data['from'])
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
136 log.debug("_receivedTreatment [from_jid = %s]" % from_jid)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
137 otrctx = self.context_managers[profile].getContextForUser(from_jid)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
138
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
139 encrypted = True
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
140 try:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
141 res = otrctx.receiveMessage(data['body'].encode('utf-8'), appdata=(from_jid, profile))
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
142 except potr.context.UnencryptedMessage:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
143 log.warning("Received unencrypted message in an encrypted context")
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
144 # TODO: feedback to frontends (either message or popup)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
145 encrypted = False
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
146
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
147 if encrypted == False:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
148 return data
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
149 else:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
150 if res[0] != None:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
151 # decrypted messages handling.
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
152 # receiveMessage() will return a tuple, the first part of which will be the decrypted message
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
153 data['body'] = res[0].decode('utf-8')
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
154 raise failure.Failure(exceptions.SkipHistory()) # we send the decrypted message to frontends, but we don't want it in history
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
155 else:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
156 raise failure.Failure(exceptions.CancelError()) # no message at all (no history, no signal)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
157
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
158 def MessageReceivedTrigger(self, message, post_treat, profile):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
159 post_treat.addCallback(self._receivedTreatment, profile)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
160 return True
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
161
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
162 def sendMessageTrigger(self, mess_data, pre_xml_treatments, post_xml_treatments, profile):
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
163 to_jid = mess_data['to']
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
164 if mess_data['type'] != 'groupchat' and not to_jid.resource:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
165 to_jid.resource = self.host.memory.getLastResource(to_jid, profile) # FIXME: it's dirty, but frontends don't manage resources correctly now, refactoring is planed
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
166 otrctx = self.context_managers[profile].getContextForUser(to_jid)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
167 if mess_data['type'] != 'groupchat' and otrctx.state == potr.context.STATE_ENCRYPTED:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
168 log.debug("encrypting message")
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
169 otrctx.sendMessage(0, mess_data['message'].encode('utf-8'), appdata=(to_jid, profile))
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
170 client = self.host.getClient(profile)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
171 self.host.sendMessageToBridge(mess_data, client)
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
172 return False
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
173 else:
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
174 log.debug("sending message unencrypted")
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
175 return True
abcac1ac27a7 plugin otr: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
176