Error encrypting and decrypting with Python 3.4 and GPG 2.0

Issue #4 resolved
Daniel Mills
created an issue

Distro: Arch Linux Python 3.4.0 GPG 2.0.22 python-gnupg 0.3.6 installed via pip python-gnupg 0.3.7 installed from source

When trying to encrypt data an error is thrown about a "ValueError: Unknown status message: 'PROGRESS'". However valid encrypted data is still generated.

When trying to decrypt the data from the encrypt command a "TypeError: 'Crypt' does not support the buffer interface" is thrown and the data is not decrypted.

Python 3.4.0 (default, Mar 17 2014, 23:20:09) 
[GCC 4.8.2 20140206 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gnupg
>>> gpg = gnupg.GPG(use_agent=True)
>>> data = "this is a test"
>>> help(gpg)
>>> edata=gpg.encrypt(data, "51490F9E", symmetric=True)
Exception in thread Thread-8:
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 921, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.4/threading.py", line 869, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.4/site-packages/gnupg.py", line 741, in _read_response
    result.handle_status(keyword, value)
  File "/usr/lib/python3.4/site-packages/gnupg.py", line 518, in handle_status
    Verify.handle_status(self, key, value)
  File "/usr/lib/python3.4/site-packages/gnupg.py", line 275, in handle_status
    raise ValueError("Unknown status message: %r" % key)
ValueError: Unknown status message: 'PROGRESS'
>>> print(edata)
-----BEGIN PGP MESSAGE-----
Version: GnuPG v2.0.22 (GNU/Linux)

jA0EAwMCjELtGTJIiRVgySIu6qybfNTAiKvegd0CgYp4qPqqNGlL9yi4Qlj2sPJy
8c1q
=QDbk
-----END PGP MESSAGE-----

>>> ddata = gpg.decrypt(edata)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.4/site-packages/gnupg.py", line 1269, in decrypt
    data = _make_binary_stream(message, self.encoding)
  File "/usr/lib/python3.4/site-packages/gnupg.py", line 173, in _make_binary_stream
    return _make_memory_stream(s)
  File "/usr/lib/python3.4/site-packages/gnupg.py", line 161, in _make_memory_stream
    rv = BytesIO(s)
TypeError: 'Crypt' does not support the buffer interface
>>> ddata
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'ddata' is not defined
>>> 

Running the test_gnupg.py also results in mutiple failures regarding the "Unknown status PROGRESS" and eventually hangs on Doctest: gnupg.GPG.list_keys

Comments (12)

  1. Vinay Sajip repo owner

    I'm not able to reproduce the problem with GPG 2.0.17 and Python 3.4 (built from source - later than the release version). I'm not sure if the PROGRESS problem is a red herring or not - is it repeatable? Also, you can't decrypt the edata object directly - you need to try decrypting its data attribute. What result do you get if you do that?

  2. Daniel Mills reporter

    OK I was able to decrypt the edata when using it's data attirbute. Don't know why I didn't think of that.

    >>> import gnupg
    >>> gpg = gnupg.GPG(use_agent=True)
    >>> data = "this is a test"
    >>> edata=gpg.encrypt(data, "51490F9E", symmetric=True)
    Exception in thread Thread-4:
    Traceback (most recent call last):
      File "/usr/lib/python3.4/threading.py", line 921, in _bootstrap_inner
        self.run()
      File "/usr/lib/python3.4/threading.py", line 869, in run
        self._target(*self._args, **self._kwargs)
      File "/usr/lib/python3.4/site-packages/gnupg.py", line 753, in _read_response
        result.handle_status(keyword, value)
      File "/usr/lib/python3.4/site-packages/gnupg.py", line 533, in handle_status
        Verify.handle_status(self, key, value)
      File "/usr/lib/python3.4/site-packages/gnupg.py", line 279, in handle_status
        raise ValueError("Unknown status message: %r" % key)
    ValueError: Unknown status message: 'PROGRESS'
    
    >>> edata.data
    b'-----BEGIN PGP MESSAGE-----\nVersion: GnuPG v2.0.22 (GNU/Linux)\n\njA0EAwMCcXBwk7buWqtgySIiMn0Djo2aGE1BaOP6vp/txpsYEd9x2w93BkuLQo/c\nqfbl\n=jKfM\n-----END PGP MESSAGE-----\n'
    >>> ddata = gpg.decrypt(edata.data)
    >>> ddata
    <gnupg.Crypt object at 0x7fe728624a90>
    >>> print(ddata)
    this is a test
    >>> 
    

    The PROGRESS error does result in a very messy console though and should be resolved. It happens every time I try to encrypt and many times while running the test_gnupg.py script. I attached a sample of my console output from running the tests. It isn't a full run but it gives an idea of the mess.

  3. Vinay Sajip repo owner

    The PROGRESS error does result in a very messy console though and should be resolved.

    I'll try, but I can't reproduce it here. Could you please do the following:

    1. Create a short program which shows the problem, like in your original post, but enable logging at DEBUG level for the gnupg (or root) logger.
    2. Post the program, the output and the log here, so I can be sure what gpg is actually sending (I couldn't identify any problematic PROGRESS lines in the test_gnupg.log you posted earlier).
  4. Daniel Mills reporter

    That looks to have fixed it. The console is nice an clean and the logs look good.

    [user]$ python gpg_test.py 
    String to encrypte:Hello Dave
    Encrypted Data
    -----BEGIN PGP MESSAGE-----
    Version: GnuPG v2.0.22 (GNU/Linux)
    
    jA0EAwMCiCbJvZV4pxRgySCA3WSeq02epX7DLo/i2IqPZwbpG+YCPZkEn8iBQaJx
    Hg==
    =suqs
    -----END PGP MESSAGE-----
    
    Decrypted Data
    Hello Dave
    
  5. Log in to comment