paseto 2.0.0__tar.gz → 3.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- paseto-3.1.0/.gitignore +19 -0
- paseto-3.1.0/CHANGELOG.md +143 -0
- {paseto-2.0.0 → paseto-3.1.0}/LICENSE +0 -22
- paseto-3.1.0/PKG-INFO +369 -0
- paseto-3.1.0/README.md +339 -0
- paseto-3.1.0/paseto/__init__.py +44 -0
- paseto-3.1.0/paseto/_crypto.py +82 -0
- paseto-3.1.0/paseto/_json.py +106 -0
- paseto-3.1.0/paseto/_paserk_ops.py +306 -0
- paseto-3.1.0/paseto/_time.py +56 -0
- paseto-3.1.0/paseto/builder.py +288 -0
- paseto-3.1.0/paseto/exceptions.py +45 -0
- paseto-3.1.0/paseto/experimental/__init__.py +40 -0
- paseto-3.1.0/paseto/experimental/_mldsa.py +78 -0
- paseto-3.1.0/paseto/experimental/_pq.py +218 -0
- paseto-3.1.0/paseto/experimental/v5.py +27 -0
- paseto-3.1.0/paseto/experimental/v6.py +30 -0
- paseto-3.1.0/paseto/helpers.py +169 -0
- paseto-3.1.0/paseto/keyring.py +131 -0
- paseto-3.1.0/paseto/keys/asymmetric_key.py +308 -0
- paseto-3.1.0/paseto/keys/symmetric_key.py +121 -0
- paseto-3.1.0/paseto/parser.py +212 -0
- paseto-3.1.0/paseto/paserk.py +403 -0
- {paseto-2.0.0 → paseto-3.1.0}/paseto/paseto.py +92 -60
- paseto-3.1.0/paseto/protocols/protocol.py +69 -0
- paseto-3.1.0/paseto/protocols/v2.py +235 -0
- {paseto-2.0.0 → paseto-3.1.0}/paseto/protocols/v3.py +83 -64
- {paseto-2.0.0 → paseto-3.1.0}/paseto/protocols/v4.py +101 -71
- paseto-3.1.0/paseto/py.typed +0 -0
- paseto-3.1.0/paseto/rules.py +183 -0
- paseto-3.1.0/paseto/token.py +138 -0
- paseto-3.1.0/pyproject.toml +87 -0
- paseto-3.1.0/tests/__init__.py +0 -0
- paseto-3.1.0/tests/paserk_vectors/README.md +5 -0
- paseto-3.1.0/tests/paserk_vectors/k2.lid.json +30 -0
- paseto-3.1.0/tests/paserk_vectors/k2.local-pw.json +56 -0
- paseto-3.1.0/tests/paserk_vectors/k2.local-wrap.pie.json +35 -0
- paseto-3.1.0/tests/paserk_vectors/k2.local.json +37 -0
- paseto-3.1.0/tests/paserk_vectors/k2.pid.json +37 -0
- paseto-3.1.0/tests/paserk_vectors/k2.public.json +30 -0
- paseto-3.1.0/tests/paserk_vectors/k2.seal.json +39 -0
- paseto-3.1.0/tests/paserk_vectors/k2.secret-pw.json +56 -0
- paseto-3.1.0/tests/paserk_vectors/k2.secret-wrap.pie.json +35 -0
- paseto-3.1.0/tests/paserk_vectors/k2.secret.json +46 -0
- paseto-3.1.0/tests/paserk_vectors/k2.sid.json +33 -0
- paseto-3.1.0/tests/paserk_vectors/k3.lid.json +30 -0
- paseto-3.1.0/tests/paserk_vectors/k3.local-pw.json +56 -0
- paseto-3.1.0/tests/paserk_vectors/k3.local-wrap.pie.json +35 -0
- paseto-3.1.0/tests/paserk_vectors/k3.local.json +37 -0
- paseto-3.1.0/tests/paserk_vectors/k3.pid.json +31 -0
- paseto-3.1.0/tests/paserk_vectors/k3.public.json +24 -0
- paseto-3.1.0/tests/paserk_vectors/k3.seal.json +39 -0
- paseto-3.1.0/tests/paserk_vectors/k3.secret-pw.json +61 -0
- paseto-3.1.0/tests/paserk_vectors/k3.secret-wrap.pie.json +38 -0
- paseto-3.1.0/tests/paserk_vectors/k3.secret.json +43 -0
- paseto-3.1.0/tests/paserk_vectors/k3.sid.json +34 -0
- paseto-3.1.0/tests/paserk_vectors/k4.lid.json +30 -0
- paseto-3.1.0/tests/paserk_vectors/k4.local-pw.json +56 -0
- paseto-3.1.0/tests/paserk_vectors/k4.local-wrap.pie.json +35 -0
- paseto-3.1.0/tests/paserk_vectors/k4.local.json +37 -0
- paseto-3.1.0/tests/paserk_vectors/k4.pid.json +37 -0
- paseto-3.1.0/tests/paserk_vectors/k4.public.json +30 -0
- paseto-3.1.0/tests/paserk_vectors/k4.seal.json +39 -0
- paseto-3.1.0/tests/paserk_vectors/k4.secret-pw.json +56 -0
- paseto-3.1.0/tests/paserk_vectors/k4.secret-wrap.pie.json +35 -0
- paseto-3.1.0/tests/paserk_vectors/k4.secret.json +45 -0
- paseto-3.1.0/tests/paserk_vectors/k4.sid.json +34 -0
- paseto-3.1.0/tests/test_builder_parser.py +487 -0
- paseto-3.1.0/tests/test_claims.py +76 -0
- paseto-3.1.0/tests/test_experimental.py +385 -0
- paseto-3.1.0/tests/test_helpers.py +43 -0
- paseto-3.1.0/tests/test_json_time.py +104 -0
- paseto-3.1.0/tests/test_keyring.py +69 -0
- paseto-3.1.0/tests/test_keys.py +77 -0
- paseto-3.1.0/tests/test_lucidity.py +36 -0
- paseto-3.1.0/tests/test_paserk.py +225 -0
- paseto-3.1.0/tests/test_paserk_encrypted.py +415 -0
- paseto-3.1.0/tests/test_rules.py +199 -0
- paseto-3.1.0/tests/test_v2.py +82 -0
- paseto-3.1.0/tests/test_v2_vectors.py +13 -0
- paseto-3.1.0/tests/test_v3.py +169 -0
- paseto-3.1.0/tests/test_v3_vectors.py +12 -0
- paseto-3.1.0/tests/test_v4.py +120 -0
- paseto-3.1.0/tests/test_v4_vectors.py +12 -0
- paseto-3.1.0/tests/v2_raw_vectors.json +167 -0
- paseto-3.1.0/tests/v3_raw_vectors.json +183 -0
- paseto-3.1.0/tests/v4_raw_vectors.json +187 -0
- paseto-3.1.0/tests/vector.py +105 -0
- paseto-2.0.0/PKG-INFO +0 -108
- paseto-2.0.0/README.md +0 -83
- paseto-2.0.0/paseto/__init__.py +0 -7
- paseto-2.0.0/paseto/exceptions.py +0 -22
- paseto-2.0.0/paseto/helpers.py +0 -106
- paseto-2.0.0/paseto/keys/asymmetric_key.py +0 -153
- paseto-2.0.0/paseto/keys/symmetric_key.py +0 -78
- paseto-2.0.0/paseto/protocols/protocol.py +0 -6
- paseto-2.0.0/paseto/protocols/v2.py +0 -188
- paseto-2.0.0/pyproject.toml +0 -27
- {paseto-2.0.0 → paseto-3.1.0}/paseto/keys/__init__.py +0 -0
- {paseto-2.0.0 → paseto-3.1.0}/paseto/protocols/__init__.py +0 -0
paseto-3.1.0/.gitignore
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format is based
|
|
4
|
+
on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
|
|
5
|
+
follows [Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [3.1.0] - 2026-12-05
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- PASERK key serialization (`paseto.paserk`) for v2, v3 and v4: `local`,
|
|
13
|
+
`public` and `secret` keys, and their `lid` / `pid` / `sid` IDs. Also
|
|
14
|
+
available as `key.to_paserk()`, `key.paserk_id()` and
|
|
15
|
+
`SymmetricKey.from_paserk(...)` (and the asymmetric key classes).
|
|
16
|
+
Loading requires the expected version, and rejects malformed strings,
|
|
17
|
+
wrong lengths, invalid keys and Ed25519 secret keys whose public half
|
|
18
|
+
doesn't match the seed. Tested against all official PASERK vectors for
|
|
19
|
+
these types.
|
|
20
|
+
- Encrypted PASERKs: `paseto.paserk.wrap()` / `unwrap()` (`local-wrap.pie`,
|
|
21
|
+
`secret-wrap.pie`), `password_wrap()` / `password_unwrap()` (`local-pw`,
|
|
22
|
+
`secret-pw`) and `seal()` / `unseal()` (`seal`) for v2, v3 and v4. Built
|
|
23
|
+
only from PyNaCl, pycryptodome and the standard library. Password
|
|
24
|
+
unwrapping refuses Argon2id/PBKDF2 costs above 4x the defaults unless
|
|
25
|
+
raised explicitly. Tested against all official vectors for these types,
|
|
26
|
+
and pypaseto's output is opened by paragonie/paserk-php.
|
|
27
|
+
- `KeyRing.add()` now returns the `kid` and defaults it to the key's PASERK
|
|
28
|
+
ID (the `pid` of the public key in a public ring).
|
|
29
|
+
- `paseto.Builder` and `paseto.Parser`, modeled on the reference
|
|
30
|
+
implementation (paragonie/paseto) and now the recommended API. Each is
|
|
31
|
+
fixed to one version (from the key) and one purpose; tokens of any other
|
|
32
|
+
kind are rejected before any cryptography runs. Secure defaults: tokens
|
|
33
|
+
expire after one hour unless `exp` is set, and the Parser rejects tokens
|
|
34
|
+
without `exp` unless created with `non_expiring=True`.
|
|
35
|
+
- Validation rules in `paseto.rules`: `NotExpired`, `ValidAt`, `IssuedBy`,
|
|
36
|
+
`ForAudience`, `Subject`, `IdentifiedBy` and `FooterJSON`, plus custom
|
|
37
|
+
rules. Time rules take an optional `leeway` for clock skew.
|
|
38
|
+
- `paseto.Token`, returned by `Parser.parse()`, with typed accessors for the
|
|
39
|
+
registered claims.
|
|
40
|
+
- `paseto.KeyRing`: several keys for one version and purpose, selected by
|
|
41
|
+
the `kid` in a token's JSON footer. Keys of the wrong version or purpose
|
|
42
|
+
are rejected, and an unknown or missing `kid` fails.
|
|
43
|
+
- `paseto.RuleViolation` (now the base of `PasetoTokenExpired`, which is
|
|
44
|
+
still a `PasetoValidationError`) and `paseto.KeyNotFoundException`.
|
|
45
|
+
- Implicit assertions given as a dict are JSON-encoded exactly as PHP's
|
|
46
|
+
`json_encode()` does, so they interoperate with paragonie/paseto.
|
|
47
|
+
- `scripts/php_interop/run.py`, a Docker-based cross-check against
|
|
48
|
+
paragonie/paseto.
|
|
49
|
+
|
|
50
|
+
The existing `create()` / `parse()` functions are unchanged.
|
|
51
|
+
|
|
52
|
+
### Fixed
|
|
53
|
+
- Experimental v5/v6 reported that they don't support implicit assertions,
|
|
54
|
+
although they do.
|
|
55
|
+
- v3 `public` tokens: signatures are now always in low-S form. About half
|
|
56
|
+
of the signatures pypaseto made had a high S value, which
|
|
57
|
+
paragonie/paseto (the reference implementation) rejects as malleable, so
|
|
58
|
+
those tokens couldn't be verified there. Both forms are valid ECDSA, and
|
|
59
|
+
pypaseto still verifies high-S signatures, so existing tokens keep
|
|
60
|
+
working.
|
|
61
|
+
|
|
62
|
+
## [3.0.1] - 2026-12-05
|
|
63
|
+
|
|
64
|
+
The first 3.x release on PyPI. **3.0.0 was tagged on GitHub but never
|
|
65
|
+
published to PyPI**: its release workflow failed before publishing. 3.0.1
|
|
66
|
+
contains everything in the
|
|
67
|
+
[3.0.0 notes](https://github.com/rlittlefield/pypaseto/blob/main/CHANGELOG.md#300---2026-12-05-not-published-to-pypi);
|
|
68
|
+
if you're upgrading from 2.x, read them, including the breaking changes.
|
|
69
|
+
|
|
70
|
+
### Fixed
|
|
71
|
+
- Release workflow: the tag/version check compared against color-coded
|
|
72
|
+
`uv` output, which failed the 3.0.0 release. (No library code changed.)
|
|
73
|
+
|
|
74
|
+
## [3.0.0] - 2026-12-05 (not published to PyPI)
|
|
75
|
+
|
|
76
|
+
### Security
|
|
77
|
+
- Reject non-canonical base64 in tokens (padding, or non-zero trailing bits).
|
|
78
|
+
Previously one valid token could be rewritten into other distinct token
|
|
79
|
+
strings that still authenticated and parsed to the same claims. This
|
|
80
|
+
matters if you deduplicate, cache or revoke tokens by their string value.
|
|
81
|
+
**This is a breaking change** (see below), so it is not backported to 2.x.
|
|
82
|
+
|
|
83
|
+
### Breaking
|
|
84
|
+
- Tokens are decoded strictly, as the PASETO spec requires: base64 padding
|
|
85
|
+
(`=`), non-canonical trailing bits, and characters outside the base64url
|
|
86
|
+
alphabet are rejected with `PasetoException`. Tokens from non-compliant
|
|
87
|
+
libraries that pad their base64 will no longer parse.
|
|
88
|
+
- Python 3.10 or newer is required (3.8 and 3.9 are end-of-life).
|
|
89
|
+
- PASETO v2 emits a `DeprecationWarning`; it will be removed in a future
|
|
90
|
+
major version. Use v4.
|
|
91
|
+
- `pysodium` is replaced by `PyNaCl` and `pendulum` is no longer a
|
|
92
|
+
dependency.
|
|
93
|
+
- Protocol operations now reject keys of the wrong purpose (for example a
|
|
94
|
+
local key passed to `sign`) with `InvalidPurposeException`, and a key for
|
|
95
|
+
the wrong version raises `InvalidVersionException` for every operation.
|
|
96
|
+
- `exp` claims written by `create(exp_seconds=...)` are now always in UTC
|
|
97
|
+
(`+00:00`) instead of the local timezone offset.
|
|
98
|
+
|
|
99
|
+
### Fixed
|
|
100
|
+
- `parse()` on v2 tokens raised `NameError`.
|
|
101
|
+
- `AsymmetricSecretKey` built from a 32-byte Ed25519 seed stored the public
|
|
102
|
+
key instead of the secret key.
|
|
103
|
+
- v3 48-byte secret keys were decoded as little-endian; the spec is
|
|
104
|
+
big-endian.
|
|
105
|
+
- `encode()` / `from_encoded_string()` on all key classes now work.
|
|
106
|
+
- `create()` no longer mutates the claims dict passed to it.
|
|
107
|
+
- Empty payloads no longer fail with "Encryption failed".
|
|
108
|
+
- Truncated tokens raise `PasetoException`.
|
|
109
|
+
- Key `repr()` no longer includes key material.
|
|
110
|
+
- v3: an invalid public key (not a point on P-384) raises `PasetoException`
|
|
111
|
+
instead of a raw `ValueError`. Public keys are now imported as SEC1 points
|
|
112
|
+
by pycryptodome rather than through a hand-built DER prefix.
|
|
113
|
+
- v3: keys on other curves (e.g. a P-256 or Ed25519 PEM) are rejected when
|
|
114
|
+
the key is constructed, with a clear `PasetoException`. Previously they
|
|
115
|
+
were accepted and failed later in `sign`/`verify` with misleading errors
|
|
116
|
+
(or a raw `ValueError`).
|
|
117
|
+
- v3: public keys given as an uncompressed (97-byte) SEC1 point are accepted
|
|
118
|
+
and normalized to the compressed form.
|
|
119
|
+
|
|
120
|
+
### Added
|
|
121
|
+
- Python 3.13 and 3.14 support; macOS is tested again.
|
|
122
|
+
- No system libsodium needed: it is bundled in PyNaCl's wheels.
|
|
123
|
+
- v2/v4 keys can be loaded from PEM/DER; v3 public keys from PEM/DER.
|
|
124
|
+
- Type hints and a `py.typed` marker; `paseto.__version__`.
|
|
125
|
+
- Test vectors synced with paseto-standard/test-vectors, including
|
|
126
|
+
signing from the vector secret keys.
|
|
127
|
+
- **Experimental** support for PASETO v5 and v6 (post-quantum ML-DSA
|
|
128
|
+
`public` tokens) under `paseto.experimental`. Importing it emits a
|
|
129
|
+
`PasetoExperimentalWarning`; it is exempt from semantic versioning and may
|
|
130
|
+
change in any release. `public` tokens need `pip install "paseto[experimental]"`
|
|
131
|
+
(`cryptography>=48`).
|
|
132
|
+
- `paseto.PasetoExperimentalWarning`.
|
|
133
|
+
|
|
134
|
+
## [2.0.0] - 2024-06-04
|
|
135
|
+
- Dropping support for python 3.7
|
|
136
|
+
- Adding support for python 3.11 and 3.12
|
|
137
|
+
- Dependency updates for pendulum, pysodium, pycryptodomex
|
|
138
|
+
|
|
139
|
+
[Unreleased]: https://github.com/rlittlefield/pypaseto/compare/v3.1.0...HEAD
|
|
140
|
+
[3.1.0]: https://github.com/rlittlefield/pypaseto/compare/v3.0.1...v3.1.0
|
|
141
|
+
[3.0.1]: https://github.com/rlittlefield/pypaseto/compare/v3.0.0...v3.0.1
|
|
142
|
+
[3.0.0]: https://github.com/rlittlefield/pypaseto/compare/c2c231d...v3.0.0
|
|
143
|
+
[2.0.0]: https://pypi.org/project/paseto/2.0.0/
|
|
@@ -1,28 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2018 J. Ryan Littlefield
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
MIT License
|
|
25
|
-
|
|
26
4
|
Copyright (c) 2018 Jim Dabell
|
|
27
5
|
|
|
28
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
paseto-3.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: paseto
|
|
3
|
+
Version: 3.1.0
|
|
4
|
+
Summary: Platform-Agnostic Security Tokens for Python (PASETO)
|
|
5
|
+
Project-URL: Repository, https://github.com/rlittlefield/pypaseto
|
|
6
|
+
Project-URL: Changelog, https://github.com/rlittlefield/pypaseto/blob/main/CHANGELOG.md
|
|
7
|
+
Project-URL: Issues, https://github.com/rlittlefield/pypaseto/issues
|
|
8
|
+
Author-email: Ryan Littlefield <ryan@ryanlittlefield.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: jwt,paseto,pypaseto,token
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Topic :: Security :: Cryptography
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: pycryptodomex>=3.20.0
|
|
26
|
+
Requires-Dist: pynacl>=1.5.0
|
|
27
|
+
Provides-Extra: experimental
|
|
28
|
+
Requires-Dist: cryptography>=48; extra == 'experimental'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
PASETO Tokens for Python
|
|
32
|
+
========================
|
|
33
|
+
[](https://pypi.org/project/paseto/)
|
|
34
|
+
[](https://pypi.org/project/paseto/)
|
|
35
|
+
[](https://pypi.org/project/paseto/)
|
|
36
|
+
[](https://github.com/rlittlefield/pypaseto/actions/workflows/main.yml)
|
|
37
|
+
[](https://scorecard.dev/viewer/?uri=github.com/rlittlefield/pypaseto)
|
|
38
|
+
|
|
39
|
+
This is an unofficial implementation of
|
|
40
|
+
[PASETO: Platform-Agnostic Security Tokens](https://paseto.io/) for Python.
|
|
41
|
+
|
|
42
|
+
PASETO versions supported: v2 (deprecated), v3, and v4.
|
|
43
|
+
|
|
44
|
+
**Use v4 for new projects** (or v3 if you need NIST-approved algorithms).
|
|
45
|
+
PASETO v2 is deprecated by the specification; pypaseto still verifies and
|
|
46
|
+
creates v2 tokens but emits a `DeprecationWarning`, and v2 support will be
|
|
47
|
+
removed in a future major release.
|
|
48
|
+
|
|
49
|
+
Installation
|
|
50
|
+
------------
|
|
51
|
+
|
|
52
|
+
pip install paseto
|
|
53
|
+
|
|
54
|
+
Python 3.10 or newer is required. All cryptographic dependencies ship as
|
|
55
|
+
wheels (libsodium is bundled in PyNaCl), so no system libraries are needed.
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
Usage
|
|
59
|
+
-----
|
|
60
|
+
|
|
61
|
+
Build tokens with `paseto.Builder` and read them with `paseto.Parser`. These
|
|
62
|
+
follow the API of [paragonie/paseto](https://github.com/paragonie/paseto),
|
|
63
|
+
the reference implementation, and are secure by default:
|
|
64
|
+
|
|
65
|
+
- A Builder or Parser handles exactly one protocol version (taken from the
|
|
66
|
+
key) and one purpose: `local` (encrypted) or `public` (signed). Tokens of
|
|
67
|
+
any other version or purpose are rejected.
|
|
68
|
+
- Tokens expire after **one hour** unless you set `exp`, and a Parser
|
|
69
|
+
rejects tokens **without** an `exp` claim. Both can be turned off
|
|
70
|
+
explicitly with `non_expiring=True`.
|
|
71
|
+
- Registered claims (`iss`, `sub`, `aud`, `exp`, `nbf`, `iat`, `jti`) are
|
|
72
|
+
type-checked when building, and validated with rules when parsing.
|
|
73
|
+
|
|
74
|
+
### Local (symmetric, encrypted) tokens
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from datetime import timedelta
|
|
78
|
+
|
|
79
|
+
from paseto import Builder, Parser
|
|
80
|
+
from paseto.keys.symmetric_key import SymmetricKey
|
|
81
|
+
from paseto.protocols.v4 import ProtocolVersion4
|
|
82
|
+
from paseto.rules import ForAudience, IssuedBy
|
|
83
|
+
|
|
84
|
+
key = SymmetricKey.generate(protocol=ProtocolVersion4)
|
|
85
|
+
|
|
86
|
+
token = (
|
|
87
|
+
Builder.local(key)
|
|
88
|
+
.with_issuer("auth.example.com")
|
|
89
|
+
.with_audience("api.example.com")
|
|
90
|
+
.with_subject("user-123")
|
|
91
|
+
.with_expiration(timedelta(minutes=5)) # default: 1 hour
|
|
92
|
+
.with_claims({"roles": ["admin"]})
|
|
93
|
+
.encode()
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
parser = Parser.local(
|
|
97
|
+
key, rules=[IssuedBy("auth.example.com"), ForAudience("api.example.com")]
|
|
98
|
+
)
|
|
99
|
+
parsed = parser.parse(token) # raises on any failure
|
|
100
|
+
parsed.subject # 'user-123'
|
|
101
|
+
parsed.get("roles") # ['admin']
|
|
102
|
+
parsed.expiration # datetime.datetime(2026, 12, 5, 16, 45, tzinfo=datetime.timezone.utc)
|
|
103
|
+
parsed.claims # all claims, as a dict
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Builders are immutable: each `with_*` method returns a new Builder, so you
|
|
107
|
+
can configure one once and reuse it. A `timedelta` is resolved when
|
|
108
|
+
`encode()` runs, not when it's set.
|
|
109
|
+
|
|
110
|
+
### Public (asymmetric, signed) tokens
|
|
111
|
+
|
|
112
|
+
Signed tokens are readable by anyone, but only the holder of the secret key
|
|
113
|
+
can create them; anyone with the public key can verify them:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from paseto import Builder, Parser
|
|
117
|
+
from paseto.keys.asymmetric_key import AsymmetricSecretKey
|
|
118
|
+
from paseto.protocols.v4 import ProtocolVersion4
|
|
119
|
+
|
|
120
|
+
secret_key = AsymmetricSecretKey.generate(protocol=ProtocolVersion4)
|
|
121
|
+
public_key = secret_key.get_public_key()
|
|
122
|
+
|
|
123
|
+
token = Builder.public(secret_key).with_subject("user-123").encode()
|
|
124
|
+
parsed = Parser.public(public_key).parse(token)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Validation rules
|
|
128
|
+
|
|
129
|
+
`Parser` always applies `NotExpired` (unless `non_expiring=True`). Add more
|
|
130
|
+
from `paseto.rules`:
|
|
131
|
+
|
|
132
|
+
| Rule | Checks |
|
|
133
|
+
| --- | --- |
|
|
134
|
+
| `NotExpired()` | `exp` is present and not in the past |
|
|
135
|
+
| `ValidAt()` | `iat` and `nbf` aren't in the future, and `exp` isn't in the past. **All three must be present.** |
|
|
136
|
+
| `IssuedBy(iss)` | `iss` equals the given string |
|
|
137
|
+
| `ForAudience(aud)` | `aud` equals the given string |
|
|
138
|
+
| `Subject(sub)` | `sub` equals the given string |
|
|
139
|
+
| `IdentifiedBy(jti)` | `jti` equals the given string |
|
|
140
|
+
| `FooterJSON()` | the footer is a JSON object within size limits |
|
|
141
|
+
|
|
142
|
+
As in the reference implementation, a rule fails when the claim it checks
|
|
143
|
+
is missing. The time rules accept `leeway=timedelta(seconds=30)` to tolerate
|
|
144
|
+
clock skew between servers (default: none).
|
|
145
|
+
|
|
146
|
+
A failed rule raises `paseto.RuleViolation`; expired tokens raise its
|
|
147
|
+
subclass `paseto.PasetoTokenExpired`. Custom rules are any object with a
|
|
148
|
+
`check(token)` method that raises `RuleViolation`:
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from paseto import RuleViolation
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
class AdminOnly:
|
|
155
|
+
def check(self, token):
|
|
156
|
+
if "admin" not in (token.get("roles") or []):
|
|
157
|
+
raise RuleViolation("admins only")
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
parser = Parser.local(key, rules=[AdminOnly()])
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
All errors derive from `paseto.PasetoException`.
|
|
164
|
+
|
|
165
|
+
### Footers, key IDs and key rings
|
|
166
|
+
|
|
167
|
+
The footer is authenticated but **not encrypted**. It's typically used for a
|
|
168
|
+
key ID (`kid`), so the verifier can pick the right key, for example during
|
|
169
|
+
key rotation:
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
from paseto import Builder, KeyRing, Parser
|
|
173
|
+
|
|
174
|
+
ring = KeyRing.local(ProtocolVersion4)
|
|
175
|
+
ring.add(old_key)
|
|
176
|
+
kid = ring.add(new_key) # e.g. 'k4.lid.…', the key's PASERK ID
|
|
177
|
+
|
|
178
|
+
token = Builder.local(ring).with_footer({"kid": kid}).encode()
|
|
179
|
+
parsed = Parser.local(ring).parse(token) # selects the key by the footer's kid
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Without an explicit `kid`, `add()` uses the key's [PASERK](#serializing-keys-paserk)
|
|
183
|
+
ID: the `lid` for local keys, and the `pid` of the public key in a public
|
|
184
|
+
ring (so a signer's ring holding secret keys and a verifier's ring holding
|
|
185
|
+
public keys agree). You can also choose your own: `ring.add(key, "2026-01")`.
|
|
186
|
+
|
|
187
|
+
A key ring holds keys for one version and purpose only, and rejects any
|
|
188
|
+
other key. Parsing fails if the footer's `kid` is missing or unknown; there
|
|
189
|
+
is no fallback key. The footer is size-checked before it's decoded.
|
|
190
|
+
|
|
191
|
+
For signed tokens, `KeyRing.public(...)` can hold secret keys (to sign, and
|
|
192
|
+
to verify with their public halves) or only public keys (to verify).
|
|
193
|
+
|
|
194
|
+
A footer whose `kid` or `wpk` holds a [PASERK](https://github.com/paseto-standard/paserk)
|
|
195
|
+
that would reveal a key (`local`, `public`, `secret`, `local-pw` or
|
|
196
|
+
`secret-pw`) is rejected.
|
|
197
|
+
|
|
198
|
+
### Implicit assertions (v3 and newer)
|
|
199
|
+
|
|
200
|
+
Implicit assertions are authenticated like the footer but not stored in the
|
|
201
|
+
token, so the parser must supply the same value. Use them to bind a token to
|
|
202
|
+
a context, such as a tenant:
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
token = Builder.local(key).with_implicit_assertions({"tenant": "acme"}).encode()
|
|
206
|
+
Parser.local(key, implicit_assertions={"tenant": "acme"}).parse(token)
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Dicts are JSON-encoded byte-for-byte as PHP's `json_encode()` does, so
|
|
210
|
+
tokens interoperate with paragonie/paseto.
|
|
211
|
+
|
|
212
|
+
### Serializing keys (PASERK)
|
|
213
|
+
|
|
214
|
+
[PASERK](https://github.com/paseto-standard/paserk) is the standard string
|
|
215
|
+
format for PASETO keys, shared with other PASETO libraries (v2, v3 and v4):
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
from paseto.keys.asymmetric_key import AsymmetricSecretKey
|
|
219
|
+
from paseto.keys.symmetric_key import SymmetricKey
|
|
220
|
+
from paseto.protocols.v4 import ProtocolVersion4
|
|
221
|
+
|
|
222
|
+
secret_key = AsymmetricSecretKey.generate(protocol=ProtocolVersion4)
|
|
223
|
+
stored = secret_key.to_paserk() # 'k4.secret.…': store it like the key itself
|
|
224
|
+
secret_key = AsymmetricSecretKey.from_paserk(stored, ProtocolVersion4)
|
|
225
|
+
|
|
226
|
+
public_paserk = secret_key.get_public_key().to_paserk() # 'k4.public.…'
|
|
227
|
+
local_paserk = SymmetricKey.generate(ProtocolVersion4).to_paserk() # 'k4.local.…'
|
|
228
|
+
|
|
229
|
+
secret_key.get_public_key().paserk_id() # 'k4.pid.…': safe to share, e.g. as a kid
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Loading always takes the version you expect: a `k3.…` string is rejected
|
|
233
|
+
when `ProtocolVersion4` is given, so the string can't choose the algorithm.
|
|
234
|
+
The same functions are available as `paseto.paserk.serialize()`,
|
|
235
|
+
`deserialize()` and `key_id()`.
|
|
236
|
+
|
|
237
|
+
`local`, `public` and `secret` PASERKs **contain the key**. Never put them
|
|
238
|
+
in a token footer (the Builder rejects that); use the ID instead.
|
|
239
|
+
|
|
240
|
+
#### Encrypting keys
|
|
241
|
+
|
|
242
|
+
PASERK can also store a key encrypted, in three ways:
|
|
243
|
+
|
|
244
|
+
```python
|
|
245
|
+
from paseto import paserk
|
|
246
|
+
|
|
247
|
+
wrapping_key = SymmetricKey.generate(ProtocolVersion4)
|
|
248
|
+
local_key = SymmetricKey.generate(ProtocolVersion4)
|
|
249
|
+
|
|
250
|
+
# with another symmetric key: 'k4.local-wrap.pie.…' / 'k4.secret-wrap.pie.…'
|
|
251
|
+
wrapped = paserk.wrap(local_key, wrapping_key)
|
|
252
|
+
local_key = paserk.unwrap(wrapped, wrapping_key)
|
|
253
|
+
|
|
254
|
+
# with a password (Argon2id for v2/v4, PBKDF2-SHA384 for v3): 'k4.local-pw.…'
|
|
255
|
+
protected = paserk.password_wrap(local_key, "correct horse battery staple")
|
|
256
|
+
local_key = paserk.password_unwrap(
|
|
257
|
+
protected, "correct horse battery staple", ProtocolVersion4
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
# to a public key, so only its secret key can open it: 'k4.seal.…'
|
|
261
|
+
sealed = paserk.seal(local_key, secret_key.get_public_key())
|
|
262
|
+
local_key = paserk.unseal(sealed, secret_key)
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
- Opening always uses the version of the key you pass (or `protocol`), so
|
|
266
|
+
the string can't choose the algorithm.
|
|
267
|
+
- A password-wrapped PASERK states its own Argon2id or PBKDF2 cost.
|
|
268
|
+
`password_unwrap()` refuses costs above 4× the defaults before doing any
|
|
269
|
+
work; raise `max_memlimit`, `max_opslimit` or `max_iterations` if you
|
|
270
|
+
deliberately use stronger settings.
|
|
271
|
+
- `local-wrap`, `secret-wrap` and `seal` PASERKs are safe in a footer (for
|
|
272
|
+
example as `wpk`). Password-wrapped ones aren't, since anyone who sees one
|
|
273
|
+
can guess passwords offline, and the Builder rejects them.
|
|
274
|
+
|
|
275
|
+
Keys can also be stored as raw unpadded base64url (`key.encode()` and
|
|
276
|
+
`AsymmetricSecretKey.from_encoded_string(...)`), and asymmetric keys
|
|
277
|
+
constructed from PEM/DER (`AsymmetricSecretKey(pem_bytes, ProtocolVersion4)`);
|
|
278
|
+
v4 secret keys also accept a 32-byte Ed25519 seed.
|
|
279
|
+
|
|
280
|
+
### The legacy `create` / `parse` API
|
|
281
|
+
|
|
282
|
+
`paseto.create()` and `paseto.parse()` from pypaseto 2.x still work
|
|
283
|
+
unchanged, and their tokens are compatible with `Builder` and `Parser`. They
|
|
284
|
+
are less strict: `create()` adds no `exp` unless you pass `exp_seconds`, and
|
|
285
|
+
`parse()` accepts tokens without one. Prefer `Builder` and `Parser` for new
|
|
286
|
+
code.
|
|
287
|
+
|
|
288
|
+
```python
|
|
289
|
+
import paseto
|
|
290
|
+
|
|
291
|
+
token = paseto.create(
|
|
292
|
+
key=key, claims={"sub": "alice"}, exp_seconds=300, footer={"kid": "k1"}
|
|
293
|
+
)
|
|
294
|
+
parsed = paseto.parse(key=key, token=token, required_claims=["sub"])
|
|
295
|
+
parsed["message"] # {'exp': '...', 'sub': 'alice'}
|
|
296
|
+
parsed["footer"] # {'kid': 'k1'}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
To migrate, replace `create()` with a `Builder` and `parse()` with a
|
|
300
|
+
`Parser`:
|
|
301
|
+
|
|
302
|
+
- Tokens made without `exp_seconds` have no `exp`, which a default `Parser`
|
|
303
|
+
rejects. Issue new tokens with a `Builder` (which sets `exp`), or parse
|
|
304
|
+
old ones with `non_expiring=True`.
|
|
305
|
+
- `required_claims` has no direct equivalent: each registered-claim rule
|
|
306
|
+
already fails when its claim is missing, and a custom rule can require
|
|
307
|
+
any other claim.
|
|
308
|
+
- `parse()` returns a dict with the footer JSON-decoded; `Parser.parse()`
|
|
309
|
+
returns a `Token` whose `footer` is the raw bytes (use `footer_json()`).
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
Experimental: PASETO v5 and v6 (post-quantum)
|
|
313
|
+
---------------------------------------------
|
|
314
|
+
|
|
315
|
+
pypaseto has **experimental** support for the draft PASETO v5 and v6
|
|
316
|
+
versions, which sign `public` tokens with the post-quantum ML-DSA algorithm
|
|
317
|
+
(FIPS 204):
|
|
318
|
+
|
|
319
|
+
| Version | `local` | `public` |
|
|
320
|
+
| ------- | ------------------------------ | ---------------------------- |
|
|
321
|
+
| v5 | AES-256-CTR + HMAC-SHA384 (as v3) | ML-DSA-87 |
|
|
322
|
+
| v6 | XChaCha20 + BLAKE2b-MAC (as v4) | ML-DSA-44 |
|
|
323
|
+
|
|
324
|
+
> [!WARNING]
|
|
325
|
+
> The v5/v6 specification is not final, and there are no official test
|
|
326
|
+
> vectors yet. Everything under `paseto.experimental` is **exempt from
|
|
327
|
+
> semantic versioning**: its API and token format may change incompatibly in
|
|
328
|
+
> any release, including patch releases. Don't use it for long-lived tokens.
|
|
329
|
+
|
|
330
|
+
Opt in by importing from `paseto.experimental`, which emits a
|
|
331
|
+
`paseto.PasetoExperimentalWarning`. `public` tokens also need the optional
|
|
332
|
+
ML-DSA dependency:
|
|
333
|
+
|
|
334
|
+
pip install "paseto[experimental]"
|
|
335
|
+
|
|
336
|
+
```python
|
|
337
|
+
import warnings
|
|
338
|
+
|
|
339
|
+
import paseto
|
|
340
|
+
|
|
341
|
+
# acknowledge the experimental status (optional; silences the warning)
|
|
342
|
+
warnings.filterwarnings("ignore", category=paseto.PasetoExperimentalWarning)
|
|
343
|
+
|
|
344
|
+
from paseto.experimental.v6 import ProtocolVersion6
|
|
345
|
+
from paseto.keys.asymmetric_key import AsymmetricSecretKey
|
|
346
|
+
|
|
347
|
+
secret_key = AsymmetricSecretKey.generate(protocol=ProtocolVersion6)
|
|
348
|
+
token = paseto.Builder.public(secret_key).with_subject("alice").encode()
|
|
349
|
+
parsed = paseto.Parser.public(secret_key.get_public_key()).parse(token)
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
v5/v6 secret keys are 32-byte ML-DSA seeds; public keys are the raw ML-DSA
|
|
353
|
+
public keys (2592 bytes for v5, 1312 for v6). v5/v6 tokens are parsed more
|
|
354
|
+
strictly than earlier versions, as their specification requires (for
|
|
355
|
+
example, an empty footer component is rejected).
|
|
356
|
+
|
|
357
|
+
The spec's optional "opaque" token format is not supported yet.
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
Development
|
|
361
|
+
-----------
|
|
362
|
+
|
|
363
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). Report security issues privately as
|
|
364
|
+
described in [SECURITY.md](SECURITY.md).
|
|
365
|
+
|
|
366
|
+
Changelog
|
|
367
|
+
---------
|
|
368
|
+
|
|
369
|
+
See [CHANGELOG.md](CHANGELOG.md).
|