Skip to content

Commit

Permalink
Merge branch 'release/3.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
isislovecruft committed Aug 1, 2018
2 parents ada4932 + 9452415 commit 7845714
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 132 deletions.
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pretty_bad_protocol/_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 12 additions & 1 deletion pretty_bad_protocol/_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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":
Expand Down
12 changes: 7 additions & 5 deletions pretty_bad_protocol/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions pretty_bad_protocol/gnupg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
74 changes: 37 additions & 37 deletions pretty_bad_protocol/test/files/kat.pub
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2
Version: GnuPG v1

mQINBFPcDfoBEACjsm+2o3Ip5IFXA9mUMGuSfWBL2G2bMvB8ZEjp9+DmiWzDUApH
Bk5RQaXXN1lp41Z4POQy9FV735rpBJLcb36/uU8Fm1LwLBqJYcUiB2JsAUsS7scS
Expand All @@ -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
2iaY2l1Un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ggIB7CI0fi47AYVgMtvSe7LF4
odSPkuz35bxOb/bfTNLgWYqkyQV+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-----
Loading

0 comments on commit 7845714

Please sign in to comment.