Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 52 additions & 7 deletions modules/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
from shlex import split
from subprocess import check_output
from time import sleep
import gobject
import re
# Custom Modules:
import cfg
import prefs
Expand Down Expand Up @@ -632,7 +634,43 @@ def cleanup_filemode(self, *args):


#--------------------------------------------------- HERE BE GTK SIGNAL CBs


# Separate function for loading the e-mails and putting them to
# the recepient menu completion
# Despite calling launchxface, it does not
# show the status etc, because it used to hang for some reason
# that I was not able to determine (something with threads
# and processes, I guess)
def loadmails(self):

def loadmails_string_list():
if self.engine == 'OpenSSL':
#I don't know how to do this in OpenSSL at all => empty list
return list()
else:
keys_string = self.launchxface('list-keys')
keys_all=keys_string.split('\n')
mails = list()
for line in keys_all:
line_fields = line.split(':')
if line_fields[0] == 'uid':
longer=line_fields[9]
match = re.search(r'<([^>]*)>$', longer)
if match is not None:
mails.append(match.group(1))
return mails

mails = gtk.ListStore(gobject.TYPE_STRING)
for mail in loadmails_string_list() :
mails.append([mail])

completion = gtk.EntryCompletion()
completion.set_model(mails)
completion.set_text_column(0)
completion.set_minimum_key_length(0)

self.g_recip.set_completion(completion)

# Called by window destroy / Quit menu item
def action_quit(self, w):
"""Shutdown application and any child process."""
Expand Down Expand Up @@ -916,6 +954,7 @@ def action_toggle_asymmetric(self, w):
asymm_widgets = [self.g_reciplabel, self.g_recip, self.g_enctoself]

if w.get_active():
self.loadmails()
# If entering toggled state, allow recip entry, enctoself
for widget in asymm_widgets:
widget.set_sensitive (True)
Expand Down Expand Up @@ -1121,7 +1160,7 @@ def launchxface(self, action):
passwd = None # If passwd was '' , set to None, which will trigger gpg-agent if necessary

# INTERLUDE: If operating in textinput mode, check for input text
if not self.x.io['infile']:
if (not self.x.io['infile']) and (action != 'list-keys'):
# Make sure textview has a proper message in it
if self.test_msgbuff_isempty("Input your message text first."):
return False
Expand Down Expand Up @@ -1208,11 +1247,13 @@ def launchxface(self, action):
self.buff2.set_text('')

# Setup stderr file descriptors & update task status while processing
self.x.io['stderr'] = pipe()
glib.io_add_watch(
self.x.io['stderr'][0],
glib.IO_IN | glib.IO_HUP,
self.update_task_status)
if not (action=='list-keys'):
#for some reason, list-keys just hangs if I don't put this here
self.x.io['stderr'] = pipe()
glib.io_add_watch(
self.x.io['stderr'][0],
glib.IO_IN | glib.IO_HUP,
self.update_task_status)

if self.engine in 'OpenSSL':
# ATTEMPT EN-/DECRYPTION w/OPENSSL
Expand Down Expand Up @@ -1324,6 +1365,10 @@ def launchxface(self, action):

if action in 'verify':
self.infobar('x_verify_success')
elif action in 'list-keys':
keys = self.x.io['stdout']
self.x.io['stdout'] = 0
return keys
else:
# Set TextBuffer to gpg stdout
self.buff.set_text(self.x.io['stdout'])
Expand Down
17 changes: 14 additions & 3 deletions modules/crypt_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def gpg2():
# Main gpg interface method
def gpg(
self,
action= None, # One of: enc, dec, embedsign, clearsign, detachsign, verify
action= None, # One of: enc, dec, embedsign, clearsign, detachsign, verify, list-keys
encsign= False, # Add '--sign' when encrypting?
digest= None, # One of: sha256, sha1, etc; None == use gpg defaults
localuser= None, # Value passed to --local-user to set default key for signing, etc
Expand Down Expand Up @@ -163,6 +163,11 @@ def gpg(
cmd.append('--status-fd')
cmd.append(str(self.io['gstatus'][1]))

# Listkeys - just list all the keys (duh)
if action == 'list-keys':
cmd.append('--list-public-keys')
cmd.append('--with-colons')

# Setup passphrase file descriptor for symmetric enc/dec
if (action in 'enc' and symmetric and passwd and not encsign) or (
action in 'dec' and symmetric and passwd):
Expand Down Expand Up @@ -258,7 +263,12 @@ def gpg(
self.childprocess = Popen(cmd, stdout=PIPE, stderr=self.io['stderr'][1])
# Otherwise, only difference for Popen is we need the stdin pipe
else:
self.childprocess = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=self.io['stderr'][1])
if (action == "list-keys") :
#hack so list-keys does not hang
#I am not sure why
self.childprocess = Popen(cmd, stdin=PIPE, stdout=PIPE)
else:
self.childprocess = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=self.io['stderr'][1])

# Time to communicate! Save output for later
self.io['stdout'] = self.childprocess.communicate(input=self.io['stdin'])[0]
Expand All @@ -269,7 +279,8 @@ def gpg(
# Close os file descriptors
if fd_pwd_R: close(fd_pwd_R)
sleep(0.1) # Sleep a bit to ensure everything gets read
close(self.io['stderr'][1])
if not (action == "list-keys") :
close(self.io['stderr'][1])
if self.io['gstatus']:
close(self.io['gstatus'][1])

Expand Down