Skip to content
This repository has been archived by the owner on Jan 2, 2020. It is now read-only.

PyGPGME-based library #47

Open
wants to merge 106 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 96 commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
c371c12
Merge branch 'copyrights' into develop
andreimacavei Sep 20, 2014
b4c8282
Now it announces the local fingerprint in the TXT record.
andreimacavei Oct 11, 2014
3226ced
Keyserver: added the new fingerprint field to the call to start the k…
andreimacavei Oct 11, 2014
875b3d7
Merge remote-tracking branch 'muelli/master' into merge_develop-orgin…
andreimacavei Jun 12, 2015
561c229
Added a gpg/gpg.py file and gpg/example.py.
andreimacavei Jun 16, 2015
3049d12
gpg.py: Added functions for gpgme support on key import/export.
andreimacavei Jun 21, 2015
be4dacb
Added more functions with gpg calls into gpg.py.
andreimacavei Jun 21, 2015
cf501e5
Replaced KeyringCopy class definition with a method that returns a Ke…
andreimacavei Jun 25, 2015
9182c86
Sections.py: Moved global functions that calls gpg into gpg.py.
andreimacavei Jun 25, 2015
6a723a5
Moved all gpg calls from Sections.py to gpg.py.
andreimacavei Jun 25, 2015
1205915
SignPages.py: Replaced monkeysign.gpg with keysign.gpg.gpg.
andreimacavei Jun 25, 2015
dedd334
GPGQRCode.py: Replaced monkeysign.gpg with keysign.gpg.gpg import
andreimacavei Jun 25, 2015
40f5933
Finished replacing all gpg calls from monkeysign.gpg with keysign.gpg…
andreimacavei Jun 25, 2015
dd74dd5
example.py: Created get_key and get_keylist functions. Added gpg test…
andreimacavei Jun 25, 2015
37ce774
gpg.py: Added a gpgme implementation of UIDExport (not yet functional).
andreimacavei Jun 26, 2015
de84047
gpg.py: Surrounded key import with try-catch block.
andreimacavei Jun 26, 2015
7785aa8
Made it to raise ValueError instead of returning None value.
andreimacavei Jul 1, 2015
19ec326
Added a KeyringGPG class.
andreimacavei Jul 2, 2015
0999eae
Renamed method to resemble better what it returns.
andreimacavei Jul 5, 2015
fb9f529
on_key_selected: replaces the gpg calls with gpgme
andreimacavei Jul 7, 2015
c37bfdd
gpg: Added a default homedir field to KeyringGPG
andreimacavei Jul 7, 2015
adb0c54
KeyringGPG: check if gpg home is temporary before removing dir
andreimacavei Jul 7, 2015
d333049
KeyringGPG: updated docstrings
andreimacavei Jul 7, 2015
9aa3d99
set_up_tmp_dir: moved the secrets copying to another function
andreimacavei Jul 7, 2015
0759821
gpg: Added function for extracting fingerpring and key data of a key.
andreimacavei Jul 7, 2015
d065d8f
on_key_selected: made it call gpg functions from gpg library.
andreimacavei Jul 7, 2015
8493c92
gpg: Updated docstrings
andreimacavei Jul 7, 2015
f5fbdf0
gpg: More docstrings update
andreimacavei Jul 7, 2015
5e2530f
gpg: enclosed deletion of system environment var in try-catch block
andreimacavei Jul 7, 2015
c2a9f26
gpg: made copy_secrets to copy the secret keys now.
andreimacavei Jul 8, 2015
e82809a
gpg: Made import_key_to_tmpdir to import a key without changing globa…
andreimacavei Jul 10, 2015
a742473
gpg: Fixed import_key_to_tmpdir
andreimacavei Jul 10, 2015
b8784f5
Renamed gpg library function and made gpghome optional argument
andreimacavei Jul 13, 2015
1247997
gpg: set_up_temp_dir sets now gnupg homedir only for current context
andreimacavei Jul 13, 2015
7da0c7b
gpg: removed lib function and made it to reset gnupg dir to its defau…
andreimacavei Jul 13, 2015
8c2b3d0
gpg: Renamed library functions for setting and reseting temp gnupg dir
andreimacavei Jul 13, 2015
631c4c3
Sections.py: Prepared GetKeySection for replacing gpg calls with new …
andreimacavei Jul 14, 2015
822939d
gpg: Added gpg_import_keydata lib function which imports a key from i…
andreimacavei Jul 14, 2015
4340dd1
Sections.py: Added calls from gpg library along with old monkeysign API
andreimacavei Jul 15, 2015
8c90fac
gpg: Encoded keydata as 'utf-8' because unicode doesn't work with PyG…
andreimacavei Jul 15, 2015
e8a159c
Added gpg lib function and replaced more old API calls in Sections.py
andreimacavei Jul 15, 2015
ee45d05
gpg: Added two functions to help with displaying info about a key.
andreimacavei Jul 15, 2015
db68dfb
More code replacement with new gpg library calls.
andreimacavei Jul 15, 2015
fcb7927
Sections: removed old gpg API which is not used anymore
andreimacavei Jul 16, 2015
0c69cca
gpg: Some changes which give the library functions a more proper use.
andreimacavei Jul 18, 2015
8cff28e
gpg: Deleted code that wasn't used anymore
andreimacavei Jul 18, 2015
8689d30
gpg: gpg_copy_secrets now copies the user's secring.
andreimacavei Jul 21, 2015
16d5c47
gpg: Added gpg_sign_uid which signs a given userId of a key
andreimacavei Jul 21, 2015
f6c84a1
Made gpg_reset_engine to accept an optional argument as for the curre…
andreimacavei Jul 22, 2015
bbbca3e
gpg: Added gpg_encrypt_data function which will be used to encrypt ke…
andreimacavei Jul 23, 2015
a71da8e
Sections.py: Updated sign_key_async method to use our new gpg lib
andreimacavei Jul 23, 2015
b3507ef
Deleted unused UIDExport_gpgme func and cleaned up code.
andreimacavei Jul 23, 2015
d66d408
gpg_encrypt_data: added docstrings for function
andreimacavei Jul 23, 2015
19af4a2
Sections: we now remove the temporary dir created when we download ke…
andreimacavei Jul 23, 2015
6fb2255
KeysPage.py: replaced old gpg API
andreimacavei Jul 23, 2015
88ad53b
Added gpg_get_siglist lib function and more API replacement in SignPa…
andreimacavei Jul 24, 2015
d62e72a
KeyPresent: replaced old gpg API
andreimacavei Jul 24, 2015
32f216b
gpg: Finished the replacement of monkeysign with gpgme.
andreimacavei Jul 24, 2015
577ecaf
gpg: deleted extra test code from the library
andreimacavei Aug 2, 2015
30cb394
gpg: added a test suite for gpg library
andreimacavei Aug 2, 2015
caf94b1
Sections.py: removed MonkeysignUI which wasn't used anymore.
andreimacavei Aug 2, 2015
f245aa4
Merged with muelli/master
andreimacavei Aug 2, 2015
b4a779b
Updated RELEASE_NOTES and requirements files
andreimacavei Aug 2, 2015
6ceb524
Updated copyrights
andreimacavei Aug 2, 2015
aef766c
gpg: Fixed ImportError for Python3 on StringIO
andreimacavei Aug 4, 2015
49bed8b
gpg: Added a '__name__' argument to logging.getLogger()
andreimacavei Aug 4, 2015
b5073a9
gpg: Refactored gpg_import_key_by_fpr funtion to be more clear about …
andreimacavei Aug 4, 2015
09ec352
gpg: raised ValueError now contains the logged string
andreimacavei Aug 4, 2015
21057f8
Renamed extract_keydata function and updated the docstrings
andreimacavei Aug 4, 2015
406cfe4
test_gpg_copy_secrets: made it to verify keys in a more pythonic way
andreimacavei Aug 4, 2015
79b0080
test.py: fixed function name and removed obsolete test
andreimacavei Aug 8, 2015
43614ea
gpg: fixed gpg_import_key and switched to BytesIO instead of StringIO…
andreimacavei Aug 9, 2015
32f8613
gpg: small improvement on getting the default gpg home
andreimacavei Aug 9, 2015
45ba7bf
export_key: added support for exporting key with additional 'mode' ar…
andreimacavei Aug 16, 2015
bd6ff0e
gpg: Contexts can be set easier, w/o having to specify user's default…
andreimacavei Aug 16, 2015
11733d6
gpg_copy_secrets: gpg_default path is now more robust
andreimacavei Aug 17, 2015
3bc8ed8
Fixed tests which were broken by latest code updates.
andreimacavei Aug 17, 2015
2035793
'gpg_import_keydata' will now return the results object generated by …
andreimacavei Aug 17, 2015
3e1ad2b
Code refactoring to make 'gpg_sign_uid' more robust.
andreimacavei Aug 17, 2015
88ddd4d
Improved the way we get the selected key fpr from within the UI.
andreimacavei Aug 17, 2015
b16133a
Updated 'gpg_sign_uid' to sign also the uids that were already signed.
andreimacavei Aug 17, 2015
4bef2db
Changed gpg_copy_secrets to gpg_export_private_key.
andreimacavei Aug 20, 2015
1ae536a
Eliminated a possible filesystem leak by exporting the private key to…
andreimacavei Aug 20, 2015
f99bd86
Added a 'secret_key' argument to 'gpg_sign_uid' function.
andreimacavei Aug 20, 2015
642fdc8
Fixed a bug in GPGQRCode.py widget which was causing gks-qrcode scrip…
andreimacavei Aug 22, 2015
01edc64
test: imported StringIO from IO for Python3 compatibility
muelli Sep 2, 2015
99f6605
gpg: Do not encode keydata on import
muelli Sep 2, 2015
4763a97
Sections: Debugging the keylist after downloading the key
muelli Sep 2, 2015
779217d
Sections: Made it work again by not deleting the keyring too early
muelli Sep 2, 2015
dc0952d
gpg test: Asserted that we have more signatures than before
muelli Sep 2, 2015
39c6a2c
Merge pull request #14 from muelli/pygpgme
andreimacavei Sep 14, 2015
dcf0e3f
Sections: Now it also removes the gpg tmpdir after saving the downloa…
andreimacavei Sep 14, 2015
8df5ed2
GPGQRCode: change error message and exit value
andreimacavei Oct 1, 2015
67195f2
Sections: Changed download_key_http to return bytes through content f…
andreimacavei Apr 8, 2016
7d2107a
gpg: gpg_get_keylist can receive extra argument for key expired
andreimacavei Apr 18, 2016
32902ae
Removed the gpg_ prefix from gpg functions.
andreimacavei Apr 18, 2016
faa997c
Sections: updated the way we get the imported key.
andreimacavei May 30, 2016
486dfde
Sections: Updated the in code comments for signing keys
andreimacavei May 30, 2016
620ec60
Sections: moved log call before the respective function
andreimacavei May 31, 2016
30ed79b
SignPages: fix the init for the cached context
andreimacavei May 31, 2016
5199d57
SignPages: use list comprehension for creating sigs list
andreimacavei May 31, 2016
2674491
gpg: update argument name to be more specific
andreimacavei Jun 2, 2016
8d9e434
gpg: Add lib function that returns user's personal keys.
andreimacavei Jun 5, 2016
bff37ea
gpg: Update lib function and remove validation from within it.
andreimacavei Jun 5, 2016
4509c43
gpg: Update message about export private key thread
andreimacavei Jun 7, 2016
efe80f1
gpg: Add `export_secret_keys` function.
andreimacavei Jun 7, 2016
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

clean:
rm -f *.pyc
find . -name "*.pyc" -type f -delete
6 changes: 5 additions & 1 deletion RELEASE_NOTES
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ This is the v0.3 release and bring a few tiny fixes all over the program.
Changes
==========

-Major
* New gpg library which replaces monkeysign dependency
* Optimised finding the correct key to download
* Removed once discovered clients if they disappear

-Minor
* Experimental compatibility for older Gtk versions (set_always_show_image)
* Minor UI improvement: Do not delete the manually typed fingerprint when going back
* Also accept more correctly typed fingerprint with a more relaxed verification routine
Expand All @@ -17,5 +21,5 @@ Resources
=========

Download: https://github.com/muelli/geysigning/releases/download/0.3/gnome-keysign-0.3.tar.gz
sha256sum:
sha256sum:
Web site: https://wiki.gnome.org/GnomeKeysign
15 changes: 10 additions & 5 deletions keysign/GPGQRCode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# Copyright 2014 Tobias Mueller <[email protected]>
# Copyright 2015 Andrei Macavei <[email protected]>
#
# This file is part of GNOME Keysign.
#
Expand All @@ -20,20 +21,24 @@
for keys and selects the one matching your input
"""
from gi.repository import Gtk
from monkeysign.gpg import Keyring
import gpgme
from gpg import gpg

from QRCode import QRImage

def main():
import sys
if len(sys.argv) < 2:
print ("Usage: {} <KEY>".format(sys.argv[0]))
sys.exit(1)
key = sys.argv[1]
keyring = Keyring()
keys = keyring.get_keys(key)
keyring = gpgme.Context()
keys = gpg.get_keylist(keyring, key)
# Heh, we take the first key here. Maybe we should raise a warning
# or so, when there is more than one key.
fpr = keys.items()[0][0]
fpr = keys[0].subkeys[0].fpr
data = 'OPENPGP4FPR:' + fpr

w = Gtk.Window()
w.connect("delete-event", Gtk.main_quit)
w.set_default_size(100,100)
Expand Down
24 changes: 12 additions & 12 deletions keysign/KeyPresent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# encoding: utf-8
# Copyright 2014 Tobias Mueller <[email protected]>
# Copyright 2015 Andrei Macavei <[email protected]>
#
# This file is part of GNOME Keysign.
#
Expand All @@ -26,7 +27,8 @@
from gi.repository import Gtk, GLib
from gi.repository import GObject

from monkeysign.gpg import Keyring
import gpgme
from gpg import gpg

# These are relative imports
from __init__ import __version__
Expand All @@ -41,7 +43,7 @@
class KeyPresent(Gtk.Application):
"""A demo application showing how to display sufficient details
about a key such that it can be sent securely.

Note that the main purpose is to enable secure transfer, not
reviewing key details. As such, the implementation might change
a lot, depending on the method of secure transfer.
Expand Down Expand Up @@ -127,16 +129,14 @@ def main(args=sys.argv):
format='%(name)s (%(levelname)s): %(message)s')
try:
arguments = parse_command_line(args)

#if arguments.gpg:
# keyid = arguments.file
# keyring = Keyring()
# # this is a dict {fpr: key-instance}
# found_keys = keyring.get_keys(keyid)
# ctx = gpgme.Context()
# found_keys = gpg.get_keylist(ctx, keyid)
# # We take the first item we found and export the actual keydata
# fpr = found_keys.items()[0][0]
# keyring.export_data(fpr=fpr, secret=False)
# keydata = keyring.context.stdout
# fpr = found_keys[0].subkeys[0].fpr
# keydata = gpg.extract_keydata(ctx, fpr, True)
#else:
# keydata = open(arguments.file, 'r').read()
fpr = arguments.fpr
Expand All @@ -146,12 +146,12 @@ def main(args=sys.argv):
GLib.unix_signal_add_full(GLib.PRIORITY_HIGH, signal.SIGINT, lambda *args : app.quit(), None)
except AttributeError:
pass

exit_status = app.run(fpr)

return exit_status


finally:
logging.shutdown()

Expand Down
55 changes: 28 additions & 27 deletions keysign/KeysPage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# encoding: utf-8
# Copyright 2015 Andrei Macavei <[email protected]>
# Copyright 2014 Tobias Mueller <[email protected]>
#
# This file is part of GNOME Keysign.
Expand All @@ -26,9 +27,10 @@
from gi.repository import Gtk, GLib
from gi.repository import GObject

from monkeysign.gpg import Keyring
import gpgme

# These are relative imports
from gpg import gpg
from __init__ import __version__

log = logging.getLogger()
Expand All @@ -37,10 +39,10 @@
class KeysPage(Gtk.VBox):
'''This represents a list of keys with the option for the user
to select one key to proceed.

This class emits a `key-selection-changed' signal when the user
initially selects a key such that it is highlighted.

The `key-selected' signal is emitted when the user commits
to a key, i.e. by pressing a designated button to make his
selection public.
Expand All @@ -58,7 +60,7 @@ class KeysPage(Gtk.VBox):

def __init__(self, show_public_keys=False):
'''Sets the widget up.

The show_public_keys parameter is meant for development
purposes only. If set to True, the widget will show
the public keys, too. Otherwise, secret keys are shown.
Expand All @@ -71,19 +73,18 @@ def __init__(self, show_public_keys=False):
# TreeView, i.e. in get_items_from_selection.
self.store = Gtk.ListStore(str, str, str)

# FIXME: this should be moved to KeySignSection
self.keyring = Keyring() # the user's keyring
# XXX: maybe we can move this to KeySignSection in Sections.py
self.ctx = gpgme.Context()

self.keysDict = {}

# FIXME: this should be a callback function to update the display
# when a key is changed/deleted
for key in self.keyring.get_keys(None, secret=True, public=show_public_keys).values():
if key.invalid or key.disabled or key.expired or key.revoked:
# FIXME: implement a callback that refreshes the UIDs when they change
for key in gpg.get_keylist(self.ctx, None, True):
if key.revoked or key.expired or key.invalid or key.subkeys[0].disabled:
continue

uidslist = key.uidslist #UIDs: Real Name (Comment) <email@address>
keyid = str(key.keyid()) # the key's short id
uidslist = key.uids
keyid = key.subkeys[0].fpr[-8:]

if not keyid in self.keysDict:
self.keysDict[keyid] = key
Expand Down Expand Up @@ -125,7 +126,7 @@ def __init__(self, show_public_keys=False):
self.treeView.append_column(nameColumn)
self.treeView.append_column(emailColumn)
self.treeView.append_column(keyColumn)

self.treeView.connect('row-activated', self.on_row_activated)

# make the tree view resposive to single click selection
Expand Down Expand Up @@ -173,14 +174,14 @@ def get_items_from_selection(self, selection=None):

def on_selection_changed(self, selection, *args):
log.debug('Selected new TreeView item %s = %s', selection, args)

name, email, keyid = self.get_items_from_selection(selection)

key = self.keysDict[keyid]
self.emit('key-selection-changed', keyid)

try:
exp_date = datetime.fromtimestamp(float(key.expiry))
exp_date = datetime.fromtimestamp(float(key.subkeys[0].expires))
expiry = "{:%Y-%m-%d %H:%M:%S}".format(exp_date)
except ValueError, e:
expiry = "No expiration date"
Expand All @@ -207,7 +208,7 @@ def on_selection_changed(self, selection, *args):
def on_row_activated(self, treeview, tree_path, column):
'''A callback for when the user "activated" a row,
e.g. by double-clicking an entry.

It emits the key-selected signal.
'''
# We just hijack the existing function.
Expand All @@ -222,15 +223,15 @@ def on_publish_button_clicked(self, button, key, *args):
to publish a key on the network. It will emit a "key-selected"
signal with the ID of the selected key.'''
log.debug('Clicked publish for key (%s) %s (%s)', type(key), key, args)
keyid = key.keyid()
keyid = key.subkeys[0].fpr[-8:]
self.emit('key-selected', keyid)




class Keys(Gtk.Application):
"""A widget which displays keys in a user's Keyring.

Once the user has selected a key, the key-selected
signal will be thrown.
"""
Expand Down Expand Up @@ -273,7 +274,7 @@ def on_activate(self, app):
def on_key_selection_changed(self, button, key):
"""This is the connected to the KeysPage's key-selection-changed
signal

As a user of that widget, you would show more details
in the GUI or prepare for a final commitment by the user.
"""
Expand All @@ -282,13 +283,13 @@ def on_key_selection_changed(self, button, key):

def on_key_selected(self, button, key):
"""This is the connected to the KeysPage's key-selected signal

As a user of that widget, you would enable buttons or proceed
with the GUI.
"""
self.log.info('User committed to a key! %s', key)


def parse_command_line(argv):
"""Parse command line argument. See -h option

Expand Down Expand Up @@ -321,18 +322,18 @@ def main(args=sys.argv):
format='%(name)s (%(levelname)s): %(message)s')
try:
arguments = parse_command_line(args)

app = Keys()
try:
GLib.unix_signal_add_full(GLib.PRIORITY_HIGH, signal.SIGINT, lambda *args : app.quit(), None)
except AttributeError:
pass

exit_status = app.run(None)

return exit_status


finally:
logging.shutdown()

Expand Down
1 change: 1 addition & 0 deletions keysign/Keyserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def start(self, data=None, fpr=None, port=None, *args, **kwargs):

tries = 10

fpr = self.fpr if self.fpr else "FIXME fingerprint"
kd = data if data else self.keydata

class KeyRequestHandler(KeyRequestHandlerBase):
Expand Down
Loading