JOSE
JSON Web Signature, Encryption, Key and Token formats (RFC 7515-7519, RFC 8037).
oxcrypto.jose reads and writes JOSE compact serializations. JSON handling
uses serde_json; every signature, MAC, key-wrap and content-encryption step
runs on the oxcrypto primitives documented under
Signatures, Key exchange,
Key wrapping and
Authenticated encryption.
Each operation takes the algorithm as a selector (JWS.ES256, JWE.A128KW).
Decoding checks that the protected header names exactly that algorithm, so a
token cannot pick its own verification algorithm:
alg: none(in any letter case) raisesInvalidTag, andverifyreturnsFalse. There is no selector for unsecured tokens.- A token whose
algorencdiffers from the selector raisesInvalidTag. - A key of the wrong type for the selector raises
TypeError: an HMAC selector accepts onlybytes, a signature selector only a key object of the matching family. A public key can therefore not be used as an HMAC secret. - An ECDSA key on a different curve than the selector, an RSA key under 2048
bits or an HMAC key shorter than the hash output raises
ValueError. - A
critheader raisesValueError; no critical extensions are supported.
Failed signature, MAC or decryption checks raise InvalidTag; malformed
tokens, headers and keys raise ValueError; inputs of the wrong type raise
TypeError. unverified_header(token) returns the protected header without
checking anything, for choosing a key by kid.
Formats
- JWS compact signatures and MACs (RFC 7515, RFC 7518 section 3, RFC 8037).
- JWE compact encryption (RFC 7516, RFC 7518 sections 4-5, RFC 8037).
- JWK key import, export and RFC 7638 thumbprints (RFC 7517, RFC 7518 section 6, RFC 8037).
- JWT claims validation over JWS (RFC 7519).
Zeroization
JOSE adds no long-lived key objects; keys are the existing oxcrypto key types
and follow their zeroization notes. Content-encryption keys, key-encryption
keys, ECDH shared secrets, Concat KDF and PBES2 outputs and decrypted
plaintext buffers are held in Zeroizing buffers and wiped when a call
returns. Private JWK members are decoded into wiped buffers.
Zeroization does not cover:
- Secrets, passwords, JWK text and plaintext passed in or returned as Python
bytesorstr. Python owns these objects and oxcrypto does not wipe them. - Short-lived stack copies made by
aes,aes-gcm,aes-kw,hmac,rsaand the elliptic-curve crates during a call. - Intermediate strings
serde_jsonbuilds while parsing a private JWK.
Treat zeroization as defense in depth. It does not guarantee that secrets are gone from process memory.
JWS and JWE use compact serialization. A JWE zip header raises ValueError.