mpdavis / python-jose

A JOSE implementation in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Instantiating RSAKey with tuple of (rsa.PublicKey, rsa.PrivateKey) does not work

dusktreader opened this issue · comments

I was trying to instantiate an instance of RSAKey with a generated RSA key from rsa. However, it seems this line from RSAKey.__init__ is not functioning correctly: https://github.com/mpdavis/python-jose/blob/master/jose/backends/rsa_backend.py#L143

Here is the error in action:

In [34]: import rsa

In [35]: key = rsa.newkeys(2048, poolsize=4)

In [36]: RSAKey(key, "RS256")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-36-e1b32112b6c1> in <module>
----> 1 RSAKey(key, "RS256")

~/.cache/pypoetry/virtualenvs/armada-security-CJSf3laA-py3.8/lib/python3.8/site-packages/jose/backends/cryptography_backend.py in __init__(self, key, algorithm, cryptography_backend)
    270             return
    271
--> 272         raise JWKError("Unable to parse an RSA_JWK from key: %s" % key)
    273
    274     def _process_jwk(self, jwk_dict):

TypeError: not all arguments converted during string formatting

In [37]: type(key)
Out[37]: tuple

In [38]: type(key[0])
Out[38]: rsa.key.PublicKey

In [39]: type(key[1])
Out[39]: rsa.key.PrivateKey

I'm an idiot. Need to instantiate with one or the other of private, public; not a tuple of both.