diff options
author | Florent Le Coz <louiz@louiz.org> | 2011-11-13 18:39:07 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2011-11-13 18:39:07 +0100 |
commit | 3ea5eb6163181ba016cfddcc616a171d7f309e76 (patch) | |
tree | 696fef8697181b96616d7953195c4324d1834cfa /plugins/gpg/__init__.py | |
parent | 35335ccb5b0ef743228ac25bffcc16ffc090ad55 (diff) | |
parent | c4f7d9b98a229ad52e834313ab93f0f9ebc77884 (diff) | |
download | poezio-3ea5eb6163181ba016cfddcc616a171d7f309e76.tar.gz poezio-3ea5eb6163181ba016cfddcc616a171d7f309e76.tar.bz2 poezio-3ea5eb6163181ba016cfddcc616a171d7f309e76.tar.xz poezio-3ea5eb6163181ba016cfddcc616a171d7f309e76.zip |
Merge branch 'master' of http://git.louiz.org/poezio
Diffstat (limited to 'plugins/gpg/__init__.py')
-rw-r--r-- | plugins/gpg/__init__.py | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/plugins/gpg/__init__.py b/plugins/gpg/__init__.py index 5662bd4f..01ca6ab2 100644 --- a/plugins/gpg/__init__.py +++ b/plugins/gpg/__init__.py @@ -1,4 +1,6 @@ from gpg import gnupg +from sleekxmpp.xmlstream.stanzabase import JID + from xml.etree import cElementTree as ET import xml.sax.saxutils @@ -54,7 +56,7 @@ class Plugin(BasePlugin): self.add_event_handler('conversation_say_after', self.on_conversation_say) self.add_event_handler('conversation_msg', self.on_conversation_msg) - self.add_tab_command(ConversationTab, 'gpg', self.command_gpg, "Usage: /gpg <force|disable>\nGpg: Force or disable gpg encryption with this fulljid.", lambda the_input: the_input.auto_completion(['force', 'disable'])) + self.add_command('gpg', self.command_gpg, "Usage: /gpg <force|disable|setkey> [JID] [keyid]\nGpg: Force or disable gpg encryption with the fulljid of the current conversation. The setkey argument lets you associate a keyid with the given bare JID.", self.gpg_completion) ConversationTab.add_information_element('gpg', self.display_encryption_status) def cleanup(self): @@ -121,7 +123,7 @@ class Plugin(BasePlugin): return signed = to.full in self.contacts.keys() if signed: - veryfied = self.contacts[to.full] == 'valid' + veryfied = self.contacts[to.full] in ('valid', 'forced') else: veryfied = False if veryfied: @@ -155,11 +157,46 @@ class Plugin(BasePlugin): """ if jid.full not in self.contacts.keys(): return '' - return ' GPG Key: %s' % self.contacts[jid.full] + status = self.contacts[jid.full] + self.core.information('%s' % (status,)) + if status in ('valid', 'invalid', 'signed'): + return ' GPG Key: %s (%s)' % (status, 'encrypted' if status == 'valid' else 'NOT encrypted',) + else: + return ' GPG: Encryption %s' % (status,) def command_gpg(self, args): - # TODO - return + """ + A command to force or disable the encryption, or to assign a keyid to a JID + """ + args = args.split() + if not args: + return self.core.command_help("gpg") + if len(args) >= 2: + jid = JID(args[1]) + else: + if isinstance(self.core.current_tab(), ConversationTab): + jid = JID(self.core.current_tab().get_name()) + command = args[0] + if command == 'force' or command == 'enable': + # we can force encryption only with contact having an associated + # key, otherwise we cannot encrypt at all + if self.config.has_section('keys') and jid.bare in self.config.options('keys'): + self.contacts[JID(jid).full] = 'forced' + else: + self.core.information('Cannot force encryption: no key associated with %s' % (jid.bare), 'Info') + elif command == 'disable': + self.contacts[JID(jid).full] = 'disabled' + elif command == 'setkey': + if len(args) != 3: + return self.core.command_help("gpg") + if not self.config.has_section('keys'): + self.config.add_section('keys') + self.config.set(jid.bare, args[2], 'keys') + self.config.write() + self.core.refresh_window() + + def gpg_completion(self, the_input): + return the_input.auto_completion(['force', 'disable', 'setkey'], ' ') def remove_gpg_headers(self, text): lines = text.splitlines() |