ACF
acfstandard.io
Developer docs
EN
Signatures

Vérifier en Python

Vérifiez la signature Ed25519 d’une sortie acf-mcp en Python avec la bibliothèque cryptography (PyPI). Compatible avec un pipeline d’audit Python ou un job Airflow.

iNote
Une seule dépendance : pip install cryptography. Aucune connexion réseau. La vérification est constant-time grâce à l’implémentation libsodium derrière cryptography.

Installation

bash
pip install 'cryptography>=42'

Snippet complet

verify_doctrine.pypython
import base64
import json
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey
from cryptography.hazmat.primitives.serialization import load_der_public_key
from cryptography.exceptions import InvalidSignature

PUBLIC_KEY_SPKI_B64 = (
    "MCowBQYDK2VwAyEAojtKfh20SGGV63LMETjZBXRWo2tY0viAYziG/y3/L0s="
)

# 1. Decode the SPKI-encoded public key.
spki = base64.b64decode(PUBLIC_KEY_SPKI_B64)
public_key = load_der_public_key(spki)
assert isinstance(public_key, Ed25519PublicKey), (
    "Unexpected key type — acf-mcp uses Ed25519"
)

# 2. Load the signed tool output.
with open("tool-output.json", "r", encoding="utf-8") as f:
    signed = json.load(f)

# 3. The signed message is the doctrine_hash field as UTF-8.
message = signed["doctrine_hash"].encode("utf-8")

# 4. Strip "ed25519:" prefix, decode signature from base64.
sig_b64 = signed["doctrine_signature"].removeprefix("ed25519:")
signature = base64.b64decode(sig_b64)

# 5. Verify.
try:
    public_key.verify(signature, message)
    print("✓ signature valid")
except InvalidSignature:
    print("✗ signature INVALID")

Intégration CI

Pour vérifier toutes les sorties archivées dans un job CI : wrappez ce script dans une fonction verify(path: str) -> bool et appelez-la sur chaque fichier d’./audit-trail/*.json. La signature est déterministe, donc un test de régression pin-able sur doctrine_hash détecte immédiatement toute mutation silencieuse.

Modes d’échec

  • InvalidSignature le contenu a été altéré OU la clé publique fournie n’est pas la bonne.
  • UnsupportedAlgorithm version de cryptography < 2.6. Mettre à jour.
  • ValueError sur base64 — la signature a perdu des caractères en copier-coller (paddings = manquants).