commit python-jwcrypto for openSUSE:Factory
Hello community, here is the log from the commit of package python-jwcrypto for openSUSE:Factory checked in at 2018-06-29 22:36:46 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-jwcrypto (Old) and /work/SRC/openSUSE:Factory/.python-jwcrypto.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "python-jwcrypto" Fri Jun 29 22:36:46 2018 rev:5 rq:619738 version:0.5.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-jwcrypto/python-jwcrypto.changes 2018-06-27 10:21:38.879541948 +0200 +++ /work/SRC/openSUSE:Factory/.python-jwcrypto.new/python-jwcrypto.changes 2018-06-29 22:36:46.857982002 +0200 @@ -1,0 +2,8 @@ +Wed Jun 27 20:45:14 UTC 2018 - michael@stroeder.com + +- update to upstream release 0.5.0: + * Better validation of JWE + * Avoid deprecation warnings + * Tested to work with python 3.7 + +------------------------------------------------------------------- Old: ---- jwcrypto-0.4.2.tar.gz New: ---- jwcrypto-0.5.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-jwcrypto.spec ++++++ --- /var/tmp/diff_new_pack.NwN3rV/_old 2018-06-29 22:36:47.357981569 +0200 +++ /var/tmp/diff_new_pack.NwN3rV/_new 2018-06-29 22:36:47.361981565 +0200 @@ -18,7 +18,7 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-jwcrypto -Version: 0.4.2 +Version: 0.5.0 Release: 0 Summary: Python module package implementing JOSE Web standards License: LGPL-3.0-only ++++++ jwcrypto-0.4.2.tar.gz -> jwcrypto-0.5.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jwcrypto-0.4.2/PKG-INFO new/jwcrypto-0.5.0/PKG-INFO --- old/jwcrypto-0.4.2/PKG-INFO 2017-08-01 17:58:06.000000000 +0200 +++ new/jwcrypto-0.5.0/PKG-INFO 2018-06-27 12:27:24.000000000 +0200 @@ -1,10 +1,10 @@ -Metadata-Version: 1.1 +Metadata-Version: 1.2 Name: jwcrypto -Version: 0.4.2 +Version: 0.5.0 Summary: Implementation of JOSE Web standards Home-page: https://github.com/latchset/jwcrypto -Author: JWCrypto Project Contributors -Author-email: simo@redhat.com +Maintainer: JWCrypto Project Contributors +Maintainer-email: simo@redhat.com License: LGPLv3+ Description: UNKNOWN Platform: UNKNOWN @@ -12,6 +12,7 @@ Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 Classifier: Intended Audience :: Developers Classifier: Topic :: Security Classifier: Topic :: Software Development :: Libraries :: Python Modules diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jwcrypto-0.4.2/README.md new/jwcrypto-0.5.0/README.md --- old/jwcrypto-0.4.2/README.md 2015-07-10 18:38:15.000000000 +0200 +++ new/jwcrypto-0.5.0/README.md 2018-06-27 08:24:18.000000000 +0200 @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/latchset/jwcrypto.svg?branch=master)](https://travis-ci.org/latchset/jwcrypto) + JWCrypto ======== diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jwcrypto-0.4.2/jwcrypto/common.py new/jwcrypto-0.5.0/jwcrypto/common.py --- old/jwcrypto-0.4.2/jwcrypto/common.py 2017-08-01 10:46:38.000000000 +0200 +++ new/jwcrypto-0.5.0/jwcrypto/common.py 2018-06-27 08:24:18.000000000 +0200 @@ -16,12 +16,12 @@ def base64url_decode(payload): - l = len(payload) % 4 - if l == 2: + size = len(payload) % 4 + if size == 2: payload += '==' - elif l == 3: + elif size == 3: payload += '=' - elif l != 0: + elif size != 0: raise ValueError('Invalid base64 string') return urlsafe_b64decode(payload.encode('utf-8')) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jwcrypto-0.4.2/jwcrypto/jwa.py new/jwcrypto-0.5.0/jwcrypto/jwa.py --- old/jwcrypto-0.4.2/jwcrypto/jwa.py 2017-08-01 10:46:38.000000000 +0200 +++ new/jwcrypto-0.5.0/jwcrypto/jwa.py 2018-06-27 08:24:22.000000000 +0200 @@ -141,15 +141,15 @@ def sign(self, key, payload): skey = key.get_op_key('sign', self._curve) signature = skey.sign(payload, ec.ECDSA(self.hashfn)) - r, s = ec_utils.decode_rfc6979_signature(signature) - l = key.get_curve(self._curve).key_size - return _encode_int(r, l) + _encode_int(s, l) + r, s = ec_utils.decode_dss_signature(signature) + size = key.get_curve(self._curve).key_size + return _encode_int(r, size) + _encode_int(s, size) def verify(self, key, payload, signature): pkey = key.get_op_key('verify', self._curve) r = signature[:len(signature) // 2] s = signature[len(signature) // 2:] - enc_signature = ec_utils.encode_rfc6979_signature( + enc_signature = ec_utils.encode_dss_signature( int(hexlify(r), 16), int(hexlify(s), 16)) pkey.verify(enc_signature, payload, ec.ECDSA(self.hashfn)) @@ -828,7 +828,7 @@ class _EcdhEsAes256Kw(_EcdhEs): name = 'ECDH-ES+A256KW' - description = 'ECDH-ES using Concat KDF and "A128KW" wrapping' + description = 'ECDH-ES using Concat KDF and "A256KW" wrapping' keysize = 256 algorithm_usage_location = 'alg' algorithm_use = 'kex' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jwcrypto-0.4.2/jwcrypto/jwe.py new/jwcrypto-0.5.0/jwcrypto/jwe.py --- old/jwcrypto-0.4.2/jwcrypto/jwe.py 2017-08-01 15:22:08.000000000 +0200 +++ new/jwcrypto-0.5.0/jwcrypto/jwe.py 2018-06-27 08:24:22.000000000 +0200 @@ -3,6 +3,7 @@ import zlib from jwcrypto import common +from jwcrypto.common import JWException from jwcrypto.common import base64url_decode, base64url_encode from jwcrypto.common import json_decode, json_encode from jwcrypto.jwa import JWA @@ -40,7 +41,7 @@ """Default allowed algorithms""" -class InvalidJWEData(Exception): +class InvalidJWEData(JWException): """Invalid JWE Object. This exception is raised when the JWE Object is invalid and/or @@ -58,7 +59,7 @@ super(InvalidJWEData, self).__init__(msg) -# These have been moved to jwcrypto.common, maintain here for bacwards compat +# These have been moved to jwcrypto.common, maintain here for backwards compat InvalidCEKeyLength = common.InvalidCEKeyLength InvalidJWEKeyLength = common.InvalidJWEKeyLength InvalidJWEKeyType = common.InvalidJWEKeyType @@ -269,7 +270,19 @@ if compact: for invalid in 'aad', 'unprotected': if invalid in self.objects: - raise InvalidJWEOperation("Can't use compact encoding") + raise InvalidJWEOperation( + "Can't use compact encoding when the '%s' parameter" + "is set" % invalid) + if 'protected' not in self.objects: + raise InvalidJWEOperation( + "Can't use compat encoding without protected headers") + else: + ph = json_decode(self.objects['protected']) + for required in 'alg', 'enc': + if required not in ph: + raise InvalidJWEOperation( + "Can't use compat encoding, '%s' must be in the " + "protected header" % required) if 'recipients' in self.objects: if len(self.objects['recipients']) != 1: raise InvalidJWEOperation("Invalid number of recipients") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jwcrypto-0.4.2/jwcrypto/jwk.py new/jwcrypto-0.5.0/jwcrypto/jwk.py --- old/jwcrypto-0.4.2/jwcrypto/jwk.py 2017-08-01 10:46:38.000000000 +0200 +++ new/jwcrypto-0.5.0/jwcrypto/jwk.py 2018-06-27 12:24:24.000000000 +0200 @@ -1,8 +1,9 @@ # Copyright (C) 2015 JWCrypto Project Contributors - see LICENSE file import os - from binascii import hexlify, unhexlify +from collections import namedtuple +from enum import Enum from cryptography import x509 from cryptography.hazmat.backends import default_backend @@ -12,6 +13,7 @@ from six import iteritems +from jwcrypto.common import JWException from jwcrypto.common import base64url_decode, base64url_encode from jwcrypto.common import json_decode, json_encode @@ -22,36 +24,59 @@ 'oct': 'Octet sequence'} """Registry of valid Key Types""" + # RFC 7518 - 7.5 # It is part of the JWK Parameters Registry, but we want a more # specific map for internal usage -JWKValuesRegistry = {'EC': {'crv': ('Curve', 'Public', 'Required'), - 'x': ('X Coordinate', 'Public', 'Required'), - 'y': ('Y Coordinate', 'Public', 'Required'), - 'd': ('ECC Private Key', 'Private', None)}, - 'RSA': {'n': ('Modulus', 'Public', 'Required'), - 'e': ('Exponent', 'Public', 'Required'), - 'd': ('Private Exponent', 'Private', None), - 'p': ('First Prime Factor', 'Private', None), - 'q': ('Second Prime Factor', 'Private', None), - 'dp': ('First Factor CRT Exponent', 'Private', - None), - 'dq': ('Second Factor CRT Exponent', 'Private', - None), - 'qi': ('First CRT Coefficient', 'Private', None)}, - 'oct': {'k': ('Key Value', 'Private', 'Required')}} +class ParmType(Enum): + name = 'A string with a name' + b64 = 'Base64url Encoded' + b64U = 'Base64urlUint Encoded' + unsupported = 'Unsupported Parameter' + + +JWKParameter = namedtuple('Parameter', 'description public required type') +JWKValuesRegistry = { + 'EC': { + 'crv': JWKParameter('Curve', True, True, ParmType.name), + 'x': JWKParameter('X Coordinate', True, True, ParmType.b64), + 'y': JWKParameter('Y Coordinate', True, True, ParmType.b64), + 'd': JWKParameter('ECC Private Key', False, False, ParmType.b64), + }, + 'RSA': { + 'n': JWKParameter('Modulus', True, True, ParmType.b64), + 'e': JWKParameter('Exponent', True, True, ParmType.b64U), + 'd': JWKParameter('Private Exponent', False, False, ParmType.b64U), + 'p': JWKParameter('First Prime Factor', False, False, ParmType.b64U), + 'q': JWKParameter('Second Prime Factor', False, False, ParmType.b64U), + 'dp': JWKParameter('First Factor CRT Exponent', + False, False, ParmType.b64U), + 'dq': JWKParameter('Second Factor CRT Exponent', + False, False, ParmType.b64U), + 'qi': JWKParameter('First CRT Coefficient', + False, False, ParmType.b64U), + 'oth': JWKParameter('Other Primes Info', + False, False, ParmType.unsupported), + }, + 'oct': { + 'k': JWKParameter('Key Value', False, True, ParmType.b64), + } +} """Registry of valid key values""" -JWKParamsRegistry = {'kty': ('Key Type', 'Public', ), - 'use': ('Public Key Use', 'Public'), - 'key_ops': ('Key Operations', 'Public'), - 'alg': ('Algorithm', 'Public'), - 'kid': ('Key ID', 'Public'), - 'x5u': ('X.509 URL', 'Public'), - 'x5c': ('X.509 Certificate Chain', 'Public'), - 'x5t': ('X.509 Certificate SHA-1 Thumbprint', 'Public'), - 'x5t#S256': ('X.509 Certificate SHA-256 Thumbprint', - 'Public')} +JWKParamsRegistry = { + 'kty': JWKParameter('Key Type', True, None, None), + 'use': JWKParameter('Public Key Use', True, None, None), + 'key_ops': JWKParameter('Key Operations', True, None, None), + 'alg': JWKParameter('Algorithm', True, None, None), + 'kid': JWKParameter('Key ID', True, None, None), + 'x5u': JWKParameter('X.509 URL', True, None, None), + 'x5c': JWKParameter('X.509 Certificate Chain', True, None, None), + 'x5t': JWKParameter('X.509 Certificate SHA-1 Thumbprint', + True, None, None), + 'x5t#S256': JWKParameter('X.509 Certificate SHA-256 Thumbprint', + True, None, None) +} """Regstry of valid key parameters""" # RFC 7518 - 7.6 @@ -83,7 +108,7 @@ 'secp521r1': 'P-521'} -class InvalidJWKType(Exception): +class InvalidJWKType(JWException): """Invalid JWK Type Exception. This exception is raised when an invalid parameter type is used. @@ -98,7 +123,7 @@ self.value, list(JWKTypesRegistry.keys())) -class InvalidJWKUsage(Exception): +class InvalidJWKUsage(JWException): """Invalid JWK usage Exception. This exception is raised when an invalid key usage is requested, @@ -123,7 +148,7 @@ valid) -class InvalidJWKOperation(Exception): +class InvalidJWKOperation(JWException): """Invalid JWK Operation Exception. This exception is raised when an invalid key operation is requested, @@ -150,7 +175,7 @@ valid) -class InvalidJWKValue(Exception): +class InvalidJWKValue(JWException): """Invalid JWK Value Exception. This exception is raised when an invalid/unknown value is used in the @@ -210,6 +235,7 @@ @classmethod def generate(cls, **kwargs): obj = cls() + kty = None try: kty = kwargs['kty'] gen = getattr(obj, '_generate_%s' % kty) @@ -219,6 +245,7 @@ return obj def generate_key(self, **params): + kty = None try: kty = params.pop('generate') gen = getattr(self, '_generate_%s' % kty) @@ -346,8 +373,26 @@ names.remove(name) for name, val in iteritems(JWKValuesRegistry[kty]): - if val[2] == 'Required' and name not in self._key: + if val.required and name not in self._key: raise InvalidJWKValue('Missing required value %s' % name) + if val.type == ParmType.unsupported and name in self._key: + raise InvalidJWKValue('Unsupported parameter %s' % name) + if val.type == ParmType.b64 and name in self._key: + # Check that the value is base64url encoded + try: + base64url_decode(self._key[name]) + except Exception: # pylint: disable=broad-except + raise InvalidJWKValue( + '"%s" is not base64url encoded' % name + ) + if val[3] == ParmType.b64U and name in self._key: + # Check that the value is Base64urlUInt encoded + try: + self._decode_int(self._key[name]) + except Exception: # pylint: disable=broad-except + raise InvalidJWKValue( + '"%s" is not Base64urlUInt encoded' % name + ) # Unknown key parameters are allowed # Let's just store them out of the way @@ -385,6 +430,19 @@ ' "key_ops" values specified at' ' the same time') + @classmethod + def from_json(cls, key): + """Creates a RFC 7517 JWK from the standard JSON format. + + :param key: The RFC 7517 representation of a JWK. + """ + obj = cls() + try: + jkey = json_decode(key) + except Exception as e: # pylint: disable=broad-except + raise InvalidJWKValue(e) + return obj.import_key(**jkey) + def export(self, private_key=True): """Exports the key in the standard JSON format. Exports the key regardless of type, if private_key is False @@ -405,19 +463,23 @@ It fails if one is not available like when this function is called on a symmetric key. """ + pub = self._public_params() + return json_encode(pub) + + def _public_params(self): if not self.has_public: raise InvalidJWKType("No public key available") pub = {} preg = JWKParamsRegistry for name in preg: - if preg[name][1] == 'Public': + if preg[name].public: if name in self._params: pub[name] = self._params[name] reg = JWKValuesRegistry[self._params['kty']] for param in reg: - if reg[param][1] == 'Public': + if reg[param].public: pub[param] = self._key[param] - return json_encode(pub) + return pub def _export_all(self): d = dict() @@ -439,6 +501,10 @@ return self._export_all() raise InvalidJWKType("Not a symmetric key") + def public(self): + pub = self._public_params() + return JWK(**pub) + @property def has_public(self): """Whether this JWK has an asymmetric Public key.""" @@ -446,7 +512,7 @@ return False reg = JWKValuesRegistry[self._params['kty']] for value in reg: - if reg[value][1] == 'Public' and value in self._key: + if reg[value].public and value in self._key: return True @property @@ -456,7 +522,7 @@ return False reg = JWKValuesRegistry[self._params['kty']] for value in reg: - if reg[value][1] == 'Private' and value in self._key: + if not reg[value].public and value in self._key: return True return False @@ -700,7 +766,7 @@ t = {'kty': self._params['kty']} for name, val in iteritems(JWKValuesRegistry[t['kty']]): - if val[2] == 'Required': + if val.required: t[name] = self._key[name] digest = hashes.Hash(hashalg, backend=default_backend()) digest.update(bytes(json_encode(t).encode('utf8'))) @@ -733,6 +799,12 @@ super(JWKSet, self).__setitem__('keys', _JWKkeys()) self.update(*args, **kwargs) + def __iter__(self): + return self['keys'].__iter__() + + def __contains__(self, key): + return self['keys'].__contains__(key) + def __setitem__(self, key, val): if key == 'keys': self['keys'].add(val) @@ -769,7 +841,7 @@ """ try: jwkset = json_decode(keyset) - except: + except Exception: # pylint: disable=broad-except raise InvalidJWKValue() if 'keys' not in jwkset: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jwcrypto-0.4.2/jwcrypto/jws.py new/jwcrypto-0.5.0/jwcrypto/jws.py --- old/jwcrypto-0.4.2/jwcrypto/jws.py 2017-08-01 10:46:38.000000000 +0200 +++ new/jwcrypto-0.5.0/jwcrypto/jws.py 2018-06-27 08:24:22.000000000 +0200 @@ -1,5 +1,6 @@ # Copyright (C) 2015 JWCrypto Project Contributors - see LICENSE file +from jwcrypto.common import JWException from jwcrypto.common import base64url_decode, base64url_encode from jwcrypto.common import json_decode, json_encode from jwcrypto.jwa import JWA @@ -30,7 +31,7 @@ """Default allowed algorithms""" -class InvalidJWSSignature(Exception): +class InvalidJWSSignature(JWException): """Invalid JWS Signature. This exception is raised when a signature cannot be validated. @@ -47,7 +48,7 @@ super(InvalidJWSSignature, self).__init__(msg) -class InvalidJWSObject(Exception): +class InvalidJWSObject(JWException): """Invalid JWS Object. This exception is raised when the JWS Object is invalid and/or @@ -63,7 +64,7 @@ super(InvalidJWSObject, self).__init__(msg) -class InvalidJWSOperation(Exception): +class InvalidJWSOperation(JWException): """Invalid JWS Object. This exception is raised when a requested operation cannot @@ -495,7 +496,7 @@ jhl = list() for o in obj['signatures']: jh = dict() - if 'protected' in obj: + if 'protected' in o: p = json_decode(o['protected']) jh = self._merge_headers(jh, p) jh = self._merge_headers(jh, o.get('header', dict())) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jwcrypto-0.4.2/jwcrypto/jwt.py new/jwcrypto-0.5.0/jwcrypto/jwt.py --- old/jwcrypto-0.4.2/jwcrypto/jwt.py 2017-08-01 10:46:38.000000000 +0200 +++ new/jwcrypto-0.5.0/jwcrypto/jwt.py 2018-06-27 08:24:22.000000000 +0200 @@ -5,7 +5,7 @@ from six import string_types -from jwcrypto.common import json_decode, json_encode +from jwcrypto.common import JWException, json_decode, json_encode from jwcrypto.jwe import JWE from jwcrypto.jwk import JWK, JWKSet from jwcrypto.jws import JWS @@ -22,7 +22,7 @@ 'jti': 'JWT ID'} -class JWTExpired(Exception): +class JWTExpired(JWException): """Json Web Token is expired. This exception is raised when a token is expired accoring to its claims. @@ -39,7 +39,7 @@ super(JWTExpired, self).__init__(msg) -class JWTNotYetValid(Exception): +class JWTNotYetValid(JWException): """Json Web Token is not yet valid. This exception is raised when a token is not valid yet according to its @@ -57,7 +57,7 @@ super(JWTNotYetValid, self).__init__(msg) -class JWTMissingClaim(Exception): +class JWTMissingClaim(JWException): """Json Web Token claim is invalid. This exception is raised when a claim does not match the expected value. @@ -74,7 +74,7 @@ super(JWTMissingClaim, self).__init__(msg) -class JWTInvalidClaimValue(Exception): +class JWTInvalidClaimValue(JWException): """Json Web Token claim is invalid. This exception is raised when a claim does not match the expected value. @@ -91,7 +91,7 @@ super(JWTInvalidClaimValue, self).__init__(msg) -class JWTInvalidClaimFormat(Exception): +class JWTInvalidClaimFormat(JWException): """Json Web Token claim format is invalid. This exception is raised when a claim is not in a valid format. @@ -108,7 +108,7 @@ super(JWTInvalidClaimFormat, self).__init__(msg) -class JWTMissingKeyID(Exception): +class JWTMissingKeyID(JWException): """Json Web Token is missing key id. This exception is raised when trying to decode a JWT with a key set @@ -126,7 +126,7 @@ super(JWTMissingKeyID, self).__init__(msg) -class JWTMissingKey(Exception): +class JWTMissingKey(JWException): """Json Web Token is using a key not in the key set. This exception is raised if the key that was used is not available @@ -155,15 +155,15 @@ """Creates a JWT object. :param header: A dict or a JSON string with the JWT Header data. - :param claims: A dict or a string withthe JWT Claims data. + :param claims: A dict or a string with the JWT Claims data. :param jwt: a 'raw' JWT token :param key: A (:class:`jwcrypto.jwk.JWK`) key to deserialize - the token. A (:class:`jwcrypt.jwk.JWKSet`) can also be used. + the token. A (:class:`jwcrypto.jwk.JWKSet`) can also be used. :param algs: An optional list of allowed algorithms :param default_claims: An optional dict with default values for registred claims. A None value for NumericDate type claims will cause generation according to system time. Only the values - fro RFC 7519 - 4.1 are evaluated. + from RFC 7519 - 4.1 are evaluated. :param check_claims: An optional dict of claims that must be present in the token, if the value is not None the claim must match exactly. @@ -224,6 +224,10 @@ @claims.setter def claims(self, c): + if self._reg_claims and not isinstance(c, dict): + # decode c so we can set default claims + c = json_decode(c) + if isinstance(c, dict): self._add_default_claims(c) self._claims = json_encode(c) @@ -380,8 +384,8 @@ if value in claims[name]: continue raise JWTInvalidClaimValue( - "Invalid '%s' value. Expected '%s' in '%s'" % ( - name, value, claims[name])) + "Invalid '%s' value. Expected '%s' to be in '%s'" % ( + name, claims[name], value)) elif name == 'exp': if value is not None: @@ -398,7 +402,7 @@ else: if value is not None and value != claims[name]: raise JWTInvalidClaimValue( - "Invalid '%s' value. Expected '%d' got '%d'" % ( + "Invalid '%s' value. Expected '%s' got '%s'" % ( name, value, claims[name])) def make_signed_token(self, key): @@ -437,7 +441,7 @@ :param jwt: a 'raw' JWT token. :param key: A (:class:`jwcrypto.jwk.JWK`) verification or - decryption key, or a (:class:`jwcrypt.jwk.JWKSet`) that + decryption key, or a (:class:`jwcrypto.jwk.JWKSet`) that contains a key indexed by the 'kid' header. """ c = jwt.count('.') diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jwcrypto-0.4.2/jwcrypto/tests.py new/jwcrypto-0.5.0/jwcrypto/tests.py --- old/jwcrypto-0.4.2/jwcrypto/tests.py 2017-08-01 10:46:38.000000000 +0200 +++ new/jwcrypto-0.5.0/jwcrypto/tests.py 2018-06-27 08:24:22.000000000 +0200 @@ -3,7 +3,6 @@ from __future__ import unicode_literals import copy - import unittest from cryptography.hazmat.backends import default_backend @@ -329,6 +328,15 @@ ks3 = jwk.JWKSet.from_json(ks.export()) self.assertEqual(len(ks), len(ks3)) + # Test Keyset with mutiple keys + ksm = jwk.JWKSet.from_json(json_encode(PrivateKeys)) + num = 0 + for item in ksm: + self.assertTrue(isinstance(item, jwk.JWK)) + self.assertTrue(item in ksm) + num += 1 + self.assertEqual(num, len(PrivateKeys['keys'])) + def test_thumbprint(self): for i in range(0, len(PublicKeys['keys'])): k = jwk.JWK(**PublicKeys['keys'][i]) @@ -378,6 +386,25 @@ self.assertFalse(pubkey.has_private) self.assertEqual(prikey.key_id, pubkey.key_id) + def test_public(self): + key = jwk.JWK.from_pem(RSAPrivatePEM, password=RSAPrivatePassword) + self.assertTrue(key.has_public) + self.assertTrue(key.has_private) + pubkey = key.public() + self.assertTrue(pubkey.has_public) + self.assertFalse(pubkey.has_private) + # finally check public works + e = jwe.JWE('plaintext', '{"alg":"RSA-OAEP","enc":"A256GCM"}') + e.add_recipient(pubkey) + enc = e.serialize() + d = jwe.JWE() + d.deserialize(enc, key) + self.assertEqual(d.payload, b'plaintext') + + def test_invalid_value(self): + with self.assertRaises(jwk.InvalidJWKValue): + jwk.JWK(kty='oct', k=b'\x01') + # RFC 7515 - A.1 A1_protected = \ @@ -556,7 +583,11 @@ 'key2': jwk.JWK(**A3_key), 'protected2': bytes(bytearray(A3_protected)).decode('utf-8'), 'header2': json_encode({"kid": "e9bc097a-ce51-4036-9562-d2ade882db0d"}), - 'serialized': A6_serialized} + 'serialized': A6_serialized, + 'jose_header': [{"kid": "2010-12-29", + "alg": "RS256"}, + {"kid": "e9bc097a-ce51-4036-9562-d2ade882db0d", + "alg": "ES256"}]} A7_example = \ '{' + \ @@ -630,6 +661,7 @@ sig = s.serialize() s.deserialize(sig, A6_example['key1']) s.deserialize(A6_serialized, A6_example['key2']) + self.assertEqual(A6_example['jose_header'], s.jose_header) def test_A7(self): s = jws.JWS(A6_example['payload']) @@ -843,6 +875,26 @@ e = jwe.JWE(algs=['A256KW']) e.deserialize(E_A5_ex, E_A4_ex['key2']) + def test_compact_protected_header(self): + """Compact representation requires a protected header""" + e = jwe.JWE(E_A1_ex['plaintext']) + e.add_recipient(E_A1_ex['key'], E_A1_ex['protected']) + + with self.assertRaises(jwe.InvalidJWEOperation): + e.serialize(compact=True) + + def test_compact_invalid_header(self): + with self.assertRaises(jwe.InvalidJWEOperation): + e = jwe.JWE(E_A1_ex['plaintext'], E_A1_ex['protected'], + aad='XYZ', recipient=E_A1_ex['key']) + e.serialize(compact=True) + + with self.assertRaises(jwe.InvalidJWEOperation): + e = jwe.JWE(E_A1_ex['plaintext'], E_A1_ex['protected'], + unprotected='{"jku":"https://example.com/keys.jwks"}', + recipient=E_A1_ex['key']) + e.serialize(compact=True) + MMA_vector_key = jwk.JWK(**E_A2_key) MMA_vector_ok_cek = \ @@ -1018,6 +1070,39 @@ keyset.add(key) jwt.JWT(jwt=token, key=keyset, check_claims={'exp': 1300819380}) + def test_invalid_claim_type(self): + key = jwk.JWK(**E_A2_key) + claims = {"testclaim": "test"} + claims.update(A1_claims) + t = jwt.JWT(A1_header, claims) + t.make_encrypted_token(key) + token = t.serialize() + + # Wrong string + self.assertRaises(jwt.JWTInvalidClaimValue, jwt.JWT, jwt=token, + key=key, check_claims={"testclaim": "ijgi"}) + + # Wrong type + self.assertRaises(jwt.JWTInvalidClaimValue, jwt.JWT, jwt=token, + key=key, check_claims={"testclaim": 123}) + + # Correct + jwt.JWT(jwt=token, key=key, check_claims={"testclaim": "test"}) + + def test_claim_params(self): + key = jwk.JWK(**E_A2_key) + default_claims = {"iss": "test", "exp": None} + string_claims = '{"string_claim":"test"}' + string_header = '{"alg":"RSA1_5","enc":"A128CBC-HS256"}' + t = jwt.JWT(string_header, string_claims, + default_claims=default_claims) + t.make_encrypted_token(key) + token = t.serialize() + + # Check default_claims + jwt.JWT(jwt=token, key=key, check_claims={"iss": "test", "exp": None, + "string_claim": "test"}) + class ConformanceTests(unittest.TestCase): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jwcrypto-0.4.2/jwcrypto.egg-info/PKG-INFO new/jwcrypto-0.5.0/jwcrypto.egg-info/PKG-INFO --- old/jwcrypto-0.4.2/jwcrypto.egg-info/PKG-INFO 2017-08-01 17:58:06.000000000 +0200 +++ new/jwcrypto-0.5.0/jwcrypto.egg-info/PKG-INFO 2018-06-27 12:27:24.000000000 +0200 @@ -1,10 +1,10 @@ -Metadata-Version: 1.1 +Metadata-Version: 1.2 Name: jwcrypto -Version: 0.4.2 +Version: 0.5.0 Summary: Implementation of JOSE Web standards Home-page: https://github.com/latchset/jwcrypto -Author: JWCrypto Project Contributors -Author-email: simo@redhat.com +Maintainer: JWCrypto Project Contributors +Maintainer-email: simo@redhat.com License: LGPLv3+ Description: UNKNOWN Platform: UNKNOWN @@ -12,6 +12,7 @@ Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 Classifier: Intended Audience :: Developers Classifier: Topic :: Security Classifier: Topic :: Software Development :: Libraries :: Python Modules diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jwcrypto-0.4.2/setup.py new/jwcrypto-0.5.0/setup.py --- old/jwcrypto-0.4.2/setup.py 2017-08-01 17:57:50.000000000 +0200 +++ new/jwcrypto-0.5.0/setup.py 2018-06-27 12:27:18.000000000 +0200 @@ -6,7 +6,7 @@ setup( name = 'jwcrypto', - version = '0.4.2', + version = '0.5.0', license = 'LGPLv3+', maintainer = 'JWCrypto Project Contributors', maintainer_email = 'simo@redhat.com', @@ -18,6 +18,7 @@ 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', 'Intended Audience :: Developers', 'Topic :: Security', 'Topic :: Software Development :: Libraries :: Python Modules' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jwcrypto-0.4.2/tox.ini new/jwcrypto-0.5.0/tox.ini --- old/jwcrypto-0.4.2/tox.ini 2017-08-01 17:50:59.000000000 +0200 +++ new/jwcrypto-0.5.0/tox.ini 2018-06-27 12:24:24.000000000 +0200 @@ -1,5 +1,5 @@ [tox] -envlist = lint,py27,py34,py35,py36,pep8py2,pep8py3,doc,sphinx +envlist = lint,py27,py34,py35,py36,py37,pep8py2,pep8py3,doc,sphinx skip_missing_interpreters = true [testenv]
participants (1)
-
root