tidying things up.
This commit is contained in:
parent
abd773b52e
commit
39bea5fd40
|
@ -1494,6 +1494,10 @@ class ChatControl(ChatControlBase):
|
||||||
toggle_gpg_menuitem.set_active(isactive)
|
toggle_gpg_menuitem.set_active(isactive)
|
||||||
toggle_gpg_menuitem.set_property('sensitive', is_sensitive)
|
toggle_gpg_menuitem.set_property('sensitive', is_sensitive)
|
||||||
|
|
||||||
|
# TODO: check that the remote client supports e2e
|
||||||
|
isactive = self.session.enable_encryption
|
||||||
|
toggle_e2e_menuitem.set_active(isactive)
|
||||||
|
|
||||||
# If we don't have resource, we can't do file transfer
|
# If we don't have resource, we can't do file transfer
|
||||||
# in transports, contact holds our info we need to disable it too
|
# in transports, contact holds our info we need to disable it too
|
||||||
if contact.resource and contact.jid.find('@') != -1:
|
if contact.resource and contact.jid.find('@') != -1:
|
||||||
|
@ -1943,14 +1947,11 @@ class ChatControl(ChatControlBase):
|
||||||
tb.set_active(not tb.get_active())
|
tb.set_active(not tb.get_active())
|
||||||
|
|
||||||
def _on_toggle_e2e_menuitem_activate(self, widget):
|
def _on_toggle_e2e_menuitem_activate(self, widget):
|
||||||
#if 'security' in self.session.features and self.session.features['security'] == 'e2e':
|
|
||||||
if self.session.enable_encryption:
|
if self.session.enable_encryption:
|
||||||
self.session.enable_encryption = False
|
self.session.enable_encryption = False
|
||||||
print "terminating e2e."
|
|
||||||
self.session.terminate_e2e()
|
self.session.terminate_e2e()
|
||||||
else:
|
else:
|
||||||
self.session.enable_encryption = True
|
self.session.enable_encryption = True
|
||||||
print "negotiating e2e."
|
|
||||||
self.session.negotiate_e2e()
|
self.session.negotiate_e2e()
|
||||||
|
|
||||||
def got_connected(self):
|
def got_connected(self):
|
||||||
|
|
|
@ -55,23 +55,47 @@ class StanzaSession(object):
|
||||||
|
|
||||||
self.last_send = time.time()
|
self.last_send = time.time()
|
||||||
|
|
||||||
|
# an encrypted stanza negotiation has several states. i've represented them as the following values in the 'status'
|
||||||
|
# attribute of the session object:
|
||||||
|
|
||||||
|
# 1. None:
|
||||||
|
# default state
|
||||||
|
# 2. 'requested-e2e':
|
||||||
|
# this client has initiated an esession negotiation and is waiting for
|
||||||
|
# a response
|
||||||
|
# 3. 'responded-e2e':
|
||||||
|
# this client has responded to an esession negotiation request and is
|
||||||
|
# waiting for the initiator to identify itself and complete the
|
||||||
|
# negotiation
|
||||||
|
# 4. 'identified-alice':
|
||||||
|
# this client identified itself and is waiting for the responder to
|
||||||
|
# identify itself and complete the negotiation
|
||||||
|
# 5. 'active':
|
||||||
|
# an encrypted session has been successfully negotiated. messages of
|
||||||
|
# any of the types listed in 'encryptable_stanzas' should be encrypted
|
||||||
|
# before they're sent.
|
||||||
|
# 6. 'sent-terminate':
|
||||||
|
# this client has sent a termination notice and is waiting for
|
||||||
|
# acknowledgement.
|
||||||
|
|
||||||
|
# the transition between these states is handled in gajim.py's
|
||||||
|
# handle_session_negotiation method.
|
||||||
|
|
||||||
class EncryptedStanzaSession(StanzaSession):
|
class EncryptedStanzaSession(StanzaSession):
|
||||||
def __init__(self, conn, jid, thread_id, type = 'chat'):
|
def __init__(self, conn, jid, thread_id, type = 'chat'):
|
||||||
StanzaSession.__init__(self, conn, jid, thread_id, type = 'chat')
|
StanzaSession.__init__(self, conn, jid, thread_id, type = 'chat')
|
||||||
|
|
||||||
self.n = 128
|
|
||||||
|
|
||||||
self.cipher = AES
|
|
||||||
self.hash_alg = SHA256
|
|
||||||
|
|
||||||
self.compression = None
|
|
||||||
|
|
||||||
self.xes = {}
|
self.xes = {}
|
||||||
self.es = {}
|
self.es = {}
|
||||||
|
|
||||||
|
self.n = 128
|
||||||
|
|
||||||
self.enable_encryption = False
|
self.enable_encryption = False
|
||||||
|
|
||||||
|
# _s denotes 'self' (ie. this client)
|
||||||
self._kc_s = None
|
self._kc_s = None
|
||||||
|
|
||||||
|
# _o denotes 'other' (ie. the client at the other end of the session)
|
||||||
self._kc_o = None
|
self._kc_o = None
|
||||||
|
|
||||||
# keep the encrypter updated with my latest cipher key
|
# keep the encrypter updated with my latest cipher key
|
||||||
|
@ -298,6 +322,12 @@ class EncryptedStanzaSession(StanzaSession):
|
||||||
|
|
||||||
not_acceptable = []
|
not_acceptable = []
|
||||||
|
|
||||||
|
self.encryptable_stanzas = ['message']
|
||||||
|
self.sas_algs = 'sas28x5'
|
||||||
|
self.cipher = AES
|
||||||
|
self.hash_alg = SHA256
|
||||||
|
self.compression = None
|
||||||
|
|
||||||
x.addChild(node=xmpp.DataField(name='FORM_TYPE', value='urn:xmpp:ssn'))
|
x.addChild(node=xmpp.DataField(name='FORM_TYPE', value='urn:xmpp:ssn'))
|
||||||
x.addChild(node=xmpp.DataField(name='accept', value='true'))
|
x.addChild(node=xmpp.DataField(name='accept', value='true'))
|
||||||
|
|
||||||
|
@ -360,6 +390,13 @@ class EncryptedStanzaSession(StanzaSession):
|
||||||
# 'Alice Accepts'
|
# 'Alice Accepts'
|
||||||
def accept_e2e_alice(self, form):
|
def accept_e2e_alice(self, form):
|
||||||
# 1. Verify that the ESession options selected by Bob are acceptable
|
# 1. Verify that the ESession options selected by Bob are acceptable
|
||||||
|
|
||||||
|
self.encryptable_stanzas = ['message']
|
||||||
|
self.sas_algs = 'sas28x5'
|
||||||
|
self.cipher = AES
|
||||||
|
self.hash_alg = SHA256
|
||||||
|
self.compression = None
|
||||||
|
|
||||||
# 2. Return a <not-acceptable/> error to Bob unless: 1 < d < p - 1
|
# 2. Return a <not-acceptable/> error to Bob unless: 1 < d < p - 1
|
||||||
self.form_b = ''.join(map(lambda el: xmpp.c14n.c14n(el), form.getChildren()))
|
self.form_b = ''.join(map(lambda el: xmpp.c14n.c14n(el), form.getChildren()))
|
||||||
|
|
||||||
|
|
16
src/gajim.py
16
src/gajim.py
|
@ -1657,33 +1657,23 @@ class Interface:
|
||||||
|
|
||||||
def handle_session_negotiation(self, account, data):
|
def handle_session_negotiation(self, account, data):
|
||||||
jid, session, form = data
|
jid, session, form = data
|
||||||
# XXX check negotiation state, etc.
|
|
||||||
# XXX check if we can autoaccept
|
|
||||||
|
|
||||||
# order of e2e statuses:
|
|
||||||
# 1. Alice, Bob: None
|
|
||||||
# 2. Alice: requested-e2e
|
|
||||||
# 3. Bob: responded-e2e
|
|
||||||
# 4. Alice: identified-alice
|
|
||||||
# 5. Alice, Bob: active
|
|
||||||
|
|
||||||
|
# encrypted session states
|
||||||
if form.getType() == 'form' and u'e2e' in map(lambda x: x[1], form.getField('security').getOptions()):
|
if form.getType() == 'form' and u'e2e' in map(lambda x: x[1], form.getField('security').getOptions()):
|
||||||
print 'responding'
|
|
||||||
session.respond_e2e_bob(form)
|
session.respond_e2e_bob(form)
|
||||||
return
|
return
|
||||||
elif session.status == 'requested-e2e' and form.getType() == 'submit':
|
elif session.status == 'requested-e2e' and form.getType() == 'submit':
|
||||||
print 'accepting (alice)'
|
|
||||||
session.accept_e2e_alice(form)
|
session.accept_e2e_alice(form)
|
||||||
return
|
return
|
||||||
elif session.status == 'responded-e2e' and form.getType() == 'result':
|
elif session.status == 'responded-e2e' and form.getType() == 'result':
|
||||||
print 'accepting (bob)'
|
|
||||||
session.accept_e2e_bob(form)
|
session.accept_e2e_bob(form)
|
||||||
return
|
return
|
||||||
elif session.status == 'identified-alice' and form.getType() == 'result':
|
elif session.status == 'identified-alice' and form.getType() == 'result':
|
||||||
print 'completing'
|
|
||||||
session.final_steps_alice(form)
|
session.final_steps_alice(form)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# non-esession negotiation. this isn't very useful, but i'm keeping it around
|
||||||
|
# to test my test suite.
|
||||||
if form.getType() == 'form':
|
if form.getType() == 'form':
|
||||||
ctrl = gajim.interface.msg_win_mgr.get_control(str(jid), account)
|
ctrl = gajim.interface.msg_win_mgr.get_control(str(jid), account)
|
||||||
if not ctrl:
|
if not ctrl:
|
||||||
|
|
Loading…
Reference in New Issue