diff --git a/.gitignore b/.gitignore index ae7c3ce..f36e996 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,7 @@ nosetests.xml *~ *.swp *.swo +*.orig # tags TAGS @@ -56,10 +57,10 @@ tags *random_seed* *.log tests/doctests/* -gnupg/test/doctests/* -gnupg/test/logs/* -gnupg/test/tmp/* -gnupg/test/files/* +pretty_bad_protocol/test/doctests/* +pretty_bad_protocol/test/logs/* +pretty_bad_protocol/test/tmp/* +pretty_bad_protocol/test/files/* # Ignore distutils record of installed files: installed-files.txt diff --git a/Makefile b/Makefile index cb64de9..578c65b 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ SHELL=/bin/sh -TESTDIR=./gnupg/test +TESTDIR=./pretty_bad_protocol/test TESTHANDLE=$(TESTDIR)/test_gnupg.py -FILES=$(SHELL find ./gnupg/ -name "*.py" -printf "%p,") +FILES=$(SHELL find ./pretty_bad_protocol/ -name "*.py" -printf "%p,") PYTHON=$(SHELL which python) PYTHON3=$(SHELL which python3) -PKG_NAME=python-gnupg +PKG_NAME=pretty_bad_protocol DOC_DIR=docs DOC_BUILD_DIR:=$(DOC_DIR)/_build DOC_HTML_DIR:=$(DOC_BUILD_DIR)/html @@ -29,8 +29,8 @@ cleanup-src: pycremoval cleanup-tests: cleanup-src cd $(TESTDIR) && rm -f \#*\# - mkdir -p gnupg/test/tmp - mkdir -p gnupg/test/logs + mkdir -p $(TESTDIR)/tmp + mkdir -p $(TESTDIR)/logs cleanup-tests-all: cleanup-tests rm -rf tests/tmp @@ -42,6 +42,10 @@ cleanup-build: cleanup-dist: -rm -rf dist +clean: cleanup-build cleanup-tests-all cleanup-src + +dist-clean: clean cleanup-dist + # it's not strictly necessary that gnupg2, gpg-agent, pinentry, or pip be # installed, so ignore error exit statuses for those commands test-before: cleanup-src cleanup-tests @@ -111,11 +115,9 @@ coverage-html: coverage html --rcfile=".coveragerc" clean-test: - touch gnupg/test/placeholder.log - mv gnupg/test/*.log gnupg/test/logs/ - rm gnupg/test/logs/placeholder.log - touch gnupg/test/random_seed_is_sekritly_pi - rm gnupg/test/random_seed* + -mv $(TESTDIR)/*.log $(TESTDIR)/logs/ + -rm $(TESTDIR)/logs/placeholder.log + -rm $(TESTDIR)/random_seed* test: test-run clean-test diff --git a/README b/README index 503ae32..f1cb30b 100644 --- a/README +++ b/README @@ -1,10 +1,10 @@ .. -*- coding: utf-8; mode: rst; -*- -************************************** -python-gnupg |On PyPI| -************************************** +******************************************************* +pretty-bad-protocol (a.k.a. python-gnupg) |On PyPI| +******************************************************* -Rewrite of `Vinay Sajip's python-gnupg `__, +Complete rewrite of `Vinay Sajip's python-gnupg `__, including patches to fix a shell injection vulnerability due to unsanitised inputs being passed to ``subprocess.Popen([...], shell=True)``. @@ -21,6 +21,11 @@ From `PyPI `__ It's simple. Just do:: + [sudo] pip install pretty-bad-security + +Additionally, the legacy way to install versions of this library < +3.0.0 is:: + [sudo] pip install gnupg -------- @@ -42,8 +47,7 @@ Optionally, to build the Sphinx documentation_, do:: To get started using python-gnupg's API, see the documentation_, and import the module like so:: - >>> import gnupg - + >>> from pretty_bad_protocol import gnupg The primary interface class you'll likely want to interact with is ``gnupg.GPG``:: @@ -76,7 +80,11 @@ The primary interface class you'll likely want to interact with is ``gnupg.GPG`` Bug Reports & Feature Requests ============================== -Our bugtracker can be found -`on Github `__. Public -comments and discussions are also welcome on the bugtracker, or as -`tweets `__. Patches are always welcome. +Our bugtracker can be found `on Github +`__. Public comments and +discussions are also welcome on the bugtracker. Patches are always welcome. + +I increasingly have less and less time to deal with maintaining this +module. Please be patient, and if there is a patch your project +urgently needs, please consider temporarily forking until I or one of +the other maintainers can get to your issue. diff --git a/docs/conf.py b/docs/conf.py index 0bb50b3..bdb2a1f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -61,7 +61,7 @@ # built documents. # # The short X.Y version. -import gnupg +from pretty_bad_protocol import gnupg version = gnupg.__version__ # The full version, including alpha/beta/rc tags. release = gnupg.__version__ diff --git a/gnupg/__init__.py b/pretty_bad_protocol/__init__.py similarity index 91% rename from gnupg/__init__.py rename to pretty_bad_protocol/__init__.py index 5c1430c..0f6bf25 100644 --- a/gnupg/__init__.py +++ b/pretty_bad_protocol/__init__.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- # # This file is part of python-gnupg, a Python interface to GnuPG. @@ -35,12 +34,15 @@ __license__ = copyleft.full_text __copyleft__ = copyleft.copyright +gnupg.__version__ = __version__ +gnupg.__authors__ = __authors__ +gnupg.__licence__ = __license__ +gnupg.__copyleft__ = __copyleft__ + ## do not set __package__ = "gnupg", else we will end up with ## gnupg.<*allofthethings*> __all__ = ["GPG", "_util", "_parsers", "_meta", "_logger"] -## avoid the "from gnupg import gnupg" idiom -del gnupg del absolute_import del copyleft del get_versions diff --git a/gnupg/_ansistrm.py b/pretty_bad_protocol/_ansistrm.py similarity index 100% rename from gnupg/_ansistrm.py rename to pretty_bad_protocol/_ansistrm.py diff --git a/gnupg/_logger.py b/pretty_bad_protocol/_logger.py similarity index 100% rename from gnupg/_logger.py rename to pretty_bad_protocol/_logger.py diff --git a/gnupg/_meta.py b/pretty_bad_protocol/_meta.py similarity index 100% rename from gnupg/_meta.py rename to pretty_bad_protocol/_meta.py diff --git a/gnupg/_parsers.py b/pretty_bad_protocol/_parsers.py similarity index 99% rename from gnupg/_parsers.py rename to pretty_bad_protocol/_parsers.py index 7dd1ed7..e7e950b 100644 --- a/gnupg/_parsers.py +++ b/pretty_bad_protocol/_parsers.py @@ -1090,6 +1090,8 @@ def _handle_status(self, key, value): self.status += " on {}".format(str(value)) elif key == "NODATA": self.status = nodata(value) + elif key == "PROGRESS": + self.status = progress(value.split(" ", 1)[0]) else: raise ValueError("Unknown status message: %r" % key) @@ -1498,6 +1500,7 @@ def _handle_status(self, key, value): "PROGRESS", "PINENTRY_LAUNCHED", "SUCCESS", + "UNEXPECTED", ): pass elif key == "KEY_CONSIDERED": @@ -1653,7 +1656,7 @@ def _handle_status(self, key, value): else: pass else: - raise ValueError("Unknown status message: %r" % key) + raise ValueError("Unknown status message: %r %r" % (key, value)) class Crypt(Verify): diff --git a/gnupg/_trust.py b/pretty_bad_protocol/_trust.py similarity index 97% rename from gnupg/_trust.py rename to pretty_bad_protocol/_trust.py index bc87a62..1e118bd 100644 --- a/gnupg/_trust.py +++ b/pretty_bad_protocol/_trust.py @@ -60,6 +60,7 @@ def export_ownertrust(cls, trustdb=None): export_proc = cls._open_subprocess(['--export-ownertrust']) tdb = open(trustdb, 'wb') _util._threaded_copy_data(export_proc.stdout, tdb) + export_proc.wait() def import_ownertrust(cls, trustdb=None): """Import ownertrust from a trustdb file. @@ -79,6 +80,7 @@ def import_ownertrust(cls, trustdb=None): log.error("trustdb file %s does not exist!" % trustdb) _util._threaded_copy_data(tdb, import_proc.stdin) + import_proc.wait() def fix_trustdb(cls, trustdb=None): """Attempt to repair a broken trustdb.gpg file. @@ -106,3 +108,5 @@ def fix_trustdb(cls, trustdb=None): export_proc = cls._open_subprocess(['--export-ownertrust']) import_proc = cls._open_subprocess(['--import-ownertrust']) _util._threaded_copy_data(export_proc.stdout, import_proc.stdin) + export_proc.wait() + import_proc.wait() diff --git a/gnupg/_util.py b/pretty_bad_protocol/_util.py similarity index 100% rename from gnupg/_util.py rename to pretty_bad_protocol/_util.py diff --git a/gnupg/_version.py b/pretty_bad_protocol/_version.py similarity index 100% rename from gnupg/_version.py rename to pretty_bad_protocol/_version.py diff --git a/gnupg/copyleft.py b/pretty_bad_protocol/copyleft.py similarity index 100% rename from gnupg/copyleft.py rename to pretty_bad_protocol/copyleft.py diff --git a/gnupg/gnupg.py b/pretty_bad_protocol/gnupg.py similarity index 100% rename from gnupg/gnupg.py rename to pretty_bad_protocol/gnupg.py diff --git a/gnupg/test/__init__.py b/pretty_bad_protocol/test/__init__.py similarity index 100% rename from gnupg/test/__init__.py rename to pretty_bad_protocol/test/__init__.py diff --git a/gnupg/test/doctests/README b/pretty_bad_protocol/test/doctests/README similarity index 100% rename from gnupg/test/doctests/README rename to pretty_bad_protocol/test/doctests/README diff --git a/gnupg/test/files/cypherpunk_manifesto b/pretty_bad_protocol/test/files/cypherpunk_manifesto similarity index 100% rename from gnupg/test/files/cypherpunk_manifesto rename to pretty_bad_protocol/test/files/cypherpunk_manifesto diff --git a/gnupg/test/files/kat.pub b/pretty_bad_protocol/test/files/kat.pub similarity index 100% rename from gnupg/test/files/kat.pub rename to pretty_bad_protocol/test/files/kat.pub diff --git a/gnupg/test/files/kat.sec b/pretty_bad_protocol/test/files/kat.sec similarity index 100% rename from gnupg/test/files/kat.sec rename to pretty_bad_protocol/test/files/kat.sec diff --git a/gnupg/test/files/test_key_1.pub b/pretty_bad_protocol/test/files/test_key_1.pub similarity index 100% rename from gnupg/test/files/test_key_1.pub rename to pretty_bad_protocol/test/files/test_key_1.pub diff --git a/gnupg/test/files/test_key_1.sec b/pretty_bad_protocol/test/files/test_key_1.sec similarity index 100% rename from gnupg/test/files/test_key_1.sec rename to pretty_bad_protocol/test/files/test_key_1.sec diff --git a/gnupg/test/files/test_key_2.pub b/pretty_bad_protocol/test/files/test_key_2.pub similarity index 100% rename from gnupg/test/files/test_key_2.pub rename to pretty_bad_protocol/test/files/test_key_2.pub diff --git a/gnupg/test/files/test_key_2.sec b/pretty_bad_protocol/test/files/test_key_2.sec similarity index 100% rename from gnupg/test/files/test_key_2.sec rename to pretty_bad_protocol/test/files/test_key_2.sec diff --git a/gnupg/test/test_gnupg.py b/pretty_bad_protocol/test/test_gnupg.py similarity index 100% rename from gnupg/test/test_gnupg.py rename to pretty_bad_protocol/test/test_gnupg.py diff --git a/gnupg/test/test_parsers.py b/pretty_bad_protocol/test/test_parsers.py similarity index 100% rename from gnupg/test/test_parsers.py rename to pretty_bad_protocol/test/test_parsers.py diff --git a/setup.py b/setup.py index 08cdfb8..a409fa6 100644 --- a/setup.py +++ b/setup.py @@ -36,10 +36,10 @@ _isPyPy = True -versioneer.versionfile_source = 'gnupg/_version.py' -versioneer.versionfile_build = 'gnupg/_version.py' +versioneer.versionfile_source = 'pretty_bad_protocol/_version.py' +versioneer.versionfile_build = 'pretty_bad_protocol/_version.py' versioneer.tag_prefix = '' -versioneer.parentdir_prefix = 'gnupg-' +versioneer.parentdir_prefix = 'pretty-bad-protocol-' __author__ = "Isis Agora Lovecruft" __contact__ = 'isis@patternsinthevoid.net' @@ -97,7 +97,7 @@ def get_requirements(): setuptools.setup( - name = "gnupg", + name = "pretty-bad-protocol", description="A Python wrapper for GnuPG", long_description = """\ This module allows easy access to GnuPG's key management, encryption and \ @@ -118,11 +118,13 @@ def get_requirements(): maintainer_email=__contact__, url=__url__, - package_dir={'gnupg': 'gnupg'}, - packages=['gnupg'], + package_dir={ + 'pretty_bad_protocol': 'pretty_bad_protocol', + }, + packages=['pretty_bad_protocol'], package_data={'': ['README', 'LICENSE', 'TODO', 'requirements.txt']}, scripts=['versioneer.py'], - test_suite='gnupg.test.test_gnupg', + test_suite='pretty_bad_protocol.test.test_gnupg', install_requires=requires, dependency_links=deplinks,