Ticket #733: gpg-agent-hawke.patch

File gpg-agent-hawke.patch, 8.7 KB (added by hawke, 5 years ago)

Modified patch which also fixes the BADSIG detection and does not sign auto-presence

  • src/common/connection.py

     
    13831383                        #Get bookmarks from private namespace 
    13841384                        self.get_bookmarks() 
    13851385         
    1386         def change_status(self, show, msg, sync = False): 
     1386        def change_status(self, show, msg, sync = False, auto = False): 
    13871387                if sync: 
    1388                         self.change_status2(show, msg) 
     1388                        self.change_status2(show, msg, auto) 
    13891389                else: 
    1390                         t = threading.Thread(target=self.change_status2, args = (show, msg)) 
     1390                        t = threading.Thread(target=self.change_status2, args = (show, msg, auto)) 
    13911391                        t.start() 
    13921392 
    1393         def change_status2(self, show, msg): 
     1393        def change_status2(self, show, msg, auto = False): 
    13941394                if not show in STATUS_LIST: 
    13951395                        return -1 
    13961396                sshow = show # show to be send 
    13971397                if show == 'online': 
    13981398                        sshow = None 
    1399                 signed = '' 
    14001399                if not msg: 
    14011400                        lowered_uf_status_msg = helpers.get_uf_show(show).lower() 
    14021401                        if lowered_uf_status_msg == _('invisible'): # do not show I'm invisible! 
    14031402                                lowered_uf_status_msg = _('offline') 
    14041403                        msg = _("I'm %s") % lowered_uf_status_msg 
     1404 
     1405                # sign presence 
     1406                signed = '' 
    14051407                keyID = gajim.config.get_per('accounts', self.name, 'keyid') 
    1406                 if keyID and USE_GPG: 
    1407                         if self.connected < 2 and self.gpg.passphrase is None: 
     1408                if keyID and USE_GPG and not auto and not show == 'offline': 
     1409                        # translates to: 
     1410                        # if we are not yet online, 
     1411                        # were not given a passphrase 
     1412                        # and won't use the gpg-agent 
     1413                        #   then cry out loud. 
     1414                        use_gpg_agent = gajim.config.get('usegpgagent') 
     1415                        if self.connected < 2 and self.gpg.passphrase is None and not use_gpg_agent: 
    14081416                                # We didn't set a passphrase 
    14091417                                self.dispatch('ERROR', (_('OpenPGP passphrase was not given'), 
    14101418                                        #%s is the account name here 
    14111419                                        _('You will be connected to %s without OpenPGP.') % self.name)) 
    1412                         else: 
     1420                        # ... we have a passphrase or use the agent, so we can sign 
     1421                        elif self.gpg.passphrase is not None or use_gpg_agent: 
    14131422                                signed = self.gpg.sign(msg, keyID) 
    14141423                                if signed == 'BAD_PASSPHRASE': 
    14151424                                        signed = '' 
    14161425                                        if self.connected < 2: 
    14171426                                                self.dispatch('BAD_PASSPHRASE', ()) 
     1427                        else: 
     1428                                signed = '' 
    14181429                self.status = msg 
    14191430                if show != 'offline' and not self.connected: 
    14201431                        self.connection = self.connect() 
     
    18481859 
    18491860        def gpg_passphrase(self, passphrase): 
    18501861                if USE_GPG: 
    1851                         self.gpg.passphrase = passphrase 
     1862                        use_gpg_agent = gajim.config.get('usegpgagent') 
     1863                        if use_gpg_agent: 
     1864                                self.gpg.passphrase = None 
     1865                        else: 
     1866                                self.gpg.passphrase = passphrase 
    18521867 
    18531868        def ask_gpg_keys(self): 
    18541869                if USE_GPG: 
  • src/common/config.py

     
    108108                'send_os_info': [ opt_bool, True ], 
    109109                'check_for_new_version': [ opt_bool, False ], 
    110110                'usegpg': [ opt_bool, False ], 
     111                'usegpgagent': [ opt_bool, False ], 
    111112                'log_notif_in_user_file': [ opt_bool, True ], 
    112113                'log_notif_in_sep_file': [ opt_bool, True ], 
    113114                'change_roster_title': [ opt_bool, True ], 
  • src/common/GnuPG.py

     
    1717## GNU General Public License for more details. 
    1818## 
    1919 
    20 from tempfile import * 
     20##from tempfile import * 
     21from os import tmpfile 
    2122 
    2223USE_GPG = True 
    2324 
     
    115116 
    116117                        try: proc.wait() 
    117118                        except IOError: pass 
    118                         if resp.has_key('GOOD_PASSPHRASE'): 
     119                        if resp.has_key('GOOD_PASSPHRASE') or resp.has_key('SIG_CREATED'): 
    119120                                return self._stripHeaderFooter(output) 
    120121                        return 'BAD_PASSPHRASE' 
    121122 
     
    124125                                return str 
    125126                        if not str: 
    126127                                return '' 
    127                         f = TemporaryFile(prefix='gajim') 
     128                        #f = TemporaryFile(prefix='gajim') 
     129                        f = tmpfile() 
    128130                        fd = f.fileno() 
    129131                        f.write(str) 
    130132                        f.seek(0) 
     
    147149                        keyid = '' 
    148150                        if resp.has_key('GOODSIG'): 
    149151                                keyid = resp['GOODSIG'].split()[0] 
    150                         elif resp.has_key('BADSIG'): 
    151                                 keyid = resp['BADSIG'].split()[0] 
     152                        #elif resp.has_key('BADSIG'): 
     153                        #       keyid = resp['BADSIG'].split()[0] 
    152154                        return keyid 
    153155 
    154156                def get_keys(self, secret = False): 
  • src/roster_window.py

     
    11711171                        del self.gpg_passphrase[keyid] 
    11721172                return False 
    11731173 
    1174         def send_status(self, account, status, txt, sync = False): 
     1174        def send_status(self, account, status, txt, sync = False, auto = False): 
    11751175                if status != 'offline': 
    11761176                        if gajim.connections[account].connected < 2: 
    11771177                                model = self.tree.get_model() 
     
    12021202                                        gajim.config.set_per('accounts', account, 'password', passphrase) 
    12031203 
    12041204                        keyid = None 
    1205                         save_gpg_pass = True 
    1206                         save_gpg_pass = gajim.config.get_per('accounts', account,  
    1207                                 'savegpgpass') 
     1205                        use_gpg_agent = gajim.config.get('usegpgagent') 
     1206                        # we don't need to bother with the passphrase if we use the agent 
     1207                        if use_gpg_agent: 
     1208                                save_gpg_pass = False 
     1209                        else: 
     1210                                save_gpg_pass = gajim.config.get_per('accounts', account,  
     1211                                        'savegpgpass') 
    12081212                        keyid = gajim.config.get_per('accounts', account, 'keyid') 
    12091213                        if keyid and gajim.connections[account].connected < 2 and \ 
    12101214                                gajim.config.get('usegpg'): 
    1211                                 if save_gpg_pass: 
    1212                                         passphrase = gajim.config.get_per('accounts', account,  
    1213                                                                                                                                         'gpgpassword') 
     1215                                 
     1216                                if use_gpg_agent: 
     1217                                        self.gpg_passphrase[keyid] = None 
    12141218                                else: 
    1215                                         if self.gpg_passphrase.has_key(keyid): 
    1216                                                 passphrase = self.gpg_passphrase[keyid] 
    1217                                                 save = False 
     1219                                        if save_gpg_pass: 
     1220                                                passphrase = gajim.config.get_per('accounts', account, 'gpgpassword') 
    12181221                                        else: 
    1219                                                 w = dialogs.PassphraseDialog( 
    1220                                                         _('Passphrase Required'), 
    1221                                                         _('Enter GPG key passphrase for account %s') % account,  
    1222                                                         _('Save passphrase')) 
    1223                                                 passphrase, save = w.run() 
    1224                                         if passphrase == -1: 
    1225                                                 passphrase = None 
    1226                                         else: 
    1227                                                 self.gpg_passphrase[keyid] = passphrase 
    1228                                                 gobject.timeout_add(30000, self.forget_gpg_passphrase, keyid) 
    1229                                         if save: 
    1230                                                 gajim.config.set_per('accounts', account, 'savegpgpass', True) 
    1231                                                 gajim.config.set_per('accounts', account, 'gpgpassword',  
    1232                                                                                                         passphrase) 
    1233                                 gajim.connections[account].gpg_passphrase(passphrase) 
    1234                 gajim.connections[account].change_status(status, txt, sync) 
     1222                                                if self.gpg_passphrase.has_key(keyid): 
     1223                                                        passphrase = self.gpg_passphrase[keyid] 
     1224                                                        save = False 
     1225                                                else: 
     1226                                                        w = dialogs.PassphraseDialog( 
     1227                                                                _('Passphrase Required'), 
     1228                                                                _('Enter GPG key passphrase for account %s') % account,  
     1229                                                                _('Save passphrase')) 
     1230                                                        passphrase, save = w.run() 
     1231                                                if passphrase == -1: 
     1232                                                        passphrase = None 
     1233                                                else: 
     1234                                                        self.gpg_passphrase[keyid] = passphrase 
     1235                                                        gobject.timeout_add(30000, self.forget_gpg_passphrase, keyid) 
     1236                                                if save: 
     1237                                                        gajim.config.set_per('accounts', account, 'savegpgpass', True) 
     1238                                                        gajim.config.set_per('accounts', account, 'gpgpassword',  
     1239                                                                                                                passphrase) 
     1240                                        gajim.connections[account].gpg_passphrase(passphrase) 
     1241                                         
     1242                gajim.connections[account].change_status(status, txt, sync, auto) 
    12351243                for room_jid in self.plugin.windows[account]['gc']: 
    12361244                        if room_jid != 'tabbed': 
    12371245                                nick = self.plugin.windows[account]['gc'][room_jid].nicks[room_jid] 
  • src/gajim.py

     
    658658                        config.GroupchatConfigWindow(self, account, jid, array[1]) 
    659659 
    660660        def handle_event_bad_passphrase(self, account, array): 
     661                use_gpg_agent = gajim.config.get('usegpgagent', False) 
     662                if use_gpg_agent: 
     663                  return 
    661664                keyID = gajim.config.get_per('accounts', account, 'keyid') 
    662665                self.roster.forget_gpg_passphrase(keyID) 
    663666                dialogs.WarningDialog(_('Your passphrase is incorrect'), 
     
    822825                                #we save out online status 
    823826                                gajim.status_before_autoaway[account] = \ 
    824827                                        gajim.connections[account].status 
    825                                 #we go away 
     828                                #we go away (noting auto status) 
    826829                                self.roster.send_status(account, 'away', 
    827                                         gajim.config.get('autoaway_message')) 
     830                                        gajim.config.get('autoaway_message',True)) 
    828831                                gajim.sleeper_state[account] = 'autoaway' 
    829832                        elif state == common.sleepy.STATE_XAWAY and (\ 
    830833                                gajim.sleeper_state[account] == 'autoaway' or \ 
     
    832835                                gajim.config.get('autoxa'): 
    833836                                #we go extended away 
    834837                                self.roster.send_status(account, 'xa', 
    835                                         gajim.config.get('autoxa_message')) 
     838                                        gajim.config.get('autoxa_message', True)) 
    836839                                gajim.sleeper_state[account] = 'autoxa' 
    837840                return True # renew timeout (loop for ever) 
    838841