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

NotImplementedError: Haven't implemented Hash Algorithm : 10 #2

Open
alexlance opened this issue Jun 9, 2020 · 7 comments
Open

NotImplementedError: Haven't implemented Hash Algorithm : 10 #2

alexlance opened this issue Jun 9, 2020 · 7 comments

Comments

@alexlance
Copy link

Hi there,

I get this error when I try and decrypt a file:

  File "checker.py", line 95, in <module>
    main()
  File "checker.py", line 74, in main
    dest = process_one_file(bucket, key)
  File "checker.py", line 43, in process_one_file
    tempf = util.decrypt_file(GPG_CONFIG, client_name, tempf)
  File "/root/app/util.py", line 309, in decrypt_file
    key.parse(conf['privatekey'])
  File "/usr/local/lib/python3.7/site-packages/gpglib/structures.py", line 155, in parse
    self.consume(region)
  File "/usr/local/lib/python3.7/site-packages/gpglib/structures.py", line 58, in consume
    self.packet_consumer.consume(self, region)
  File "/usr/local/lib/python3.7/site-packages/gpglib/packet_parser.py", line 47, in consume
    kwargs = self.content_parser.consume(tag, message, kwargs) or {}
  File "/usr/local/lib/python3.7/site-packages/gpglib/content_parsers/delegators.py", line 40, in consume
    return parser.consume(tag, message, tag.body, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/gpglib/content_parsers/keys.py", line 28, in consume
    hasher = Mapped.algorithms.hashes[hash_algorithm]
  File "/usr/local/lib/python3.7/site-packages/gpglib/content_parsers/crypt.py", line 68, in __getitem__
    raise NotImplementedError("Haven't implemented %s : %s" % (self.type, key))
NotImplementedError: Haven't implemented Hash Algorithm : 10

What's hash algo 10? How do we go about implementing it?

I've attached the gpg-key I was using and a snippet of code:

from gpglib.structures import EncryptedMessage, Key

key = Key(passphrase='test passphrase')                                                                                                                                                                                                               
key.parse(k)

key.txt

@delfick
Copy link
Owner

delfick commented Jun 9, 2020

It appears hash 10 is SHA512

So you'd have to add below this line to use this class

Are you able to make a local copy with that change and see if it works?

@alexlance
Copy link
Author

alexlance commented Jun 9, 2020

Added a PR , but note, that the PR gets me past the error mentioned in the issue, but now I am stuck on an error like:

gpglib.errors.PGPException: Data was encrypted with RSA key '1325********', which was't found

Have regenerated a key a few times now, it seems convinced that the data was encrypted with a different key. shakes fist at sky

@delfick
Copy link
Owner

delfick commented Jun 10, 2020

oh no, so if you use your key to generate new information, it works?

@alexlance
Copy link
Author

Okay so if I generate a normal RSA key and use the default key length in gpg 2.2.12 (which is 3072 bits) then my script is not able to decrypt any files, I get an error like:

gpglib.errors.PGPException: Data was encrypted with RSA key '6196606***', which was't found

But, if I create a new RSA gpg key with a bit length of 2048, then yes, it is successfully able to decrypt the file!

I feel like it miiight be something to do with this:

version, key_id, key_algo = region.readlist("""

Like it's not getting the full 3072 bits to identify the key correctly? Is it hard to patch gpglib2 to handle arbitrary key sizes? Or am I barking up the wrong bits...

@delfick
Copy link
Owner

delfick commented Jun 12, 2020

I made this a long time ago for a very specific purpose. I'm not entirely sure how to fix this and unfortunately I already have too many things happening at the moment to take too deep a look.

A good place to start if you want to figure it out is https://tools.ietf.org/html/rfc4880

Though feel free to ask specific questions about how the code works if you do go down that path :)

@alexlance
Copy link
Author

Yep that's totally fair enough, not enough hours in the day at the moment 👍

Btw looks like key length of 4096 also has the same error as above. I'll try and wrap my head around the rfc a bit more.

Cheers for any help, I feel like it's nearly there!

@delfick
Copy link
Owner

delfick commented Jun 12, 2020

cool. Thanks. I believe in you!

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

No branches or pull requests

2 participants