Author: bct Date: 2007-06-26 22:55:49 +0200 (Tue, 26 Jun 2007) New Revision: 8318
Modified: branches/e2e_encryption/src/chat_control.py branches/e2e_encryption/src/common/stanza_session.py branches/e2e_encryption/src/gajim.py Log: tidying things up.
Modified: branches/e2e_encryption/src/chat_control.py =================================================================== --- branches/e2e_encryption/src/chat_control.py 2007-06-26 11:37:01 UTC (rev 8317) +++ branches/e2e_encryption/src/chat_control.py 2007-06-26 20:55:49 UTC (rev 8318) @@ -1493,7 +1493,11 @@ is_sensitive = gpg_btn.get_property('sensitive') toggle_gpg_menuitem.set_active(isactive) 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 # in transports, contact holds our info we need to disable it too if contact.resource and contact.jid.find('@') != -1: @@ -1943,14 +1947,11 @@ tb.set_active(not tb.get_active())
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: self.session.enable_encryption = False - print "terminating e2e." self.session.terminate_e2e() else: self.session.enable_encryption = True - print "negotiating e2e." self.session.negotiate_e2e()
def got_connected(self):
Modified: branches/e2e_encryption/src/common/stanza_session.py =================================================================== --- branches/e2e_encryption/src/common/stanza_session.py 2007-06-26 11:37:01 UTC (rev 8317) +++ branches/e2e_encryption/src/common/stanza_session.py 2007-06-26 20:55:49 UTC (rev 8318) @@ -55,23 +55,47 @@
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): def __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.es = {}
+ self.n = 128 + self.enable_encryption = False
+ # _s denotes 'self' (ie. this client) self._kc_s = None + + # _o denotes 'other' (ie. the client at the other end of the session) self._kc_o = None
# keep the encrypter updated with my latest cipher key @@ -298,6 +322,12 @@
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='accept', value='true'))
@@ -360,6 +390,13 @@ # 'Alice Accepts' def accept_e2e_alice(self, form): # 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 self.form_b = ''.join(map(lambda el: xmpp.c14n.c14n(el), form.getChildren()))
Modified: branches/e2e_encryption/src/gajim.py =================================================================== --- branches/e2e_encryption/src/gajim.py 2007-06-26 11:37:01 UTC (rev 8317) +++ branches/e2e_encryption/src/gajim.py 2007-06-26 20:55:49 UTC (rev 8318) @@ -1657,33 +1657,23 @@
def handle_session_negotiation(self, account, 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()): - print 'responding' session.respond_e2e_bob(form) return elif session.status == 'requested-e2e' and form.getType() == 'submit': - print 'accepting (alice)' session.accept_e2e_alice(form) return elif session.status == 'responded-e2e' and form.getType() == 'result': - print 'accepting (bob)' session.accept_e2e_bob(form) return elif session.status == 'identified-alice' and form.getType() == 'result': - print 'completing' session.final_steps_alice(form) return
+ # non-esession negotiation. this isn't very useful, but i'm keeping it around + # to test my test suite. if form.getType() == 'form': ctrl = gajim.interface.msg_win_mgr.get_control(str(jid), account) if not ctrl: