Pass use_agent to GPG init instead of overwrite

This commit is contained in:
Philipp Hörist 2017-06-08 18:55:05 +02:00
parent b5e9b07a07
commit 92b0a15521
2 changed files with 8 additions and 11 deletions

View file

@ -132,7 +132,7 @@ class CommonConnection:
self.USE_GPG = False self.USE_GPG = False
if gajim.HAVE_GPG: if gajim.HAVE_GPG:
self.USE_GPG = True self.USE_GPG = True
self.gpg = gpg.GnuPG(gajim.config.get('use_gpg_agent')) self.gpg = gpg.GnuPG()
self.status = '' self.status = ''
self.old_show = '' self.old_show = ''
self.priority = gajim.get_priority(name, 'offline') self.priority = gajim.get_priority(name, 'offline')
@ -234,8 +234,7 @@ class CommonConnection:
signed = '' signed = ''
keyID = gajim.config.get_per('accounts', self.name, 'keyid') keyID = gajim.config.get_per('accounts', self.name, 'keyid')
if keyID and self.USE_GPG: if keyID and self.USE_GPG:
use_gpg_agent = gajim.config.get('use_gpg_agent') if self.gpg.passphrase is None and not self.gpg.use_agent:
if self.gpg.passphrase is None and not use_gpg_agent:
# We didn't set a passphrase # We didn't set a passphrase
return None return None
signed = self.gpg.sign(msg, keyID) signed = self.gpg.sign(msg, keyID)
@ -566,8 +565,7 @@ class CommonConnection:
def gpg_passphrase(self, passphrase): def gpg_passphrase(self, passphrase):
if self.gpg: if self.gpg:
use_gpg_agent = gajim.config.get('use_gpg_agent') if self.gpg.use_agent:
if use_gpg_agent:
self.gpg.passphrase = None self.gpg.passphrase = None
else: else:
self.gpg.passphrase = passphrase self.gpg.passphrase = passphrase
@ -614,7 +612,7 @@ class CommonConnection:
self.server_resource = self._compute_resource() self.server_resource = self._compute_resource()
if gajim.HAVE_GPG: if gajim.HAVE_GPG:
self.USE_GPG = True self.USE_GPG = True
self.gpg = gpg.GnuPG(gajim.config.get('use_gpg_agent')) self.gpg = gpg.GnuPG()
gajim.nec.push_incoming_event(BeforeChangeShowEvent(None, gajim.nec.push_incoming_event(BeforeChangeShowEvent(None,
conn=self, show=show, message=msg)) conn=self, show=show, message=msg))
self.connect_and_init(show, msg, sign_msg) self.connect_and_init(show, msg, sign_msg)
@ -892,8 +890,7 @@ class Connection(CommonConnection, ConnectionHandlers):
return return
if gajim.HAVE_GPG: if gajim.HAVE_GPG:
self.USE_GPG = True self.USE_GPG = True
self.gpg = gpg.GnuPG(gajim.config.get( self.gpg = gpg.GnuPG()
'use_gpg_agent'))
gajim.nec.push_incoming_event( gajim.nec.push_incoming_event(
AccountCreatedEvent(None, conn=self, AccountCreatedEvent(None, conn=self,
account_info = self.new_account_info)) account_info = self.new_account_info))

View file

@ -32,14 +32,14 @@ if HAVE_GPG:
gnupg.logger = logging.getLogger('gajim.c.gnupg') gnupg.logger = logging.getLogger('gajim.c.gnupg')
class GnuPG(gnupg.GPG): class GnuPG(gnupg.GPG):
def __init__(self, use_agent=False): def __init__(self):
gnupg.GPG.__init__(self, gpgbinary=GPG_BINARY) use_agent = gajim.config.get('use_gpg_agent')
gnupg.GPG.__init__(self, gpgbinary=GPG_BINARY, use_agent=use_agent)
encoding = gajim.config.get('pgp_encoding') encoding = gajim.config.get('pgp_encoding')
if encoding: if encoding:
self.encoding = encoding self.encoding = encoding
self.decode_errors = 'replace' self.decode_errors = 'replace'
self.passphrase = None self.passphrase = None
self.use_agent = use_agent
self.always_trust = [] # list of keyID to always trust self.always_trust = [] # list of keyID to always trust
def _setup_my_options(self): def _setup_my_options(self):