Skip to content

Preparation for persistent storage of dynamic information. #48

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

Merged
merged 53 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
3567970
Astract storage applied.
rohe May 12, 2020
7e121e1
Major change.
rohe May 12, 2020
281d5a3
Missing file.
rohe May 12, 2020
0fa5db9
Name should probably be first parameter.
rohe May 19, 2020
6f34394
Handed over to KeyIssuer.
rohe May 19, 2020
54aad6a
Changed repr
rohe May 19, 2020
3e6a0e2
Finger print of certificates.
rohe May 19, 2020
0997327
Test item serializing
rohe May 19, 2020
1d77678
Missing arguments.
rohe May 19, 2020
1d3ecc8
Repr similar to KeyJar.
rohe May 19, 2020
14c4c21
Worked on persistent storage.
rohe May 28, 2020
abce366
replace token, use username
jschlyter May 31, 2020
e595912
Remove aslist tests.
rohe Jun 6, 2020
d24f476
Removed duplicated exceptions.
rohe Jun 6, 2020
970e284
No dependency on oidcmsg.
rohe Jun 6, 2020
c39ee49
A bit of documentation.
rohe Jun 6, 2020
22acc84
Astract storage applied.
rohe May 12, 2020
11f73f8
Major change.
rohe May 12, 2020
0c791cb
Missing file.
rohe May 12, 2020
14fbc43
Name should probably be first parameter.
rohe May 19, 2020
87ce3cd
Handed over to KeyIssuer.
rohe May 19, 2020
43ce1aa
Changed repr
rohe May 19, 2020
e056a39
Finger print of certificates.
rohe May 19, 2020
ceba266
Test item serializing
rohe May 19, 2020
3e26237
Missing arguments.
rohe May 19, 2020
4e3153f
Repr similar to KeyJar.
rohe May 19, 2020
c1e4893
Worked on persistent storage.
rohe May 28, 2020
03ca4ae
Remove aslist tests.
rohe Jun 6, 2020
4d2f3ca
Removed duplicated exceptions.
rohe Jun 6, 2020
3e45bcf
No dependency on oidcmsg.
rohe Jun 6, 2020
f015370
A bit of documentation.
rohe Jun 6, 2020
1b4840b
Merge branch 'abstorage' of github.com:IdentityPython/JWTConnect-Pyth…
rohe Jun 8, 2020
eb73ee8
Missing file
rohe Jun 8, 2020
467254c
Clearer demarcation between KeyIssuer and KeyJar.
rohe Jun 9, 2020
508602d
More logging
rohe Jun 16, 2020
6b1b9e4
Function made into a class method.
rohe Jun 17, 2020
e478269
Function made into a class method.
rohe Jun 17, 2020
2c4e16a
Added deprecated_alias decorator.
rohe Jun 17, 2020
d04af74
Use deprecated_alias decorator.
rohe Jun 17, 2020
2ee6ba7
Removed SimpleList was a leftover.
rohe Jun 17, 2020
4085ad4
Removed QUOTE converter class. Not CryptoJWT specific.
rohe Jun 17, 2020
7cb595b
raise KeyError if key KeyIssuer is not found
jschlyter Jun 18, 2020
a7db299
fix is not check
jschlyter Jun 18, 2020
610897a
consistency did not kill the cat
jschlyter Jun 18, 2020
7b5d58b
use is/is not
jschlyter Jun 18, 2020
c49f0e8
Placeholder right now.
rohe Jun 18, 2020
9d1eada
Wrong reference
rohe Jun 18, 2020
6e20a60
Check against None
rohe Jun 18, 2020
9cf2593
Both ways should return the same result.
rohe Jun 18, 2020
5f05c22
Merged
rohe Jun 18, 2020
4f6d4a5
raise KeyError if issuer is not found
jschlyter Jun 18, 2020
674fff2
If no such issuer return None.
rohe Jun 22, 2020
02de6f2
Merge pull request #47 from IdentityPython/abstorage
rohe Jun 22, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ python:
addons:
apt:
packages:
-
-
install:
- pip install codecov
- pip install tox
Expand All @@ -26,6 +26,6 @@ deploy:
tags: true
distributions: bdist_wheel
skip_existing: true
user: __token__
username: __token__
password:
secure: "kW7wRRnQDkeD/bvDrktoLTLrFV4W0B548PhtXVBD7rfbx09oE+jmoM6Ojc2y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GABp4Bkica7KsBmWgQ0ZFMPO6bXB6bU5w8a+wlOY/6I8b06/cIOIyMh8Tas7UwO2/e0L65qhAkR3u1evmagex94w9UameP+518yYik0L5uwrn7vPeRNpH1UEctd3RG73HlEdu8wMCo0pPrvFqsQGtIiPTLPx99453z8Z/raWwAa1Zpn2c8mSm9YIOQZ20rsiFy1vfwAm2b7/dfm005hUirmfwtiG7Oq8iLdg=
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
author="Roland Hedberg",
author_email="roland@catalogix.se",
license="Apache 2.0",
packages=["cryptojwt", "cryptojwt/jwe", "cryptojwt/jwk", "cryptojwt/jws", "cryptojwt/tools"],
packages=["cryptojwt", "cryptojwt/jwe", "cryptojwt/jwk", "cryptojwt/jws", "cryptojwt/tools",
"cryptojwt/serialize"],
package_dir={"": "src"},
classifiers=[
"Development Status :: 4 - Beta",
Expand Down
2 changes: 1 addition & 1 deletion src/cryptojwt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
except ImportError:
pass

__version__ = '0.8.4'
__version__ = '1.0.0'

logger = logging.getLogger(__name__)

Expand Down
20 changes: 12 additions & 8 deletions src/cryptojwt/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ class MissingKey(JWKESTException):
""" No usable key """


class KeyIOError(Exception):
pass


class UnknownKeyType(KeyIOError):
pass


class UpdateFailed(KeyIOError):
pass


class UnknownKeytype(Invalid):
"""An unknown key type"""

Expand Down Expand Up @@ -87,18 +99,10 @@ class WrongKeyType(JWKESTException):
pass


class UnknownKeyType(JWKESTException):
pass


class UnsupportedKeyType(JWKESTException):
pass


class UpdateFailed(JWKESTException):
pass


class WrongUsage(JWKESTException):
pass

Expand Down
9 changes: 9 additions & 0 deletions src/cryptojwt/jwk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ def appropriate_for(self, usage, **kwargs):
elif self.key_ops:
return usage in self.key_ops

def update(self):
pass


def pems_to_x5c(cert_chain):
"""
Expand Down Expand Up @@ -303,6 +306,12 @@ def certificate_fingerprint(der, hash="sha256"):
return ':'.join([fp[i:i + 2] for i in range(0, len(fp), 2)]).upper()


def calculate_x5t(der, hash='sha1'):
val = certificate_fingerprint(der, hash)
val = val.replace(':', '')
return base64.b64encode(as_bytes(val))


def pem_hash(pem_file):
with open(pem_file, "r") as fp:
pem = fp.read()
Expand Down
2 changes: 1 addition & 1 deletion src/cryptojwt/jwk/jwk.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def key_from_jwk_dict(jwk_dict, private=None):
"""

# uncouple from the original item
_jwk_dict = copy.copy(jwk_dict)
_jwk_dict = copy.deepcopy(jwk_dict)

if 'kty' not in _jwk_dict:
raise MissingValue('kty missing')
Expand Down
37 changes: 20 additions & 17 deletions src/cryptojwt/jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(self, key_jar=None, iss='', lifetime=0,
enc_enc="A128CBC-HS256", enc_alg="RSA1_5", msg_cls=None,
iss2msg_cls=None, skew=15,
allowed_sign_algs=None, allowed_enc_algs=None,
allowed_enc_encs=None):
allowed_enc_encs=None, zip=''):
self.key_jar = key_jar # KeyJar instance
self.iss = iss # My identifier
self.lifetime = lifetime # default life time of the signature
Expand All @@ -99,6 +99,7 @@ def __init__(self, key_jar=None, iss='', lifetime=0,
self.allowed_sign_algs = allowed_sign_algs
self.allowed_enc_algs = allowed_enc_algs
self.allowed_enc_encs = allowed_enc_encs
self.zip = zip

def receiver_keys(self, recv, use):
"""
Expand All @@ -107,7 +108,7 @@ def receiver_keys(self, recv, use):
:param use: What the keys should be usable for
:return: A list of keys.
"""
return self.key_jar.get(use, owner=recv)
return self.key_jar.get(use, issuer_id=recv)

def receivers(self):
"""Return a list of identifiers.
Expand All @@ -117,20 +118,22 @@ def receivers(self):
"""
return self.key_jar.owners

def my_keys(self, owner_id='', use='sig'):
_k = self.key_jar.get(use, owner=owner_id)
if owner_id != '':
def my_keys(self, issuer_id='', use='sig'):
_k = self.key_jar.get(use, issuer_id=issuer_id)
if issuer_id != '':
try:
_k.extend(self.key_jar.get(use, owner=''))
_k.extend(self.key_jar.get(use, issuer_id=''))
except KeyError:
pass
return _k

def _encrypt(self, payload, recv, cty='JWT'):
def _encrypt(self, payload, recv, cty='JWT', zip=''):
kwargs = {"alg": self.enc_alg, "enc": self.enc_enc}

if cty:
kwargs["cty"] = cty
if zip:
kwargs['zip'] = zip

# use the clients public key for encryption
_jwe = JWE(payload, **kwargs)
Expand Down Expand Up @@ -173,28 +176,28 @@ def pack_init(self, recv, aud):

return argv

def pack_key(self, owner_id='', kid=''):
def pack_key(self, issuer_id='', kid=''):
"""
Find a key to be used for signing the Json Web Token

:param owner_id: Owner of the keys to chose from
:param issuer_id: Owner of the keys to chose from
:param kid: Key ID
:return: One key
"""
keys = pick_key(self.my_keys(owner_id, 'sig'), 'sig', alg=self.alg,
keys = pick_key(self.my_keys(issuer_id, 'sig'), 'sig', alg=self.alg,
kid=kid)

if not keys:
raise NoSuitableSigningKeys('kid={}'.format(kid))

return keys[0] # Might be more then one if kid == ''

def pack(self, payload=None, kid='', owner='', recv='', aud=None, **kwargs):
def pack(self, payload=None, kid='', issuer_id='', recv='', aud=None, **kwargs):
"""

:param payload: Information to be carried as payload in the JWT
:param kid: Key ID
:param owner: The owner of the the keys that are to be used for signing
:param issuer_id: The owner of the the keys that are to be used for signing
:param recv: The intended immediate receiver
:param aud: Intended audience for this JWS/JWE, not expected to
contain the recipient.
Expand All @@ -221,12 +224,12 @@ def pack(self, payload=None, kid='', owner='', recv='', aud=None, **kwargs):

_args['jti'] = _jti

if not owner and self.iss:
owner = self.iss
if not issuer_id and self.iss:
issuer_id = self.iss

if self.sign:
if self.alg != 'none':
_key = self.pack_key(owner, kid)
_key = self.pack_key(issuer_id, kid)
# _args['kid'] = _key.kid
else:
_key = None
Expand All @@ -238,9 +241,9 @@ def pack(self, payload=None, kid='', owner='', recv='', aud=None, **kwargs):

if _encrypt:
if not self.sign:
return self._encrypt(_sjwt, recv, cty='json')
return self._encrypt(_sjwt, recv, cty='json', zip=self.zip)

return self._encrypt(_sjwt, recv)
return self._encrypt(_sjwt, recv, zip=self.zip)
else:
return _sjwt

Expand Down
Loading