Changeset 9113 for trunk/src/common/stanza_session.py
- Timestamp:
- 12/08/07 06:49:38 (12 months ago)
- Files:
-
- 1 modified
-
trunk/src/common/stanza_session.py (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/common/stanza_session.py
r9064 r9113 72 72 '''A negotiation has been cancelled, so reset this session to its default state.''' 73 73 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 76 78 self.status = None 77 79 self.negotiated = {} … … 93 95 94 96 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 96 98 self.status = None 97 99 … … 106 108 107 109 # 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' 109 111 # attribute of the session object: 110 112 … … 144 146 # _s denotes 'self' (ie. this client) 145 147 self._kc_s = None 146 148 147 149 # _o denotes 'other' (ie. the client at the other end of the session) 148 150 self._kc_o = None … … 162 164 self.decrypter = self.cipher.new(self._kc_o, self.cipher.MODE_CTR, 163 165 counter=self.decryptcounter) 164 166 165 167 def get_kc_o(self): 166 168 return self._kc_o … … 168 170 kc_s = property(get_kc_s, set_kc_s) 169 171 kc_o = property(get_kc_o, set_kc_o) 170 172 171 173 def encryptcounter(self): 172 174 self.c_s = (self.c_s + 1) % (2 ** self.n) 173 175 return crypto.encode_mpi_with_padding(self.c_s) 174 176 175 177 def decryptcounter(self): 176 178 self.c_o = (self.c_o + 1) % (2 ** self.n) … … 232 234 def decompress(self, compressed): 233 235 if self.compression == None: 234 return compressed 236 return compressed 235 237 236 238 def encrypt(self, encryptable): … … 344 346 345 347 mac_o_calculated = self.hmac(self.ks_o, content) 346 348 347 349 if self.negotiated['recv_pubkey']: 348 350 hash = crypto.sha256(mac_o_calculated) … … 381 383 b64ed = base64.b64encode(self.hash(pubkey_s)) 382 384 pubkey_s = '<fingerprint>%s</fingerprint>' % b64ed 383 385 384 386 id_s = self.encrypt(pubkey_s + sign_s) 385 387 else: … … 396 398 # XXX save retained secret? 397 399 self.check_identity(lambda : ()) 398 400 399 401 return (xmpp.DataField(name='identity', value=base64.b64encode(id_s)), \ 400 402 xmpp.DataField(name='mac', value=base64.b64encode(m_s))) … … 438 440 439 441 self.n_s = crypto.generate_nonce() 440 442 441 443 x.addChild(node=xmpp.DataField(name='my_nonce', value=base64.b64encode(self.n_s), typ='hidden')) 442 444 … … 455 457 456 458 self.send(request) 457 459 458 460 # 4.3 esession response (bob) 459 461 def verify_options_bob(self, form): … … 571 573 572 574 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), 575 577 'nonce': self.n_o } 576 578 … … 667 669 self.verify_identity(form, self.d, True, 'b') 668 670 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()) 670 672 rshashes = [self.hmac(self.n_s, rs) for (rs,v) in srses] 671 673 … … 678 680 result.addChild(node=xmpp.DataField(name='rshashes', value=rshashes)) 679 681 result.addChild(node=xmpp.DataField(name='dhkeys', value=base64.b64encode(crypto.encode_mpi(e)))) 680 682 681 683 self.form_o = ''.join(map(lambda el: xmpp.c14n.c14n(el), form.getChildren())) 682 684 … … 688 690 feature.addChild(node=result) 689 691 self.send(accept) 690 692 691 693 if self.sigmai: 692 694 self.status = 'active' … … 694 696 else: 695 697 self.status = 'identified-alice' 696 698 697 699 # 4.5 esession accept (bob) 698 700 def accept_e2e_bob(self, form): … … 725 727 726 728 srs = '' 727 729 728 730 srses = secrets.secrets().retained_secrets(self.conn.name, self.jid.getStripped()) 729 731 rshashes = [base64.b64decode(rshash) for rshash in form.getField('rshashes').getValues()] … … 768 770 self.enable_encryption = True 769 771 772 if hasattr(self, 'control'): 773 self.control.print_esession_details() 774 770 775 def final_steps_alice(self, form): 771 776 srs = '' … … 794 799 self.verify_identity(form, self.d, False, 'b') 795 800 # Note: If Alice discovers an error then she SHOULD ignore any encrypted content she received in the stanza. 796 801 797 802 if self.negotiated['logging'] == 'mustnot': 798 803 self.loggable = False … … 800 805 self.status = 'active' 801 806 self.enable_encryption = True 807 808 if hasattr(self, 'control'): 809 self.control.print_esession_details() 802 810 803 811 # calculate and store the new retained secret
