isislovecruft / python-gnupg

A modified version of python-gnupg, including security patches, extensive documentation, and extra features.
Other
424 stars 172 forks source link

Error in gen_key() on Windows because of wrong directories #204

Open instantname opened 7 years ago

instantname commented 7 years ago

System: Windows 7, GnuPG 1.4.22, Python 3.6.0, python-gnupg 2.3.0

I tried to create a key like that:

gpg = gnupg.GPG(binary='C:/gnupg/gpg.exe', homedir='C:/Users/instantname/AppData/Roaming/gnupg')
input_data = gpg.gen_key_input(key_type="RSA", key_length=1024)
key = gpg.gen_key(input_data)

This lead to the following error:

In [6]: key.status
Out[6]: 'key not created'

In [7]: key.stderr
Out[7]: "gpg: can't create `C:/Users/instantname/AppData/Roaming/gnupg\\C:/Users/instantname/AppData/Roaming/gnupgsecring.gpg.lock': \r\ngpg: keyblock resource `C:/Users/instantname/AppData/Roaming/gnupg\\C:/Users/instantname/AppData/Roaming/gnupgsecring.gpg': general error\r\ngpg: can't create `C:/Users/instantname/AppData/Roaming/gnupg\\C:/Users/instantname/AppData/Roaming/gnupgpubring.gpg.lock': \r\ngpg: keyblock resource `C:/Users/instantname/AppData/Roaming/gnupg\\C:/Users/instantname/AppData/Roaming/gnupgpubring.gpg': general error\r\n[GNUPG:] PROGRESS primegen + 0 0\r\n[GNUPG:] PROGRESS primegen + 0 0\r\n[GNUPG:] PROGRESS primegen + 0 0\r\n[GNUPG:] PROGRESS primegen + 0 0\r\n[GNUPG:] PROGRESS primegen + 0 0\r\n[GNUPG:] PROGRESS primegen X 100 100\r\n[GNUPG:] PROGRESS primegen . 0 0\r\n[GNUPG:] PROGRESS primegen + 0 0\r\n[GNUPG:] PROGRESS primegen + 0 0\r\n[GNUPG:] PROGRESS primegen + 0 0\r\n[GNUPG:] PROGRESS primegen + 0 0\r\n[GNUPG:] PROGRESS primegen + 0 0\r\n[GNUPG:] PROGRESS primegen X 100 100\r\n[GNUPG:] GOOD_PASSPHRASE\r\ngpg: no writable public keyring found: eof\r\ngpg: key generation failed: eof\r\n[GNUPG:] KEY_NOT_CREATED \r\n"

The directories seem to be messed up.

If instead I specify the homedir path with backslashes when instantiating GPG, I obtain:

In [8]: gpg = gnupg.GPG(binary='C:/gnupg/gpg.exe', homedir='C:\\Users\\instantname\\AppData\\Roaming\\gnupg')
Traceback (most recent call last):

  File "<ipython-input-9-474e162cf5f4>", line 1, in <module>
    gpg = gnupg.GPG(binary='C:/gnupg/gpg.exe', homedir='C:\\Users\\instantname\\AppData\\Roaming\\gnupg')

  File "C:\Users\instantname\Anaconda3\lib\site-packages\gnupg\gnupg.py", line 125, in __init__
    ignore_homedir_permissions=ignore_homedir_permissions,

  File "C:\Users\instantname\Anaconda3\lib\site-packages\gnupg\_meta.py", line 183, in __init__
    self.homedir = os.path.expanduser(home) if home else _util._conf

  File "C:\Users\instantname\Anaconda3\lib\site-packages\gnupg\_util.py", line 765, in __set__
    getattr(obj, self.fset.__name__)(value)

  File "C:\Users\instantname\Anaconda3\lib\site-packages\gnupg\_meta.py", line 440, in _homedir_setter
    raise RuntimeError(str(ae))

RuntimeError: Homedir ''C:\Users\instantname\AppData\Roaming\gnupg'' needs read/write permissions

although I do have the read/write permissions.