Commit Graph

849 Commits (04b9a13a515114cf899c858122e71b51e46f3226)

Author SHA1 Message Date
Isis Lovecruft 4780f4443d
Add clearer logging to gnupg.GPGBase._read_data(). 2013-10-08 11:44:45 +00:00
Isis Lovecruft 78400df41c
Use type(data)().join() trick regardless of running py3k.
This is a rather elegant trick from upstream to deal with the differences
between bytesarrays, strings, and unicode literals between Python2.x and
Py3k. However, it doesn't actually make a difference if we're running Py3k or
not to use the trick, since it dynamically calls the builtin type for the
native string in any Python version. It works like so:

  >>> import sys
  >>> data = '{}\n2 + 2 ≠ 5'.format(sys.version[:5])
  >>> print(data)
  3.3.2
  2 + 2 ≠ 5
  >>> type(data)
  <class 'str'>
  >>> type(data)()
  ''
  >>> unicodedata = u'Mon corps et moi étions un, á cause de cette corde maudite.'
  >>> type(unicodedata)
  <class 'str'>

Also, in Python2.x:

  >>> import sys
  >>> data = '{}\n2 + 2 ≠ 5'.format(sys.version[:5])
  >>> print data
  2.7.5
  2 + 2 ≠ 5
  >>> type(data)
  <type 'str'>
  >>> type(data)()
  ''
  >>> unicodedata = u'Mon corps et moi étions un, á cause de cette corde maudite.'
  >>> type(unicodedata)
  <type 'unicode'>
  >>> type(unicodedata)()
  u''
2013-10-08 10:30:12 +00:00
Isis Lovecruft ade3ec97ee
Give gnupg.GPGBase._read_data() a better docstring. 2013-10-08 10:28:37 +00:00
Isis Lovecruft 10d7e61ee4
Delete output file created by test_copy_data_bytesio() unittest. 2013-10-08 10:27:04 +00:00
Isis Lovecruft 9164c8dc83
Add a fake status-fd command to create a trustdb.gpg if missing.
For some reason, in GnuPG>=2.x, a missing/corrupted trustdb is a fatal
error. This means that if the homedir was just changed, and any command which
utilizes keys is called (e.g. sign, encrypt, decrypt, etc.) GnuPG dies without
executing the command because we can't find a valid trustdb.

What's even more is that there is a new command in GnuPG>=2.x:
'--fix-trustdb'. You'd think it would, you know, *fix the trustdb*. Hah! Think
again! It prints out a series of shell commands (incorrect ones, at that, as
they don't respect the relevant env variables such as $GNUPGHOME) in a format
which is *not* exec'able (i.e. you can't do something similar to how

    $ exec `ssh-agent`

is used). Software engineering, motherfuckers. #FML.
2013-10-08 10:16:10 +00:00
Isis Lovecruft 70c029b2d8
Log stderr userland messages from GnuPG at their corresponding log levels. 2013-10-08 10:14:59 +00:00
Isis Lovecruft c26f4d57ac
Add the import/export ownertrust methods if GnuPG>=2.x is detected.
We should only add these methods (or rather, link them to their corresponding
functions in the gnupg._trust module) if using GnuPG>=2.x.

 * ADD --export-ownertrust and --import-ownertrust functionality.
2013-10-08 10:13:41 +00:00
Isis Lovecruft 1a38da7b2f
Add gnupg._trust module for functions dealing with trustdb.
* ADD function gnupg._trust._create_trustdb().
 * ADD function gnupg._trust.import_ownertrust().
 * ADD function gnupg._trust.export_ownertrust().
 * ADD function gnupg._trust.fix_trustdb().
2013-10-08 10:07:52 +00:00
Isis Lovecruft 4955fed865
Separate gnupg.GPGBase._read_response() into multiple functions.
* ADD function _util._deprefix() for stripping a given prefix from the
   beginning of another string.
 * ADD function _util._separate_keywork() for extracting the keyword from the
   beginning of status-fd output.
 * REMOVE excess EOL whitespace.
 * CLEANUP method gnupg.GPGBase._read_response().
2013-10-08 09:58:27 +00:00
Isis Lovecruft 47c891814f
Change function gnupg._util._find_binary() to also find gpg2.
* CHANGE _find_binary() utility function to look for a gpg2 binary on the
   users PATH if no binary is given and gpg is not found.
 * FIXES an error where only gpg=>1.4.x was found.
2013-10-08 08:53:54 +00:00
Isis Lovecruft 9f6908ffb0
Remove unused unittest.TestCase.setUpClass() method.
* REMOVE boilerplated unittest.TestCase.setUpClass() method, as it did
   nothing and was not being called anywhere.
2013-10-08 08:50:08 +00:00
Isis Lovecruft 903ffd3906
FIX unittest test_copy_data_bytesio().
* CHANGE unittest test_copy_data_bytesio() to actually check that the output
   data matches the original message string given to io.BytesIO().
 * REMOVE class test.test_gnupg.ResultStringIO, as it is now not used
   anywhere.
 * FIXES test_copy_data_bytesio() not actually testing what it was supposed
   to.
2013-10-08 08:46:19 +00:00
Isis Lovecruft 0166b4bc6a
Fix test failure due to static binary path arg in unittest.
* CHANGE unittest test_make_args_drop_protected_options() to discover the
   path to the GnuPG binary; the discovered path SHOULD be the same as that
   which was discovered upon class instantiation.
 * FIXES failure in unittest test_make_args_drop_protected_options() which was
   caused by the path to the GnuPG binary being hardcoded.
2013-10-08 08:27:22 +00:00
Isis Lovecruft 3d57d359bd
Merge remote-tracking branch 'drebs/feature/allow-choice-of-digest-algo-when-signing' into develop 2013-10-08 08:26:15 +00:00
drebs 93c87bcd88 Allow choice of digest algorithm when signing. 2013-10-05 13:10:03 -03:00
Isis Lovecruft 7f74ab7df9
Add another OpenPGP in DNS doc 2013-09-30 06:28:31 +00:00
Garrett Robinson faeef9c25a special case verbose=True to avoid passing invalid options to gpg --debug-level 2013-09-07 13:25:09 -07:00
Isis Lovecruft 467cad9634
Add documentation on publishing OpenPGP records in DNS.
* Taken from Dan Mahoney's post at
   http://www.gushi.org/make-dns-cert/HOWTO.html

 * Re-markdown-ified with http://html2markdown.com/, the source of which lives
   here: https://github.com/domchristie/to-markdown
2013-08-30 11:42:38 +00:00
Isis Lovecruft edae8be10c
Merge branch 'master' into develop 2013-07-31 22:41:55 +00:00
Isis Lovecruft abf981a1ca
Merge branch 'release/1.2.2' 2013-07-31 22:41:46 +00:00
Isis Lovecruft 17faf6ac4f
Fix unittest run failure if pip<1.3.1.
* CHANGE Makefile test-before target to optionally include version and
   installed package information on gnupg2, pinentry, gpg-agent, and pip.
 * FIXES issue #15:
   https://github.com/isislovecruft/python-gnupg/issues/15
 * CLOSES issue #15.
2013-07-31 22:26:18 +00:00
Isis Lovecruft 8cccef433d
Remove __package__ setting and import code in test_gnupg.py.
* FIXES bug which caused py3k tests to fail to run.
2013-07-31 22:23:30 +00:00
Isis Lovecruft 08f066ddfc
Add py3k targets to Makefile: 'test', 'install', 'uninstall', 'reinstall'. 2013-07-31 12:27:00 +00:00
Isis Lovecruft 1e5c1c2311
Merge remote-tracking branch 'mmn/fixes_for_test_gpg_binary_version_str' into develop
* ADD patches from Mikael Nordfeldth.
 * FIXES #14 issues with strcmp in unittests looking for string literals when
   Python3 expects byte strings.
 * TODO: perhaps there should be a generalized function in
   gnupg/test/test_gnupg.py which automatically translates Python2 strings to
   b'' strings.
 * CLOSES issue #14.
2013-07-30 12:05:51 +00:00
Isis Lovecruft 1d22ce5adb
Merge remote-tracking branch 'mmn/file_and_io_handling_diff' into develop
* ADD patch by Mikael Nordfeldth to file python3 syntax compatibility due to
   the 'file' builtin being removed.
       isinstance(foo, file) → hasattr(foo, 'read'), or,
       file = _io._IOBase
 * CLOSES issue #13.
   https://github.com/isislovecruft/python-gnupg/pull/13
2013-07-29 20:57:25 +00:00
Isis Lovecruft 143042e2a0
Merge remote-tracking branch 'mmn/simple_indentation_error' into develop
* ADD patch by Mikael Nordfeldth.
 * FIXES wrong identation level on a unittest docstring.
 * CLOSES issue #11.
2013-07-29 19:15:13 +00:00
Isis Lovecruft 8f01040fa1
Merge branch 'fix/5-genkeyinput-default-type' into develop
* FIXES issues #5 and #11
   https://github.com/isislovecruft/python-gnupg/issues/5
   https://github.com/isislovecruft/python-gnupg/issues/11
 * ADD checks for and attribute GPG.binary_version
 * CHANGE to generating RSA keys for GnuPG 1.x, and 'default' keys for GnuPG
   2.x, because GnuPG 1.x doesn't understand the 'Key-Type: default' batch
   file directive.
2013-07-29 19:01:40 +00:00
Mikael Nordfeldth aa6ced5d14 stdout.read() wants bytes, which failed on Py3 str
I don't know how far back the b"byte string" syntax is compatible with this change in Python 2.x, but in 2.7.3 it works as it should.
2013-07-29 00:27:54 +02:00
Mikael Nordfeldth 314e670ada test_gpg_binary_version_str failed for non-English
This patch sets the environment variable LANGUGE to 'en', meaning English translation is used for outputs. The string comparisons in test_gpg_binary_version_str failed otherwise when using a non-English locale. Another choice may be to set LANG=C to avoid locales all-in-all.
2013-07-29 00:27:49 +02:00
Mikael Nordfeldth ce76fd130a Grammar fix, repeated word in test description 2013-07-29 00:27:45 +02:00
Isis Lovecruft bbeba9263e
Update TODO file with tasks done and further work needed. 2013-07-28 20:38:49 +00:00
Mikael Nordfeldth 1bdf0290ab File and IO handling in Py3 is different than Py2
Instead of checking whether data isinstance of 'file', then we check that
it is file-like _enough_ to be treated as a file (i.e. it hasattr 'read').
2013-07-28 18:35:16 +02:00
Mikael Nordfeldth 167d51f15e Simple indentation error fix 2013-07-28 18:17:52 +02:00
Isis Lovecruft 1e867d6e11
If using GnuPG v1.x, use {'Key-Type': 'RSA'} in GPG.gen_key_input().
* CHANGE default key type to RSA for older GnuPG versions, since they seems
   to not understand using a 'default' key type.
 * UPDATE docstring for GPG.gen_key_input().
2013-07-28 11:38:43 +00:00
Isis Lovecruft 6eccbe7048
Make default gen_key_input() Key-Type conditional on GnuPG version.
* ADD functions _util._match_version_string(), _util._is_gpg2(), and
   _util._is_gpg1() for determining whether to set the default Key-Type to
   'default' (for GnuPG v2.x) or to 'RSA' (for GnuPG v1.x).
 * ADD class attribute GPG.binary_version, which stores the GnuPG executable's
   version string, which should be in the form x.x.x, where 'x' is an integer.
2013-07-28 11:28:49 +00:00
Isis Lovecruft 72174ad535
Merge branch 'master' into develop 2013-07-27 21:16:45 +00:00
Isis Lovecruft 52f3dc8ca6
Merge branch 'release/1.2.1' 2013-07-27 21:15:26 +00:00
Isis Lovecruft eb668b3f00
Merge branch 'master' into develop 2013-07-27 20:49:20 +00:00
Isis Lovecruft 436506ec16
Merge branch 'release/1.2.0' 2013-07-27 20:42:59 +00:00
Isis Lovecruft 73bab0d0e0
Add scripts/pep8.py for checking PEP conformity. 2013-07-27 19:44:28 +00:00
Isis Lovecruft 420d2b590d
Remove TODO item for keyring separation in GPG.gen_key_input() and GPG.gen_key(). 2013-07-27 19:42:37 +00:00
Isis Lovecruft b54cb8ee42
Update docs/index.rst to point to online text of new license. 2013-07-27 19:37:07 +00:00
Isis Lovecruft 6b154c294e
Change LICENSE to GPLv3+, after discussion with intrigeri.
* ADD docs/change-license-emails.txt, which includes email exchanges between
   myself and intrigeri, including links to Debian and LEAP mailing lists with
   arguments for and against using AGPL for a library.
 * CHANGE license header for all files.
 * CHANGE LICENSE file and gnupg/copyright.py to use GPLv3+ text.
2013-07-27 19:27:53 +00:00
Isis Lovecruft e2646cb4c4
Merge remote-tracking branch 'mmn/python3_KeysView_object_is_not_indexable' into develop
* FIX Python3 error where a :class:`collections.OrderedDict` instance,
   including it's keys() method, is not iterable.
 * CLOSES PR#7 In Python 3 OrderedDict.keys() are not indexable
2013-07-27 17:33:53 +00:00
Isis Lovecruft bab8e4f54d
Merge remote-tracking branch 'mmn/xrange_replaces_range_in_python3' into develop
* CHANGE an occurence of xrange() iteration over a fixed length list to use
   range(); Python3's range() function is equivalent to Python2's xrange(),
   while the small fixed length of the list in this case doesn't effect speed
   at all.
2013-07-27 08:13:04 +00:00
Isis Lovecruft 8bad2f3c05
Merge remote-tracking branch 'mmn/mktime_takes_localtime_not_gmtime' into develop
* FIX struct_time inputs to time.mktime() to use localtime() not gmtime().
 * CLOSES #9: "mktime takes local time, not UTC"
   https://github.com/isislovecruft/python-gnupg/pull/9
2013-07-26 14:32:43 +00:00
Isis Lovecruft 6858fe5fa3
Merge branch 'mmn/python3_install_issue_with_chmod_and_exception_handling' into develop
* FIX exception raising and handling in _utils.py to use Python3 syntax.
 * FIX os.chmod call in _utils._make_passphrase() to use stat bitmasks.
2013-07-26 13:52:07 +00:00
Mikael Nordfeldth 9ff03b5be7 mktime takes localtime, or we skew the clocks
The following snippet shows that to create a proper timestamp, we should
feed mktime() with localtime() data rather than gmtime(), as it is locale
aware.

>>> from time import mktime, gmtime, localtime
>>> bad    = gmtime(mktime(gmtime()))
>>> good   = gmtime(mktime(localtime()))
>>> judge  = gmtime()
>>> if bad == good: "You're using UTC. Demonstration is impossible."
... elif bad == judge: "I can be wrong"
... elif good == judge: "but this shows I'm right"
...
"but this shows I'm right"

The above code checks whether gmtime() == gmtime(timestamp) from
mktime(). Obviously we don't get the same 'now' if we feed the bad value
to mktime.
2013-07-26 01:02:46 +02:00
Mikael Nordfeldth 59c19c8816 xrange is called 'range' in python3, change is python2 compatible 2013-07-25 00:18:13 +02:00
Mikael Nordfeldth f80f216625 mktime takes local time, not UTC
GPG signature timestamps are considered UTC, this may cause times to be off
by delta > 1000 in def test_signature_string_verification because it
incorrectly gave gmtime() as an argument to mktime().

Python 2 and 3 docs both say that mktime should have a struct_time argument
"which expresses the time in local time, not UTC". So the test is now using
time.localtime() instead of time.gmtime()
2013-07-24 17:28:18 +02:00