def setUp(self): self.key = jwk_from_dict(json.loads(load_testdata('oct.json', 'r'))) self.signature = b64decode( 'dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk') self.message = ( b'eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9' b'.' b'eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt' b'cGxlLmNvbS9pc19yb290Ijp0cnVlfQ')
def jwt2john(jwt): """ Convert signature from base64 to hex, and separate it from the data by a # so that John can parse it. """ jwt_bytes = jwt.encode('ascii') parts = jwt_bytes.split(b'.') data = parts[0] + b'.' + parts[1] signature = hexlify(b64decode(str(parts[2]))) return (data + b'#' + signature).decode('ascii')
def setUp(self): self.key = jwk_from_dict(json.loads(load_testdata('oct.json', 'r'))) self.signature = b64decode( 'dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk' ) self.message = ( b'eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9' b'.' b'eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt' b'cGxlLmNvbS9pc19yb290Ijp0cnVlfQ' )
def jwk_to_rsa(key): """Convert a deserialized JWK into an RSA Public Key instance.""" e = int(codecs.encode(b64decode(key['e'].encode('ascii')), 'hex'), 16) n = int(codecs.encode(b64decode(key['n'].encode('ascii')), 'hex'), 16) return rsa.RSAPublicNumbers(e, n).public_key(default_backend())
def test_b64decode(): ret = ('eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQog' 'Imh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ') expected = (b'{"iss":"joe",\r\n "exp":1300819380,\r\n ' b'"http://example.com/is_root":true}') assert b64decode(ret) == expected