Author: asterix
Date: 2009-02-19 23:47:38 +0100 (Thu, 19 Feb 2009)
New Revision: 11123
Modified:
trunk/src/common/GnuPG.py
trunk/src/common/connection.py
trunk/src/gajim.py
Log:
ask user what to do when GPG key is not trusted.
Modified: trunk/src/common/GnuPG.py
===================================================================
--- trunk/src/common/GnuPG.py 2009-02-19 20:17:05 UTC (rev 11122)
+++ trunk/src/common/GnuPG.py 2009-02-19 22:47:38 UTC (rev 11123)
@@ -35,6 +35,7 @@
GnuPGInterface.GnuPG.__init__(self)
self.use_agent = use_agent
self._setup_my_options()
+ self.always_trust = False
def _setup_my_options(self):
self.options.armor = 1
@@ -71,10 +72,13 @@
resp[ keyword ] = ""
return resp
- def encrypt(self, str_, recipients):
+ def encrypt(self, str_, recipients, always_trust=False):
self.options.recipients = recipients # a list!
- proc = self.run(['--encrypt'], create_fhs=['stdin', 'stdout', 'status',
+ opt = ['--encrypt']
+ if always_trust or self.always_trust:
+ opt.append('--always-trust')
+ proc = self.run(opt, create_fhs=['stdin', 'stdout', 'status',
'stderr'])
proc.handles['stdin'].write(str_)
try:
@@ -100,6 +104,9 @@
try: proc.wait()
except IOError: pass
+ if 'INV_RECP' in resp and resp['INV_RECP'].split()[0] == '10':
+ # unusable recipient "Key not trusted"
+ return '', 'NOT_TRUSTED'
if 'BEGIN_ENCRYPTION' in resp and 'END_ENCRYPTION' in resp:
# Encryption succeeded, even if there is output on stderr. Maybe
# verbose is on
Modified: trunk/src/common/connection.py
===================================================================
--- trunk/src/common/connection.py 2009-02-19 20:17:05 UTC (rev 11122)
+++ trunk/src/common/connection.py 2009-02-19 22:47:38 UTC (rev 11123)
@@ -1180,17 +1180,33 @@
elif keyID.endswith('MISMATCH'):
error = _('The contact\'s key (%s) does not match the key assigned in Gajim.' % keyID[:8])
else:
- def encrypt_thread(msg, keyID):
+ def encrypt_thread(msg, keyID, always_trust=False):
# encrypt message. This function returns (msgenc, error)
- return self.gpg.encrypt(msg, [keyID])
- gajim.thread_interface(encrypt_thread, [msg, keyID],
- self._on_message_encrypted, [type_, msg, msgtxt,
- original_message, fjid, resource, jid, xhtml, subject,
- chatstate, composing_xep, forward_from, delayed, session,
- form_node, user_nick, keyID, callback, callback_args])
+ return self.gpg.encrypt(msg, [keyID], always_trust)
+ def _on_encrypted(output):
+ msgenc, error = output
+ if error == 'NOT_TRUSTED':
+ def _on_always_trust(answer):
+ if answer:
+ gajim.thread_interface(encrypt_thread, [msg, keyID,
+ True], _on_encrypted, [])
+ else:
+ self._on_message_encrypted(output, type_, msg, msgtxt,
+ original_message, fjid, resource, jid, xhtml,
+ subject, chatstate, composing_xep, forward_from,
+ delayed, session, form_node, user_nick, keyID,
+ callback, callback_args)
+ self.dispatch('GPG_ALWAYS_TRUST', _on_always_trust)
+ else:
+ self._on_message_encrypted(output, type_, msg, msgtxt,
+ original_message, fjid, resource, jid, xhtml, subject,
+ chatstate, composing_xep, forward_from, delayed, session,
+ form_node, user_nick, keyID, callback, callback_args)
+ gajim.thread_interface(encrypt_thread, [msg, keyID, False],
+ _on_encrypted, [])
return
- self._on_message_encrypted(self, ('', error), type_, msg, msgtxt,
+ self._on_message_encrypted(('', error), type_, msg, msgtxt,
original_message, fjid, resource, jid, xhtml, subject, chatstate,
composing_xep, forward_from, delayed, session, form_node, user_nick,
keyID, callback, callback_args)
Modified: trunk/src/gajim.py
===================================================================
--- trunk/src/gajim.py 2009-02-19 20:17:05 UTC (rev 11122)
+++ trunk/src/gajim.py 2009-02-19 22:47:38 UTC (rev 11123)
@@ -1532,6 +1532,21 @@
self.gpg_passphrase[keyid] = request
request.add_callback(account, callback)
+ def handle_event_gpg_always_trust(self, account, callback):
+ #('GPG_ALWAYS_TRUST', account, callback)
+ def on_yes(checked):
+ if checked:
+ gajim.connections[account].gpg.always_trust = True
+ callback(True)
+
+ def on_no():
+ callback(False)
+
+ dialogs.YesNoDialog(_('GPG key not trusted'), _('The GPG key used to '
+ 'encrypt this chat is not trusted. Do you really want to encrypt this '
+ 'message?'), checktext=_('Do _not ask me again'),
+ on_response_yes=on_yes, on_response_no=on_no)
+
def handle_event_password_required(self, account, array):
#('PASSWORD_REQUIRED', account, None)
text = _('Enter your password for account %s') % account
@@ -2295,6 +2310,7 @@
self.handle_event_unique_room_id_unsupported,
'UNIQUE_ROOM_ID_SUPPORTED': self.handle_event_unique_room_id_supported,
'GPG_PASSWORD_REQUIRED': self.handle_event_gpg_password_required,
+ 'GPG_ALWAYS_TRUST': self.handle_event_gpg_always_trust,
'PASSWORD_REQUIRED': self.handle_event_password_required,
'SSL_ERROR': self.handle_event_ssl_error,
'FINGERPRINT_ERROR': self.handle_event_fingerprint_error,