Commit 392fe501 authored by Simo Sorce's avatar Simo Sorce

Fix generation of symmetric keys

Symmetric keys are stored base64 encoded. The generation code was storing
them as raw bytes instead.
Thanks to Frank Siebelinst for reporting the issue and suggesting a fix.

Closes #9
Signed-off-by: default avatarSimo Sorce <simo@redhat.com>
parent 9d52a18a
......@@ -206,7 +206,7 @@ class JWK(object):
del params['size']
key = os.urandom(size // 8)
params['kty'] = 'oct'
params['k'] = key
params['k'] = base64url_encode(key)
self.import_key(**params)
def _encode_int(self, i):
......
......@@ -196,6 +196,14 @@ class TestJWK(unittest.TestCase):
k2 = jwk.JWK(**json_decode(jk))
self.assertEqual(k.key_id, k2.key_id)
def test_generate_oct_key(self):
key = jwk.JWK(generate='oct', size=128)
E = jwe.JWE('test', '{"alg":"A128KW","enc":"A128GCM"}')
E.add_recipient(key)
e = E.serialize()
E.deserialize(e, key)
self.assertEqual(E.payload, 'test')
# RFC 7515 - A.1
A1_protected = \
[123, 34, 116, 121, 112, 34, 58, 34, 74, 87, 84, 34, 44, 13, 10, 32,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment