Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
102 changes: 97 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,99 @@
*.pyc
**/*.pyc
*.egg-info
build
dist
# Created by https://www.gitignore.io/api/python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
.venv/
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject

# End of https://www.gitignore.io/api/python

/apidesign.txt
/pycrypto/
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: python
python:
- "2.7"
- "3.5"
- "3.6"
install: pip install tox-travis
script: tox
cache: pip
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include README.md
include README.rst
64 changes: 40 additions & 24 deletions README.md → README.rst
Original file line number Diff line number Diff line change
@@ -1,47 +1,56 @@
python-jws
=====
A Python implementation of [JSON Web Signatures draft 02](http://self-issued.info/docs/draft-jones-json-web-signature.html)
==========

Also now works on Python 3.3+ as well as Python 2.7+. However, it's a naive conversion to support both Python 2 and Python 3 so there may well be hidden bugs.
A Python implementation of `JSON Web Signatures draft
02 <http://self-issued.info/docs/draft-jones-json-web-signature.html>`__

Also now works on Python 3.3+ as well as Python 2.7+. However, it's a
naive conversion to support both Python 2 and Python 3 so there may well
be hidden bugs.

Installing
----------
$ pip install jws

::

$ pip install jws

Algorithms
----------
The JWS spec reserves several algorithms for cryptographic signing. Out of the 9, this library currently supports 7:

The JWS spec reserves several algorithms for cryptographic signing. Out
of the 9, this library currently supports 7:

**HMAC** native
**HMAC** -- native

* HS256 HMAC using SHA-256 hash algorithm
* HS384 HMAC using SHA-384 hash algorithm
* HS512 HMAC using SHA-512 hash algorithm
- HS256 -- HMAC using SHA-256 hash algorithm
- HS384 -- HMAC using SHA-384 hash algorithm
- HS512 -- HMAC using SHA-512 hash algorithm

**RSA** -- requires pycrypto >= 2.5: ``pip install pycrypto``

**RSA** – requires pycrypto >= 2.5: ``pip install pycrypto``
- RS256 -- RSA using SHA-256 hash algorithm

* RS256 – RSA using SHA-256 hash algorithm
**ECDSA** -- requires ecdsa lib: ``pip install ecdsa``

**ECDSA** – requires ecdsa lib: ``pip install ecdsa``

* ES256 – ECDSA using P-256 curve and SHA-256 hash algorithm
* ES384 – ECDSA using P-384 curve and SHA-384 hash algorithm
* ES512 – ECDSA using P-521 curve and SHA-512 hash algorithm
- ES256 -- ECDSA using P-256 curve and SHA-256 hash algorithm
- ES384 -- ECDSA using P-384 curve and SHA-384 hash algorithm
- ES512 -- ECDSA using P-521 curve and SHA-512 hash algorithm

There is also a mechanism for extending functionality by adding your own
algorithms without cracking open the whole codebase. See the advanced usage
section for an example.
algorithms without cracking open the whole codebase. See the advanced
usage section for an example.

For RSA and ECDSA, all crypto libraries are lazily loaded so you won't need the dependencies unless you try to use the functionality.
For RSA and ECDSA, all crypto libraries are lazily loaded so you won't
need the dependencies unless you try to use the functionality.

Usage
-----

Let's check out some examples.

::

>>> import jws
>>> header = { 'alg': 'HS256' }
>>> payload = { 'claim': 'JSON is the raddest.', 'iss': 'brianb' }
Expand All @@ -55,6 +64,8 @@ Let's check out some examples.

Now with a real key!

::

>>> import ecdsa
>>> sk256 = ecdsa.SigningKey.generate(curve=ecdsa.NIST256p)
>>> vk = sk256.get_verifying_key()
Expand All @@ -65,8 +76,11 @@ Now with a real key!

Advanced Usage
--------------

Make this file

::

# file: sillycrypto.py
import jws
from jws.algos import AlgorithmBase, SignatureError
Expand All @@ -90,6 +104,8 @@ Make this file

And in an interpreter:

::

>>> import jws
>>> header = { 'alg': 'F7U12' }
>>> payload = { 'claim': 'wutt' }
Expand All @@ -107,9 +123,8 @@ And in an interpreter:
....
jws.exceptions.SignatureError: nope


Other Stuff
---------
-----------

Check out
https://github.com/brianloveswords/python-jws/blob/master/examples/minijwt.py
Expand All @@ -120,10 +135,11 @@ https://github.com/brianloveswords/python-jws/blob/master/examples/ragecrypto.py
for a rage-comic inspired cryptography extension.

TODO
-------
* Write about all the rad stuff that can be done around headers (as extensible as crypto algos)
* Pull in JWK support
----

- Write about all the rad stuff that can be done around headers (as
extensible as crypto algos)
- Pull in JWK support

Tests
-----
Expand Down
136 changes: 0 additions & 136 deletions README.txt

This file was deleted.

8 changes: 4 additions & 4 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Automate the release
def release():
local("python setup.py sdist register upload")
local("python2.5 setup.py bdist_egg register upload")
local("python2.6 setup.py bdist_egg register upload")
local("python2.7 setup.py bdist_egg register upload")
local("python setup.py sdist bdist_wheel upload")
local("python2.5 setup.py bdist_egg upload")
local("python2.6 setup.py bdist_egg upload")
local("python2.7 setup.py bdist_egg upload")
Loading