carlos / platform Public

edge: seal probe-burst notice bodies (AES-256-GCM under an HKDF mesh key)

A rolled-back box keeps its edges file, burst_notices flag included,
until something else rewrites it, and its edge hands the notice to the
app on that host. The body is now sealed: AES-256-GCM under a key HKDF-
SHA256 derives from the mesh signing key (info carlos-burst-notice-v1),
a random 12-byte nonce, the receiver and timestamp as associated data,
base64(nonce||ciphertext) on the wire. The MAC header is unchanged and
covers the sealed body. The receiver verifies, then opens under either
mirrored key, and refuses (404, counted) anything that does not open.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev d1ab27c77055e31fb3f70e9c9d2667d4b0bbf215 parent 5b91ae3
2 files changed, +293 −28
  • internal/edge/burst_notice.go +114 −10
  • internal/edge/burst_notice_test.go +179 −18
diff --git a/internal/edge/burst_notice.go b/internal/edge/burst_notice.go
index c57d3a611..ed88a6861 100644
--- a/internal/edge/burst_notice.go
+++ b/internal/edge/burst_notice.go
@@ -3,6 +3,12 @@ package edge
import (
"bytes"
"context"
+ "crypto/aes"
+ "crypto/cipher"
+ "crypto/hkdf"
+ "crypto/rand"
+ "crypto/sha256"
+ "encoding/base64"
"encoding/json"
"fmt"
"io"
@@ -11,6 +17,7 @@ import (
"net/netip"
"net/url"
"slices"
+ "strconv"
"strings"
"sync"
"time"
@@ -34,11 +41,18 @@ import (
// so the cap holds however the trips and the queues line up. A notice that
// cannot be sent within 10 seconds of its trip is dropped, since the scanner
// will trip the other box by itself if it gets there. Every drop is counted.
+//
+// The body is sealed (AES-256-GCM under a key derived from the mesh key)
+// as well as signed. The burst_notices flag keeps notices away from a box
+// without the interceptor, but a box rolled back to an older build keeps
+// its last file, flag included, until something else rewrites it, and its
+// edge hands the notice to the app on that host. Sealed, all that app ever
+// sees is ciphertext: no client, no box name, no reference.
const (
burstNoticePath = "/.carlos/burst-notice"
burstNoticeAuthHeader = "X-Carlos-Burst-Auth"
- // burstNoticeMaxBody bounds a notice's body; a real one is under 200
- // bytes.
+ // burstNoticeMaxBody bounds a notice's sealed body; a real one is
+ // about 300 bytes.
burstNoticeMaxBody = 512
// burstNoticeQueue is each peer's queue length.
burstNoticeQueue = 64
@@ -62,7 +76,11 @@ const (
burstNoticeMaxWait = time.Second
)
-// burstNoticeWire is a notice's JSON body.
+// burstNoticeKeyInfo is the HKDF info that derives the notice's sealing
+// key from the mesh key, so the sealing key is never the MAC key.
+const burstNoticeKeyInfo = "carlos-burst-notice-v1"
+
+// burstNoticeWire is a notice's JSON body, before it is sealed.
type burstNoticeWire struct {
Client string `json:"client"`
Until int64 `json:"until"`
@@ -85,6 +103,7 @@ type burstNoticeStats struct {
RefusedNoKey int64 // no mesh key or no box name to check against
RefusedBody int64 // too big, too slow or unreadable
RefusedAuth int64 // bad, stale or another box's signature
+ RefusedSealed int64 // signed, but the body does not open
RefusedNotice int64 // malformed, or the client not a canonical /32 or /64
RefusedUntil int64 // expiry passed or more than a cool-down ahead
RefusedCap int64 // over burstNoticeAcceptPerMinute
@@ -197,7 +216,7 @@ func (e *Edge) sendBurstNotices(client netip.Prefix, until time.Time, ref string
return
}
body, err := json.Marshal(burstNoticeWire{Client: client.String(), Until: until.Unix(), From: e.box, Ref: ref})
- if err != nil || len(body) > burstNoticeMaxBody {
+ if err != nil || burstNoticeSealedLen(len(body)) > burstNoticeMaxBody {
e.logThrottled("burst-notice-too-big", fmt.Sprintf("probe-burst notice for %s not sent: its body is over %d bytes", client, burstNoticeMaxBody))
return
}
@@ -377,8 +396,8 @@ func (e *Edge) dispatchBurstNotice(n *burstNotices, p *burstPeer, nt burstNotice
n.count(func(s *burstNoticeStats) { s.Sent++ })
}
-// transmitBurstNotice signs nt now, under the key current at dispatch, and
-// sends it to the peer's front door over the backhaul transport, so it is
+// transmitBurstNotice seals and signs nt now, under the key current at
+// dispatch, and sends it to the peer's front door over the backhaul transport, so it is
// verified against the certificate the peer serves for nt.host.
func (e *Edge) transmitBurstNotice(nt burstNotice, now time.Time) error {
current, next := e.homes.Load().meshKeys()
@@ -386,15 +405,19 @@ func (e *Edge) transmitBurstNotice(nt burstNotice, now time.Time) error {
if len(key) == 0 {
return fmt.Errorf("no mesh key to sign with")
}
+ sealed, err := sealBurstNotice(key, nt.box, now, nt.body)
+ if err != nil {
+ return err
+ }
ctx, cancel := context.WithTimeout(context.Background(), burstNoticeSendTimeout)
defer cancel()
u := url.URL{Scheme: "https", Host: nt.host, Path: burstNoticePath}
- req, err := http.NewRequestWithContext(ctx, http.MethodPost, u.String(), bytes.NewReader(nt.body))
+ req, err := http.NewRequestWithContext(ctx, http.MethodPost, u.String(), bytes.NewReader(sealed))
if err != nil {
return err
}
- req.Header.Set("Content-Type", "application/json")
- req.Header.Set(burstNoticeAuthHeader, signBurstNotice(key, nt.box, now, nt.body))
+ req.Header.Set("Content-Type", "application/octet-stream")
+ req.Header.Set(burstNoticeAuthHeader, signBurstNotice(key, nt.box, now, sealed))
resp, err := e.backhaulTransport(nt.dial).RoundTrip(req)
if err != nil {
return err
@@ -412,6 +435,7 @@ const (
burstRefusedNoKey = "no-key"
burstRefusedBody = "body"
burstRefusedAuth = "auth"
+ burstRefusedSealed = "sealed"
burstRefusedNotice = "notice"
burstRefusedUntil = "until"
burstRefusedCap = "cap"
@@ -459,8 +483,16 @@ func (e *Edge) serveBurstNotice(w http.ResponseWriter, r *http.Request) bool {
e.refuseBurstNotice(w, r, burstRefusedAuth)
return true
}
+ // The MAC covered the timestamp, so it is the one the body was sealed
+ // under.
+ ts, _, _ := strings.Cut(auth[0], ":")
+ plain, ok := openBurstNotice(current, next, e.box, ts, body)
+ if !ok {
+ e.refuseBurstNotice(w, r, burstRefusedSealed)
+ return true
+ }
var msg burstNoticeWire
- if err := json.Unmarshal(body, &msg); err != nil {
+ if err := json.Unmarshal(plain, &msg); err != nil {
e.refuseBurstNotice(w, r, burstRefusedNotice)
return true
}
@@ -501,6 +533,8 @@ func (e *Edge) refuseBurstNotice(w http.ResponseWriter, r *http.Request, reason
s.RefusedBody++
case burstRefusedAuth:
s.RefusedAuth++
+ case burstRefusedSealed:
+ s.RefusedSealed++
case burstRefusedNotice:
s.RefusedNotice++
case burstRefusedUntil:
@@ -540,3 +574,73 @@ func burstNoticeClient(s string) (netip.Prefix, bool) {
}
return p, true
}
+
+// burstNoticeAEAD is AES-256-GCM under the notice key HKDF-SHA256 derives
+// from meshKey.
+func burstNoticeAEAD(meshKey []byte) (cipher.AEAD, error) {
+ k, err := hkdf.Key(sha256.New, meshKey, nil, burstNoticeKeyInfo, 32)
+ if err != nil {
+ return nil, err
+ }
+ block, err := aes.NewCipher(k)
+ if err != nil {
+ return nil, err
+ }
+ return cipher.NewGCM(block)
+}
+
+// burstNoticeAD binds a sealed body to its receiver and its timestamp, the
+// two things the MAC binds besides the body itself.
+func burstNoticeAD(receiver, ts string) []byte {
+ return []byte(receiver + "\n" + ts)
+}
+
+// burstNoticeSealedLen is the wire length of a sealed body of n bytes:
+// base64 of a 12-byte nonce, the ciphertext and the 16-byte tag.
+func burstNoticeSealedLen(n int) int {
+ return base64.StdEncoding.EncodedLen(12 + n + 16)
+}
+
+// sealBurstNotice is a notice's wire body: base64(nonce || ciphertext)
+// under a fresh random nonce, with the receiver and the timestamp the
+// signature carries as associated data.
+func sealBurstNotice(key []byte, receiver string, now time.Time, plain []byte) ([]byte, error) {
+ aead, err := burstNoticeAEAD(key)
+ if err != nil {
+ return nil, err
+ }
+ nonce := make([]byte, aead.NonceSize())
+ if _, err := rand.Read(nonce); err != nil {
+ return nil, err
+ }
+ raw := aead.Seal(nonce, nonce, plain, burstNoticeAD(receiver, strconv.FormatInt(now.Unix(), 10)))
+ out := make([]byte, base64.StdEncoding.EncodedLen(len(raw)))
+ base64.StdEncoding.Encode(out, raw)
+ return out, nil
+}
+
+// openBurstNotice opens a sealed body under either mirrored key, as the
+// MAC is verified, so a rotation never refuses a notice.
+func openBurstNotice(current, next []byte, receiver, ts string, body []byte) ([]byte, bool) {
+ enc := base64.StdEncoding.Strict()
+ raw := make([]byte, enc.DecodedLen(len(body)))
+ n, err := enc.Decode(raw, body)
+ if err != nil {
+ return nil, false
+ }
+ raw = raw[:n]
+ ad := burstNoticeAD(receiver, ts)
+ for _, key := range [][]byte{next, current} {
+ if len(key) == 0 {
+ continue
+ }
+ aead, err := burstNoticeAEAD(key)
+ if err != nil || len(raw) < aead.NonceSize()+aead.Overhead() {
+ continue
+ }
+ if plain, err := aead.Open(nil, raw[:aead.NonceSize()], raw[aead.NonceSize():], ad); err == nil {
+ return plain, true
+ }
+ }
+ return nil, false
+}
diff --git a/internal/edge/burst_notice_test.go b/internal/edge/burst_notice_test.go
index 925d0b71e..a40ca3482 100644
--- a/internal/edge/burst_notice_test.go
+++ b/internal/edge/burst_notice_test.go
@@ -2,16 +2,20 @@ package edge
import (
"bufio"
+ "bytes"
"context"
"crypto/rand"
"crypto/tls"
+ "encoding/base64"
"errors"
"fmt"
"io"
"net"
"net/http"
"net/http/httptest"
+ "net/http/httputil"
"net/netip"
+ "net/url"
"slices"
"strings"
"sync"
@@ -49,12 +53,32 @@ type noticeEdge struct {
// reached this box's 443.
mu sync.Mutex
at []time.Time
- // appNotice counts the requests for burstNoticePath this box's app saw.
+ // wire is the body of each of those requests as it arrived.
+ wire [][]byte
+ // appNotice counts the requests for burstNoticePath this box's app
+ // saw, and appBodies holds their bodies.
appNotice atomic.Int64
+ appBodies [][]byte
+ // older makes the box's 443 behave as a build without the interceptor:
+ // every request goes straight to the app, as that build's route lookup
+ // would send it.
+ older atomic.Bool
}
func (x *noticeEdge) edge() *Edge { return x.be.live.Load().edge }
+func (x *noticeEdge) wireBodies() [][]byte {
+ x.mu.Lock()
+ defer x.mu.Unlock()
+ return slices.Clone(x.wire)
+}
+
+func (x *noticeEdge) appSaw() [][]byte {
+ x.mu.Lock()
+ defer x.mu.Unlock()
+ return slices.Clone(x.appBodies)
+}
+
func (x *noticeEdge) arrivals() []time.Time {
x.mu.Lock()
defer x.mu.Unlock()
@@ -120,12 +144,17 @@ func (s *noticeScene) add(t *testing.T, box, ip, host, acct, app string, adverti
x := &noticeEdge{file: &noticeFile{box: box, ip: ip, host: host, advertise: advertise}, rec: &lockedRecorder{}}
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == burstNoticePath {
+ b, _ := io.ReadAll(r.Body)
+ x.mu.Lock()
+ x.appBodies = append(x.appBodies, b)
+ x.mu.Unlock()
x.appNotice.Add(1)
}
w.WriteHeader(http.StatusNotFound)
io.WriteString(w, "the app's own 404")
}))
t.Cleanup(backend.Close)
+ toApp := httputil.NewSingleHostReverseProxy(&url.URL{Scheme: "http", Host: backend.Listener.Addr().String()})
be := &backhaulEdge{store: release.NewDirStore(s.bucket), reg: openReg(t), box: box}
if err := be.reg.Upsert(registry.Route{Host: host, Kind: "service", Addr: backend.Listener.Addr().String(),
Status: "ready", Account: acct, App: app}); err != nil {
@@ -143,6 +172,22 @@ func (s *noticeScene) add(t *testing.T, box, ip, host, acct, app string, adverti
x.mu.Lock()
x.at = append(x.at, s.clock.now())
x.mu.Unlock()
+ // The body as it is read, never read ahead: a stalled body must
+ // stall the edge, not this tap.
+ var wire bytes.Buffer
+ r.Body = struct {
+ io.Reader
+ io.Closer
+ }{io.TeeReader(r.Body, &wire), r.Body}
+ defer func() {
+ x.mu.Lock()
+ x.wire = append(x.wire, wire.Bytes())
+ x.mu.Unlock()
+ }()
+ }
+ if x.older.Load() {
+ toApp.ServeHTTP(w, r)
+ return
}
be.live.Load().edge.ServeHTTP(w, r)
}))
@@ -241,6 +286,17 @@ func (x *noticeEdge) post(auth, body string) *httptest.ResponseRecorder {
return w
}
+// seal is a notice as a sender puts it on the wire for to: plain sealed
+// under key at ts, and the signature over the sealed body.
+func seal(t *testing.T, key []byte, to string, ts time.Time, plain string) (auth, body string) {
+ t.Helper()
+ b, err := sealBurstNotice(key, to, ts, []byte(plain))
+ if err != nil {
+ t.Fatal(err)
+ }
+ return signBurstNotice(key, to, ts, b), string(b)
+}
+
func noticeBody(client string, until time.Time, from, ref string) string {
return fmt.Sprintf(`{"client":%q,"until":%d,"from":%q,"ref":%q}`, client, until.Unix(), from, ref)
}
@@ -328,14 +384,13 @@ func TestBurstNoticeRefusesForgery(t *testing.T) {
if !strings.Contains(client, "/") {
client += "/32"
}
- body := noticeBody(client, c.until, "annie", "x")
- if w := b.post(signBurstNotice(c.key, c.to, c.ts, []byte(body)), body); w.Code != http.StatusNotFound {
+ if w := b.post(seal(t, c.key, c.to, c.ts, noticeBody(client, c.until, "annie", "x"))); w.Code != http.StatusNotFound {
t.Errorf("%s: answered %d, want 404", c.name, w.Code)
}
}
// A valid signature over a different body.
- body := noticeBody("203.0.113.9/32", now.Add(burstCooldown), "annie", "x")
- sig := signBurstNotice(s.key, "betty", now, []byte(noticeBody("203.0.113.10/32", now.Add(burstCooldown), "annie", "x")))
+ _, body := seal(t, s.key, "betty", now, noticeBody("203.0.113.9/32", now.Add(burstCooldown), "annie", "x"))
+ sig, _ := seal(t, s.key, "betty", now, noticeBody("203.0.113.10/32", now.Add(burstCooldown), "annie", "x"))
if w := b.post(sig, body); w.Code != http.StatusNotFound {
t.Errorf("a signature over another body: answered %d, want 404", w.Code)
}
@@ -351,8 +406,7 @@ func TestBurstNoticeRefusesForgery(t *testing.T) {
// The same shape, properly signed, applies: the refusals above were the
// faults and nothing else.
- good := noticeBody("203.0.113.11/32", now.Add(burstCooldown), "annie", "x")
- if w := b.post(signBurstNotice(s.key, "betty", now, []byte(good)), good); w.Code != http.StatusNoContent {
+ if w := b.post(seal(t, s.key, "betty", now, noticeBody("203.0.113.11/32", now.Add(burstCooldown), "annie", "x"))); w.Code != http.StatusNoContent {
t.Fatalf("a valid notice: answered %d, want 204", w.Code)
}
if _, _, ok := b.edge().burst.cooling(noticePrefix(t, "203.0.113.11")); !ok {
@@ -380,8 +434,7 @@ func TestBurstNoticeNoKeyNoSendNoAccept(t *testing.T) {
key := make([]byte, 32)
rand.Read(key)
now := s.clock.now()
- body := noticeBody("203.0.113.8/32", now.Add(burstCooldown), "annie", "x")
- if w := b.post(signBurstNotice(key, "betty", now, []byte(body)), body); w.Code != http.StatusNotFound {
+ if w := b.post(seal(t, key, "betty", now, noticeBody("203.0.113.8/32", now.Add(burstCooldown), "annie", "x"))); w.Code != http.StatusNotFound {
t.Fatalf("betty with no key answered %d, want 404", w.Code)
}
if _, _, ok := b.edge().burst.cooling(noticePrefix(t, "203.0.113.8")); ok {
@@ -435,8 +488,7 @@ func TestBurstNoticeCaps(t *testing.T) {
applied, refused := 0, 0
for i := range 610 {
client := fmt.Sprintf("198.19.%d.%d", i/250, i%250+1)
- body := noticeBody(client+"/32", now.Add(burstCooldown), "annie", "x")
- switch w := b.post(signBurstNotice(s.key, "betty", now, []byte(body)), body); w.Code {
+ switch w := b.post(seal(t, s.key, "betty", now, noticeBody(client+"/32", now.Add(burstCooldown), "annie", "x"))); w.Code {
case http.StatusNoContent:
applied++
case http.StatusNotFound:
@@ -568,7 +620,7 @@ func TestBurstNoticeStalledBodyBounded(t *testing.T) {
b := s.add(t, "betty", "127.0.0.12", "blog.example.com", "bab", "blog", true)
s.publish(t)
now := s.clock.now()
- body := noticeBody("203.0.113.7/32", now.Add(burstCooldown), "annie", "x")
+ auth, body := seal(t, s.key, "betty", now, noticeBody("203.0.113.7/32", now.Add(burstCooldown), "annie", "x"))
conn, err := tls.Dial("tcp", net.JoinHostPort(b.file.ip, s.port), &tls.Config{ServerName: b.file.host, RootCAs: s.ca.pool, NextProtos: []string{"http/1.1"}})
if err != nil {
@@ -576,8 +628,8 @@ func TestBurstNoticeStalledBodyBounded(t *testing.T) {
}
defer conn.Close()
start := time.Now()
- fmt.Fprintf(conn, "POST %s HTTP/1.1\r\nHost: %s\r\n%s: %s\r\nContent-Type: application/json\r\nContent-Length: %d\r\n\r\n%s",
- burstNoticePath, b.file.host, burstNoticeAuthHeader, signBurstNotice(s.key, "betty", now, []byte(body)), len(body), body[:10])
+ fmt.Fprintf(conn, "POST %s HTTP/1.1\r\nHost: %s\r\n%s: %s\r\nContent-Type: application/octet-stream\r\nContent-Length: %d\r\n\r\n%s",
+ burstNoticePath, b.file.host, burstNoticeAuthHeader, auth, len(body), body[:10])
conn.SetReadDeadline(time.Now().Add(10 * time.Second))
br := bufio.NewReader(conn)
resp, err := http.ReadResponse(br, nil)
@@ -605,8 +657,7 @@ func TestBurstNoticeStalledBodyBounded(t *testing.T) {
}
// An oversized body is refused the same way.
- big := noticeBody("203.0.113.7/32", now.Add(burstCooldown), "annie", strings.Repeat("x", burstNoticeMaxBody))
- if w := b.post(signBurstNotice(s.key, "betty", now, []byte(big)), big); w.Code != http.StatusNotFound {
+ if w := b.post(seal(t, s.key, "betty", now, noticeBody("203.0.113.7/32", now.Add(burstCooldown), "annie", strings.Repeat("x", burstNoticeMaxBody)))); w.Code != http.StatusNotFound {
t.Fatalf("an oversized notice answered %d, want 404", w.Code)
}
if st := b.edge().notices.stats(); st.RefusedBody != 2 {
@@ -614,6 +665,117 @@ func TestBurstNoticeStalledBodyBounded(t *testing.T) {
}
}
+// A notice on the wire is sealed: nothing in its body names the client,
+// either box or the trip, and it fits the receiver's cap.
+func TestBurstNoticeWireBodyIsOpaque(t *testing.T) {
+ s := newNoticeScene(t, true)
+ a := s.add(t, "annie", "127.0.0.11", "shop.example.com", "bdk", "shop", true)
+ b := s.add(t, "betty", "127.0.0.12", "blog.example.com", "bab", "blog", true)
+ s.publish(t)
+
+ // An IPv6 client too: the longest client key a notice carries.
+ for _, client := range []string{"203.0.113.7", "2001:db8:1:2::7"} {
+ for i := range burstThreshold {
+ r := httptest.NewRequest(http.MethodGet, "http://"+a.file.host+scanPath(i), nil)
+ r.RemoteAddr = net.JoinHostPort(client, "40000")
+ a.edge().ServeHTTP(httptest.NewRecorder(), r)
+ }
+ }
+ waitFor(t, 5*time.Second, "both notices applied", func() bool { return b.edge().notices.stats().Accepted == 2 })
+ a.rec.mu.Lock()
+ trips := slices.Clone(a.rec.trips)
+ a.rec.mu.Unlock()
+ if len(trips) != 2 {
+ t.Fatalf("annie filed %d trips, want 2", len(trips))
+ }
+ wire := b.wireBodies()
+ if len(wire) != 2 {
+ t.Fatalf("betty saw %d notice bodies, want 2", len(wire))
+ }
+ for _, body := range wire {
+ if len(body) > burstNoticeMaxBody {
+ t.Fatalf("a notice body of %d bytes, over the %d cap", len(body), burstNoticeMaxBody)
+ }
+ for _, clear := range []string{"203.0.113", "2001:db8", "annie", "betty", "client", "until", trips[0].Ref, trips[1].Ref} {
+ if bytes.Contains(body, []byte(clear)) {
+ t.Fatalf("the notice body carries %q in clear: %s", clear, body)
+ }
+ }
+ }
+}
+
+// R3-1 whatever the rollout: a box that still advertises notices but runs
+// a build without the interceptor (rolled back, its file not yet
+// rewritten) hands its app the notice, and the app gets only ciphertext.
+func TestBurstNoticeOlderPeerSeesOnlyCiphertext(t *testing.T) {
+ s := newNoticeScene(t, true)
+ a := s.add(t, "annie", "127.0.0.11", "shop.example.com", "bdk", "shop", true)
+ c := s.add(t, "carol", "127.0.0.13", "docs.example.com", "bab", "docs", true)
+ c.older.Store(true)
+ s.publish(t)
+
+ const client = "203.0.113.7"
+ s.trip(t, a, client)
+ waitFor(t, 5*time.Second, "the notice to carol", func() bool { return transmitted(a) == 1 })
+ got := c.appSaw()
+ if len(got) != 1 {
+ t.Fatalf("carol's app saw %d notices, want the one the older build passes on", len(got))
+ }
+ a.rec.mu.Lock()
+ ref := a.rec.trips[0].Ref
+ a.rec.mu.Unlock()
+ for _, clear := range []string{client, "annie", "carol", "client", ref} {
+ if bytes.Contains(got[0], []byte(clear)) {
+ t.Fatalf("carol's app was handed %q in clear: %s", clear, got[0])
+ }
+ }
+ if _, err := base64.StdEncoding.Strict().DecodeString(string(got[0])); err != nil {
+ t.Fatalf("carol's app was handed something other than the sealed body: %q", got[0])
+ }
+}
+
+// A notice whose signature checks but whose body does not open under the
+// mesh key, or opens only for another receiver or time, is refused.
+func TestBurstNoticeRefusesWhatDoesNotOpen(t *testing.T) {
+ s := newNoticeScene(t, true)
+ s.add(t, "annie", "127.0.0.11", "shop.example.com", "bdk", "shop", true)
+ b := s.add(t, "betty", "127.0.0.12", "blog.example.com", "bab", "blog", true)
+ s.publish(t)
+ now := s.clock.now()
+ other := make([]byte, len(s.key))
+ rand.Read(other)
+ plain := func(i int) string {
+ return noticeBody(fmt.Sprintf("203.0.113.%d/32", i), now.Add(burstCooldown), "annie", "x")
+ }
+ sealedWith := func(key []byte, to string, ts time.Time, p string) string {
+ b, err := sealBurstNotice(key, to, ts, []byte(p))
+ if err != nil {
+ t.Fatal(err)
+ }
+ return string(b)
+ }
+ cases := map[string]string{
+ "sealed under another key": sealedWith(other, "betty", now, plain(1)),
+ "sealed for another box": sealedWith(s.key, "carol", now, plain(2)),
+ "sealed at another time": sealedWith(s.key, "betty", now.Add(-time.Second), plain(3)),
+ "not sealed at all": plain(4),
+ "cut short": sealedWith(s.key, "betty", now, plain(5))[:20],
+ }
+ for name, body := range cases {
+ if w := b.post(signBurstNotice(s.key, "betty", now, []byte(body)), body); w.Code != http.StatusNotFound {
+ t.Errorf("%s: answered %d, want 404", name, w.Code)
+ }
+ }
+ for i := 1; i <= 5; i++ {
+ if _, _, ok := b.edge().burst.cooling(noticePrefix(t, fmt.Sprintf("203.0.113.%d", i))); ok {
+ t.Errorf("203.0.113.%d is cooling after a notice that did not open", i)
+ }
+ }
+ if st := b.edge().notices.stats(); st.RefusedSealed != 5 || st.RefusedAuth != 0 || st.Accepted != 0 {
+ t.Fatalf("betty's counts %+v, want five refused as not opening", st)
+ }
+}
+
// The path alone is not a notice: without the header it is the app's.
func TestBurstNoticePathWithoutAuthReachesApp(t *testing.T) {
s := newNoticeScene(t, true)
@@ -669,7 +831,7 @@ func TestBurstNoticeIsNotAHop(t *testing.T) {
b := s.add(t, "betty", "127.0.0.12", "blog.example.com", "bab", "blog", true)
s.publish(t)
now := s.clock.now()
- body := noticeBody("203.0.113.7/32", now.Add(burstCooldown), "annie", "x")
+ sig, body := seal(t, s.key, "betty", now, noticeBody("203.0.113.7/32", now.Add(burstCooldown), "annie", "x"))
for name, sig := range map[string]string{
"hop for the host": signHop(s.key, b.file.host, now),
"hop for the box": signHop(s.key, "betty", now),
@@ -687,7 +849,6 @@ func TestBurstNoticeIsNotAHop(t *testing.T) {
t.Fatalf("betty's counts %+v, want four auth refusals", st)
}
- sig := signBurstNotice(s.key, "betty", now, []byte(body))
for _, host := range []string{"betty", b.file.host} {
if verifyHopEitherKey(s.key, nil, host, sig, now) || verifyHopDoorEitherKey(s.key, nil, host, sig, now) {
t.Fatalf("a notice signature verifies as a hop or door mark for %s", host)