Skip to content
This repository was archived by the owner on Nov 13, 2023. It is now read-only.

Commit f1b4845

Browse files
committed
Support ES256K and EdDSA
1 parent 7343cb7 commit f1b4845

26 files changed

+396
-297
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Module for generating and verifying [JSON Web Tokens](http://self-issued.info/do
55
- **Note:** From version 2.0.1 the namespace has changed from `jwt` to `python_jwt`, in order to avoid conflict with [PyJWT](https://github.com/jpadilla/pyjwt).
66
- **Note:** Versions 1.0.0 and later fix [a vulnerability](https://www.timmclean.net/2015/02/25/jwt-alg-none.html) in JSON Web Token verification so please upgrade if you're using this functionality. The API has changed so you will need to update your application. [verify_jwt](http://rawgit.davedoesdev.com/davedoesdev/python-jwt/master/docs/_build/html/index.html#python_jwt.verify_jwt) now requires you to specify which signature algorithms are allowed.
77
- Uses [jwcrypto](https://jwcrypto.readthedocs.io) to do the heavy lifting.
8-
- Supports [__RS256__, __RS384__, __RS512__](http://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-14#section-3.3), [__PS256__, __PS384__, __PS512__](http://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-14#section-3.5), [__HS256__, __HS384__, __HS512__](http://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-14#section-3.2) and [__none__](http://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-14#section-3.6) signature algorithms.
8+
- Supports [__RS256__, __RS384__, __RS512__](https://tools.ietf.org/html/rfc7518#section-3.3), [__PS256__, __PS384__, __PS512__](https://tools.ietf.org/html/rfc7518#section-3.5), [__HS256__, __HS384__, __HS512__](https://tools.ietf.org/html/rfc7518#section-3.2), [__ES256__, __ES384__, __ES512__](https://tools.ietf.org/html/rfc7518#section-3.4), [__ES256K__](https://tools.ietf.org/html/draft-ietf-cose-webauthn-algorithms-05#section-3.2), [__EdDSA__](https://tools.ietf.org/html/rfc8037#section-3.1) and [__none__](http://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-14#section-3.6) signature algorithms.
99
- Unit tests, including tests for interoperability with [jose](https://github.com/panva/jose).
1010
- Supports Python 2,7 and 3.6+. **Note:** [generate_jwt](http://rawgit.davedoesdev.com/davedoesdev/python-jwt/master/docs/_build/html/index.html#python_jwt.generate_jwt) returns the token as a Unicode string, even on Python 2.7.
1111

bench/generate_token_bench.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# pylint: disable=wrong-import-position,wrong-import-order
66
from datetime import timedelta
77
from bench.unitbench import Benchmark
8-
from test.fixtures import payload, priv_keys, priv_key, algs
8+
from test.fixtures import payload, priv_keys, algs
99
from bench.reporter import Reporter
1010
import python_jwt as jwt
1111

@@ -25,7 +25,7 @@ def make_bench_generate_token(alg):
2525
""" Return function which will generate token for particular algorithm """
2626
def f(_):
2727
""" Generate token """
28-
privk = priv_keys[alg].get('default', priv_key)
28+
privk = priv_keys[alg]['python-jwt']
2929
jwt.generate_jwt(payload, privk, alg, timedelta(seconds=5))
3030
return f
3131

bench/load_key_bench.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# pylint: disable=wrong-import-position,wrong-import-order
66
from bench.unitbench import Benchmark
7-
from test.fixtures import priv_pem, to_bytes_2and3
7+
from test.fixtures import rsa_priv_pem, to_bytes_2and3
88
from bench.reporter import Reporter
99
from jwcrypto.jwk import JWK
1010

@@ -21,7 +21,7 @@ def repeats(self):
2121

2222
def bench_RSA(self):
2323
""" Import key """
24-
JWK.from_pem(to_bytes_2and3(priv_pem))
24+
JWK.from_pem(to_bytes_2and3(rsa_priv_pem))
2525

2626
if __name__ == "__main__":
2727
#pylint: disable=W0402

bench/verify_token_bench.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# pylint: disable=wrong-import-position,wrong-import-order
66
from datetime import timedelta
77
from bench.unitbench import Benchmark
8-
from test.fixtures import payload, priv_keys, priv_key, pub_keys, pub_key, algs
8+
from test.fixtures import payload, priv_keys, pub_keys, algs
99
from bench.reporter import Reporter
1010
import python_jwt as jwt
1111

@@ -23,11 +23,11 @@ def repeats(self):
2323
#pylint: disable=W0621
2424
def make_bench_verify_token(alg):
2525
""" Return function which will generate token for particular algorithm """
26-
privk = priv_keys[alg].get('default', priv_key)
26+
privk = priv_keys[alg]['python-jwt']
2727
token = jwt.generate_jwt(payload, privk, alg, timedelta(days=1))
2828
def f(_):
2929
""" Verify token """
30-
pubk = pub_keys[alg].get('default', pub_key)
30+
pubk = pub_keys[alg]['python-jwt']
3131
jwt.verify_jwt(token, pubk, [alg])
3232
return f
3333

coverage/coverage.xml

+48-47
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" ?>
2-
<coverage branch-rate="1" branches-covered="56" branches-valid="56" complexity="0" line-rate="1" lines-covered="87" lines-valid="87" timestamp="1573723579508" version="4.5.4">
2+
<coverage branch-rate="1" branches-covered="56" branches-valid="56" complexity="0" line-rate="1" lines-covered="88" lines-valid="88" timestamp="1598304879802" version="4.5.4">
33
<!-- Generated by coverage.py: https://coverage.readthedocs.io -->
44
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
55
<sources>
@@ -40,64 +40,65 @@
4040
<line hits="1" number="88"/>
4141
<line hits="1" number="89"/>
4242
<line hits="1" number="90"/>
43-
<line hits="1" number="92"/>
44-
<line hits="1" number="100"/>
45-
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="141"/>
46-
<line hits="1" number="142"/>
47-
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="144"/>
48-
<line hits="1" number="146"/>
49-
<line hits="1" number="148"/>
50-
<line hits="1" number="150"/>
51-
<line hits="1" number="152"/>
52-
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="153"/>
53-
<line hits="1" number="154"/>
54-
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="155"/>
55-
<line hits="1" number="156"/>
56-
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="158"/>
43+
<line hits="1" number="91"/>
44+
<line hits="1" number="93"/>
45+
<line hits="1" number="101"/>
46+
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="142"/>
47+
<line hits="1" number="143"/>
48+
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="145"/>
49+
<line hits="1" number="147"/>
50+
<line hits="1" number="149"/>
51+
<line hits="1" number="151"/>
52+
<line hits="1" number="153"/>
53+
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="154"/>
54+
<line hits="1" number="155"/>
55+
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="156"/>
56+
<line hits="1" number="157"/>
5757
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="159"/>
5858
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="160"/>
59-
<line hits="1" number="161"/>
60-
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="162"/>
61-
<line hits="1" number="163"/>
62-
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="165"/>
63-
<line hits="1" number="166"/>
59+
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="161"/>
60+
<line hits="1" number="162"/>
61+
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="163"/>
62+
<line hits="1" number="164"/>
63+
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="166"/>
6464
<line hits="1" number="167"/>
6565
<line hits="1" number="168"/>
66-
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="169"/>
67-
<line hits="1" number="170"/>
68-
<line hits="1" number="172"/>
69-
<line hits="1" number="174"/>
66+
<line hits="1" number="169"/>
67+
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="170"/>
68+
<line hits="1" number="171"/>
69+
<line hits="1" number="173"/>
7070
<line hits="1" number="175"/>
71-
<line hits="1" number="177"/>
72-
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="178"/>
71+
<line hits="1" number="176"/>
72+
<line hits="1" number="178"/>
7373
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="179"/>
74-
<line hits="1" number="180"/>
75-
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="181"/>
76-
<line hits="1" number="182"/>
77-
<line hits="1" number="184"/>
78-
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="185"/>
74+
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="180"/>
75+
<line hits="1" number="181"/>
76+
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="182"/>
77+
<line hits="1" number="183"/>
78+
<line hits="1" number="185"/>
7979
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="186"/>
80-
<line hits="1" number="187"/>
81-
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="188"/>
82-
<line hits="1" number="189"/>
83-
<line hits="1" number="191"/>
84-
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="192"/>
80+
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="187"/>
81+
<line hits="1" number="188"/>
82+
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="189"/>
83+
<line hits="1" number="190"/>
84+
<line hits="1" number="192"/>
8585
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="193"/>
86-
<line hits="1" number="194"/>
87-
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="195"/>
88-
<line hits="1" number="196"/>
89-
<line hits="1" number="198"/>
90-
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="199"/>
86+
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="194"/>
87+
<line hits="1" number="195"/>
88+
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="196"/>
89+
<line hits="1" number="197"/>
90+
<line hits="1" number="199"/>
9191
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="200"/>
92-
<line hits="1" number="201"/>
93-
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="202"/>
94-
<line hits="1" number="203"/>
95-
<line hits="1" number="205"/>
96-
<line hits="1" number="209"/>
97-
<line hits="1" number="221"/>
92+
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="201"/>
93+
<line hits="1" number="202"/>
94+
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="203"/>
95+
<line hits="1" number="204"/>
96+
<line hits="1" number="206"/>
97+
<line hits="1" number="210"/>
9898
<line hits="1" number="222"/>
9999
<line hits="1" number="223"/>
100100
<line hits="1" number="224"/>
101+
<line hits="1" number="225"/>
101102
</lines>
102103
</class>
103104
</classes>

coverage/html/index.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,28 @@ <h1>Coverage report:
7171
<tfoot>
7272
<tr class="total">
7373
<td class="name left">Total</td>
74-
<td>87</td>
74+
<td>88</td>
7575
<td>0</td>
7676
<td>0</td>
7777

7878
<td>56</td>
7979
<td>0</td>
8080

81-
<td class="right" data-ratio="143 143">100%</td>
81+
<td class="right" data-ratio="144 144">100%</td>
8282
</tr>
8383
</tfoot>
8484
<tbody>
8585

8686
<tr class="file">
8787
<td class="name left"><a href="python_jwt___init___py.html">python_jwt/__init__.py</a></td>
88-
<td>87</td>
88+
<td>88</td>
8989
<td>0</td>
9090
<td>0</td>
9191

9292
<td>56</td>
9393
<td>0</td>
9494

95-
<td class="right" data-ratio="143 143">100%</td>
95+
<td class="right" data-ratio="144 144">100%</td>
9696
</tr>
9797

9898
</tbody>
@@ -107,7 +107,7 @@ <h1>Coverage report:
107107
<div class="content">
108108
<p>
109109
<a class="nav" href="https://coverage.readthedocs.io">coverage.py v4.5.4</a>,
110-
created at 2019-11-14 09:26
110+
created at 2020-08-24 22:34
111111
</p>
112112
</div>
113113
</div>

0 commit comments

Comments
 (0)