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

Work in progress: Use asymmetric.utils.Prehashed from cryptography 1.6 #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

stavxyz
Copy link
Owner

@stavxyz stavxyz commented Dec 12, 2016

https://cryptography.io/en/latest/hazmat/primitives/asymmetric/utils/#cryptography.hazmat.primitives.asymmetric.utils.Prehashed

Tests aren't passing yet, still need to dig in.

Previous logic was using stavxyz/cryptography@fe0f048

My first go went like this:

        signature = self.private_key.sign(
            data,
            padding.PKCS1v15(),
            utils.Prehashed(hashes.SHA1())
        )

but we get this:

Traceback (most recent call last):
  File "~/requests-chef/requests_chef/mixlib_auth.py", line 110, in __call__
    signed = self.private_key.sign(canonical_request, b64=True)
  File "~/requests-chef/requests_chef/mixlib_auth.py", line 191, in sign
    utils.Prehashed(hashes.SHA1())
  File "~/.virtualenvs/requests-chef-dev/lib/python2.7/site-packages/cryptography/hazmat/backends/openssl/rsa.py", line 459, in sign
    self._backend, data, algorithm
  File "~/.virtualenvs/requests-chef-dev/lib/python2.7/site-packages/cryptography/hazmat/backends/openssl/utils.py", line 42, in _calculate_digest_and_algorithm
    "The provided data must be the same length as the hash "
ValueError: The provided data must be the same length as the hash algorithm's digest size.

So I changed to:

        signature = self.private_key.sign(
            hashlib.sha1(data).digest(),
            padding.PKCS1v15(),
            utils.Prehashed(hashes.SHA1())
        )

but the tests fail, and I assume requests to a chef server would also fail.

@stavxyz stavxyz changed the title Use asymmetric.utils.Prehashed from cryptography 1.6 Work in progress: Use asymmetric.utils.Prehashed from cryptography 1.6 Dec 12, 2016
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

Successfully merging this pull request may close these issues.

None yet

1 participant