comparison sat/plugins/plugin_sec_otr.py @ 3226:2f406b762788

core (memory/encryption): encryption session are now restored on client connection
author Goffi <goffi@goffi.org>
date Sun, 22 Mar 2020 18:39:12 +0100
parents dcebc585c29f
children e756e0eb1be4
comparison
equal deleted inserted replaced
3225:843a9279fb5a 3226:2f406b762788
167 167
168 if state == potr.context.STATE_PLAINTEXT: 168 if state == potr.context.STATE_PLAINTEXT:
169 feedback = _("/!\\ conversation with %(other_jid)s is now UNENCRYPTED") % { 169 feedback = _("/!\\ conversation with %(other_jid)s is now UNENCRYPTED") % {
170 "other_jid": self.peer.full() 170 "other_jid": self.peer.full()
171 } 171 }
172 d = client.encryption.stop(self.peer, NS_OTR) 172 d = defer.ensureDeferred(client.encryption.stop(self.peer, NS_OTR))
173 d.addCallback(self.stopCb, feedback=feedback) 173 d.addCallback(self.stopCb, feedback=feedback)
174 d.addErrback(self.stopEb) 174 d.addErrback(self.stopEb)
175 return 175 return
176 elif state == potr.context.STATE_ENCRYPTED: 176 elif state == potr.context.STATE_ENCRYPTED:
177 client.encryption.start(self.peer, NS_OTR) 177 defer.ensureDeferred(client.encryption.start(self.peer, NS_OTR))
178 try: 178 try:
179 trusted = self.isTrusted() 179 trusted = self.isTrusted()
180 except TypeError: 180 except TypeError:
181 trusted = False 181 trusted = False
182 trusted_str = _("trusted") if trusted else _("untrusted") 182 trusted_str = _("trusted") if trusted else _("untrusted")
199 ) 199 )
200 elif state == potr.context.STATE_FINISHED: 200 elif state == potr.context.STATE_FINISHED:
201 feedback = D_("OTR conversation with {other_jid} is FINISHED").format( 201 feedback = D_("OTR conversation with {other_jid} is FINISHED").format(
202 other_jid=self.peer.full() 202 other_jid=self.peer.full()
203 ) 203 )
204 d = client.encryption.stop(self.peer, NS_OTR) 204 d = defer.ensureDeferred(client.encryption.stop(self.peer, NS_OTR))
205 d.addCallback(self.stopCb, feedback=feedback) 205 d.addCallback(self.stopCb, feedback=feedback)
206 d.addErrback(self.stopEb) 206 d.addErrback(self.stopEb)
207 return 207 return
208 else: 208 else:
209 log.error(D_("Unknown OTR state")) 209 log.error(D_("Unknown OTR state"))
806 ) # FIXME: full jid may not be known 806 ) # FIXME: full jid may not be known
807 807
808 otrctx = client._otr_context_manager.getContextForUser(to_jid) 808 otrctx = client._otr_context_manager.getContextForUser(to_jid)
809 809
810 if otrctx.state != potr.context.STATE_PLAINTEXT: 810 if otrctx.state != potr.context.STATE_PLAINTEXT:
811 client.encryption.start(to_jid, NS_OTR) 811 defer.ensureDeferred(client.encryption.start(to_jid, NS_OTR))
812 client.encryption.setEncryptionFlag(mess_data) 812 client.encryption.setEncryptionFlag(mess_data)
813 if not mess_data["to"].resource: 813 if not mess_data["to"].resource:
814 # if not resource was given, we force it here 814 # if not resource was given, we force it here
815 mess_data["to"] = to_jid 815 mess_data["to"] = to_jid
816 return True 816 return True