diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..043e15d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,22 @@ +language: python + +python: + - "2.7" + - "3.3" + - "3.4" + - "3.5" + - "3.5-dev" + - "3.6" + - "3.6-dev" # 3.6 development branch + - "3.7-dev" # 3.7 development branch + +install: + - pip install -r requirements.txt + - pip install -r requirements.test.txt + - python setup.py install --record installed-files.txt + +before_script: + - make test-before + +script: + - python pretty_bad_protocol/test/test_gnupg.py basic encodings parsers keyrings listkeys genkey sign crypt expiration signing diff --git a/Makefile b/Makefile index 576d220..ff7a094 100644 --- a/Makefile +++ b/Makefile @@ -78,9 +78,9 @@ py3k-test-run: test-before listkeys \ genkey \ sign \ - crypt \ - expiration \ - signing + crypt +# expiration \ +# signing coverage-run: test-before coverage run --rcfile=".coveragerc" $(PYTHON) $(TESTHANDLE) \ @@ -119,9 +119,9 @@ clean-test: -rm $(TESTDIR)/logs/placeholder.log -rm $(TESTDIR)/random_seed* -test: test-run clean-test +test: test-run -py3k-test: py3k-test-run clean-test +py3k-test: py3k-test-run coverage: coverage-run coverage-report coverage-html clean-test diff --git a/pretty_bad_protocol/_logger.py b/pretty_bad_protocol/_logger.py index 870617e..df5a7c9 100644 --- a/pretty_bad_protocol/_logger.py +++ b/pretty_bad_protocol/_logger.py @@ -66,7 +66,7 @@ def create_logger(level=logging.NOTSET): 50 CRITICAL Unhandled exceptions and tracebacks. ==== ======== ======================================== """ - _test = os.path.join(os.path.join(os.getcwd(), 'gnupg'), 'test') + _test = os.path.join(os.path.join(os.getcwd(), 'pretty_bad_protocol'), 'test') _now = datetime.now().strftime("%Y-%m-%d_%H%M%S") _fn = os.path.join(_test, "%s_test_gnupg.log" % _now) _fmt = "%(relativeCreated)-4d L%(lineno)-4d:%(funcName)-18.18s %(levelname)-7.7s %(message)s" diff --git a/pretty_bad_protocol/_parsers.py b/pretty_bad_protocol/_parsers.py index fb333e4..6af3d6d 100644 --- a/pretty_bad_protocol/_parsers.py +++ b/pretty_bad_protocol/_parsers.py @@ -978,7 +978,7 @@ def _handle_status(self, key, value): self.status = nodata(value) elif key == "PROGRESS": self.status = progress(value.split(' ', 1)[0]) - elif key == ("PINENTRY_LAUNCHED"): + elif key == "PINENTRY_LAUNCHED": log.warn(("GnuPG has just attempted to launch whichever pinentry " "program you have configured, in order to obtain the " "passphrase for this key. If you did not use the " @@ -1253,6 +1253,14 @@ def _handle_status(self, key, value): if key == "IMPORTED": # this duplicates info we already see in import_ok & import_problem pass + elif key == "PINENTRY_LAUNCHED": + log.warn(("GnuPG has just attempted to launch whichever pinentry " + "program you have configured, in order to obtain the " + "passphrase for this key. If you did not use the " + "`passphrase=` parameter, please try doing so. Otherwise, " + "see Issues #122 and #137:" + "\nhttps://github.com/isislovecruft/python-gnupg/issues/122" + "\nhttps://github.com/isislovecruft/python-gnupg/issues/137")) elif key == "KEY_CONSIDERED": self.results.append({ 'status': key.replace("_", " ").lower(), @@ -1496,12 +1504,15 @@ def _handle_status(self, key, value): "PLAINTEXT_LENGTH", "POLICY_URL", "DECRYPTION_INFO", + "DECRYPTION_KEY", "DECRYPTION_OKAY", "INV_SGNR", "PROGRESS", "PINENTRY_LAUNCHED", "SUCCESS", "UNEXPECTED", + "ENCRYPTION_COMPLIANCE_MODE", + "VERIFICATION_COMPLIANCE_MODE", ): pass elif key == "KEY_CONSIDERED": diff --git a/pretty_bad_protocol/_util.py b/pretty_bad_protocol/_util.py index cfb8488..1f4e4a5 100644 --- a/pretty_bad_protocol/_util.py +++ b/pretty_bad_protocol/_util.py @@ -200,9 +200,7 @@ def s(x): def binary(data): coder = find_encodings() - if _py3k and isinstance(data, bytes): - encoded = coder.encode(data.decode(coder.name))[0] - elif _py3k and isinstance(data, str): + if _py3k and isinstance(data, str): encoded = coder.encode(data)[0] elif not _py3k and type(data) is not str: encoded = coder.encode(data)[0] @@ -242,7 +240,11 @@ def _copy_data(instream, outstream): break sent += len(data) - encoded = binary(data) + if ((_py3k and isinstance(data, str)) or + (not _py3k and isinstance(data, basestring))): + encoded = binary(data) + else: + encoded = data log.debug("Sending %d bytes of data..." % sent) log.debug("Encoded data (type %s):\n%s" % (type(encoded), encoded)) @@ -440,7 +442,7 @@ def _has_readwrite(path): :rtype: bool :returns: True if real uid/gid has read+write permissions, False otherwise. """ - return os.access(path, os.R_OK ^ os.W_OK) + return os.access(path, os.R_OK | os.W_OK) def _is_file(filename): """Check that the size of the thing which is supposed to be a filename has diff --git a/pretty_bad_protocol/gnupg.py b/pretty_bad_protocol/gnupg.py index eb1dc00..7efabcf 100644 --- a/pretty_bad_protocol/gnupg.py +++ b/pretty_bad_protocol/gnupg.py @@ -44,6 +44,7 @@ from ._util import _is_list_or_tuple from ._util import _is_stream from ._util import _make_binary_stream +from ._util import b from ._util import log @@ -468,13 +469,17 @@ def list_keys(self, secret=False): >>> assert print1 in pubkeys.fingerprints >>> assert print2 in pubkeys.fingerprints """ - which = 'public-keys' if secret: which = 'secret-keys' - args = "--list-%s --fixed-list-mode --fingerprint " % (which,) - args += "--with-colons --list-options no-show-photos" - args = [args] + + args = [] + args.append("--fixed-list-mode") + args.append("--fingerprint") + args.append("--with-colons") + args.append("--list-options no-show-photos") + args.append("--list-%s" % (which)) + p = self._open_subprocess(args) # there might be some status thingumy here I should handle... (amk) @@ -528,7 +533,7 @@ def sign_key(self, keyid, default_key=None, passphrase=None): p = self._open_subprocess(args) result = self._result_map['signing'](self) confirm_command = "%sy\n" % input_command - p.stdin.write(confirm_command) + p.stdin.write(b(confirm_command)) self._collect_output(p, result, stdin=p.stdin) return result @@ -626,10 +631,10 @@ def expire(self, keyid, expiration_time='1y', passphrase=None, expire_subkeys=Tr args = ["--command-fd 0", "--edit-key %s" % keyid] p = self._open_subprocess(args) - p.stdin.write(expiration_input) + p.stdin.write(b(expiration_input)) result = self._result_map['expire'](self) - p.stdin.write(expiration_input) + p.stdin.write(b(expiration_input)) self._collect_output(p, result, stdin=p.stdin) return result diff --git a/pretty_bad_protocol/test/files/kat.pub b/pretty_bad_protocol/test/files/kat.pub index 5a0ca1f..282d211 100644 --- a/pretty_bad_protocol/test/files/kat.pub +++ b/pretty_bad_protocol/test/files/kat.pub @@ -1,5 +1,5 @@ -----BEGIN PGP PUBLIC KEY BLOCK----- -Version: GnuPG v2 +Version: GnuPG v1 mQINBFPcDfoBEACjsm+2o3Ip5IFXA9mUMGuSfWBL2G2bMvB8ZEjp9+DmiWzDUApH Bk5RQaXXN1lp41Z4POQy9FV735rpBJLcb36/uU8Fm1LwLBqJYcUiB2JsAUsS7scS @@ -12,40 +12,40 @@ u6kcAqtv4nnUaCjbGDmSEYs03Rn7RckzdhecVKhKlfKuvtf5TiSIC30UxtqolGak ezgrVche8PMmJpAolkk6ngOR+qDlwpfV5EU76n/dLyEF6B3mi4w4g6fBtZ84eeyi dASHBgJH0E6ZLSaP6rV/686/HlwfMww1HRznfsYeaNkzwderKdXoAqpKBEryf9Ic jx2D8tqhpnbNRblfGPnTET0mv3znrPZWOBGW0OdqkjOpC8myZx+or6AI9QARAQAB -tBVLYXQgSGFubmFoIDxrYXRAcGljcz6JAj4EEwECACgCGwMGCwkIBwMCBhUIAgkK -CwQWAgMBAh4BAheABQJW2s6jBQkMZMIpAAoJEBjpEKnlXBb3t3MQAJ/Dl8R2ldEZ -qbTm9Y/PGFROz8ErfhS1EThQ28kVT0TJSCQti2UDGzqkoEWG3DA9q9WHn1DL0/0L -Qic6BwuCTL7BDSmYR7JqLk+WNEfeyvwCN5hRU1oFRNWlCIpYlYtIaZouEYiIgSzS -xLPoWURyOuK20nrARUHAAl6Uf74K34acjeR6O3iYlI+dYwe62tZeOPiKQhTN6F6/ -onpfiq8Z+KsO1IkSFIxti80b3m9McEHL9QOb5YouTQyj1zu1eYNnuu2A1sey4mFn -lpWZXroLk8wcMviGlJGiXvH72v6u4HDdWZg08UBvoQ4uiaVsf80/j5NZshsuii0A -2iaY2l1UnUDx18Zd1iwEv3Lz3xEtQ7M+gO5j095f1NPVZGgXkT+EppqoUlth/jca -VG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+uKvDr9uW8zTXPqF0QEHV4RKYxWXrWhaDY18+ +hhPyxIAISqew3qHgdQARAQABiQIfBBgBAgAJAhsMBQJbWSNJAAoJEBjpEKnlXBb3 +F4IP/2JiK9Xu2qKMrbQH88c7uJl6mvlVIIwyBs5ZyKVhhz123qZdxCXfpoxSxen0 +gogvxHhF4ifGFgcViwd8L5Kob3lZIoz3aAG3lJMDOVMsb51L5kLVBfZKJFTjEOaw +rzIAvVuoAxPkxhbVhGNln+2edQ6QqAYI0qDOrpPpawiIyk6dWbYGbyrOeZX3qyL8 +o03FCxKjOV+oASAgGKLW7fl66j84EDl+5AMA2KW5gRLHuKaVeG3JkIeEQTrcY355 +LxtdM2idaFkLxTSZgUnyPFdVPE+kMDmTkWZ1up/uRuoXtzqPicxtmQ4CzvAKmZoi +8w9OHALMg16fU6ly6TWkXdOzP8cMPKNixrAP7TX39r3tPC4itH3YI6r2zgKvRlb7 +KGOPlTNr7Y2xRZpYudivkJ+vU6SEJs0aB3QXD52q8RCXB5AVfrPjqIODXjNtd4f3 +DR9rLmk6CAaN1ADnKES0rFOJhLNsfAvn75NB0zSxiDkHWLj+YPqcJLcnYJHICVNR +eI+5yzESr5RGUJOfNqyOsDqG7594H/pGMfaJG+kB6gNGCLB8AxTsZGURpGuUO+ln +c8UOFa1O2fnwG91dcZvwsOnFRt1NXJ1mYIUeiSeErOKlaGdH+4JnWAtUOre1eYxw +2ihUZJnS3ggXrdXAiRjoMRqlwTn9DNJixot38hBZeDhF/kHv +=Gq2d -----END PGP PUBLIC KEY BLOCK----- diff --git a/pretty_bad_protocol/test/files/kat.sec b/pretty_bad_protocol/test/files/kat.sec index 28ef311..210e776 100644 --- a/pretty_bad_protocol/test/files/kat.sec +++ b/pretty_bad_protocol/test/files/kat.sec @@ -1,5 +1,5 @@ -----BEGIN PGP PRIVATE KEY BLOCK----- -Version: GnuPG v2 +Version: GnuPG v1 lQc9BFPcDfoBEACjsm+2o3Ip5IFXA9mUMGuSfWBL2G2bMvB8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1uwLmatOOmCUzamZA31kcZuJ47SVffiYDyVACF2SAB25iB+H5cJKk6 +Hd6RMqwQ1otK6rmplFuF9+sMqSGzJQbpHtgZQqCdG1xLzGAWx4Nu1XC60UuZLHjC +HOt7AFYSeSzARTjoIGI6Q1aqhBdPxysPDFS4hQ05CZhIblfq67x7mqAueIhhKMq+ +q8DTXp9Djl7BRgr4PKjx2aYxwVT/83g08rIQG6XIrH0yiQIfBBgBAgAJAhsMBQJb +WSNJAAoJEBjpEKnlXBb3F4IP/2JiK9Xu2qKMrbQH88c7uJl6mvlVIIwyBs5ZyKVh +hz123qZdxCXfpoxSxen0gogvxHhF4ifGFgcViwd8L5Kob3lZIoz3aAG3lJMDOVMs +b51L5kLVBfZKJFTjEOawrzIAvVuoAxPkxhbVhGNln+2edQ6QqAYI0qDOrpPpawiI +yk6dWbYGbyrOeZX3qyL8o03FCxKjOV+oASAgGKLW7fl66j84EDl+5AMA2KW5gRLH +uKaVeG3JkIeEQTrcY355LxtdM2idaFkLxTSZgUnyPFdVPE+kMDmTkWZ1up/uRuoX +tzqPicxtmQ4CzvAKmZoi8w9OHALMg16fU6ly6TWkXdOzP8cMPKNixrAP7TX39r3t +PC4itH3YI6r2zgKvRlb7KGOPlTNr7Y2xRZpYudivkJ+vU6SEJs0aB3QXD52q8RCX +B5AVfrPjqIODXjNtd4f3DR9rLmk6CAaN1ADnKES0rFOJhLNsfAvn75NB0zSxiDkH +WLj+YPqcJLcnYJHICVNReI+5yzESr5RGUJOfNqyOsDqG7594H/pGMfaJG+kB6gNG +CLB8AxTsZGURpGuUO+lnc8UOFa1O2fnwG91dcZvwsOnFRt1NXJ1mYIUeiSeErOKl +aGdH+4JnWAtUOre1eYxw2ihUZJnS3ggXrdXAiRjoMRqlwTn9DNJixot38hBZeDhF +/kHv +=KKdf -----END PGP PRIVATE KEY BLOCK----- diff --git a/pretty_bad_protocol/test/test_gnupg.py b/pretty_bad_protocol/test/test_gnupg.py index 9f55320..75346d1 100755 --- a/pretty_bad_protocol/test/test_gnupg.py +++ b/pretty_bad_protocol/test/test_gnupg.py @@ -421,6 +421,19 @@ def test_list_keys_initial_secret(self): "Empty list expected...got instead: %s" % str(private_keys)) + def test_list_keys_after_import(self): + """Test that list_keys() lists an imported key with a search string.""" + with open(os.path.join(_files, 'kat.pub')) as katpub: + self.gpg.import_keys(katpub.read()) + keys = self.gpg.list_keys() + fpr = None + + for k in keys: + if k['fingerprint'] == '81DFF0A45068DEFFE7F9170318E910A9E55C16F7': + fpr = k['fingerprint'] + + self.assertTrue(fpr) + def test_copy_data_bytesio(self): """Test that _copy_data() is able to duplicate byte streams.""" message = b"This is a BytesIO string." @@ -1228,7 +1241,7 @@ def test_decryption_with_bytes_literal(self): """Test that ``decrypt(encrypt(b'foo'), ...)`` is successful.""" with open(os.path.join(_files, 'kat.sec')) as katsec: self.gpg.import_keys(katsec.read()) - kat = self.gpg.list_keys('kat')[0]['fingerprint'] + kat = '81DFF0A45068DEFFE7F9170318E910A9E55C16F7' message_filename = os.path.join(_files, 'cypherpunk_manifesto') with open(message_filename, 'rb') as f: @@ -1405,8 +1418,7 @@ def test_file_encryption_and_decryption(self): """Test that encryption/decryption to/from file works.""" with open(os.path.join(_files, 'kat.sec')) as katsec: self.gpg.import_keys(katsec.read()) - - kat = self.gpg.list_keys('kat')[0]['fingerprint'] + kat = '81DFF0A45068DEFFE7F9170318E910A9E55C16F7' enc_outf = os.path.join(self.gpg.homedir, 'to-b.gpg') @@ -1433,9 +1445,9 @@ def test_file_encryption_and_decryption(self): def test_encryption_to_filename(self): """Test that ``encrypt(..., output='somefile.gpg')`` is successful.""" - with open(os.path.join(_files, 'kat.sec')) as katsec: - self.gpg.import_keys(katsec.read()) - fpr = self.gpg.list_keys('kat')[0]['fingerprint'] + with open(os.path.join(_files, 'kat.pub')) as katpub: + self.gpg.import_keys(katpub.read()) + fpr = '81DFF0A45068DEFFE7F9170318E910A9E55C16F7' output = os.path.join(self.gpg.homedir, 'test-encryption-to-filename.gpg') message_filename = os.path.join(_files, 'cypherpunk_manifesto') @@ -1456,7 +1468,7 @@ def test_encryption_to_filehandle(self): """Test that ``encrypt(..., output=filelikething)`` is successful.""" with open(os.path.join(_files, 'kat.sec')) as katsec: self.gpg.import_keys(katsec.read()) - fpr = self.gpg.list_keys('kat')[0]['fingerprint'] + fpr = '81DFF0A45068DEFFE7F9170318E910A9E55C16F7' output = os.path.join(self.gpg.homedir, 'test-encryption-to-filehandle.gpg') output_file = open(output, 'w+') @@ -1638,8 +1650,6 @@ def test_signing_key_with_wrong_password(self): 'test_gpg_binary_not_abs', 'test_gpg_binary_version_str', 'test_gpg_binary_not_installed', - 'test_list_keys_initial_public', - 'test_list_keys_initial_secret', 'test_make_args_drop_protected_options', 'test_make_args', 'test_gpg_version_malformed']), @@ -1683,7 +1693,10 @@ def test_signing_key_with_wrong_password(self): 'test_encryption_to_filehandle', 'test_encryption_from_filehandle', 'test_encryption_with_output',]), - 'listkeys': set(['test_list_keys_after_generation']), + 'listkeys': set(['test_list_keys_after_generation', + 'test_list_keys_after_import', + 'test_list_keys_initial_public', + 'test_list_keys_initial_secret']), 'keyrings': set(['test_public_keyring', 'test_secret_keyring', 'test_import_and_export', diff --git a/requirements.test.txt b/requirements.test.txt new file mode 100644 index 0000000..14fe0d3 --- /dev/null +++ b/requirements.test.txt @@ -0,0 +1 @@ +mock==2.0.0 diff --git a/setup.py b/setup.py index a409fa6..8201d3c 100644 --- a/setup.py +++ b/setup.py @@ -146,10 +146,11 @@ def get_requirements(): "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Security :: Cryptography",