Show
Ignore:
Timestamp:
12/08/07 06:49:38 (12 months ago)
Author:
bct
Message:

realtime notification of esession begin/end

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/common/stanza_session.py

    r9064 r9113  
    7272                '''A negotiation has been cancelled, so reset this session to its default state.''' 
    7373 
    74                 # XXX notify the user    
    75                  
     74                if hasattr(self, 'control'): 
     75                        msg = _('Session negotiation cancelled') 
     76                        self.control.print_conversation_line(self, msg, 'status', '', None) 
     77 
    7678                self.status = None 
    7779                self.negotiated = {} 
     
    9395 
    9496        def acknowledge_termination(self): 
    95                 # we could send an acknowledgement message here, but we won't. 
     97                # we could send an acknowledgement message to the remote client here 
    9698                self.status = None 
    9799 
     
    106108 
    107109# an encrypted stanza negotiation has several states. i've represented them 
    108 # as the following values in the 'status'  
     110# as the following values in the 'status' 
    109111# attribute of the session object: 
    110112 
     
    144146                # _s denotes 'self' (ie. this client) 
    145147                self._kc_s = None 
    146          
     148 
    147149                # _o denotes 'other' (ie. the client at the other end of the session) 
    148150                self._kc_o = None 
     
    162164                self.decrypter = self.cipher.new(self._kc_o, self.cipher.MODE_CTR, 
    163165                        counter=self.decryptcounter) 
    164          
     166 
    165167        def get_kc_o(self): 
    166168                return self._kc_o 
     
    168170        kc_s = property(get_kc_s, set_kc_s) 
    169171        kc_o = property(get_kc_o, set_kc_o) 
    170          
     172 
    171173        def encryptcounter(self): 
    172174                self.c_s = (self.c_s + 1) % (2 ** self.n) 
    173175                return crypto.encode_mpi_with_padding(self.c_s) 
    174          
     176 
    175177        def decryptcounter(self): 
    176178                self.c_o = (self.c_o + 1) % (2 ** self.n) 
     
    232234        def decompress(self, compressed): 
    233235                if self.compression == None: 
    234                         return compressed  
     236                        return compressed 
    235237 
    236238        def encrypt(self, encryptable): 
     
    344346 
    345347                mac_o_calculated = self.hmac(self.ks_o, content) 
    346          
     348 
    347349                if self.negotiated['recv_pubkey']: 
    348350                        hash = crypto.sha256(mac_o_calculated) 
     
    381383                                b64ed = base64.b64encode(self.hash(pubkey_s)) 
    382384                                pubkey_s = '<fingerprint>%s</fingerprint>' % b64ed 
    383                  
     385 
    384386                        id_s = self.encrypt(pubkey_s + sign_s) 
    385387                else: 
     
    396398                                # XXX save retained secret? 
    397399                                self.check_identity(lambda : ()) 
    398                  
     400 
    399401                return (xmpp.DataField(name='identity', value=base64.b64encode(id_s)), \ 
    400402                                                xmpp.DataField(name='mac', value=base64.b64encode(m_s))) 
     
    438440 
    439441                self.n_s = crypto.generate_nonce() 
    440          
     442 
    441443                x.addChild(node=xmpp.DataField(name='my_nonce', value=base64.b64encode(self.n_s), typ='hidden')) 
    442444 
     
    455457 
    456458                self.send(request) 
    457          
     459 
    458460        # 4.3 esession response (bob) 
    459461        def verify_options_bob(self, form): 
     
    571573 
    572574                to_add = { 'my_nonce': self.n_s, 
    573                                                          'dhkeys': crypto.encode_mpi(self.d),  
    574                                                          'counter': crypto.encode_mpi(self.c_o),  
     575                                                         'dhkeys': crypto.encode_mpi(self.d), 
     576                                                         'counter': crypto.encode_mpi(self.c_o), 
    575577                                                         'nonce': self.n_o } 
    576578 
     
    667669                        self.verify_identity(form, self.d, True, 'b') 
    668670                else: 
    669                         srses = secrets.secrets().retained_secrets(self.conn.name, self.jid.getStripped())  
     671                        srses = secrets.secrets().retained_secrets(self.conn.name, self.jid.getStripped()) 
    670672                        rshashes = [self.hmac(self.n_s, rs) for (rs,v) in srses] 
    671673 
     
    678680                        result.addChild(node=xmpp.DataField(name='rshashes', value=rshashes)) 
    679681                        result.addChild(node=xmpp.DataField(name='dhkeys', value=base64.b64encode(crypto.encode_mpi(e)))) 
    680                  
     682 
    681683                        self.form_o = ''.join(map(lambda el: xmpp.c14n.c14n(el), form.getChildren())) 
    682684 
     
    688690                feature.addChild(node=result) 
    689691                self.send(accept) 
    690          
     692 
    691693                if self.sigmai: 
    692694                        self.status = 'active' 
     
    694696                else: 
    695697                        self.status = 'identified-alice' 
    696          
     698 
    697699        # 4.5 esession accept (bob) 
    698700        def accept_e2e_bob(self, form): 
     
    725727 
    726728                srs = '' 
    727          
     729 
    728730                srses = secrets.secrets().retained_secrets(self.conn.name, self.jid.getStripped()) 
    729731                rshashes = [base64.b64decode(rshash) for rshash in form.getField('rshashes').getValues()] 
     
    768770                self.enable_encryption = True 
    769771 
     772                if hasattr(self, 'control'): 
     773                        self.control.print_esession_details() 
     774 
    770775        def final_steps_alice(self, form): 
    771776                srs = '' 
     
    794799                self.verify_identity(form, self.d, False, 'b') 
    795800# Note: If Alice discovers an error then she SHOULD ignore any encrypted content she received in the stanza. 
    796          
     801 
    797802                if self.negotiated['logging'] == 'mustnot': 
    798803                        self.loggable = False 
     
    800805                self.status = 'active' 
    801806                self.enable_encryption = True 
     807 
     808                if hasattr(self, 'control'): 
     809                        self.control.print_esession_details() 
    802810 
    803811        # calculate and store the new retained secret