SPB Git

Repository Public

signer.go 3.3 KB 88 lines go

1/**2 * =============================================================================3 *                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : MacLustr Command Center (MCC)8 * File             : services/internal/orchestrator/signer.go9 * Module           : services10 * Repository       : https://git.spboucher.ai/maclustr-command-center11 * Project Website  : https://clustr.spboucher.ai12 * Created          : 2026-11-1813 * Last Modified    : 2026-11-1814 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Package orchestrator is the durable action worker. All truth lives in43// PostgreSQL: the process keeps no state that a restart would lose, and every44// transition is a single transaction, so a crash at any point leaves each45// action either before or after a step, never in between.46package orchestrator4748import (49	"context"50	"crypto/ed25519"5152	"github.com/jackc/pgx/v5/pgxpool"5354	"clustr.spboucher.ai/mcc/internal/signkey"55)5657// Signer holds the Ed25519 key that signs agent commands. The private key58// never leaves the orchestrator's secrets directory; the database only ever59// receives the public key (command_keys).60type Signer struct {61	KeyID string62	priv  ed25519.PrivateKey63}6465func (s *Signer) Public() ed25519.PublicKey   { return s.priv.Public().(ed25519.PublicKey) }66func (s *Signer) Private() ed25519.PrivateKey { return s.priv }6768// KeyID derives the short identifier of a public key.69func KeyID(pub ed25519.PublicKey) string { return signkey.ID(pub) }7071// LoadOrCreateKey reads an Ed25519 seed (hex, mode 0600) or creates it.72func LoadOrCreateKey(path string) (ed25519.PrivateKey, error) { return signkey.LoadOrCreate(path) }7374// LoadSigner loads (or creates on first start) the command signing key and75// registers its public half in command_keys.76func LoadSigner(ctx context.Context, pool *pgxpool.Pool, path string) (*Signer, error) {77	priv, err := LoadOrCreateKey(path)78	if err != nil {79		return nil, err80	}81	s := &Signer{priv: priv}82	s.KeyID = KeyID(s.Public())83	if _, err := pool.Exec(ctx, `insert into command_keys(key_id, public_key) values ($1,$2) on conflict (key_id) do nothing`, s.KeyID, []byte(s.Public())); err != nil {84		return nil, err85	}86	return s, nil87}88
Files main
Menu

Theme