add a workarround for backward compatibility about esession. see #4396

This commit is contained in:
Yann Leboulanger 2009-10-01 22:17:19 +02:00
parent 678e3807e9
commit 4cfd56a69b
2 changed files with 28 additions and 10 deletions

View File

@ -215,6 +215,18 @@ class EncryptedStanzaSession(StanzaSession):
# has the remote contact's identity ever been verified? # has the remote contact's identity ever been verified?
self.verified_identity = False 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): def set_kc_s(self, value):
''' '''
keep the encrypter updated with my latest cipher key keep the encrypter updated with my latest cipher key
@ -376,7 +388,8 @@ class EncryptedStanzaSession(StanzaSession):
def c7lize_mac_id(self, form): def c7lize_mac_id(self, form):
kids = form.getChildren() kids = form.getChildren()
macable = [x for x in kids if x.getVar() not in ('mac', 'identity')] 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): def verify_identity(self, form, dh_i, sigmai, i_o):
m_o = base64.b64decode(form['mac']) m_o = base64.b64decode(form['mac'])
@ -409,7 +422,7 @@ class EncryptedStanzaSession(StanzaSession):
keyvalue.getTagData(x))) for x in ('Modulus', 'Exponent')) keyvalue.getTagData(x))) for x in ('Modulus', 'Exponent'))
eir_pubkey = RSA.construct((n,long(e))) eir_pubkey = RSA.construct((n,long(e)))
pubkey_o = xmpp.c14n.c14n(keyvalue) pubkey_o = xmpp.c14n.c14n(keyvalue, self._is_buggy_gajim())
else: else:
# FIXME DSA, etc. # FIXME DSA, etc.
raise NotImplementedError() raise NotImplementedError()
@ -459,7 +472,8 @@ class EncryptedStanzaSession(StanzaSession):
else: else:
pubkey_s = '' 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 old_c_s = self.c_s
content = self.n_o + self.n_s + crypto.encode_mpi(dh_i) + pubkey_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)) x.addChild(node=self.make_dhfield(modp_options, sigmai))
self.sigmai = 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) feature.addChild(node=x)
@ -689,8 +704,10 @@ class EncryptedStanzaSession(StanzaSession):
b64ed = base64.b64encode(to_add[name]) b64ed = base64.b64encode(to_add[name])
x.addChild(node=xmpp.DataField(name=name, value=b64ed)) x.addChild(node=xmpp.DataField(name=name, value=b64ed))
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 \
self.form_s = ''.join(xmpp.c14n.c14n(el) for el in x.getChildren()) in form.getChildren())
self.form_s = ''.join(xmpp.c14n.c14n(el, self._is_buggy_gajim()) for el \
in x.getChildren())
self.status = 'responded-e2e' self.status = 'responded-e2e'
@ -792,7 +809,8 @@ class EncryptedStanzaSession(StanzaSession):
result.addChild(node=xmpp.DataField(name='dhkeys', result.addChild(node=xmpp.DataField(name='dhkeys',
value=base64.b64encode(crypto.encode_mpi(e)))) 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 # MUST securely destroy K unless it will be used later to generate the
# final shared secret # final shared secret

View File

@ -21,7 +21,7 @@
''' XML canonicalisation methods (for XEP-0116) ''' ''' XML canonicalisation methods (for XEP-0116) '''
from simplexml import ustr from simplexml import ustr
def c14n(node): def c14n(node, is_buggy):
s = "<" + node.name s = "<" + node.name
if node.namespace: if node.namespace:
if not node.parent or node.parent.namespace != 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()) sorted_attrs = sorted(node.attrs.keys())
for key in sorted_attrs: for key in sorted_attrs:
if key == 'xmlns': if not is_buggy and key == 'xmlns':
continue continue
val = ustr(node.attrs[key]) val = ustr(node.attrs[key])
# like XMLescape() but with whitespace and without &gt; # like XMLescape() but with whitespace and without &gt;
@ -40,7 +40,7 @@ def c14n(node):
for a in node.kids: for a in node.kids:
if (len(node.data)-1) >= cnt: if (len(node.data)-1) >= cnt:
s = s + normalise_text(node.data[cnt]) s = s + normalise_text(node.data[cnt])
s = s + c14n(a) s = s + c14n(a, is_buggy)
cnt=cnt+1 cnt=cnt+1
if (len(node.data)-1) >= cnt: s = s + normalise_text(node.data[cnt]) if (len(node.data)-1) >= cnt: s = s + normalise_text(node.data[cnt])
if not node.kids and s.endswith('>'): if not node.kids and s.endswith('>'):