[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.
##
from tempfile import *
from os import tmpfile
USE_GPG = True
@ -115,7 +115,7 @@ else:
try: proc.wait()
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 'BAD_PASSPHRASE'
@ -124,7 +124,7 @@ else:
return str
if not str:
return ''
f = TemporaryFile(prefix='gajim')
f = tmpfile()
fd = f.fileno()
f.write(str)
f.seek(0)
@ -147,8 +147,6 @@ else:
keyid = ''
if resp.has_key('GOODSIG'):
keyid = resp['GOODSIG'].split()[0]
elif resp.has_key('BADSIG'):
keyid = resp['BADSIG'].split()[0]
return keyid
def get_keys(self, secret = False):

View File

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

View File

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

View File

@ -658,6 +658,9 @@ class Interface:
config.GroupchatConfigWindow(self, account, jid, array[1])
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')
self.roster.forget_gpg_passphrase(keyID)
dialogs.WarningDialog(_('Your passphrase is incorrect'),
@ -822,7 +825,7 @@ class Interface:
#we save out online status
gajim.status_before_autoaway[account] = \
gajim.connections[account].status
#we go away
#we go away (no auto status)
self.roster.send_status(account, 'away',
gajim.config.get('autoaway_message'))
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]
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 gajim.connections[account].connected < 2:
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)
keyid = None
save_gpg_pass = True
save_gpg_pass = gajim.config.get_per('accounts', account,
'savegpgpass')
use_gpg_agent = gajim.config.get('use_gpg_agent')
# we don't need to bother with the passphrase if we use the agent
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')
if keyid and gajim.connections[account].connected < 2 and \
gajim.config.get('usegpg'):
if save_gpg_pass:
passphrase = gajim.config.get_per('accounts', account,
'gpgpassword')
if use_gpg_agent:
self.gpg_passphrase[keyid] = None
else:
if self.gpg_passphrase.has_key(keyid):
passphrase = self.gpg_passphrase[keyid]
save = False
if save_gpg_pass:
passphrase = gajim.config.get_per('accounts', account, 'gpgpassword')
else:
w = dialogs.PassphraseDialog(
_('Passphrase Required'),
_('Enter GPG key passphrase for account %s') % account,
_('Save passphrase'))
passphrase, save = w.run()
if passphrase == -1:
passphrase = None
else:
self.gpg_passphrase[keyid] = passphrase
gobject.timeout_add(30000, self.forget_gpg_passphrase, keyid)
if save:
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)
if self.gpg_passphrase.has_key(keyid):
passphrase = self.gpg_passphrase[keyid]
save = False
else:
w = dialogs.PassphraseDialog(
_('Passphrase Required'),
_('Enter GPG key passphrase for account %s') % account,
_('Save passphrase'))
passphrase, save = w.run()
if passphrase == -1:
passphrase = None
else:
self.gpg_passphrase[keyid] = passphrase
gobject.timeout_add(30000, self.forget_gpg_passphrase, keyid)
if save:
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']:
if room_jid != 'tabbed':
nick = self.plugin.windows[account]['gc'][room_jid].nicks[room_jid]