Philipp Hörist pushed to branch master at gajim / gajim

Commits:

3 changed files:

Changes:

  • gajim/common/modules/omemo.py
    ... ... @@ -50,7 +50,7 @@
    50 50
     from omemo_dr.exceptions import KeyExchangeMessage
    
    51 51
     from omemo_dr.exceptions import MessageNotForDevice
    
    52 52
     from omemo_dr.exceptions import SelfMessage
    
    53
    -from omemo_dr.session import OMEMOSession
    
    53
    +from omemo_dr.session_manager import OMEMOSessionManager
    
    54 54
     from omemo_dr.structs import OMEMOBundle
    
    55 55
     from omemo_dr.structs import OMEMOConfig
    
    56 56
     
    
    ... ... @@ -138,7 +138,8 @@ def __init__(self, client: types.Client) -> None:
    138 138
                                        spk_cycle_seconds=86400,
    
    139 139
                                        unacknowledged_count=2000)
    
    140 140
     
    
    141
    -        self._backend = OMEMOSession(self._own_jid, storage, omemo_config)
    
    141
    +        self._backend = OMEMOSessionManager(
    
    142
    +            self._own_jid, storage, omemo_config)
    
    142 143
             self._backend.register_signal('republish-bundle',
    
    143 144
                                           self._on_republish_bundle)
    
    144 145
     
    
    ... ... @@ -179,7 +180,7 @@ def _on_room_joined(self,
    179 180
                 self.get_affiliation_list(jid)
    
    180 181
     
    
    181 182
         def _on_republish_bundle(self,
    
    182
    -                             _session: OMEMOSession,
    
    183
    +                             _session: OMEMOSessionManager,
    
    183 184
                                  _signal_name: str,
    
    184 185
                                  bundle: OMEMOBundle
    
    185 186
                                  ) -> None:
    
    ... ... @@ -187,7 +188,7 @@ def _on_republish_bundle(self,
    187 188
             self.set_bundle(bundle=bundle)
    
    188 189
     
    
    189 190
         @property
    
    190
    -    def backend(self) -> OMEMOSession:
    
    191
    +    def backend(self) -> OMEMOSessionManager:
    
    191 192
             return self._backend
    
    192 193
     
    
    193 194
         def check_send_preconditions(self, contact: types.ChatContactT) -> bool:
    
    ... ... @@ -222,17 +223,15 @@ def check_send_preconditions(self, contact: types.ChatContactT) -> bool:
    222 223
                         message=EncryptionInfoMsg.QUERY_DEVICES))
    
    223 224
                     return False
    
    224 225
     
    
    225
    -            # check if bundles are missing for some devices
    
    226
    -            if self.backend.storage.has_undecided_fingerprints(jid):
    
    227
    -                self._log.info('%s => Undecided Fingerprints for %s',
    
    228
    -                               contact.account, jid)
    
    229
    -                app.ged.raise_event(EncryptionInfo(
    
    230
    -                    account=contact.account,
    
    231
    -                    jid=contact.jid,
    
    232
    -                    message=EncryptionInfoMsg.UNDECIDED_FINGERPRINTS))
    
    233
    -                return False
    
    234
    -
    
    235
    -        if self._new_fingerprints_available(contact):
    
    226
    +        if self.backend.get_identity_infos(jid,
    
    227
    +                                           only_active=True,
    
    228
    +                                           trust=OMEMOTrust.UNDECIDED):
    
    229
    +            self._log.info('%s => Undecided Fingerprints for %s',
    
    230
    +                           contact.account, jid)
    
    231
    +            app.ged.raise_event(EncryptionInfo(
    
    232
    +                account=contact.account,
    
    233
    +                jid=contact.jid,
    
    234
    +                message=EncryptionInfoMsg.UNDECIDED_FINGERPRINTS))
    
    236 235
                 return False
    
    237 236
     
    
    238 237
             self._log.debug('%s => Sending Message to %s',
    
    ... ... @@ -240,30 +239,6 @@ def check_send_preconditions(self, contact: types.ChatContactT) -> bool:
    240 239
     
    
    241 240
             return True
    
    242 241
     
    
    243
    -    def _new_fingerprints_available(self, contact: types.ChatContactT) -> bool:
    
    244
    -        fingerprints: list[int] = []
    
    245
    -        if contact.is_groupchat:
    
    246
    -            for member_jid in self.backend.get_group_members(str(contact.jid),
    
    247
    -                                                           without_self=False):
    
    248
    -                fingerprints = self.backend.storage.get_new_fingerprints(
    
    249
    -                    member_jid)
    
    250
    -                if fingerprints:
    
    251
    -                    break
    
    252
    -
    
    253
    -        else:
    
    254
    -            fingerprints = self.backend.storage.get_new_fingerprints(
    
    255
    -                str(contact.jid))
    
    256
    -
    
    257
    -        if not fingerprints:
    
    258
    -            return False
    
    259
    -
    
    260
    -        app.ged.raise_event(EncryptionInfo(
    
    261
    -            account=contact.account,
    
    262
    -            jid=contact.jid,
    
    263
    -            message=EncryptionInfoMsg.UNDECIDED_FINGERPRINTS))
    
    264
    -
    
    265
    -        return True
    
    266
    -
    
    267 242
         def is_omemo_groupchat(self, room_jid: str) -> bool:
    
    268 243
             return room_jid in self._omemo_groupchats
    
    269 244
     
    
    ... ... @@ -417,15 +392,9 @@ def _process_muc_message(self,
    417 392
             if contact.real_jid is not None:
    
    418 393
                 return contact.real_jid.bare
    
    419 394
     
    
    420
    -        assert isinstance(properties.omemo, OMEMOMessage)
    
    421
    -        self._log.info('Groupchat: Last resort trying to find SID in DB')
    
    422
    -        from_jid = self.backend.storage.get_jid_from_device(
    
    423
    -            properties.omemo.sid)
    
    424
    -        if not from_jid:
    
    425
    -            self._log.error(
    
    426
    -                "Can't decrypt GroupChat Message from %s", resource)
    
    427
    -            return None
    
    428
    -        return from_jid
    
    395
    +        self._log.error(
    
    396
    +            'Unable to find JID for group chat message from %s', resource)
    
    397
    +        return None
    
    429 398
     
    
    430 399
         def _process_mam_message(self,
    
    431 400
                                  properties: MessageProperties
    
    ... ... @@ -564,8 +533,12 @@ def are_keys_missing(self, contact_jid: str) -> bool:
    564 533
                     for device_id in devices_without_session:
    
    565 534
                         self.request_bundle(contact_jid, device_id)
    
    566 535
     
    
    567
    -        if self.backend.has_trusted_keys(contact_jid):
    
    536
    +        if self.backend.get_identity_infos(
    
    537
    +                contact_jid,
    
    538
    +                only_active=True,
    
    539
    +                trust=[OMEMOTrust.VERIFIED, OMEMOTrust.BLIND]):
    
    568 540
                 return False
    
    541
    +
    
    569 542
             return True
    
    570 543
     
    
    571 544
         def set_bundle(self, bundle: OMEMOBundle | None = None) -> None:
    

  • gajim/common/storage/omemo.py
    ... ... @@ -712,17 +712,6 @@ def get_muc_fingerprints(self, jids: list[str]):
    712 712
     
    
    713 713
             return self._con.execute(query, jids).fetchall()
    
    714 714
     
    
    715
    -    def has_undecided_fingerprints(self, jid: str) -> bool:
    
    716
    -        query = '''SELECT public_key as "public_key [pk]" FROM identities
    
    717
    -                   WHERE recipient_id = ? AND trust = ?'''
    
    718
    -        result = self._con.execute(query,
    
    719
    -                                   (jid, OMEMOTrust.UNDECIDED)).fetchall()
    
    720
    -        undecided = [row.public_key for row in result]
    
    721
    -
    
    722
    -        inactive = self.get_inactive_sessions_keys(jid)
    
    723
    -        undecided = set(undecided) - set(inactive)
    
    724
    -        return bool(undecided)
    
    725
    -
    
    726 715
         def get_default_trust(self, jid: str) -> OMEMOTrust:
    
    727 716
             if not self._is_blind_trust_enabled():
    
    728 717
                 return OMEMOTrust.UNDECIDED
    
    ... ... @@ -734,25 +723,6 @@ def get_default_trust(self, jid: str) -> OMEMOTrust:
    734 723
                 return OMEMOTrust.BLIND
    
    735 724
             return OMEMOTrust.UNDECIDED
    
    736 725
     
    
    737
    -    def get_trusted_fingerprints(self, address: str) -> list[IdentityKey]:
    
    738
    -        query = '''SELECT public_key as "public_key [pk]" FROM identities
    
    739
    -                   WHERE recipient_id = ? AND trust IN(1, 3)'''
    
    740
    -        result = self._con.execute(query, (address,)).fetchall()
    
    741
    -        return [row.public_key for row in result]
    
    742
    -
    
    743
    -    def get_new_fingerprints(self, jid: str) -> list[int]:
    
    744
    -        query = '''SELECT _id FROM identities WHERE shown = 0
    
    745
    -                   AND recipient_id = ?'''
    
    746
    -
    
    747
    -        result = self._con.execute(query, (jid,)).fetchall()
    
    748
    -        return [row.id for row in result]
    
    749
    -
    
    750
    -    def set_shown_fingerprints(self, fingerprints: list[int]) -> None:
    
    751
    -        query = 'UPDATE identities SET shown = 1 WHERE _id IN ({})'.format(
    
    752
    -            ', '.join(['?'] * len(fingerprints)))
    
    753
    -        self._con.execute(query, fingerprints)
    
    754
    -        self._con.commit()
    
    755
    -
    
    756 726
         def set_trust(self,
    
    757 727
                       recipient_id: str,
    
    758 728
                       identity_key: IdentityKey,
    

  • gajim/gtk/omemo_trust_manager.py
    ... ... @@ -306,13 +306,10 @@ def _on_destroy(self, *args: Any) -> None:
    306 306
         def delete_fingerprint(self, *args: Any) -> None:
    
    307 307
     
    
    308 308
             def _remove():
    
    309
    -            device_id = self._identity_info.device_id
    
    310
    -
    
    311
    -            self._omemo.backend.remove_device(self._address, device_id)
    
    312
    -            self._omemo.backend.storage.delete_session(self._address,
    
    313
    -                                                       device_id)
    
    314
    -            self._omemo.backend.storage.delete_identity(
    
    315
    -                self._address, self._identity_info.public_key)
    
    309
    +            self._omemo.backend.delete_session(
    
    310
    +                self._address,
    
    311
    +                self._identity_info.device_id,
    
    312
    +                delete_identity=True)
    
    316 313
     
    
    317 314
                 listbox = cast(Gtk.ListBox, self.get_parent())
    
    318 315
                 listbox.remove(self)
    
    ... ... @@ -336,7 +333,7 @@ def set_trust(self, trust: OMEMOTrust) -> None:
    336 333
             image.get_style_context().add_class(css_class)
    
    337 334
             image.set_tooltip_text(tooltip)
    
    338 335
     
    
    339
    -        self._omemo.backend.storage.set_trust(
    
    336
    +        self._omemo.backend.set_trust(
    
    340 337
                 self._address, self._identity_info.public_key, trust)
    
    341 338
     
    
    342 339
         @property