Problem with key names or file names containing spaces on Linux

Issue #20 resolved
Anonymous created an issue

I have just updated Python GnuPG library from 0.3.1 to 0.3.6 and found problem with keys of file names which contains spaces. It works well on Windows, but fails on Linux.

My code looks like:

    def test_gpg(encrypt_for, sign_by, key_passwd):
        # create text file then encrypt it, and sign it

And I call it for 'Test Space' key:

    test_gpg('Test Space', 'Test Space', 'testspace')

It works with 0.3.1 where call to gpg looks like:

2014-10-20 12:17:57,691 gpg --status-fd 2 --no-tty --batch --passphrase-fd 0 --encrypt --recipient "Test Space" --armor --output "test_tmp.txt.gpg" --sign --default-key "Test Space"

It do not work with 0.3.6:

2014-10-20 12:20:21,134 line: u'uid:::::::0820A3342C35F98DC1F0CBB0A190E95281E3B472::Test Space:'
...
2014-10-20 12:20:21,135 ['gpg', '--status-fd', '2', '--no-tty', '--batch', '--passphrase-fd', '0', '--encrypt', '--recipient', "'Test Space'", '--armor', '--output', 'test_tmp.txt.gpg', '--sign', '--default-key', "'Test Space'"]
2014-10-20 12:20:21,138 Wrote passphrase
2014-10-20 12:20:21,138 data copier: <Thread(Thread-7, initial daemon)>, <open file 'test_tmp.txt', mode 'rb' at 0x152f390>, <open file '<fdopen>', mode 'wb' at 0x152f420>
2014-10-20 12:20:21,139 stderr reader: <Thread(Thread-8, initial daemon)>
2014-10-20 12:20:21,139 stdout reader: <Thread(Thread-9, initial daemon)>
2014-10-20 12:20:21,140 sending chunk (10): 'test, test'
2014-10-20 12:20:21,140 closed output, 10 bytes sent
2014-10-20 12:20:21,141 gpg: no default secret key: brak klucza prywatnego
2014-10-20 12:20:21,141 gpg: [stdin]: sign+encrypt failed: brak klucza prywatnego

I think that while you use subprocess.Popen() with arguments as array you do not need do anything special with those arguments.

Workaround:

On my Linux (os.name='posix') I simlply changed shell_quote() into:

def shell_quote(s):
    return s

and now it works.

Comments (5)

  1. Michał Niklas

    On my Windows machine (os.name=-'nt') this do not work if file name contains space.

    I think that in _open_subprocess() you can use the same version of Popen() for os.name='posix' for both Windows and Linux. I don't know if there is any platform that needs pcmd (command line with quotes) but Windows and Linux do not need it.

  2. Vinay Sajip repo owner

    I've been using shell=True on Windows because for some reason I hadn't determined, it wasn't working on Windows with shell=False. Time to get to the bottom of it ...

  3. Log in to comment