Python implementation of the Javascript Object Signing and Encryption (JOSE) framework

Related tags

Web Frameworks jose
Overview
JOSE
====

JOSE is a framework intended to provide a method to securely transfer
claims (such as authorization information) between parties. The JOSE framework
provides a collection of specifications to serve this purpose. A JSON Web
Token (JWT) contains claims that can be used to allow a system to apply access
control to resources it owns.

JWTs can be represented as either JSON Web Signature (JWS) or a JSON Web
Encryption (JWE) objects. Claims within a JWS can be read as they are simply
base64-encoded (but carry with them a signature for authentication). Claims
in a JWE on the other hand, are encrypted and as such, are entirely opaque
to clients using them as their means of authentication and authorization.

This library implements JWS and JWEs along with a subset of the
encryption / authentication algorithms recommended by the JOSE framework.

Documentation
=============
http://jose.readthedocs.org/en/latest

Builds
======
https://travis-ci.org/Demonware/jose
Comments
  • Bug in authentication tag computation

    Bug in authentication tag computation

    There's a bug in the way the authentication tag is computed, running all tokens issued by the library undecipherable by other libraries, since they will always fail to check the token authentication if there's authenticated data (note that for compact serialization, the header should always be authenticated).

    When computing the authentication tag, first we need to concatenate the data authenticated, the IV, the ciphertext and the length of the authenticated data in 64 bits big-endian. This is the input to the HMAC algorithm that yields the authentication tag. However, the values are concatenated in the _jwe_hash_str() method using a period between them, which is against RFC7518.

    This PR addresses the problem by removing the period, using just an empty string as glue for the concatenation. In order to keep backwards compatibility and still be able to decrypt old tokens, the legacy mode of _jwe_hash_str() is kept as is. The temporary version number has been increased to 2, so that all new tokens are encrypted with the correct authentication tag, while all the tokens issued before this change can still be identified and decrypted in legacy mode.

    opened by jaimeperez 8
  • Fix several issues with JWE encryption.

    Fix several issues with JWE encryption.

    The issues, according to the JWA spec are:

    • the AL field is not correctly calculated. It must represent the length in bits of the additional authenticated data, not in bytes. Additionally, it must be represented as an unsigned 64-bit octet string in big-endian, not as a simple string.

    5.2.2.1.4. The octet string AL is equal to the number of bits in the additional authenticated data A expressed as a 64-bit unsigned big endian integer.

    • in order to compute the authentication tag, the ciphertext must be used, not the plaintext.

    5.2.2.1.5. A message authentication tag T is computed by applying HMAC [RFC2104] to the following data, in order:

    •     the additional authenticated data A,
      
    •     the initialization vector IV,
      
    •     the ciphertext E computed in the previous step, and
      
    •     the octet string AL defined above.
      
    • in AES_CBC_HMAC_SHA2, the length of the input key equals to the digest size, that being 32, 48 and 64 octets for each of the three variants.

    The AES_CBC_HMAC_SHA2 parameters specific to AES_128_CBC_HMAC_SHA_256 are:

    •  The input key K is 32 octets long.
      
    • ENC_KEY_LEN is 16 octets.
      
    •  MAC_KEY_LEN is 16 octets.
      
    • the integrity key and encryption key are derived as the first and second half of the input key, respectively.

    The secondary keys MAC_KEY and ENC_KEY are generated from the input key K as follows. Each of these two keys is an octet string.

    •     MAC_KEY consists of the initial MAC_KEY_LEN octets of K, in order.
      
    •     ENC_KEY consists of the final ENC_KEY_LEN octets of K, in order.
      

    The number of octets in the input key K MUST be the sum of MAC_KEY_LEN and ENC_KEY_LEN. The values of these parameters are specified by the Authenticated Encryption algorithms in Sections 5.2.3 through 5.2.5. Note that the MAC key comes before the encryption key in the input key K; this is in the opposite order of the algorithm names in the identifier "AES_CBC_HMAC_SHA2".

    bug 
    opened by jaimeperez 6
  • Python 3.5   SyntaxError: invalid syntax

    Python 3.5 SyntaxError: invalid syntax

    import jose
    
      File "/py/env35/local/lib/python3.5/site-packages/jose.py", line 546
        print decrypt(deserialize_compact(jwt), {'k':key},
                    ^
    SyntaxError: invalid syntax
    

    Is this package compatible with python 3.5?

    opened by wobeng 5
  • Handled expiration exceptions during selection of decryption method.

    Handled expiration exceptions during selection of decryption method.

    decrypt chooses decrypt method (legacy or spec-compliant) using exceptions. In this commit special treatment for failures due to expiration is added. If token decryption failed due to expiration we do not want to try the other decryption method. In addition we no longer miss expiration exceptions in such cases.

    opened by yuriikonovaliuk 3
  • 1.0 Release?

    1.0 Release?

    I see there is a 1.0 version in setup, but no release on pypi? I'm interested in using this library, but would like to see some of the fixes in place first. Any update on when 1.0 will become available? Great work by the way.

    opened by hunt3r 3
  • Plaintext should not be json-encoded.

    Plaintext should not be json-encoded.

    Hi,

    Unless I am missing something, there's nothing in the JOSE JWE drafts saying that the plaintext used for JWE encryption must be a JSON object, nor that it must be json-encoded. Both the encrypt and the decrypt methods assume that the input must be a dict, and json-encode/decode it, making it difficult to deal with cases when you just want to encrypt a simple string. Even though we can just pass a string as a parameter and get it encrypted in the resulting JWE, this poses interoperability issues when using other libraries. If we use the example in the JWE draft, we can generate a JWE like this:

    jwe = jose.encrypt('The true sign of intelligence is not knowledge but imagination.', pub_jwk)
    

    If we then decrypt this with this library, we will get the same string. However, if we use a different library, we will get the string json-encoded, like:

    "The true sign of intelligence is not knowledge but imagination."
    

    Note the double quote signs. This is a problem because then we need to json-decode the plaintext, even though we didn't encode it when calling jose.encrypt()!

    I think the best approach is to assume the plaintext to be a string, and then it is up to the user to json-encode it if he or she wants to use a JSON object. Besides, the claims jargon is confusing, and very tied to the windows world. Most people not using this library for something related to windows will be confused and won't know what's that about, specially given that claims are not mentioned at all in the JOSE drafts.

    Thanks in advance!

    opened by jaimeperez 3
  • Feature/py3k

    Feature/py3k

    Have mostly adapted the jose package to work with python 3 (in addition to python 2).
    Getting tests running with multiple versions of python has necessitated rearanging some of the files but I believe that I have managed to avoid breaking the current api.

    There is one remaining problem which is that I can't figure out what format the key for hmac algorithms should be in and therefore whether, and where, it should be encoded as bytes or unicode. Will have another look at fixing it now. This problem does not affect python 2 however.

    I do have to say that the excellent test suite has made this really quite easy. Thank you.

    enhancement 
    opened by bwhmather 3
  • Unpin pycrypto. Bump version.

    Unpin pycrypto. Bump version.

    Package versions in Python packages (especially libraries) should not be pinned down. Two specific reasons why jose shouldn't do it:

    1. It doesn't look like it uses any specific functionality of version pycrypto 2.6. On the other hand it causes serious compatibility problems: pkg_resources.VersionConflict: pycrypto 2.6.1 is installed but pycrypto==2.6 is required by ['jose']
    2. pycrypto 2.6.1 fixes an important security bug.

    Please merge and upload new package to PyPI. Thanks :)

    opened by kuba 2
  • Python 3 support

    Python 3 support

    Will jose support python 3? I have been changing code to work on both 2 and 3 simulteanously since 2014, I can help you if you like.

    Our tests currently stop on the print in cli_decrypt().

    By changing the print to print() and adding "from future import print_function" jose'll work on python 2.6.0a2 and newer. If you replace the print with sys.stdout.println it'll work everywhere it works today. But since at least your travis only tests 2.7, I'd recommend print-the-function, and setting 2.7 in your setup.py.

    opened by hmpf 1
  • Update jose.py to fix the print function

    Update jose.py to fix the print function

    Python3 gives an error when importing this module. Error message shown below:

    File "/usr/local/lib/python3.7/site-packages/jose.py", line 546
        print decrypt(deserialize_compact(jwt), {'k':key},
                    ^
    SyntaxError: invalid syntax
    
    opened by 0xSaiyajin 0
  • integrating with RN

    integrating with RN

    Hi, I am looking for a way to verify the source of a content, in JSON format, that is sent to my application written in react native. I was wondering if this package is working fine with RN?

    Thanks

    opened by b-asaf 0
  • pip3 install fails

    pip3 install fails

    On Ubuntu 18.04 with Docker for Python 3.6.8, the RUN pip3 install --trusted-host pypi.python.org -r requirements.txt command fails with message:

    Collecting jose (from -r requirements.txt (line 1))
      Downloading https://files.pythonhosted.org/packages/01/3d/832caa69cd0d3be2d608d8290be2221072669aa88e87690837f6b31c480f/jose-1.0.0.tar.gz
        Complete output from command python setup.py egg_info:
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "/tmp/pip-build-z90crgu0/jose/setup.py", line 15, in <module>
            CONTRIB = open(os.path.join(here, 'CONTRIB')).read()
          File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
            return codecs.ascii_decode(input, self.errors)[0]
        UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 107: ordinal not in range(128)
    
    opened by funcelotwork 0
  • decrypt syntax?

    decrypt syntax?

    File "/usr/local/lib/python3.6/site-packages/jose.py", line 546 print decrypt(deserialize_compact(jwt), {'k':key}, ^ SyntaxError: invalid syntax

    opened by SumNeuron 5
  • serialize_compact() on python3-branch returns bytes, which is considered unserializable

    serialize_compact() on python3-branch returns bytes, which is considered unserializable

    Python3's own json-library refuses to serialize the result of serialize_compact() since it is not a py3 str but a py3 bytes. This breaks our code, at the least. I'm not sure about the best way to solve it. A flag that sets encoding and if set spits out str and not bytes? Doing another walkthrough throught the code and choosing when to use str vs. bytes instead of always using bytes? Add to the json-library upstream so that it can serialize bytes, assuming that you tell it the encoding to use?

    Anyway, the documentation for the function says it returns str, which it does not do on python3.

    opened by hmpf 3
Owner
Demonware
Demonware
Asita is a web application framework for python based on express-js framework.

Asita is a web application framework for python. It is designed to be easy to use and be more easy for javascript users to use python frameworks because it is based on express-js framework.

Mattéo 4 Nov 16, 2021
Pyrin is an application framework built on top of Flask micro-framework to make life easier for developers who want to develop an enterprise application using Flask

Pyrin A rich, fast, performant and easy to use application framework to build apps using Flask on top of it. Pyrin is an application framework built o

Mohamad Nobakht 10 Jan 25, 2022
An alternative serializer implementation for REST framework written in cython built for speed.

drf-turbo An alternative serializer implementation for REST framework written in cython built for speed. Free software: MIT license Documentation: htt

Mng 74 Dec 30, 2022
The no-nonsense, minimalist REST and app backend framework for Python developers, with a focus on reliability, correctness, and performance at scale.

The Falcon Web Framework Falcon is a reliable, high-performance Python web framework for building large-scale app backends and microservices. It encou

Falconry 9k Jan 1, 2023
The Modern And Developer Centric Python Web Framework. Be sure to read the documentation and join the Slack channel questions: http://slack.masoniteproject.com

NOTE: Masonite 2.3 is no longer compatible with the masonite-cli tool. Please uninstall that by running pip uninstall masonite-cli. If you do not unin

Masonite 1.9k Jan 4, 2023
Free and open source full-stack enterprise framework for agile development of secure database-driven web-based applications, written and programmable in Python.

Readme web2py is a free open source full-stack framework for rapid development of fast, scalable, secure and portable database-driven web-based applic

null 2k Dec 31, 2022
Ape is a framework for Web3 Python applications and smart contracts, with advanced functionality for testing, deployment, and on-chain interactions.

Ape Framework Ape is a framework for Web3 Python applications and smart contracts, with advanced functionality for testing, deployment, and on-chain i

ApeWorX Ltd. 552 Dec 30, 2022
An abstract and extensible framework in python for building client SDKs and CLI tools for a RESTful API.

django-rest-client An abstract and extensible framework in python for building client SDKs and CLI tools for a RESTful API. Suitable for APIs made wit

Certego 4 Aug 25, 2022
Bionic is Python Framework for crafting beautiful, fast user experiences for web and is free and open source

Bionic is fast. It's powered core python without any extra dependencies. Bionic offers stateful hot reload, allowing you to make changes to your code and see the results instantly without restarting your app or losing its state.

 ⚓ 0 Mar 5, 2022
Asynchronous HTTP client/server framework for asyncio and Python

Async http client/server framework Key Features Supports both client and server side of HTTP protocol. Supports both client and server Web-Sockets out

aio-libs 13.2k Jan 5, 2023
Fast, asynchronous and elegant Python web framework.

Warning: This project is being completely re-written. If you're curious about the progress, reach me on Slack. Vibora is a fast, asynchronous and eleg

vibora.io 5.7k Jan 8, 2023
Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed.

Tornado Web Server Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed. By using non-blocking ne

null 20.9k Jan 1, 2023
bottle.py is a fast and simple micro-framework for python web-applications.

Bottle: Python Web Framework Bottle is a fast, simple and lightweight WSGI micro web-framework for Python. It is distributed as a single file module a

Bottle Micro Web Framework 7.8k Dec 31, 2022
Sierra is a lightweight Python framework for building and integrating web applications

A lightweight Python framework for building and Integrating Web Applications. Sierra is a Python3 library for building and integrating web applications with HTML and CSS using simple enough syntax. You can develop your web applications with Python, taking advantage of its functionalities and integrating them to the fullest.

null 83 Sep 23, 2022
Flask Sugar is a web framework for building APIs with Flask, Pydantic and Python 3.6+ type hints.

Flask Sugar is a web framework for building APIs with Flask, Pydantic and Python 3.6+ type hints. check parameters and generate API documents automatically. Flask Sugar是一个基于flask,pyddantic,类型注解的API框架, 可以检查参数并自动生成API文档

null 162 Dec 26, 2022
Fast⚡, simple and light💡weight ASGI micro🔬 web🌏-framework for Python🐍.

NanoASGI Asynchronous Python Web Framework NanoASGI is a fast ⚡ , simple and light ?? weight ASGI micro ?? web ?? -framework for Python ?? . It is dis

Kavindu Santhusa 8 Jun 16, 2022
Dazzler is a Python async UI/Web framework built with aiohttp and react.

Dazzler is a Python async UI/Web framework built with aiohttp and react. Create dazzling fast pages with a layout of Python components and bindings to update from the backend.

Philippe Duval 17 Oct 18, 2022
Lemon is an async and lightweight API framework for python

Lemon is an async and lightweight API framework for python . Inspired by Koa and Sanic .

Joway 29 Nov 20, 2022
Endpoints is a lightweight REST api framework written in python and used in multiple production systems that handle millions of requests daily.

Endpoints Quickest API builder in the West! Endpoints is a lightweight REST api framework written in python and used in multiple production systems th

Jay Marcyes 30 Mar 5, 2022