Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions .changeset/version-check-no-step-up.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"ftw": patch
---

An owner's phone can now ask the box whether a newer Core exists
(`GET /api/version/check`) without Face ID, so the app can show the newer
version and its notes. Installing it (`POST /api/version/update`) still asks
for Face ID, and a viewer still cannot read the check.
8 changes: 5 additions & 3 deletions docs/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,11 @@ A `local` route is refused with `E_LOCAL_ONLY`, before the role and before the
ceremony, because neither of them changes it.

`configure` needs role `owner`. Most configure routes also need a `stepUp`
flag. A few household settings — the charging schedule today — skip the
ceremony: the session already proved who is asking, and a second Face ID is
more friction than the table-phone risk is worth. The box names those routes
flag. A few skip the ceremony: the charging schedule, FTW Cloud's grant and
statistics, and `GET /api/version/check`, which tells the app whether a newer
Core exists. The session already proved who is asking, and a second Face ID is
more friction than the table-phone risk is worth. Installing that Core
(`POST /api/version/update`) still needs the flag. The box names those routes
beside the handler. The app still carries no list of tiers — it asks without
the flag, and a route that still needs a ceremony answers `E_NEEDS_STEP_UP`.

Expand Down
5 changes: 4 additions & 1 deletion go/internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,10 @@ func (s *Server) routes() {
s.handle("POST /api/pv/manual_hold", Actuate, s.handlePVManualHold)
s.handle("DELETE /api/pv/manual_hold", Actuate, s.handlePVManualHoldClear)
s.handle("GET /api/pv/manual_hold", Read, s.handlePVManualHoldGet)
s.handle("GET /api/version/check", Configure, s.handleVersionCheck)
// Owner, since ?force=1 asks GitHub on the box's behalf. NoStepUp: a
// phone reads it to say whether a newer Core exists, and Face ID is the
// wrong cost for a question. The update itself keeps its ceremony.
s.handle("GET /api/version/check", Configure, s.handleVersionCheck, NoStepUp)
s.handle("POST /api/version/channel", Configure, s.handleVersionChannel)
s.handle("POST /api/version/skip", Configure, s.handleVersionSkip)
s.handle("POST /api/version/unskip", Configure, s.handleVersionUnskip)
Expand Down
71 changes: 71 additions & 0 deletions go/internal/api/api_passthrough_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,45 @@ func TestAnOwnerClearsAScheduleWithoutACeremony(t *testing.T) {
}
}

// The phone's version row reads the check without a ceremony. On a box with
// no native updater the handler itself answers, so the phone learns who
// updates FTW there rather than meeting E_NEEDS_STEP_UP.
func TestAnOwnerReadsTheVersionCheckWithoutACeremony(t *testing.T) {
rig := newAppSession(t, apiauth.RoleOwner)
rig.send(t, appproto.MsgAPIReq, 1, appproto.APIReq{
Method: appproto.APIGet,
Path: "/api/version/check",
})
head := decode[appproto.APIHeadMsg](t, rig.frames.await(t, appproto.MsgAPIHead))
if head.Status != http.StatusServiceUnavailable {
t.Fatalf("status = %d, want the handler's 503 for a box that does not update itself", head.Status)
}
}

func TestTheUpdateStillNeedsTheCeremony(t *testing.T) {
rig := newAppSession(t, apiauth.RoleOwner)
rig.send(t, appproto.MsgAPIReq, 1, appproto.APIReq{
Method: appproto.APIPost,
Path: "/api/version/update",
})
refusal := decode[appproto.ErrorBody](t, rig.frames.await(t, appproto.MsgError))
if refusal.Code != appproto.ErrNeedsStepUp {
t.Fatalf("refusal = %+v, want E_NEEDS_STEP_UP", refusal)
}
}

func TestAViewerCannotReadTheVersionCheck(t *testing.T) {
rig := newAppSession(t, apiauth.RoleViewer)
rig.send(t, appproto.MsgAPIReq, 1, appproto.APIReq{
Method: appproto.APIGet,
Path: "/api/version/check",
})
refusal := decode[appproto.ErrorBody](t, rig.frames.await(t, appproto.MsgError))
if refusal.Code != appproto.ErrScopeDenied {
t.Fatalf("refusal = %+v, want E_SCOPE_DENIED", refusal)
}
}

func TestAViewerCannotSaveASchedule(t *testing.T) {
mgr := loadpoint.NewManager()
mgr.Load([]loadpoint.Config{{ID: "garage", DriverName: "easee"}})
Expand Down Expand Up @@ -420,6 +459,38 @@ func TestScheduleConfigureSkipsTheCeremony(t *testing.T) {
}
}

// A phone asks whether a newer Core exists without Face ID; installing it,
// or anything else that changes what runs, still takes the ceremony.
func TestVersionCheckSkipsTheCeremonyButTheUpdateDoesNot(t *testing.T) {
srv := New(&Deps{})
for _, path := range []string{"/api/version/check", "/api/version/check?force=1"} {
facts := srv.Route(httptest.NewRequest(http.MethodGet, path, nil))
if facts.Tier != apiauth.TierConfigure {
t.Fatalf("GET %s tier = %q, want configure: a viewer must not make the box ask GitHub", path, facts.Tier)
}
if !facts.NoStepUp {
t.Fatalf("GET %s still needs a ceremony; reading it must not", path)
}
}
for _, path := range []string{
"/api/version/update",
"/api/version/channel",
"/api/version/skip",
"/api/version/unskip",
"/api/version/restart",
"/api/version/binary-rollback",
} {
facts := srv.Route(newSyntheticRequest("POST", path))
if facts.Tier != apiauth.TierConfigure || facts.NoStepUp {
t.Fatalf("POST %s = %+v, want configure with a ceremony", path, facts)
}
}
status := srv.Route(newSyntheticRequest("GET", "/api/version/update/status"))
if status.Tier != apiauth.TierRead {
t.Fatalf("GET /api/version/update/status tier = %q, want read", status.Tier)
}
}

// --------------------------------------------------------------------------
// The second door: actuation stays on cmd
// --------------------------------------------------------------------------
Expand Down
Loading