Ticket #3631: gajim-keyring.diff

File gajim-keyring.diff, 1.9 kB (added by asterix, 11 months ago)
  • src/common/passwords.py

     
    1919 
    2020__all__ = ['get_password', 'save_password'] 
    2121 
     22import warnings 
    2223from common import gajim 
    2324 
    2425USER_HAS_GNOMEKEYRING = False 
     
    6263                conf = gajim.config.get_per('accounts', account_name, 'password') 
    6364                if conf is None: 
    6465                        return None 
    65                 try: 
    66                         unused, auth_token = conf.split('gnomekeyring:') 
    67                         auth_token = int(auth_token) 
    68                 except ValueError: 
     66 
     67                if not conf.startswith('gnomekeyring:'): 
    6968                        password = conf 
    7069                        ## migrate the password over to keyring 
    7170                        try: 
     
    7574                                set_storage(SimplePasswordStorage()) 
    7675                        return password 
    7776                try: 
    78                         return gnomekeyring.item_get_info_sync(self.keyring, 
    79                                 auth_token).get_secret() 
     77                        attributes = dict(account_name=str(account_name), gajim=1) 
     78                        try: 
     79                                items = gnomekeyring.find_items_sync( 
     80                                        gnomekeyring.ITEM_GENERIC_SECRET, 
     81                                        attributes) 
     82                        except gnomekeyring.Error: 
     83                                items = [] 
     84                        if len(items) > 1: 
     85                                warnings.warn("multiple gnome keyring items found for account %s;" 
     86                                              " trying to use the first one..." 
     87                                              % account_name) 
     88                        if items: 
     89                                return items[0].secret 
     90                        else: 
     91                                return None 
    8092                except gnomekeyring.DeniedError: 
    8193                        return None 
    8294                except gnomekeyring.NoKeyringDaemonError: 
     
    95107                        set_storage(SimplePasswordStorage()) 
    96108                        storage.save_password(account_name, password) 
    97109                        return 
    98                 token = 'gnomekeyring:%i' % auth_token 
    99                 gajim.config.set_per('accounts', account_name, 'password', token) 
     110                ## Note: the auth token is in fact no longer used for anything 
     111                gajim.config.set_per('accounts', account_name, 'password', 'gnomekeyring:') 
    100112                if gajim.connections.has_key(account_name): 
    101113                        gajim.connections[account_name].password = password 
    102114