[Hawke patches Lukas patch :D] now Gajim can use gpg-agent

This commit is contained in:
Nikos Kouremenos 2005-08-30 21:10:14 +00:00
parent 4902e17742
commit 7d2a698fc9
5 changed files with 57 additions and 41 deletions

View file

@ -17,7 +17,7 @@
## GNU General Public License for more details. ## GNU General Public License for more details.
## ##
from tempfile import * from os import tmpfile
USE_GPG = True USE_GPG = True
@ -115,7 +115,7 @@ else:
try: proc.wait() try: proc.wait()
except IOError: pass except IOError: pass
if resp.has_key('GOOD_PASSPHRASE'): if resp.has_key('GOOD_PASSPHRASE') or resp.has_key('SIG_CREATED'):
return self._stripHeaderFooter(output) return self._stripHeaderFooter(output)
return 'BAD_PASSPHRASE' return 'BAD_PASSPHRASE'
@ -124,7 +124,7 @@ else:
return str return str
if not str: if not str:
return '' return ''
f = TemporaryFile(prefix='gajim') f = tmpfile()
fd = f.fileno() fd = f.fileno()
f.write(str) f.write(str)
f.seek(0) f.seek(0)
@ -147,8 +147,6 @@ else:
keyid = '' keyid = ''
if resp.has_key('GOODSIG'): if resp.has_key('GOODSIG'):
keyid = resp['GOODSIG'].split()[0] keyid = resp['GOODSIG'].split()[0]
elif resp.has_key('BADSIG'):
keyid = resp['BADSIG'].split()[0]
return keyid return keyid
def get_keys(self, secret = False): def get_keys(self, secret = False):

View file

@ -108,6 +108,7 @@ class Config:
'send_os_info': [ opt_bool, True ], 'send_os_info': [ opt_bool, True ],
'check_for_new_version': [ opt_bool, False ], 'check_for_new_version': [ opt_bool, False ],
'usegpg': [ opt_bool, False ], 'usegpg': [ opt_bool, False ],
'use_gpg_agent': [ opt_bool, False ],
'log_notif_in_user_file': [ opt_bool, True ], 'log_notif_in_user_file': [ opt_bool, True ],
'log_notif_in_sep_file': [ opt_bool, True ], 'log_notif_in_sep_file': [ opt_bool, True ],
'change_roster_title': [ opt_bool, True ], 'change_roster_title': [ opt_bool, True ],

View file

@ -1383,33 +1383,35 @@ class Connection:
#Get bookmarks from private namespace #Get bookmarks from private namespace
self.get_bookmarks() self.get_bookmarks()
def change_status(self, show, msg, sync = False): def change_status(self, show, msg, sync = False, auto = False):
if sync: if sync:
self.change_status2(show, msg) self.change_status2(show, msg, auto)
else: else:
t = threading.Thread(target=self.change_status2, args = (show, msg)) t = threading.Thread(target=self.change_status2, args = (show, msg, auto))
t.start() t.start()
def change_status2(self, show, msg): def change_status2(self, show, msg, auto = False):
if not show in STATUS_LIST: if not show in STATUS_LIST:
return -1 return -1
sshow = show # show to be send sshow = show # show to be send
if show == 'online': if show == 'online':
sshow = None sshow = None
signed = ''
if not msg: if not msg:
lowered_uf_status_msg = helpers.get_uf_show(show).lower() lowered_uf_status_msg = helpers.get_uf_show(show).lower()
if lowered_uf_status_msg == _('invisible'): # do not show I'm invisible! if lowered_uf_status_msg == _('invisible'): # do not show I'm invisible!
lowered_uf_status_msg = _('offline') lowered_uf_status_msg = _('offline')
msg = _("I'm %s") % lowered_uf_status_msg msg = _("I'm %s") % lowered_uf_status_msg
signed = ''
keyID = gajim.config.get_per('accounts', self.name, 'keyid') keyID = gajim.config.get_per('accounts', self.name, 'keyid')
if keyID and USE_GPG: if keyID and USE_GPG and not auto and not show == 'offline':
if self.connected < 2 and self.gpg.passphrase is None: use_gpg_agent = gajim.config.get('use_gpg_agent')
if self.connected < 2 and self.gpg.passphrase is None and not use_gpg_agent:
# We didn't set a passphrase # We didn't set a passphrase
self.dispatch('ERROR', (_('OpenPGP passphrase was not given'), self.dispatch('ERROR', (_('OpenPGP passphrase was not given'),
#%s is the account name here #%s is the account name here
_('You will be connected to %s without OpenPGP.') % self.name)) _('You will be connected to %s without OpenPGP.') % self.name))
else: elif self.gpg.passphrase is not None or use_gpg_agent:
signed = self.gpg.sign(msg, keyID) signed = self.gpg.sign(msg, keyID)
if signed == 'BAD_PASSPHRASE': if signed == 'BAD_PASSPHRASE':
signed = '' signed = ''
@ -1848,7 +1850,11 @@ class Connection:
def gpg_passphrase(self, passphrase): def gpg_passphrase(self, passphrase):
if USE_GPG: if USE_GPG:
self.gpg.passphrase = passphrase use_gpg_agent = gajim.config.get('use_gpg_agent')
if use_gpg_agent:
self.gpg.passphrase = None
else:
self.gpg.passphrase = passphrase
def ask_gpg_keys(self): def ask_gpg_keys(self):
if USE_GPG: if USE_GPG:

View file

@ -658,6 +658,9 @@ class Interface:
config.GroupchatConfigWindow(self, account, jid, array[1]) config.GroupchatConfigWindow(self, account, jid, array[1])
def handle_event_bad_passphrase(self, account, array): def handle_event_bad_passphrase(self, account, array):
use_gpg_agent = gajim.config.get('use_gpg_agent')
if use_gpg_agent:
return
keyID = gajim.config.get_per('accounts', account, 'keyid') keyID = gajim.config.get_per('accounts', account, 'keyid')
self.roster.forget_gpg_passphrase(keyID) self.roster.forget_gpg_passphrase(keyID)
dialogs.WarningDialog(_('Your passphrase is incorrect'), dialogs.WarningDialog(_('Your passphrase is incorrect'),
@ -822,7 +825,7 @@ class Interface:
#we save out online status #we save out online status
gajim.status_before_autoaway[account] = \ gajim.status_before_autoaway[account] = \
gajim.connections[account].status gajim.connections[account].status
#we go away #we go away (no auto status)
self.roster.send_status(account, 'away', self.roster.send_status(account, 'away',
gajim.config.get('autoaway_message')) gajim.config.get('autoaway_message'))
gajim.sleeper_state[account] = 'autoaway' gajim.sleeper_state[account] = 'autoaway'

View file

@ -1171,7 +1171,7 @@ _('If "%s" accepts this request you will know his status.') %jid)
del self.gpg_passphrase[keyid] del self.gpg_passphrase[keyid]
return False return False
def send_status(self, account, status, txt, sync = False): def send_status(self, account, status, txt, sync = False, auto = False):
if status != 'offline': if status != 'offline':
if gajim.connections[account].connected < 2: if gajim.connections[account].connected < 2:
model = self.tree.get_model() model = self.tree.get_model()
@ -1202,36 +1202,44 @@ _('If "%s" accepts this request you will know his status.') %jid)
gajim.config.set_per('accounts', account, 'password', passphrase) gajim.config.set_per('accounts', account, 'password', passphrase)
keyid = None keyid = None
save_gpg_pass = True use_gpg_agent = gajim.config.get('use_gpg_agent')
save_gpg_pass = gajim.config.get_per('accounts', account, # we don't need to bother with the passphrase if we use the agent
'savegpgpass') if use_gpg_agent:
save_gpg_pass = False
else:
save_gpg_pass = gajim.config.get_per('accounts', account,
'savegpgpass')
keyid = gajim.config.get_per('accounts', account, 'keyid') keyid = gajim.config.get_per('accounts', account, 'keyid')
if keyid and gajim.connections[account].connected < 2 and \ if keyid and gajim.connections[account].connected < 2 and \
gajim.config.get('usegpg'): gajim.config.get('usegpg'):
if save_gpg_pass:
passphrase = gajim.config.get_per('accounts', account, if use_gpg_agent:
'gpgpassword') self.gpg_passphrase[keyid] = None
else: else:
if self.gpg_passphrase.has_key(keyid): if save_gpg_pass:
passphrase = self.gpg_passphrase[keyid] passphrase = gajim.config.get_per('accounts', account, 'gpgpassword')
save = False
else: else:
w = dialogs.PassphraseDialog( if self.gpg_passphrase.has_key(keyid):
_('Passphrase Required'), passphrase = self.gpg_passphrase[keyid]
_('Enter GPG key passphrase for account %s') % account, save = False
_('Save passphrase')) else:
passphrase, save = w.run() w = dialogs.PassphraseDialog(
if passphrase == -1: _('Passphrase Required'),
passphrase = None _('Enter GPG key passphrase for account %s') % account,
else: _('Save passphrase'))
self.gpg_passphrase[keyid] = passphrase passphrase, save = w.run()
gobject.timeout_add(30000, self.forget_gpg_passphrase, keyid) if passphrase == -1:
if save: passphrase = None
gajim.config.set_per('accounts', account, 'savegpgpass', True) else:
gajim.config.set_per('accounts', account, 'gpgpassword', self.gpg_passphrase[keyid] = passphrase
passphrase) gobject.timeout_add(30000, self.forget_gpg_passphrase, keyid)
gajim.connections[account].gpg_passphrase(passphrase) if save:
gajim.connections[account].change_status(status, txt, sync) gajim.config.set_per('accounts', account, 'savegpgpass', True)
gajim.config.set_per('accounts', account, 'gpgpassword',
passphrase)
gajim.connections[account].gpg_passphrase(passphrase)
gajim.connections[account].change_status(status, txt, sync, auto)
for room_jid in self.plugin.windows[account]['gc']: for room_jid in self.plugin.windows[account]['gc']:
if room_jid != 'tabbed': if room_jid != 'tabbed':
nick = self.plugin.windows[account]['gc'][room_jid].nicks[room_jid] nick = self.plugin.windows[account]['gc'][room_jid].nicks[room_jid]