From 4cfd56a69bfd8d112a3b59863ba529092b7bf3df Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Thu, 1 Oct 2009 22:17:19 +0200 Subject: [PATCH] add a workarround for backward compatibility about esession. see #4396 --- src/common/stanza_session.py | 32 +++++++++++++++++++++++++------- src/common/xmpp/c14n.py | 6 +++--- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/common/stanza_session.py b/src/common/stanza_session.py index 91282e046..3d4770827 100644 --- a/src/common/stanza_session.py +++ b/src/common/stanza_session.py @@ -215,6 +215,18 @@ class EncryptedStanzaSession(StanzaSession): # has the remote contact's identity ever been verified? self.verified_identity = False + def _get_contact(self): + c = gajim.contacts.get_contact(self.conn.name, self.jid, self.resource) + if not c: + c = gajim.contacts.get_contact(self.conn.name, self.jid) + return c + + def _is_buggy_gajim(self): + c = self._get_contact() + if gajim.capscache.is_supported(c, xmpp.NS_ROSTERX): + return False + return True + def set_kc_s(self, value): ''' keep the encrypter updated with my latest cipher key @@ -376,7 +388,8 @@ class EncryptedStanzaSession(StanzaSession): def c7lize_mac_id(self, form): kids = form.getChildren() macable = [x for x in kids if x.getVar() not in ('mac', 'identity')] - return ''.join(xmpp.c14n.c14n(el) for el in macable) + return ''.join(xmpp.c14n.c14n(el, self._is_buggy_gajim()) for el in \ + macable) def verify_identity(self, form, dh_i, sigmai, i_o): m_o = base64.b64decode(form['mac']) @@ -409,7 +422,7 @@ class EncryptedStanzaSession(StanzaSession): keyvalue.getTagData(x))) for x in ('Modulus', 'Exponent')) eir_pubkey = RSA.construct((n,long(e))) - pubkey_o = xmpp.c14n.c14n(keyvalue) + pubkey_o = xmpp.c14n.c14n(keyvalue, self._is_buggy_gajim()) else: # FIXME DSA, etc. raise NotImplementedError() @@ -459,7 +472,8 @@ class EncryptedStanzaSession(StanzaSession): else: pubkey_s = '' - form_s2 = ''.join(xmpp.c14n.c14n(el) for el in form.getChildren()) + form_s2 = ''.join(xmpp.c14n.c14n(el, self._is_buggy_gajim()) for el in \ + form.getChildren()) old_c_s = self.c_s content = self.n_o + self.n_s + crypto.encode_mpi(dh_i) + pubkey_s + \ @@ -560,7 +574,8 @@ class EncryptedStanzaSession(StanzaSession): x.addChild(node=self.make_dhfield(modp_options, sigmai)) self.sigmai = sigmai - self.form_s = ''.join(xmpp.c14n.c14n(el) for el in x.getChildren()) + self.form_s = ''.join(xmpp.c14n.c14n(el, self._is_buggy_gajim()) for el \ + in x.getChildren()) feature.addChild(node=x) @@ -689,8 +704,10 @@ class EncryptedStanzaSession(StanzaSession): b64ed = base64.b64encode(to_add[name]) x.addChild(node=xmpp.DataField(name=name, value=b64ed)) - self.form_o = ''.join(xmpp.c14n.c14n(el) for el in form.getChildren()) - self.form_s = ''.join(xmpp.c14n.c14n(el) for el in x.getChildren()) + self.form_o = ''.join(xmpp.c14n.c14n(el, self._is_buggy_gajim()) for el \ + in form.getChildren()) + self.form_s = ''.join(xmpp.c14n.c14n(el, self._is_buggy_gajim()) for el \ + in x.getChildren()) self.status = 'responded-e2e' @@ -792,7 +809,8 @@ class EncryptedStanzaSession(StanzaSession): result.addChild(node=xmpp.DataField(name='dhkeys', value=base64.b64encode(crypto.encode_mpi(e)))) - self.form_o = ''.join(xmpp.c14n.c14n(el) for el in form.getChildren()) + self.form_o = ''.join(xmpp.c14n.c14n(el, self._is_buggy_gajim()) for \ + el in form.getChildren()) # MUST securely destroy K unless it will be used later to generate the # final shared secret diff --git a/src/common/xmpp/c14n.py b/src/common/xmpp/c14n.py index b21129a22..bccce8155 100644 --- a/src/common/xmpp/c14n.py +++ b/src/common/xmpp/c14n.py @@ -21,7 +21,7 @@ ''' XML canonicalisation methods (for XEP-0116) ''' from simplexml import ustr -def c14n(node): +def c14n(node, is_buggy): s = "<" + node.name if node.namespace: if not node.parent or node.parent.namespace != node.namespace: @@ -29,7 +29,7 @@ def c14n(node): sorted_attrs = sorted(node.attrs.keys()) for key in sorted_attrs: - if key == 'xmlns': + if not is_buggy and key == 'xmlns': continue val = ustr(node.attrs[key]) # like XMLescape() but with whitespace and without > @@ -40,7 +40,7 @@ def c14n(node): for a in node.kids: if (len(node.data)-1) >= cnt: s = s + normalise_text(node.data[cnt]) - s = s + c14n(a) + s = s + c14n(a, is_buggy) cnt=cnt+1 if (len(node.data)-1) >= cnt: s = s + normalise_text(node.data[cnt]) if not node.kids and s.endswith('>'):