Artifact 760acb8f65ad9f26492b1fc68a78d04d5aef64bb69f119d1478afacad6abd388:
- File
signing_test.go
— part of check-in
[612f2e7acc]
at
2026-10-23 20:05:29
on branch main
— feat(signing): sign check-ins and horizon seeds with gpg or ssh
go-libfossil signed nothing and verified nothing, so a structural-horizon clone could not tell a seed its origin minted from one substituted on disk (draft-fossil-horizon-00 ยง5.2.4, HZ-5.2-5 and HZ-5.2-6), and a repository with fossil's clearsign setting on stored its check-ins unsigned.
Signing follows fossil's contract, the same one zit follows. With clearsign on (and the legacy omitsign off), every check-in a commit or branch creation stores is clear-signed by pgp-command: unset, gpg --clearsign -o, run as COMMAND OUTFILE INFILE; a command named ssh* runs as COMMAND INFILE and its detached signature is wrapped in fossil's SSH envelope. A signer that fails, or returns text that does not strip back to the manifest, abandons the commit. NoSign and --nosign store one check-in unsigned.
An origin with clearsign on signs each seed it mints. It signs only after the request is authorized, outside the request's transaction, keeps one signature per seed and command so the seed's name is stable, and re-signs a kept signature its own horizon-seed-key no longer verifies. Keeping is best effort, so a read-only mirror still serves.
A clone given its origin's key (CloneOpts.SeedKey, repo clone --seed-key, kept as horizon-seed-key) verifies every seed on clone, pull and rebuild, and falls back to the content horizon from one unsigned or signed by another key. An SSH key is verified in process: namespace fossilscm, the configured key, no SHA-1 ssh-rsa, and exactly fossil's envelope. An OpenPGP fingerprint is verified by gpg, which must report one good signature by that key over text byte-equal to what the parser reads, with nothing after the signature. A verifier that cannot run keeps the held seed and fails the sync instead of discarding it.
fossil 2.28 and zit read the signed check-ins; a check-in zit signs with the same SSH key verifies here; zit clones a signing origin and holds its seed. (user: [email protected], size: 2202) [annotate] [blame] [check-ins using] [more...]
//go:build !js && !windows package libfossil import ( "bytes" "context" "testing" "github.com/danmestas/go-libfossil/internal/clearsign" "github.com/danmestas/go-libfossil/internal/clearsign/signtest" "github.com/danmestas/go-libfossil/internal/content" "github.com/danmestas/go-libfossil/internal/fsltype" ) // TestCommitSigning drives signing through the public API: with // SettingClearsign on, Commit stores the manifest signed by // SettingPGPCommand and NoSign stores it plain. func TestCommitSigning(t *testing.T) { r := newTestRepo(t) command, pub := signtest.SSHKey(t, "ed25519", clearsign.SSHNamespace) key, err := clearsign.ParseKey(pub) if err != nil { t.Fatal(err) } if err := r.SetConfig(SettingClearsign, "on"); err != nil { t.Fatal(err) } if err := r.SetConfig(SettingPGPCommand, command); err != nil { t.Fatal(err) } files := []FileToCommit{{Name: "a.txt", Content: []byte("a\n")}} signed, _, err := r.Commit(CommitOpts{Files: files, Comment: "signed", User: "test"}) if err != nil { t.Fatal(err) } plain, _, err := r.Commit(CommitOpts{ Files: files, Comment: "plain", User: "test", ParentID: signed, NoSign: true, }) if err != nil { t.Fatal(err) } stored := func(rid int64) []byte { data, err := content.Expand(r.Inner().DB(), fsltype.FslID(rid)) if err != nil { t.Fatal(err) } return data } if err := key.Verify(context.Background(), stored(signed)); err != nil { t.Errorf("signed check-in: %v", err) } if data := stored(plain); !bytes.HasPrefix(data, []byte("C plain")) { t.Errorf("NoSign check-in is not plain:\n%s", data) } } // TestSetConfigSeedKey: SetConfig keeps an SSH key or an OpenPGP // fingerprint as SettingHorizonSeedKey and refuses anything else. func TestSetConfigSeedKey(t *testing.T) { r := newTestRepo(t) _, pub := signtest.SSHKey(t, "ed25519", clearsign.SSHNamespace) for _, ok := range []string{pub, "0123456789ABCDEF0123456789ABCDEF01234567", ""} { if err := r.SetConfig(SettingHorizonSeedKey, ok); err != nil { t.Errorf("SetConfig(%q): %v", ok, err) } } if err := r.SetConfig(SettingHorizonSeedKey, "not a key"); err == nil { t.Error("SetConfig accepted a value that is no key") } }