-
Notifications
You must be signed in to change notification settings - Fork 1
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
_raw_packets Doesnt work - gpg: decryption failed: No secret key #6
Comments
from tiny_gnupg import GnuPG
PATH_TO_GPG_BINARY = "/usr/bin/gpg2"
gpg = GnuPG(
email_address="[email protected]",
passphrase="bobs's passphrase",
executable=PATH_TO_GPG_BINARY,
)
gpg.generate_key()
options = ["--armor", "--encrypt", "-r", gpg.fingerprint]
command = gpg.encode_command(*options)
inputs = gpg.encode_inputs("Message to myself")
encrypted_message=gpg.encrypt("Message to myself",uid=gpg.fingerprint)
decrypted_msg = gpg.decrypt(encrypted_message) This is basically the example code - it does not work for me: source venv/bin/activate
venv/bin/python tinygpgexample.py 2>&1
Traceback (most recent call last):
File "/tmp/venv/lib/python3.9/site-packages/tiny_gnupg/tiny_gnupg.py", line 1452, in _packet_fingerprint
bus.packets = self._raw_packets(target)
File "/tmp/venv/lib/python3.9/site-packages/tiny_gnupg/tiny_gnupg.py", line 1430, in _raw_packets
return terminal.enter(command, inputs, stderr=STDOUT)
File "/tmp/venv/lib/python3.9/site-packages/tiny_gnupg/tiny_gnupg.py", line 680, in __exit__
return self.if_exception(self, error)
File "/tmp/venv/lib/python3.9/site-packages/tiny_gnupg/tiny_gnupg.py", line 787, in secret_packets
raise warning if "No secret key" in warning.packets else error
File "/tmp/venv/lib/python3.9/site-packages/tiny_gnupg/tiny_gnupg.py", line 1430, in _raw_packets
return terminal.enter(command, inputs, stderr=STDOUT)
File "/tmp/venv/lib/python3.9/site-packages/tiny_gnupg/tiny_gnupg.py", line 641, in enter
result = check_output(
File "/usr/lib/python3.9/subprocess.py", line 424, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib/python3.9/subprocess.py", line 528, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/usr/bin/gpg2', '--yes', '--quiet', '--no-tty', '--options', '/tmp/venv/lib/python3.9/site-packages/tiny_gnupg/gpghome/gpg2.conf', '--homedir', '/tmp/venv/lib/python3.9/site-packages/tiny_gnupg/gpghome', '--pinentry-mode', 'cancel', '-vv', '--list-packets', '--show-session-key']' returned non-zero exit status 2.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/tinygpgexample.py", line 18, in <module>
decrypted_msg = gpg.decrypt(encrypted_message)
File "/tmp/venv/lib/python3.9/site-packages/tiny_gnupg/tiny_gnupg.py", line 1648, in decrypt
uid = self._packet_fingerprint(message)
File "/tmp/venv/lib/python3.9/site-packages/tiny_gnupg/tiny_gnupg.py", line 1452, in _packet_fingerprint
bus.packets = self._raw_packets(target)
File "/tmp/venv/lib/python3.9/site-packages/tiny_gnupg/tiny_gnupg.py", line 680, in __exit__
return self.if_exception(self, error)
File "/tmp/venv/lib/python3.9/site-packages/tiny_gnupg/tiny_gnupg.py", line 805, in invalid_pgp_packets
raise warning
TypeError: The ``target`` doesn't seem to be valid OpenPGP data. |
Curious... I'm not getting this error. Here's some thoughts:
try:
decrypted_msg = gpg.decrypt(encrypted_message)
except Exception as error:
print(f"target:\n{error.target}")
print(f"packets:\n{error.packets}") 1.a. Also, what does the
|
Thanks for your quick response. edit: Maybe you could try that: from tiny_gnupg import GnuPG
PATH_TO_GPG_BINARY = "/usr/bin/gpg2"
gpg = GnuPG(
email_address="[email protected]",
passphrase="bobs's passphrase",
executable=PATH_TO_GPG_BINARY,
)
try:
gpg.generate_key()
except Exception as e:
print(e)
|
That is quite strange... I don't have the capacity to work on creating localization support atm. But if you diagnose the exact issue, or write up a patch that is simple and has tests, I'd be willing to merge it. |
Wouldnt
--show-session-key
imply the need for a password? Sowith_passphrase=True
inencode_command
andself.user.passphrase
inencode_inputs
?But I tried that and it still fails :/
The text was updated successfully, but these errors were encountered: