ACF
acfstandard.io
Developer docs
EN
Signatures

Vérifier en Go

Vérifiez la signature Ed25519 d’une sortie acf-mcp en Go avec uniquement la bibliothèque standard — crypto/ed25519 et crypto/x509. Aucune dépendance externe.

iNote
Aucune dépendance Go modules. crypto/ed25519 est dans la stdlib depuis Go 1.13. Compilez avec go build -trimpath pour un binaire reproductible utilisable en CI ou comme outil CLI d’audit.

Snippet complet

verify_doctrine.gogo
package main

import (
	"crypto/ed25519"
	"crypto/x509"
	"encoding/base64"
	"encoding/json"
	"fmt"
	"os"
	"strings"
)

const publicKeySPKIB64 = "MCowBQYDK2VwAyEAojtKfh20SGGV63LMETjZBXRWo2tY0viAYziG/y3/L0s="

type Signed struct {
	DoctrineHash      string `json:"doctrine_hash"`
	DoctrineSignature string `json:"doctrine_signature"`
}

func main() {
	// 1. Decode the SPKI public key.
	spki, err := base64.StdEncoding.DecodeString(publicKeySPKIB64)
	if err != nil {
		fmt.Println("invalid public key encoding:", err)
		os.Exit(1)
	}
	pubAny, err := x509.ParsePKIXPublicKey(spki)
	if err != nil {
		fmt.Println("cannot parse public key:", err)
		os.Exit(1)
	}
	pub, ok := pubAny.(ed25519.PublicKey)
	if !ok {
		fmt.Println("public key is not Ed25519")
		os.Exit(1)
	}

	// 2. Load the signed tool output.
	bytesIn, err := os.ReadFile("tool-output.json")
	if err != nil {
		fmt.Println("cannot read tool output:", err)
		os.Exit(1)
	}
	var signed Signed
	if err := json.Unmarshal(bytesIn, &signed); err != nil {
		fmt.Println("cannot parse tool output:", err)
		os.Exit(1)
	}

	// 3. Recompute the signed message.
	message := []byte(signed.DoctrineHash)

	// 4. Decode the signature (strip "ed25519:" prefix, base64-decode).
	sigB64 := strings.TrimPrefix(signed.DoctrineSignature, "ed25519:")
	signature, err := base64.StdEncoding.DecodeString(sigB64)
	if err != nil {
		fmt.Println("invalid signature encoding:", err)
		os.Exit(1)
	}

	// 5. Verify.
	if ed25519.Verify(pub, message, signature) {
		fmt.Println("✓ signature valid")
	} else {
		fmt.Println("✗ signature INVALID")
		os.Exit(1)
	}
}

L’empaqueter en CLI

build.shbash
go build -trimpath -ldflags="-s -w" -o acf-verify ./verify_doctrine.go
# Use:
./acf-verify  # reads ./tool-output.json
echo "exit=$?"

Modes d’échec

  • signature INVALID + exit 1 — altération de contenu ou mauvaise clé publique. Rejouer la sortie de bout en bout.
  • public key is not Ed25519 la chaîne SPKI passée n’encode pas une clé Ed25519. Vérifier la version d’acf-mcp et la copie de la clé.
  • cannot parse public key le base64 n’est pas du DER valide. Vérifier qu’aucun retour à la ligne n’a été inséré.