Skip to main content

tup-trust

The security core of TUP: Ed25519-signed messages checked against keys pinned per sender, anti-replay (nonce and time window, kept on disk), key revocation and rotation, and a SHA-256 hash-chained audit log whose records are signed.

spec/FORMAT.md describes the bytes it signs and writes, and the tests check them against the vectors in spec/vectors.json.

Status: version 0.1.0, alpha. Licensed under Apache-2.0.

Install

Python 3.11 or later. The only dependency is cryptography (41 or later).

pip install tup-trust
pip install "./tup-trust[dev]"   # from a clone of the repository, with pytest to run the tests

Use

import json, os, tempfile
from tup_trust import CryptoSigner, HashChainLog, SignedMessage

home = tempfile.mkdtemp()
alice = CryptoSigner(os.path.join(home, "alice"), sender_id="alice")
bob = CryptoSigner(os.path.join(home, "bob"), sender_id="bob")
alice.initialize()   # creates the key pair the first time, loads it afterwards
bob.initialize()

# Bob pins Alice's public key. He gets it from her out of band, never from the message.
bob.register_trusted_key("alice", alice.get_public_key())

wire = json.dumps(alice.sign({"text": "hola"}, recipient="bob").to_dict())

msg = SignedMessage.from_dict(json.loads(wire))
bob.verify(msg, expected_sender="alice")   # True
bob.verify(msg, expected_sender="alice")   # False: the same message twice is a replay
bob.last_verify_error                      # 'nonce repetido (replay)'

log = HashChainLog(os.path.join(home, "bob", "audit.jsonl"),
                   signing_key=bob.key_manager.private_key)
log.append({"event": "received", "sender": "alice", "message": json.loads(wire)})
head = log.head()   # keep it somewhere the log's writer cannot change
HashChainLog.verify(log.path, expected_head=head["hash"],
                    public_key_hex=bob.get_public_key())   # (True, 1, None)

Pinned keys live in memory. The application stores them and pins them again when it starts (TUP-MCP keeps them in trusted_keys.json).

What CryptoSigner.verify() checks

It returns True only if all of these hold, in this order. Otherwise it returns False, and last_verify_error says why.

  1. The members have the right types and sender_id is not empty.
  2. The sender is expected_sender, if you give one.
  3. public_key is a valid key. It is not on the revocation list, and it is pinned for that sender_id. The key a message carries is never trusted by itself.
  4. The recipient is expected_recipient, if you give one. If you don't, a message addressed to someone else is rejected.
  5. The Ed25519 signature is valid for the signed bytes (FORMAT.md 3.2).
  6. The message is fresh. Its time is within ±300 seconds, and the pair (sender, nonce) is seen only once. This runs only after the signature is valid, so forged messages cannot use up other people's nonces.

Files

CryptoSigner(keys_dir) keeps these files in keys_dir. The default is $TUP_TRUST_HOME/keys, or ~/.tup-trust/keys.

File Content
private_key.pem Ed25519 private key, PKCS#8, not encrypted. Created with mode 0600 on Linux and macOS
public_key.pem The public key
replay_nonces.jsonl Nonces seen within the window, so that a restart does not open a replay
revocation_list.json Revoked keys. If it cannot be read, every key counts as revoked
key_archive.json, rotation_history.jsonl Earlier keys and the rotation history

Design notes

  • Default folder: ~/.tup-trust, or $TUP_TRUST_HOME.
  • HashChainLog.append() refuses NaN and infinities before writing anything, and raises ValueError. HashChainLog.verify() rejects those values, duplicate keys and invalid UTF-8. compute_record_hash(record, strict=True) refuses them too. For any other record it gives the same hash.
  • Three modules: crypto, audit_log and key_policy. CryptoSigner(responder=...) accepts any object with allows() and observe_verification(): it is told about every rejection, and the senders or origins it quarantines are blocked.

Limits

  • The private key sits unencrypted on disk. On Windows the file mode is not applied, so the folder's permissions protect it.
  • Replay state is loaded when a signer starts. Two processes that verify for the same agent at the same time do not see each other's nonces.
  • Messages more than 300 seconds old, or from more than 300 seconds in the future, are rejected. Clocks must be roughly in sync.
  • The revocation list is local. Nothing distributes it to other machines.
  • The audit log shows that records were deleted from its end only if you saved a head elsewhere. Whoever holds the log's signing key can rewrite it.
  • It has not been audited by a third party.

Tests

cd tup-trust
python -m pytest

On Windows 11 with Python 3.11.9: 83 passed and 1 skipped. The skipped test checks the private key's file mode, which Windows does not apply.

License

Apache-2.0. See LICENSE and NOTICE. Copyright 2025-2026 Zhofri Guaman.


Resumen en español

tup-trust es el núcleo de seguridad de TUP: mensajes firmados con Ed25519 y verificados contra claves fijadas por emisor, anti-replay (nonce y ventana de tiempo, guardados en disco), revocación y rotación de claves, y un registro de auditoría encadenado con SHA-256 y firmado. Los formatos están en spec/FORMAT.md.

  • Se instala con pip install tup-trust.
  • La clave privada se guarda sin cifrar. En Windows la protegen los permisos de la carpeta.
  • Las claves fijadas viven en memoria: la aplicación las guarda y las vuelve a fijar al arrancar.
  • Licencia Apache-2.0.

Metadata

Release files for tup-trust 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tup-trust 0.1.0
File Size Uploaded Provenance Actions
tup_trust-0.1.0.tar.gz 33.5 kB With provenance Details for tup_trust-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tup-trust 0.1.0
File Interpreter ABI Platform Actions
tup_trust-0.1.0-py3-none-any.whl Python 3 none any Details for tup_trust-0.1.0-py3-none-any.whl

Total release size: 59.6 kB

Release files / tup_trust-0.1.0.tar.gz

Download URL tup_trust-0.1.0.tar.gz
Size 33.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7e34e307f873905a58a565e11fef5ee41fdefe8413e5e645f95aba4fd14cff68
BLAKE2b-256 checksum
How to use checksums
9f2d1122bbfaea6e24c365b0197a04db9072eb1fd2cc44d5aefc5e88bcb55366
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.

Transparency log

Release files / tup_trust-0.1.0-py3-none-any.whl

Download URL tup_trust-0.1.0-py3-none-any.whl
Size 26.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29b9736dcf2a85cf3ffeb7e3d67b0cc6b2690b35ac14d1389a8447d8f5b7818e
BLAKE2b-256 checksum
How to use checksums
1b2dff450b62d4ad64d2d443e8cfb778cbc9ce4fcfecab8ef3e27535a54fcec7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.

Transparency log

Security for tup-trust 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tup_trust-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page