latchset / jwcrypto

Implements JWK,JWS,JWE specifications using python-cryptography
GNU Lesser General Public License v3.0
438 stars 118 forks source link

Can't sign a JWT with an ed25519 JWK #350

Closed jamie-at-arkifi closed 8 months ago

jamie-at-arkifi commented 8 months ago
  File "/Users/jamie/code/blount/tsauth/main.py", line 197, in docker_auth
    token.make_signed_token(jwk)
  File "/Users/jamie/.local/share/virtualenvs/blount-z19IO5O9/lib/python3.12/site-packages/jwcrypto/jwt.py", line 586, in make_signed_token
    t.add_signature(key, protected=self.header)
  File "/Users/jamie/.local/share/virtualenvs/blount-z19IO5O9/lib/python3.12/site-packages/jwcrypto/jws.py", line 545, in add_signature
    sig = c.sign()
          ^^^^^^^^
  File "/Users/jamie/.local/share/virtualenvs/blount-z19IO5O9/lib/python3.12/site-packages/jwcrypto/jws.py", line 152, in sign
    signature = self.engine.sign(self.key, sigin)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jamie/.local/share/virtualenvs/blount-z19IO5O9/lib/python3.12/site-packages/jwcrypto/jwa.py", line 116, in sign
    skey = base64url_decode(key.get_op_key('sign'))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jamie/.local/share/virtualenvs/blount-z19IO5O9/lib/python3.12/site-packages/jwcrypto/common.py", line 21, in base64url_decode
    size = len(payload) % 4
           ^^^^^^^^^^^^^^^^
TypeError: object of type 'cryptography.hazmat.bindings._rust.openssl.ed25519.Ed25519PrivateKey' has no len()

alg is HS256, key is OKP with crv of Ed25519.

jamie-at-arkifi commented 8 months ago

If you have a Ed25519 key, you gotta use an alg of EdDSA