Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PY3: 2.30 decrypt_file fails with "gpg: no valid OpenPGP data found" #198

Open
nixwiz opened this issue Jun 29, 2017 · 2 comments
Open

PY3: 2.30 decrypt_file fails with "gpg: no valid OpenPGP data found" #198

nixwiz opened this issue Jun 29, 2017 · 2 comments

Comments

@nixwiz
Copy link

nixwiz commented Jun 29, 2017

Yes,

this is similar to #102 , but that has languished for 2 years.

Using the following sample program:

import gnupg
homedir='/home/vagrant'
gpg = gnupg.GPG(homedir=homedir)
stream = open('testfile.gpg', "rb")
gpg_passphrase="passphrase"
outpath = "testfile.dec"
decrypted = gpg.decrypt_file(stream, passphrase=gpg_passphrase, output=outpath, always_trust=True)
print("ok: {} status: {}\nstderr: {}".format(decrypted.ok, decrypted.status, decrypted.stderr))

Works with 2.7, but fails on 3.6 with "gpg: no valid OpenPGP data found". It appears to come down to how _write_passphrase sends the passphrase into gpg. Looking at strace output comparisons between 2.7 and 3.6 shows that the passphrase is written with extra characters in 3.6 (assuming this is a result of being encoded).

2.7 strace snippet (7917 is PID of python calling gpg as PID 7921):

7917  write(5, "passphrase\n", 11)      = 11
[lines deleted]
7921  read(0, "p", 1)                   = 1
7921  read(0, "a", 1)                   = 1
7921  read(0, "s", 1)                   = 1
7921  read(0, "s", 1)                   = 1
7921  read(0, "p", 1)                   = 1
7921  read(0, "h", 1)                   = 1
7921  read(0, "r", 1)                   = 1
7921  read(0, "a", 1)                   = 1
7921  read(0, "s", 1)                   = 1
7921  read(0, "e", 1)                   = 1
7921  read(0, "\n", 1)                  = 1
7921  read(0,  <unfinished ...>

3.6 strace snippet (7908 is PID of python calling gpg as PID):

7908  write(6, "passphrase\n\357\277\275\1\f\3\357\277\275\22\0q\357\277\275\357\277\275Un\1"..., 640) = 640
[lines deleted]
7907  <... read resumed> "p", 1)        = 1
7907  read(0, "a", 1)                   = 1
7907  read(0, "s", 1)                   = 1
7907  read(0, "s", 1)                   = 1
7907  read(0, "p", 1)                   = 1
7907  read(0, "h", 1)                   = 1
7907  read(0, "r", 1)                   = 1
7907  read(0, "a", 1)                   = 1
7907  read(0, "s", 1)                   = 1
7907  read(0, "e", 1)                   = 1
7907  read(0, "\n", 1)                  = 1
7907  read(0, "\357\277\275\1\f\3\357\277\275\22\0q\357\277\275\357\277\275Un\1\7\357\277\275\35_m\r\357\277\275"..., 8192) = 629
7907  read(0,  <unfinished ...>
@instantname
Copy link
Contributor

Have a look at #102 again. I have revived the issue with what might be a fix.

@dikshantshahi
Copy link

I am using Python 3.9 and getting the same issue. Also #102 didnt help. Is there any resolution for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants