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

JWK.load does not work with a str as input type for data #11

Open
canihavesomecoffee opened this issue Feb 27, 2018 · 1 comment
Open
Labels
bug priority: unplanned Work that we believe should be done, but does not have a higher priority.

Comments

@canihavesomecoffee
Copy link

canihavesomecoffee commented Feb 27, 2018

Hi,

I'm trying to load a previously saved private key into a JWK instance using the JWK.load method.

The documentation (https://josepy.readthedocs.io/en/latest/api/jwk/) indicates that the load method expects a str to be passed to the data object, but whenever I do this, I'm getting an exception, resulting in the next stacktrace:

File "C:/Users/xxx/Desktop/xxx/certificate_requester.py", line 13, in __main__
    key = jose.JWK.load(data=private_key)
  File "C:\Users\xxx\Desktop\xxx\venv\lib\site-packages\josepy\jwk.py", line 108, in load
    key = cls._load_cryptography_key(data, password, backend)
  File "C:\Users\xxx\Desktop\xxx\venv\lib\site-packages\josepy\jwk.py", line 83, in _load_cryptography_key
    return loader(data, backend)
  File "C:\Users\xxx/\Desktop\xxx\venv\lib\site-packages\cryptography\hazmat\primitives\serialization.py", line 24, in load_pem_public_key
    return backend.load_pem_public_key(data)
  File "C:\Users\xxx/\Desktop\xxx\venv\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 1019, in load_pem_public_key
    mem_bio = self._bytes_to_bio(data)
  File "C:\Users\xxx\Desktop\xxx\venv\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 437, in _bytes_to_bio
    data_char_p = self._ffi.new("char[]", data)
TypeError: initializer for ctype 'char[]' must be a bytes or list or tuple, not str

However, when I pass in a bytes object (obtained by performing an encode('ascii') on the str instance, it's working out all fine.

Could this be due to a difference between python2 and python 3? I'm using the latter.

Environment:

  • acme 0.21.1
  • josepy 1.0.1
  • python 3.6.3
@ohemorange
Copy link
Contributor

Thanks for reporting! Looks like this might be an encoding issue; we'll look into it shortly.

@bmw bmw added the priority: unplanned Work that we believe should be done, but does not have a higher priority. label Mar 25, 2020
@bmw bmw removed their assignment Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug priority: unplanned Work that we believe should be done, but does not have a higher priority.
Projects
None yet
Development

No branches or pull requests

3 participants