Skip to main content

Notary Service support for JWT

Project description

ns_jwt: JSON Web Tokens for Notary Service

We will use RS256 (public/private key) variant of JWT signing. (Source: https://pyjwt.readthedocs.io/en/latest/usage.html#encoding-decoding-tokens-with-rs256-rsa). For signing, , NS is assumed to be in possession of a public-private keypair. Presidio can access the public key through static configuration or, possibly, by querying an endpoint on NS, that is specified in the token.

NS tokens carry the following claims:

name description type
data-set SAFE Token that points to the dataset. Presidio is able to synthesize a token with linked assertions based on data-set, project-id and user id String, Private
project-id CoManage/NS name of the project, universally unique and distinct. String, Private
ns-token SAFE Token of the NS generated from its public key String, Private
ns-name Human-readable NS name String, Private
iss NS FQDN String, Registered
sub OSF DCE rendering of DN attributes from user’s X.509 cert String, Public
exp Expiration date Date, Registered
iat Issued at date Date, Registered
name Full name of subject String, Public

For dates, a JSON numeric value representing the number of seconds from 1970-01-01T00:00:00Z UTC until the specified UTC date/time, ignoring leap seconds. This is equivalent to the IEEE Std 1003.1, 2013 Edition definition "Seconds Since the Epoch", in which each day is accounted for by exactly 86400 seconds, other than that non-integer values can be represented. See RFC 3339 for details regarding date/times in general and UTC in particular.

Setup and configuration

No external configuration except for dependencies (PyJWT, cryptography, python-dateutil).

As above, use a virtual environment

virtualenv -p $(which python3) venv
source venv/bin/activate
pip install --editable ns_jwt
pip install pytest

Testing

Simply execute the command below. The test relies on having public.pem and private.pem (public and private portions of an RSA key) to be present in the tests/ directory. You can generate new pairs using tests/gen-keypair.sh (relies on openssl installation).

pytest -v ns_jwt

Teardown and Cleanup

None needed.

Troubleshooting

CI Logon or other JWTs may not decode outright using PyJWT due to binascii.Error: Incorrect padding and jwt.exceptions.DecodeError: Invalid crypto padding. This is due to lack of base64 padding at the end of the token. Read it in as a string, then add the padding prior to decoding:

import jwt

with open('token_file.jwt') as f:
  token_string = f.read()

jwt.decode(token_string + "==", verify=False)

Any number of = can be added (at least 2) to fix the padding. If token is read in as a byte string, convert to utf-8 first: jwt_str = str(jwt_bin, 'utf-8'), then add padding (Source: https://gist.github.com/perrygeo/ee7c65bb1541ff6ac770)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ns_jwt-0.1.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

ns_jwt-0.1.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file ns_jwt-0.1.1.tar.gz.

File metadata

  • Download URL: ns_jwt-0.1.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for ns_jwt-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c462f0a763781608b766aaf7b81643e341397b76c8519366ea30607619190a14
MD5 eb44f1821681b06a8c589a6ae0d51340
BLAKE2b-256 f1de88897643e9140427b3f88b9285719a569f67c0c36ae5d664405ef7fcf906

See more details on using hashes here.

File details

Details for the file ns_jwt-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ns_jwt-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for ns_jwt-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bd76a4f45cb08c1d9979d534696de3ecffc3ef95a7bfa1b68a16ae83324e9ba9
MD5 d330d6bc2762079b8e7197c2e4a4b32e
BLAKE2b-256 4629b3d5f1e2dd3aebebdd8a2cb217fd15fceb923bc88414ea7ea3c62bfc28a9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page