we can now attach a GPG key to a contact
This commit is contained in:
parent
f594d2670d
commit
088b3870dd
|
@ -151,10 +151,14 @@ else:
|
|||
keyid = resp['BADSIG'].split()[0]
|
||||
return keyid
|
||||
|
||||
def get_secret_keys(self):
|
||||
def get_keys(self, secret = False):
|
||||
if not USE_GPG:
|
||||
return
|
||||
proc = self.run(['--with-colons', '--list-secret-keys'], \
|
||||
if secret:
|
||||
opt = '--list-secret-keys'
|
||||
else:
|
||||
opt = '--list-keys'
|
||||
proc = self.run(['--with-colons', opt], \
|
||||
create_fhs=['stdout'])
|
||||
output = proc.handles['stdout'].read()
|
||||
proc.handles['stdout'].close()
|
||||
|
@ -163,12 +167,16 @@ else:
|
|||
lines = output.split('\n')
|
||||
for line in lines:
|
||||
sline = line.split(':')
|
||||
if sline[0] == 'sec':
|
||||
if (sline[0] == 'sec' and secret) or \
|
||||
(sline[0] == 'pub' and not secret):
|
||||
keys[sline[4][8:]] = sline[9]
|
||||
return keys
|
||||
try: proc.wait()
|
||||
except IOError: pass
|
||||
|
||||
def get_secret_keys(self):
|
||||
return self.get_keys(True)
|
||||
|
||||
def _stripHeaderFooter(self, data):
|
||||
"""Remove header and footer from data"""
|
||||
if not data: return ''
|
||||
|
|
|
@ -123,6 +123,7 @@ class Config:
|
|||
'gpgpassword': [ opt_str, '' ],
|
||||
'sync_with_global_status': [ opt_bool, True ],
|
||||
'no_log_for': [ opt_str, '' ],
|
||||
'attached_gpg_keys': [ opt_str, '' ],
|
||||
}, {}),
|
||||
'statusmsg': ({
|
||||
'message': [ opt_str, '' ],
|
||||
|
|
|
@ -543,7 +543,7 @@ class Connection:
|
|||
common.xmpp.dispatcher.DefaultTimeout = 45
|
||||
con.UnregisterDisconnectHandler(con.DisconnectHandler)
|
||||
con.RegisterDisconnectHandler(self._disconnectedCB)
|
||||
con_type = con.connect(proxy=proxy, tls=usetls) #FIXME: blocking
|
||||
con_type = con.connect((hostname,5222), proxy=proxy, tls=usetls) #FIXME: blocking
|
||||
if not con_type:
|
||||
gajim.log.debug("Couldn't connect to %s" % name)
|
||||
self.connected = 0
|
||||
|
@ -951,6 +951,12 @@ class Connection:
|
|||
if USE_GPG:
|
||||
self.gpg.passphrase = passphrase
|
||||
|
||||
def ask_gpg_keys(self):
|
||||
if USE_GPG:
|
||||
keys = self.gpg.get_keys()
|
||||
return keys
|
||||
return None
|
||||
|
||||
def ask_gpg_secrete_keys(self):
|
||||
if USE_GPG:
|
||||
keys = self.gpg.get_secret_keys()
|
||||
|
|
|
@ -1303,7 +1303,7 @@ class Account_modification_window:
|
|||
def on_gpg_choose_button_clicked(self, widget, data = None):
|
||||
secret_keys = gajim.connections[self.account].ask_gpg_secrete_keys()
|
||||
if not secret_keys:
|
||||
dialogs.Error_dialog(_('error contacting %s') % service)
|
||||
dialogs.Error_dialog(_('Error while getting secret keys'))
|
||||
return
|
||||
secret_keys['None'] = 'None'
|
||||
w = dialogs.choose_gpg_key_dialog(secret_keys)
|
||||
|
|
|
@ -157,12 +157,15 @@ class choose_gpg_key_dialog:
|
|||
self.window.destroy()
|
||||
return keyID
|
||||
|
||||
def fill_tree(self, list):
|
||||
def fill_tree(self, list, selected):
|
||||
model = self.keys_treeview.get_model()
|
||||
for keyID in list.keys():
|
||||
model.append((keyID, list[keyID]))
|
||||
iter = model.append((keyID, list[keyID]))
|
||||
if keyID == selected:
|
||||
path = model.get_path(iter)
|
||||
self.keys_treeview.set_cursor(path)
|
||||
|
||||
def __init__(self, secret_keys):
|
||||
def __init__(self, secret_keys, selected = None):
|
||||
#list : {keyID: userName, ...}
|
||||
xml = gtk.glade.XML(GTKGUI_GLADE, 'choose_gpg_key_dialog', APP)
|
||||
self.window = xml.get_widget('choose_gpg_key_dialog')
|
||||
|
@ -176,7 +179,7 @@ class choose_gpg_key_dialog:
|
|||
renderer = gtk.CellRendererText()
|
||||
self.keys_treeview.insert_column_with_attributes(-1, _('User name'),
|
||||
renderer, text = 1)
|
||||
self.fill_tree(secret_keys)
|
||||
self.fill_tree(secret_keys, selected)
|
||||
|
||||
self.window.show_all()
|
||||
|
||||
|
@ -605,8 +608,13 @@ class New_message_dialog:
|
|||
if self.plugin.roster.contacts[self.account].has_key(jid):
|
||||
user = self.plugin.roster.contacts[self.account][jid][0]
|
||||
else:
|
||||
user = User(jid, jid, ['not in the roster'],
|
||||
'not in the roster', 'not in the roster', 'none', None, '', 0, '')
|
||||
keyID = ''
|
||||
attached_keys = gajim.config.get_per('accounts', self.account,
|
||||
'attached_gpg_keys').split()
|
||||
if jid in attached_keys:
|
||||
keyID = attached_keys[attached_keys.index(jid) + 1]
|
||||
user = User(jid, jid, ['not in the roster'], 'not in the roster',
|
||||
'not in the roster', 'none', None, '', 0, keyID)
|
||||
self.plugin.roster.contacts[self.account][jid] = [user]
|
||||
self.plugin.roster.add_user_to_roster(user.jid, self.account)
|
||||
|
||||
|
@ -724,8 +732,14 @@ class Popup_notification_window:
|
|||
if self.plugin.roster.contacts[self.account].has_key(self.jid):
|
||||
user = self.plugin.roster.contacts[self.account][self.jid][0]
|
||||
else:
|
||||
keyID = ''
|
||||
attached_keys = gajim.config.get_per('accounts', self.account,
|
||||
'attached_gpg_keys').split()
|
||||
if jid in attached_keys:
|
||||
keyID = attached_keys[attached_keys.index(jid) + 1]
|
||||
user = User(self.jid, self.jid, ['not in the roster'],
|
||||
'not in the roster', 'not in the roster', 'none', None, '', 0, '')
|
||||
'not in the roster', 'not in the roster', 'none', None, '', 0,
|
||||
keyID)
|
||||
self.plugin.roster.contacts[self.account][self.jid] = [user]
|
||||
self.plugin.roster.add_user_to_roster(user.self.jid, self.account)
|
||||
|
||||
|
|
11
src/gajim.py
11
src/gajim.py
|
@ -216,6 +216,10 @@ class Interface:
|
|||
new_show = statuss.index(array[1])
|
||||
jid = array[0].split('/')[0]
|
||||
keyID = array[5]
|
||||
attached_keys = gajim.config.get_per('accounts', account,
|
||||
'attached_gpg_keys').split()
|
||||
if jid in attached_keys:
|
||||
keyID = attached_keys[attached_keys.index(jid) + 1]
|
||||
resource = array[3]
|
||||
if not resource:
|
||||
resource = ''
|
||||
|
@ -394,8 +398,13 @@ class Interface:
|
|||
self.roster.add_user_to_roster(u.jid, account)
|
||||
gajim.connections[account].update_user(u.jid, u.name, u.groups)
|
||||
else:
|
||||
keyID = ''
|
||||
attached_keys = gajim.config.get_per('accounts', account,
|
||||
'attached_gpg_keys').split()
|
||||
if jid in attached_keys:
|
||||
keyID = attached_keys[attached_keys.index(jid) + 1]
|
||||
user1 = User(jid, jid, ['General'], 'online', \
|
||||
'online', 'to', '', array[1], 0, '')
|
||||
'online', 'to', '', array[1], 0, keyID)
|
||||
self.roster.contacts[account][jid] = [user1]
|
||||
self.roster.add_user_to_roster(jid, account)
|
||||
dialogs.Information_dialog(_('You are now authorized by %s') % jid)
|
||||
|
|
|
@ -374,8 +374,14 @@ class Roster_window:
|
|||
show = 'offline' # show is offline by default
|
||||
status = '' #no status message by default
|
||||
|
||||
keyID = ''
|
||||
attached_keys = gajim.config.get_per('accounts', account,
|
||||
'attached_gpg_keys').split()
|
||||
if jid in attached_keys:
|
||||
keyID = attached_keys[attached_keys.index(jid) + 1]
|
||||
user1 = User(ji, name, array[jid]['groups'], show, status,\
|
||||
array[jid]['subscription'], array[jid]['ask'], resource, 0, '')
|
||||
array[jid]['subscription'], array[jid]['ask'], resource, 0,
|
||||
keyID)
|
||||
|
||||
# when we draw the roster, we can't have twice the same
|
||||
# user with 2 resources
|
||||
|
@ -452,6 +458,34 @@ class Roster_window:
|
|||
model.set_value(iter, 5, True)
|
||||
self.tree.set_cursor(path, self.tree.get_column(0), True)
|
||||
|
||||
def on_assign_pgp_key(self, widget, user, account):
|
||||
attached_keys = gajim.config.get_per('accounts', account,
|
||||
'attached_gpg_keys').split()
|
||||
keys = {}
|
||||
keyID = 'None'
|
||||
for i in range(0, len(attached_keys)/2):
|
||||
keys[attached_keys[2*i]] = attached_keys[2*i+1]
|
||||
if attached_keys[2*i] == user.jid:
|
||||
keyID = attached_keys[2*i+1]
|
||||
public_keys = gajim.connections[account].ask_gpg_keys()
|
||||
public_keys['None'] = 'None'
|
||||
w = dialogs.choose_gpg_key_dialog(public_keys, keyID)
|
||||
keyID = w.run()
|
||||
if keyID == -1:
|
||||
return
|
||||
if keyID[0] == 'None' and user.jid in keys:
|
||||
del keys[user.jid]
|
||||
else:
|
||||
keys[user.jid] = keyID[0]
|
||||
for u in self.contacts[account][user.jid]:
|
||||
u.keyID = keyID[0]
|
||||
if self.plugin.windows[account]['chats'].has_key(user.jid):
|
||||
self.plugin.windows[account]['chats'][user.jid].draw_widgets(user)
|
||||
keys_str = ''
|
||||
for jid in keys:
|
||||
keys_str += jid + ' ' + keys[jid]
|
||||
gajim.config.set_per('accounts', account, 'attached_gpg_keys', keys_str)
|
||||
|
||||
def on_edit_groups(self, widget, user, account):
|
||||
dlg = dialogs.Edit_groups_dialog(user, account, self.plugin)
|
||||
dlg.run()
|
||||
|
@ -485,6 +519,12 @@ class Roster_window:
|
|||
item.connect('activate', self.on_edit_groups, user, account)
|
||||
item = gtk.MenuItem()
|
||||
menu.append(item)
|
||||
if gajim.config.get('usegpg'):
|
||||
item = gtk.MenuItem(_('Assign OpenPGP key'))
|
||||
menu.append(item)
|
||||
item.connect('activate', self.on_assign_pgp_key, user, account)
|
||||
item = gtk.MenuItem()
|
||||
menu.append(item)
|
||||
item = gtk.MenuItem(_('Subscription'))
|
||||
menu.append(item)
|
||||
|
||||
|
@ -651,8 +691,13 @@ class Roster_window:
|
|||
if not group:
|
||||
group = 'General'
|
||||
if not self.contacts[account].has_key(jid):
|
||||
keyID = ''
|
||||
attached_keys = gajim.config.get_per('accounts', account,
|
||||
'attached_gpg_keys').split()
|
||||
if jid in attached_keys:
|
||||
keyID = attached_keys[attached_keys.index(jid) + 1]
|
||||
user1 = User(jid, pseudo, [group], 'requested', 'requested',
|
||||
'none', 'subscribe', '', 0, '')
|
||||
'none', 'subscribe', '', 0, keyID)
|
||||
self.contacts[account][jid] = [user1]
|
||||
else:
|
||||
user1 = self.contacts[account][jid][0]
|
||||
|
@ -914,8 +959,13 @@ class Roster_window:
|
|||
def on_message(self, jid, msg, tim, account):
|
||||
'''when we receive a message'''
|
||||
if not self.contacts[account].has_key(jid):
|
||||
keyID = ''
|
||||
attached_keys = gajim.config.get_per('accounts', account,
|
||||
'attached_gpg_keys').split()
|
||||
if jid in attached_keys:
|
||||
keyID = attached_keys[attached_keys.index(jid) + 1]
|
||||
user1 = User(jid, jid, ['not in the roster'], 'not in the roster',
|
||||
'not in the roster', 'none', None, '', 0, '')
|
||||
'not in the roster', 'none', None, '', 0, keyID)
|
||||
self.contacts[account][jid] = [user1]
|
||||
self.add_user_to_roster(jid, account)
|
||||
iters = self.get_user_iter(jid, account)
|
||||
|
|
|
@ -79,6 +79,8 @@ class Tabbed_chat_window(chat.Chat):
|
|||
contact_button.set_label(user.name + ' <' + jid + '>')
|
||||
if not user.keyID:
|
||||
self.xmls[jid].get_widget('gpg_togglebutton').set_sensitive(False)
|
||||
else:
|
||||
self.xmls[jid].get_widget('gpg_togglebutton').set_sensitive(True)
|
||||
|
||||
nontabbed_status_image = self.xmls[jid].get_widget(
|
||||
'nontabbed_status_image')
|
||||
|
|
Loading…
Reference in New Issue