Skip to content

Commit 0f65fd9

Browse files
authored
Merge pull request #48 from IdentityPython/develop
Preparation for persistent storage of dynamic information.
2 parents 81c908b + 02de6f2 commit 0f65fd9

22 files changed

+2229
-566
lines changed

Diff for: .travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ python:
88
addons:
99
apt:
1010
packages:
11-
-
11+
-
1212
install:
1313
- pip install codecov
1414
- pip install tox
@@ -26,6 +26,6 @@ deploy:
2626
tags: true
2727
distributions: bdist_wheel
2828
skip_existing: true
29-
user: __token__
29+
username: __token__
3030
password:
31-
secure: "kW7wRRnQDkeD/bvDrktoLTLrFV4W0B548PhtXVBD7rfbx09oE+jmoM6Ojc2y+t18XQ0zYIfO1qXdoenzti2YiY8xGgA1EYDpHuT0d+DX3tPuLiXou+pts+dXo5Q0YJRFlmBgxtyT+eHhScojDPvDmCFQodIQhiGK1cyzV1p+jE9W/wjiCOQWSQ0LoIV/ajjIMArEmucqwU1wlXxPPgVaV2EuZ7hXBULA6C1DKJENja+qeORtDdW6DMXPJQ4AD74dR+IHaqX4W+mRjRO8wZHKBxrxQ65nZErcfwjbqWRhPIUWzkVngC21BWrs/5eMvxuSPDj4XUY/wiB/1xR883bM6YypEqlCM5x3CFA6a65iI+dfT4iqQRdwOF04oxDkNf2N1LBx8Pv01KxDs5cblv3i/TQHoBIKH8wY6yxrVT2gtcGOwj5+/Pay3PGUN4S8YyzzmSuX/trQgWl/6BD2UPDRchhz24AfV8vXPr6ljBllNdGtWVWJd0ad7u2nqTrUcec909cAhz9SHP1LO8IqCjh8XGdQATOmZXptXJLLmysN9+OwgyTA4SH0Q4FKPG/xriq2cbMCfBTnBOTb5N9ZCm1VeGZlcMdva9UDcRWjtEStAy+gnYQc10EBD060O0jUDB9qdm5zyiTSqOY701828Z2a5uMWXqWUlEsbF61BN6cuD4s="
31+
secure: sCvQSnLW2R9i01dTvG1JyZ+lU99jXjEmPeniSTB8SAZMlfIbuo8I5kjkKxxaa4uTOU3mZiWDG/wq/liUuUzxjXYLA47gwVqU6QrkgIh0/QqGIN1+GYtHqZZETueGClSS8drCgYchpknNTA+30JL/kpt4fjq5hSUFII5BuybVYbh5WVnmwjhZOnZdKxVuQrrfzNVe14wr/TY7VvtL7W5bSCigxYh4oSUiFB6WkFyPZFetqYRO5eCTRt4Tn/hT3Y5Aiz033hMFhrjB4XxuWK7P1f6WVVGRMfAwa4XuC3w0oPSp/9I0cMBtLkExs+tdq25lgmJOcdzVwo3QHPs4pn6AjHKPyoTr/jiuysKnSZCwgcMPFpORgrOWQh/qFxHqNFI0QzNasZXhEBDJaaR2pN/GLjW97NiuaCFuZ/me0SWtpdhPuJpjgx9xxwymRRC4aBu6aPrzoxFGABp4Bkica7KsBmWgQ0ZFMPO6bXB6bU5w8a+wlOY/6I8b06/cIOIyMh8Tas7UwO2/e0L65qhAkR3u1evmagex94w9UameP+518yYik0L5uwrn7vPeRNpH1UEctd3RG73HlEdu8wMCo0pPrvFqsQGtIiPTLPx99453z8Z/raWwAa1Zpn2c8mSm9YIOQZ20rsiFy1vfwAm2b7/dfm005hUirmfwtiG7Oq8iLdg=

Diff for: setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
author="Roland Hedberg",
3636
author_email="[email protected]",
3737
license="Apache 2.0",
38-
packages=["cryptojwt", "cryptojwt/jwe", "cryptojwt/jwk", "cryptojwt/jws", "cryptojwt/tools"],
38+
packages=["cryptojwt", "cryptojwt/jwe", "cryptojwt/jwk", "cryptojwt/jws", "cryptojwt/tools",
39+
"cryptojwt/serialize"],
3940
package_dir={"": "src"},
4041
classifiers=[
4142
"Development Status :: 4 - Beta",

Diff for: src/cryptojwt/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
except ImportError:
2222
pass
2323

24-
__version__ = '0.8.4'
24+
__version__ = '1.0.0'
2525

2626
logger = logging.getLogger(__name__)
2727

Diff for: src/cryptojwt/exception.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ class MissingKey(JWKESTException):
4343
""" No usable key """
4444

4545

46+
class KeyIOError(Exception):
47+
pass
48+
49+
50+
class UnknownKeyType(KeyIOError):
51+
pass
52+
53+
54+
class UpdateFailed(KeyIOError):
55+
pass
56+
57+
4658
class UnknownKeytype(Invalid):
4759
"""An unknown key type"""
4860

@@ -87,18 +99,10 @@ class WrongKeyType(JWKESTException):
8799
pass
88100

89101

90-
class UnknownKeyType(JWKESTException):
91-
pass
92-
93-
94102
class UnsupportedKeyType(JWKESTException):
95103
pass
96104

97105

98-
class UpdateFailed(JWKESTException):
99-
pass
100-
101-
102106
class WrongUsage(JWKESTException):
103107
pass
104108

Diff for: src/cryptojwt/jwk/__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ def appropriate_for(self, usage, **kwargs):
248248
elif self.key_ops:
249249
return usage in self.key_ops
250250

251+
def update(self):
252+
pass
253+
251254

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

305308

309+
def calculate_x5t(der, hash='sha1'):
310+
val = certificate_fingerprint(der, hash)
311+
val = val.replace(':', '')
312+
return base64.b64encode(as_bytes(val))
313+
314+
306315
def pem_hash(pem_file):
307316
with open(pem_file, "r") as fp:
308317
pem = fp.read()

Diff for: src/cryptojwt/jwk/jwk.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def key_from_jwk_dict(jwk_dict, private=None):
6666
"""
6767

6868
# uncouple from the original item
69-
_jwk_dict = copy.copy(jwk_dict)
69+
_jwk_dict = copy.deepcopy(jwk_dict)
7070

7171
if 'kty' not in _jwk_dict:
7272
raise MissingValue('kty missing')

Diff for: src/cryptojwt/jwt.py

+20-17
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(self, key_jar=None, iss='', lifetime=0,
8080
enc_enc="A128CBC-HS256", enc_alg="RSA1_5", msg_cls=None,
8181
iss2msg_cls=None, skew=15,
8282
allowed_sign_algs=None, allowed_enc_algs=None,
83-
allowed_enc_encs=None):
83+
allowed_enc_encs=None, zip=''):
8484
self.key_jar = key_jar # KeyJar instance
8585
self.iss = iss # My identifier
8686
self.lifetime = lifetime # default life time of the signature
@@ -99,6 +99,7 @@ def __init__(self, key_jar=None, iss='', lifetime=0,
9999
self.allowed_sign_algs = allowed_sign_algs
100100
self.allowed_enc_algs = allowed_enc_algs
101101
self.allowed_enc_encs = allowed_enc_encs
102+
self.zip = zip
102103

103104
def receiver_keys(self, recv, use):
104105
"""
@@ -107,7 +108,7 @@ def receiver_keys(self, recv, use):
107108
:param use: What the keys should be usable for
108109
:return: A list of keys.
109110
"""
110-
return self.key_jar.get(use, owner=recv)
111+
return self.key_jar.get(use, issuer_id=recv)
111112

112113
def receivers(self):
113114
"""Return a list of identifiers.
@@ -117,20 +118,22 @@ def receivers(self):
117118
"""
118119
return self.key_jar.owners
119120

120-
def my_keys(self, owner_id='', use='sig'):
121-
_k = self.key_jar.get(use, owner=owner_id)
122-
if owner_id != '':
121+
def my_keys(self, issuer_id='', use='sig'):
122+
_k = self.key_jar.get(use, issuer_id=issuer_id)
123+
if issuer_id != '':
123124
try:
124-
_k.extend(self.key_jar.get(use, owner=''))
125+
_k.extend(self.key_jar.get(use, issuer_id=''))
125126
except KeyError:
126127
pass
127128
return _k
128129

129-
def _encrypt(self, payload, recv, cty='JWT'):
130+
def _encrypt(self, payload, recv, cty='JWT', zip=''):
130131
kwargs = {"alg": self.enc_alg, "enc": self.enc_enc}
131132

132133
if cty:
133134
kwargs["cty"] = cty
135+
if zip:
136+
kwargs['zip'] = zip
134137

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

174177
return argv
175178

176-
def pack_key(self, owner_id='', kid=''):
179+
def pack_key(self, issuer_id='', kid=''):
177180
"""
178181
Find a key to be used for signing the Json Web Token
179182
180-
:param owner_id: Owner of the keys to chose from
183+
:param issuer_id: Owner of the keys to chose from
181184
:param kid: Key ID
182185
:return: One key
183186
"""
184-
keys = pick_key(self.my_keys(owner_id, 'sig'), 'sig', alg=self.alg,
187+
keys = pick_key(self.my_keys(issuer_id, 'sig'), 'sig', alg=self.alg,
185188
kid=kid)
186189

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

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

192-
def pack(self, payload=None, kid='', owner='', recv='', aud=None, **kwargs):
195+
def pack(self, payload=None, kid='', issuer_id='', recv='', aud=None, **kwargs):
193196
"""
194197
195198
:param payload: Information to be carried as payload in the JWT
196199
:param kid: Key ID
197-
:param owner: The owner of the the keys that are to be used for signing
200+
:param issuer_id: The owner of the the keys that are to be used for signing
198201
:param recv: The intended immediate receiver
199202
:param aud: Intended audience for this JWS/JWE, not expected to
200203
contain the recipient.
@@ -221,12 +224,12 @@ def pack(self, payload=None, kid='', owner='', recv='', aud=None, **kwargs):
221224

222225
_args['jti'] = _jti
223226

224-
if not owner and self.iss:
225-
owner = self.iss
227+
if not issuer_id and self.iss:
228+
issuer_id = self.iss
226229

227230
if self.sign:
228231
if self.alg != 'none':
229-
_key = self.pack_key(owner, kid)
232+
_key = self.pack_key(issuer_id, kid)
230233
# _args['kid'] = _key.kid
231234
else:
232235
_key = None
@@ -238,9 +241,9 @@ def pack(self, payload=None, kid='', owner='', recv='', aud=None, **kwargs):
238241

239242
if _encrypt:
240243
if not self.sign:
241-
return self._encrypt(_sjwt, recv, cty='json')
244+
return self._encrypt(_sjwt, recv, cty='json', zip=self.zip)
242245

243-
return self._encrypt(_sjwt, recv)
246+
return self._encrypt(_sjwt, recv, zip=self.zip)
244247
else:
245248
return _sjwt
246249

0 commit comments

Comments
 (0)