Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

### Changed

- Registrations follow the latest GOBL Net spec. A request is an ordinary delivery from the subject to the lookup, confirmed by its signature for the lookup, and needs no request token; the subject is its `from` address. The lookup drops the request signature, countersigns with a `cnf` claim binding the subject's key, and addresses the envelope back to the subject.
- The lookup keeps each address's key lineage (`Registration.Lineage`). A request signed with the current and a new key rolls over to the new key; one signed only with an unknown key starts a new lineage, and needs a verification for that key. Rollovers need no new verification, a key bound before cannot become current again, and a new holder of an address cannot inherit its verification.
- The lookup registers only verified parties: a registration needs a countersignature from an accepted verifier binding, with `cnf`, a key in the subject's lineage, and is rejected with `403` without one (`503` when the verifier's key cannot be fetched). The `gobl.lookup verify` command is removed; a subject registers again instead.
Comment thread
samlown marked this conversation as resolved.
Resolved
- Verifiers are no longer accepted delivering to the lookup on a subject's behalf; the subject registers again with the verified envelope. The renewal rule based on an unchanged digest is replaced by the lineage check.
- `GET /.well-known/gobl/who` answers with the lookup's party envelope addressed and signed for the requester, with `Vary: Authorization`.
- Deliveries to subjects carry no request token.

- Verification is now list-driven and automatic: the registry accepts a configured set of verification providers (`--verifiers` / `VERIFIERS`), and a registration or renewal arriving with a valid countersignature from one of them is verified on arrival — the countersignature is cryptographically checked against the provider's published key before being named (an unreachable key endpoint registers unverified and logs `inbox.auto_verify_unavailable`; the derivation re-runs on renewal). `gobl.lookup verify <address>` loses the `--verifier` flag and becomes a recovery command that re-derives the verifier from the stored envelope, e.g. after a provider is added to the accepted list. The discovery link stamped on countersigned envelopes uses the standard `verification` category (the previous `authority` value failed envelope validation on re-signing).

- Transient failures now answer `503 Service Unavailable` instead of
Expand Down
266 changes: 139 additions & 127 deletions README.md

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions cmd/gobl.lookup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func rootCmd() *cobra.Command {
"emit logs as structured JSON on stderr (env LOG_JSON)")
cmd.AddCommand(initCmd())
cmd.AddCommand(serveCmd())
cmd.AddCommand(verifyCmd())
cmd.AddCommand(versionCmd())
return cmd
}
Expand Down Expand Up @@ -139,7 +138,7 @@ func printError(err error) {
slog.Error("command failed", attrs...)
}

// stdOut is a small shim so the init / verify commands can write
// stdOut is a small shim so the init command can write
// human-readable confirmation to stdout without going through slog.
func stdOut(cmd *cobra.Command) io.Writer {
return cmd.OutOrStdout()
Expand Down
6 changes: 3 additions & 3 deletions cmd/gobl.lookup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ func buildDomain(ctx context.Context, cfg config.Config) (*domain.Setup, func(),
Identity: id,
Registrations: reg,
Verifiers: verifiers,
// The client and sender authenticate outbound requests as the
// lookup itself (bearer request tokens, spec §5.5).
// The client authenticates /who requests as the lookup itself
// (bearer request tokens, spec §6).
Client: goblnet.NewClient(goblnet.WithIdentity(id.Address(), id.PrivateKey)),
Sender: delivery.New(id.Address(), id.PrivateKey),
Sender: delivery.New(),
// domain.New defaults this to https://<domain> when empty.
PublicBaseURL: strings.TrimRight(cfg.PublicBaseURL, "/"),
Logger: slog.Default(),
Expand Down
78 changes: 0 additions & 78 deletions cmd/gobl.lookup/verify.go

This file was deleted.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.25.0
require (
github.com/go-kivik/kivik/v4 v4.5.2
github.com/invopop/couch v0.1.0
github.com/invopop/gobl v0.504.1-0.20260811215754-c231ee2feae5
github.com/invopop/gobl v0.512.1-0.20261115133328-2994b8d65d7a
github.com/magefile/mage v1.17.2
github.com/spf13/cobra v1.10.2
github.com/stretchr/testify v1.11.1
Expand All @@ -19,7 +19,7 @@ require (
github.com/buger/jsonparser v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/expr-lang/expr v1.17.8 // indirect
github.com/go-jose/go-jose/v4 v4.1.4 // indirect
github.com/go-jose/go-jose/v4 v4.1.6 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/jsonschema v0.14.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/expr-lang/expr v1.17.8 h1:W1loDTT+0PQf5YteHSTpju2qfUfNoBt4yw9+wOEU9VM=
github.com/expr-lang/expr v1.17.8/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/go-jose/go-jose/v4 v4.1.4 h1:moDMcTHmvE6Groj34emNPLs/qtYXRVcd6S7NHbHz3kA=
github.com/go-jose/go-jose/v4 v4.1.4/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08=
github.com/go-jose/go-jose/v4 v4.1.6 h1:sNRkftxFJxwsILiQukqp5z83QBSmntVwmgRY7AqBDO4=
github.com/go-jose/go-jose/v4 v4.1.6/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08=
github.com/go-kivik/kivik/v4 v4.5.2 h1:Xi6QyjscrWrSRQEEW/25vaWyh20ZCg3LhTm6AqFRZCc=
github.com/go-kivik/kivik/v4 v4.5.2/go.mod h1:5YlQJZim4qvaJ3T0fCAS6U4oaN4hzXK6CVY9nvN4Phg=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
Expand All @@ -34,8 +34,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/couch v0.1.0 h1:ctMKLeIxnab9KW11KtEAQSl7RzGgMxndavLphx99LpY=
github.com/invopop/couch v0.1.0/go.mod h1:xzBNVglDnLcpf1Z9BJxiIG1liESSIkMuvIczSl4zcls=
github.com/invopop/gobl v0.504.1-0.20260811215754-c231ee2feae5 h1:C124OmPhan8ocPR78006Aa/dCEdzPNlSMJZik5yTghM=
github.com/invopop/gobl v0.504.1-0.20260811215754-c231ee2feae5/go.mod h1:HmiEdQreTSQYyNbhs81VKTmI7BAJKYC/6enh9RDwnE0=
github.com/invopop/gobl v0.512.1-0.20261115133328-2994b8d65d7a h1:X8WIaoDlnXvZ2Pqqr9Xhlb3uo9HsF/fyoty76rMrcRA=
github.com/invopop/gobl v0.512.1-0.20261115133328-2994b8d65d7a/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40=
github.com/invopop/jsonschema v0.14.0 h1:MHQqLhvpNUZfw+hM3AZDYK7jxO8FZoQeQM77g8iyZjg=
github.com/invopop/jsonschema v0.14.0/go.mod h1:ygm6C2EaVNMBDPpaPlnOA2pFAxBnxGjFlMZABxm9n2I=
github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso=
Expand Down
7 changes: 3 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/invopop/couch"
)

// Config holds the options shared by the serve and verify commands.
// Config holds the options of the serve command.
//
// CouchDB may be configured in two ways: a single connection URL
// (CouchURL, from --couchdb / COUCHDB_URL — convenient for local dev),
Expand Down Expand Up @@ -47,9 +47,8 @@ type Config struct {
// https://<domain>.
PublicBaseURL string
// Verifiers lists the GOBL Net addresses of the verification
// providers this registry accepts: their countersignatures are
// named in `verifier` claims, both automatically at registration
// and by the verify command.
// providers this registry accepts: a registration needs a
// countersignature from one, which is named in its `verifier` claim.
Verifiers []string
// ShutdownTimeout bounds graceful shutdown of the HTTP server.
ShutdownTimeout time.Duration
Expand Down
23 changes: 7 additions & 16 deletions internal/domain/delivery/delivery.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"time"

"github.com/invopop/gobl"
"github.com/invopop/gobl/dsig"
"github.com/invopop/gobl/net"
)

Expand Down Expand Up @@ -51,25 +50,24 @@ type Sender interface {
}

// HTTPSender is the HTTP implementation of Sender. Construct with New;
// the zero value is not usable. Every request carries a bearer
// request token (spec §5.5) minted from the lookup's own identity.
// the zero value is not usable. Requests carry no request token: an
// inbox delivery is authenticated by the envelope's own signature
// (spec §6).
type HTTPSender struct {
client *http.Client
self net.Address
key *dsig.PrivateKey
}

// New returns an HTTPSender whose transport refuses to dial any
// resolved IP that is loopback, private, link-local, multicast, or
// unspecified, and which authenticates its requests as self.
func New(self net.Address, key *dsig.PrivateKey) *HTTPSender {
return newSender(self, key, false)
// unspecified.
func New() *HTTPSender {
return newSender(false)
}

// newSender builds an HTTPSender; allowLoopback bypasses the SSRF
// guard, intended only for tests that talk to httptest servers bound
// to 127.0.0.1. There is no public wrapper that exposes it.
func newSender(self net.Address, key *dsig.PrivateKey, allowLoopback bool) *HTTPSender {
func newSender(allowLoopback bool) *HTTPSender {
transport := &http.Transport{
ForceAttemptHTTP2: true,
MaxIdleConns: 50,
Expand All @@ -85,8 +83,6 @@ func newSender(self net.Address, key *dsig.PrivateKey, allowLoopback bool) *HTTP
// caller's context (see Send), keeping it in step with the
// domain's delivery timeout.
client: &http.Client{Transport: transport},
self: self,
key: key,
}
}

Expand All @@ -111,11 +107,6 @@ func (s *HTTPSender) Send(ctx context.Context, addr net.Address, env *gobl.Envel
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
token, err := net.NewToken(s.key, s.self, addr, 0)
if err != nil {
return fmt.Errorf("%w: mint request token: %v", ErrSendFailed, err)
}
req.Header.Set("Authorization", "Bearer "+token)
resp, err := s.client.Do(req)
if err != nil {
// Transport failures are transient: the async delivery loop
Expand Down
51 changes: 7 additions & 44 deletions internal/domain/delivery/delivery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package delivery

import (
"context"
"encoding/json"
"errors"
stdnet "net"
"net/http"
Expand All @@ -20,11 +19,6 @@ import (
"github.com/stretchr/testify/require"
)

var (
testSelf = net.Address("lookup.example")
testSelfKey = dsig.NewES256Key()
)

func buildEnvelope(t *testing.T) *gobl.Envelope {
t.Helper()
msg := &note.Message{Content: "hi"}
Expand Down Expand Up @@ -54,7 +48,7 @@ func TestSenderSend202(t *testing.T) {
// normally refuse). We use the same internal-only constructor
// trick gobl/net does for its tests, then exercise the transport
// directly via a one-off request matching what Send constructs.
s := newSender(testSelf, testSelfKey, true)
s := newSender(true)
req, _ := http.NewRequest(http.MethodPost, srv.URL+net.InboxPath, strings.NewReader(`{}`))
req.Header.Set("Content-Type", "application/json")
resp, err := s.client.Do(req)
Expand All @@ -71,7 +65,7 @@ func TestSenderRejectsLoopbackByDefault(t *testing.T) {
}))
defer srv.Close()

s := New(testSelf, testSelfKey)
s := New()
// httptest binds 127.0.0.1 — the default Sender MUST refuse.
req, _ := http.NewRequest(http.MethodPost, srv.URL+net.InboxPath, strings.NewReader(`{}`))
_, err := s.client.Do(req)
Expand All @@ -90,13 +84,13 @@ func TestSafeDialContextRejectsLoopback(t *testing.T) {
}

func TestSendNilEnvelope(t *testing.T) {
err := New(testSelf, testSelfKey).Send(context.Background(), net.Address("alice.example"), nil)
err := New().Send(context.Background(), net.Address("alice.example"), nil)
require.Error(t, err)
assert.True(t, errors.Is(err, ErrSendFailed))
}

func TestSendInvalidAddress(t *testing.T) {
err := New(testSelf, testSelfKey).Send(context.Background(), net.Address("not a domain"), buildEnvelope(t))
err := New().Send(context.Background(), net.Address("not a domain"), buildEnvelope(t))
require.Error(t, err)
assert.True(t, errors.Is(err, ErrSendFailed))
}
Expand All @@ -110,7 +104,7 @@ func TestTransportSurfacesUpstreamStatus(t *testing.T) {
w.WriteHeader(http.StatusUnauthorized)
}))
defer srv.Close()
s := newSender(testSelf, testSelfKey, true)
s := newSender(true)
req, _ := http.NewRequest(http.MethodPost, srv.URL+net.InboxPath, strings.NewReader(`{}`))
req.Header.Set("Content-Type", "application/json")
resp, err := s.client.Do(req)
Expand Down Expand Up @@ -145,11 +139,9 @@ type roundTripFunc func(*http.Request) (*http.Response, error)

func (f roundTripFunc) RoundTrip(r *http.Request) (*http.Response, error) { return f(r) }

func TestSendMintsRequestToken(t *testing.T) {
func TestSendCarriesNoRequestToken(t *testing.T) {
var got *http.Request
s := &HTTPSender{
self: testSelf,
key: testSelfKey,
client: &http.Client{Transport: roundTripFunc(func(r *http.Request) (*http.Response, error) {
got = r
return &http.Response{
Expand All @@ -162,42 +154,13 @@ func TestSendMintsRequestToken(t *testing.T) {

require.NoError(t, s.Send(context.Background(), net.Address("alice.example"), buildEnvelope(t)))
require.NotNil(t, got)
auth := got.Header.Get("Authorization")
require.True(t, strings.HasPrefix(auth, "Bearer "), "request carries a bearer token")

// The token must verify as self → alice.example.
pub, err := json.Marshal(testSelfKey.Public())
require.NoError(t, err)
client := net.NewClient(net.WithFetcher(&mapFetcher{data: map[string][]byte{
testSelf.KeyURL(testSelfKey.ID()): pub,
}}))
iss, err := client.VerifyToken(context.Background(), strings.TrimPrefix(auth, "Bearer "), "alice.example")
require.NoError(t, err)
assert.Equal(t, testSelf, iss)
}

// mapFetcher serves a URL-keyed byte map for token verification.
type mapFetcher struct {
data map[string][]byte
}

func (m *mapFetcher) Fetch(_ context.Context, url string, _ http.Header) ([]byte, error) {
if d, ok := m.data[url]; ok {
return d, nil
}
return nil, net.ErrFetchFailed
}

func (m *mapFetcher) Post(_ context.Context, _ string, _ []byte, _ http.Header) error {
return net.ErrFetchFailed
assert.Empty(t, got.Header.Get("Authorization"), "inbox deliveries are authenticated by their signatures")
}

func TestSendRetryableTaxonomy(t *testing.T) {
send := func(t *testing.T, status int) error {
t.Helper()
s := &HTTPSender{
self: testSelf,
key: testSelfKey,
client: &http.Client{Transport: roundTripFunc(func(r *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: status, Body: http.NoBody, Request: r}, nil
})},
Expand Down
Loading
Loading