@@ -29,8 +29,8 @@ Let us start with you not having any key at all and you want to create a
29
29
signed JSON Web Token (JWS _).
30
30
What to do ?
31
31
32
- Well if you know what kind of key you want, if it is a asymmetric key you can
33
- use one of the provided factory methods.
32
+ Well if you know what kind of key you want, and if it is a asymmetric key you
33
+ want, you can use one of the provided factory methods.
34
34
35
35
RSA
36
36
:py:func: `cryptojwt.jwk.rsa.new_rsa_key `
86
86
>>> ec_key.has_private_key()
87
87
True
88
88
89
- When it comes to exporting keys a :py:class: `cryptojwt.jwk.JWK ` instance
89
+ When it comes to exporting keys, a :py:class: `cryptojwt.jwk.JWK ` instance
90
90
only know how to serialize into the format described in JWK _.
91
91
92
92
>>> from cryptojwt.jwk.rsa import new_rsa_key
@@ -160,7 +160,7 @@ Key bundle
160
160
As mentioned above a key bundle is used to manage keys that have a common
161
161
origin.
162
162
163
- You can initiate a key bundle in serveral ways. You can use all the
163
+ You can initiate a key bundle in several ways. You can use all the
164
164
import variants we described above and then add the resulting key to a key
165
165
bundle::
166
166
@@ -204,14 +204,14 @@ bundle::
204
204
]
205
205
}
206
206
207
- **Note ** that you will get a JWKS representing the public keys unless you
208
- specify that you want a representation of the private keys.
207
+ **Note ** that this will get you a JWKS representing the public keys.
209
208
210
209
As an example of the special functionality of
211
210
:py:class: `cryptojwt.key_bundle.KeyBundle ` assume you have imported a file
212
211
containing a JWKS with one key into a key bundle and then some time later
213
212
another key is added to the file.
214
- This is how key bundle deals with that::
213
+
214
+ First import the file with one key::
215
215
216
216
>>> from cryptojwt.key_bundle import KeyBundle
217
217
>>> kb = KeyBundle(source="file://{}".format(fname), fileformat='jwks')
@@ -225,10 +225,13 @@ keys in the key bundle::
225
225
>>> len(_keys)
226
226
2
227
227
228
- It turns out the it contains the 2 keys that are in the file.
228
+ It turns out the key bundle now contains 2 keys. Both the keys that are in the
229
+ file.
230
+
229
231
If the change is that one key is removed then something else happens.
230
232
Assume we add one key and remove one of the ones that was there before.
231
- The file now should contain 2 keys::
233
+ The file now contain 2 keys, and you might expect the key bundle to do the
234
+ same::
232
235
233
236
>>> _keys = kb.keys()
234
237
>>> len(_keys)
@@ -264,7 +267,7 @@ Creating a key jar with your own newly minted keys you would do:
264
267
265
268
**Note* that the default issuer ID is the empty string ''.
266
269
267
- To import a JWKS you would do::
270
+ To import a JWKS you could do it by first creating a key bundle ::
268
271
269
272
>>> from cryptojwt.key_bundle import KeyBundle
270
273
>>> from cryptojwt.key_jar import KeyJar
@@ -291,6 +294,41 @@ The last line can also be expressed as::
291
294
**Note ** both variants, adds a key bundle to the list of key bundles that
292
295
belongs to '' it does not overwrite anything that was already there.
293
296
297
+ Adding a JWKS is such a common thing that there is a simpler way to do it::
298
+
299
+ >>> from cryptojwt.key_jar import KeyJar
300
+ >>> JWKS = {
301
+ "keys": [
302
+ {
303
+ "kty": "RSA",
304
+ "e": "AQAB",
305
+ "kid": "abc",
306
+ "n":
307
+ "wf-wiusGhA-gleZYQAOPQlNUIucPiqXdPVyieDqQbXXOPBe3nuggtVzeq7
308
+ pVFH1dZz4dY2Q2LA5DaegvP8kRvoSB_87ds3dy3Rfym_GUSc5B0l1TgEob
309
+ cyaep8jguRoHto6GWHfCfKqoUYZq4N8vh4LLMQwLR6zi6Jtu82nB5k8"
310
+ }
311
+ ]}
312
+ >>> key_jar = KeyJar()
313
+ >>> key_jar.import_jwks(JWKS)
314
+
315
+ The end result is the same as when you first created a key bundle and then
316
+ added it to the key jar.
317
+
318
+ When dealing with signed and/or encrypted JSON Web Tokens
319
+ :py:class: `cryptojwt.key_jar.KeyJar ` has these nice methods.
320
+
321
+ get_jwt_verify_keys
322
+ :py:func: `cryptojwt.key_jar.KeyJar.get_jwt_verify_keys ` takes an
323
+ signed JWT as input and returns a set of keys that
324
+ can be used to verify the signature. The set you get back is a best
325
+ estimate and might not contain **the ** key. How good the estimate is
326
+ depends on the information present in the JWS.
327
+
328
+ get_jwt_decrypt_keys
329
+ :py:func: `cryptojwt.key_jar.KeyJar.get_jwt_decrypt_keys ` does the
330
+ same thing but returns keys that can be used to decrypt a message.
331
+
294
332
295
333
.. _cryptography : https://cryptography.io/en/latest/
296
334
.. _JWK : https://tools.ietf.org/html/rfc7517
0 commit comments