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

Add support for Ed25519 / EdDSA, with unit tests #455

Merged
merged 1 commit into from
May 24, 2020

Conversation

Someguy123
Copy link
Contributor

Added support for EdDSA signing and verification using cryptography (version 2.6 and higher), including unit tests in the TestEd25519Algorithms class at tests/contrib/test_algorithms.py

The Ed25519Algorithm class supports loading private and public keys in PEM format, as well as public keys in OpenSSH format. If a private key is specified, it can be used for both signing and verification, as the public key can simply be interpolated from the private key.

Ed25519 JWT functionality was verified by encoding a JWT from PyJWT, decoding it with PyJWT, and also decoding it with NodeJS's Jose.

As a second interoperability test, I also signed an EdDSA JWT from NodeJS Jose, then verified it from PyJWT to confirm bi-directional interoperability.

Generating JWT with EdDSA and verifying it in python

import jwt

ed_priv = b'-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIBy9N4xfv/9qOiKrxwRKeGfO5ab6lSukKHbuC5vaJ1Mg\n-----END PRIVATE KEY-----\n'

jwt.encode({'hello': 'world'}, ed_priv, algorithm='EdDSA')

# Output: b'eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSJ9.eyJoZWxsbyI6IndvcmxkIn0.HEDJTw1jNaz82WuP3O1l5_i-eaaj3DBEKesPUsInSgKuvbav6XaLORERs7wPrmS14DN_WlzDUCn0LmVGl4VlCg'

jwt.decode(b'eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSJ9.eyJoZWxsbyI6IndvcmxkIn0.HEDJTw1jNaz82WuP3O1l5_i-eaaj3DBEKesPUsInSgKuvbav6XaLORERs7wPrmS14DN_WlzDUCn0LmVGl4VlCg', ed_priv, algorithms=['EdDSA'])

# Output: {'hello': 'world'}

Taking the JWT generated in Python and verifying it with the NodeJS jose package

var jose = require('jose');

key = jose.JWK.asKey('-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIBy9N4xfv/9qOiKrxwRKeGfO5ab6lSukKHbuC5vaJ1Mg\n-----END PRIVATE KEY-----\n');

// OKPKey {
//  crv: 'Ed25519',
//  kid: 'qQ6jEDQi_utuJJopIs6HKOUwBGparO3roUaHeHxsjgM',
//  kty: 'OKP',
//  x: 'LikrZ148aBy0gCyHQf-2ZSsvPHZVzgu1zxM32d-4KEY'
// }

jose.JWT.verify('eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSJ9.eyJoZWxsbyI6IndvcmxkIn0.HEDJTw1jNaz82WuP3O1l5_i-eaaj3DBEKesPUsInSgKuvbav6XaLORERs7wPrmS14DN_WlzDUCn0LmVGl4VlCg', key, {algorithms: ['EdDSA']})

// { hello: 'world' }

Generating an EdDSA JWT in NodeJS jose, and verifying it with PyJWT

NodeJS Signing EdDSA:

> jose.JWT.sign({'example': 'test'}, key, {algorithm: 'EdDSA'})
'eyJhbGciOiJFZERTQSIsImtpZCI6InFRNmpFRFFpX3V0dUpKb3BJczZIS09Vd0JHcGFyTzNyb1VhSGVIeHNqZ00ifQ.eyJleGFtcGxlIjoidGVzdCIsImlhdCI6MTU3MjA1NzEyNH0.dXjiE-eRL4ZLDctu0qCw8gedttMP64TykuxxOGFOR3_0FlUDPpY5K3bSqymdcUlmN4_4bEQqFZ7fRPP9Ak-iDg'

Python (PyJWT) verifying EdDSA JWT from NodeJS jose:

jwt.decode(b'eyJhbGciOiJFZERTQSIsImtpZCI6InFRNmpFRFFpX3V0dUpKb3BJczZIS09Vd0JHcGFyTzNyb1VhSGVIeHNqZ00ifQ.eyJleGFtcGxlIjoidGVzdCIsImlhdCI6MTU3MjA1NzEyNH0.dXjiE-eRL4ZLDctu0qCw8gedttMP64TykuxxOGFOR3_0FlUDPpY5K3bSqymdcUlmN4_4bEQqFZ7fRPP9Ak-iDg',
           ed_priv, algorithms=['EdDSA'])
{'example': 'test', 'iat': 1572057124}

@coveralls
Copy link

coveralls commented Oct 26, 2019

Pull Request Test Coverage Report for Build 98

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at ?%

Totals Coverage Status
Change from base Build 94: 0.0%
Covered Lines:
Relevant Lines: 0

💛 - Coveralls

1 similar comment
@coveralls
Copy link

Pull Request Test Coverage Report for Build 98

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at ?%

Totals Coverage Status
Change from base Build 94: 0.0%
Covered Lines:
Relevant Lines: 0

💛 - Coveralls

@Congee
Copy link

Congee commented Dec 25, 2019

Any blockers for this pull request?

@benwis
Copy link

benwis commented May 24, 2020

I hope this gets merged in, the Ed25519 algorithm is really nice!

@auvipy auvipy self-requested a review May 24, 2020 01:57
@auvipy auvipy merged commit 75c849e into jpadilla:master May 24, 2020
adamyi pushed a commit to adamyi/pyjwt that referenced this pull request Jul 13, 2020
@wasdee wasdee mentioned this pull request Nov 13, 2020
wasdee added a commit to wasdee/pyjwt that referenced this pull request Nov 13, 2020
@wasdee wasdee mentioned this pull request Nov 13, 2020
auvipy pushed a commit that referenced this pull request Nov 13, 2020
wasdee added a commit to wasdee/jsonwebtoken.github.io that referenced this pull request Nov 14, 2020
jpadilla/pyjwt#455 jpadilla/pyjwt#531 these are some proved about the support of pyjwt eddsa.
@jpadilla jpadilla added this to the v2.0.0 milestone Dec 21, 2020
rylanhall33 added a commit to rylanhall33/pyjwt that referenced this pull request Jun 15, 2022
xmas7 pushed a commit to RubyOnWorld/pyjwt that referenced this pull request Sep 6, 2022
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

6 participants