Docs: signing-key backup procedure, upstairs 0.108.104 upgrade plan, next security fixes for review
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 5m17s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 4m12s

No secrets in these files: public certificate facts only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-08 09:35:36 +00:00
co-authored by Claude Opus 5.5
parent 77020c38ec
commit 947c1eb040
3 changed files with 262 additions and 0 deletions
+94
View File
@@ -0,0 +1,94 @@
# Proposed for the next security review: three small fixes (0.108.105)
Prepared 8 November 2026 from audit findings S3, S8 and A5. **Not started:** no code has been written. Each fix is independent, tested on its own and reversible by reverting one commit. They ship together only if all three pass.
---
## 1. Wrong-PIN protection everywhere (S3), highest priority
**Today:**
- Only the phone's profile switch limits wrong PINs (`OrbitCompanion.kt:236-240`: 3 misses, then 5 minutes).
- These paths have no limit:
- TV After Dark unlock (`AfterDarkLock.kt:184`)
- Changing or turning off the PIN on the TV (`AfterDarkLock.kt:187`)
- TV profile switch (`Profiles.kt:257`)
- Allowing a new room (`RoomsUi.kt:127`, `RoomsUi.kt:203`)
- Phone joining is bounded per pairing (`PhoneLink.kt:275`: 3 PINs per code, 5 tries per code). A new code needs someone at the TV.
- A joined phone can type on the TV's keypad through `/api/key`, so the TV's unlimited paths can be driven remotely.
**Change:**
- One limiter inside `AfterDarkLock`, used by every PIN check, so no caller can bypass it:
- 5 wrong PINs, then 1 minute
- each further wrong PIN doubles the wait, up to 30 minutes
- a correct PIN resets the counter
- The count and the wait end time are kept in prefs, so restarting Orbit doesn't reset them. The PIN itself isn't stored.
- The screens show "Too many tries. Try again in N minutes."
- The phone's own 3-then-5-minutes rule stays as it is, on top.
**Tests:**
- 5 misses lock it.
- The right PIN during the wait is refused.
- After the wait the right PIN works and resets the counter.
- The wait doubles.
- It persists across a reload.
- Every call site goes through the limiter, checked by a test that greps for direct `pinHash` comparisons outside it.
**Risk:** low. If the limiter misbehaves, an adult might have to wait. The worst case is a 30-minute wait. Undo: revert the one commit.
**On-TV check:** enter 5 wrong PINs on After Dark and see the wait; after it, the right PIN unlocks.
## 2. Kids gate on phone browse and search (S8)
**Today:** while Kids is watching, these phone routes still answer for a joined phone, with no `OrbitCompanion.grownUp` check (`PhoneLink.kt:304-345, 469`):
- `/api/search`, `/api/shows`, `/api/suggest`, `/api/facets`
- `/api/collections`, `/api/browse`, `/api/channels` (GET), `/api/brands`
- `/api/watch`
**Change:**
- Apply the same 403 "Kids is watching. Switch to Adult." as the Create routes.
- For `/api/watch`, also refuse a channel that `lockedOut` or `profileHides` would hide, whoever is watching.
- The companion remote routes (`/api/now`, `guide`, `catchup`, `tune`) already filter to visible channels and are unchanged.
**Tests:** a PhoneLink test with Kids current:
- each route returns 403
- with Adult current, each route returns 200
- `/api/watch` to an After Dark channel while locked returns 403
**Risk:** low. The phone's Create tab shows the Kids message instead of results while Kids is on. Undo: revert.
## 3. Safe file writes (A5)
**Today:**
- Schedules and bookings are already written safely: temporary file, then rename (`ScheduleStore.kt:75`).
- So are custom channels, Director decisions, Taste state and the workspace.
- These are written in place, so a power cut mid-write can leave a cut-short file that then reads as empty:
- Continue watching (`ContinueWatching.kt:81`)
- Chair learning (`ChairLearning.kt:108`)
- Event ideas (`EventIdeas.kt:278, 281, 299, 310`)
- the event-idea day file (`ChannelScheduler.kt:193`)
- the Director report cache (`DirectorChair.kt:338`)
- Unplayable (`Unplayable.kt:35, 39`)
- Evidence state (`EvidenceReader.kt:68`)
- Rooms sync merges (`Rooms.kt:103, 106, 112`)
- the Rooms one-time copy (`Rooms.kt:190, 204`)
- Append-only logs (Taste events, evidence, collections, playback notes) are lower risk: a cut-short last line is skipped when read. They stay as they are.
**Change:**
- One helper, `writeSafely(file, text)`, based on Android's `AtomicFile`: write to a temporary file, flush, `fsync`, then rename. If the rename fails, the old file is left untouched.
- Replace each call listed above with one line. No format changes.
- Taste's existing fallback (`Taste.kt:167`) moves to the helper too.
**Tests:**
- A failing write (a stream that throws halfway) leaves the old contents readable.
- Each converted store reads back what it wrote.
- The existing 700 tests pass unchanged.
**Risk:** low and mechanical. Undo: revert.
---
## Release checks for 0.108.105
- Release build, all unit tests and lint pass.
- Install downstairs first with the usual snapshot and comparison, including the single-main-screen check.
- Then upstairs, with your approval for each TV.
+71
View File
@@ -0,0 +1,71 @@
# Orbit TV: signing key backup and recovery
Written 8 November 2026 (audit finding U1 / S2). This file has no secrets in it: no key material and no passwords. It is safe to keep in git.
## Why it matters
Android installs an update only if it's signed with the same key as the installed copy. Every Orbit build on the downstairs and upstairs TVs is signed with one key.
If that key is lost, no future build can install over them. The only way forward would be to uninstall Orbit, which wipes everything on the TV, because `allowBackup` is off. A new key can't be swapped in later without the old one, because key rotation needs both.
## What must be backed up
| Item | Where it is now | Secret? | How to back it up |
|---|---|---|---|
| The keystore file | `orbit-tv/.tooling/android/debug.keystore` (2,618 bytes, PKCS12, created 31 Oct 2026) | **Yes**: holds the private key | Encrypted copies only (below) |
| Keystore password and key password | The standard Android debug-keystore defaults (both the same) | Treat as secret alongside the file | Password manager entry "Orbit TV signing key" |
| Key alias | `androiddebugkey` | No | This file and the password manager entry |
| Encryption passphrase for the backups | Chosen by Paul when the backups are made | **Yes** | Password manager only, never on the same USB stick |
### Public facts, for checking a recovered key (not secret)
- Certificate DN: `C=US, O=Android, CN=Android Debug`
- RSA 2048-bit, SHA256withRSA, valid 31 Oct 2026 to 23 Oct 2056
- Certificate SHA-256: `042f963772f0b6f8b983742287f9487d7e2cfc8491676966c60297d3390558e1`
- The installed 0.108.104 APK verifies with APK Signature Scheme v2 and this same certificate.
## Making the two encrypted offline backups (Paul does this, or approves it step by step)
Tools already on this PC: `gpg` (for AES-256 symmetric encryption) and `cryptsetup`.
1. **Choose a strong passphrase** (5 random words or more) and save it in the password manager, together with:
- the alias
- the keystore password note
- the certificate SHA-256 above
2. **Make one encrypted file.** gpg asks for the passphrase itself, so it never appears on the command line:
```bash
gpg --symmetric --cipher-algo AES256 --output ~/orbit-signing-key.p12.gpg /home/pauljd/Documents/OrbitTV/orbit-tv/.tooling/android/debug.keystore
```
3. **Backup 1:** copy `orbit-signing-key.p12.gpg` to USB stick A. Store the stick away from the PC.
4. **Backup 2:** copy the same `.gpg` file to a second offline place: USB stick B, or the password manager's file attachment if it encrypts end to end. Keep it somewhere other than stick A.
5. **Delete the working copy** in your home folder:
```bash
shred -u ~/orbit-signing-key.p12.gpg
```
The original keystore stays where it is.
## Checking recovery safely (do this once for each backup)
This decrypts into memory only (`/dev/shm`), compares, then wipes. It never writes the key to disk.
```bash
gpg --decrypt --output /dev/shm/orbit-check.p12 /media/<stick>/orbit-signing-key.p12.gpg
keytool -list -v -keystore /dev/shm/orbit-check.p12 -alias androiddebugkey | grep 'SHA256:'
shred -u /dev/shm/orbit-check.p12
```
**Pass** means the printed SHA256 matches `04:2F:96:37:72:F0:B6:F8:B9:83:74:22:87:F9:48:7D:7E:2C:FC:84:91:67:69:66:C6:02:97:D3:39:05:58:E1`. keytool asks for the keystore password.
## Restoring after a loss
1. Decrypt one backup to `orbit-tv/.tooling/android/debug.keystore`.
2. Run the check above against it.
3. Build as usual. `apksigner verify --print-certs` on the new APK must show the SHA-256 above before installing on a TV.
## Small hardening, optional and reversible
- The keystore file is currently readable by the group (`-rw-rw-r--`). Make it owner-only:
```bash
chmod 600 /home/pauljd/Documents/OrbitTV/orbit-tv/.tooling/android/debug.keystore
```
- **Later (audit S2):** create a dedicated release key and rotate to it with `apksigner rotate`. Back it up the same way first. Both TVs need Android 9 or later; downstairs is Android 14.
+97
View File
@@ -0,0 +1,97 @@
# Upstairs: Continue watching sync issue and the 0.108.104 upgrade plan
Prepared 8 November 2026. **Nothing has been installed.** Deployment waits for Paul's approval.
## Current state
**Upstairs version:**
- I couldn't read it live at 09:35. The TV didn't answer (no ping, no adb, no Orbit on port 8099), so it is probably off or asleep.
- The last install on record is **0.108.103**, at 23:02 on 7 November (`backups/upstairs-install-0.108.103-20261107-230239`).
- When the TV is on, confirm with:
```bash
adb -s <upstairs> shell dumpsys package tv.orbit.classic | grep versionName
```
or, with no adb needed:
```bash
curl http://192.168.0.195:8099/room/version
```
**Downstairs:** 0.108.104, installed at 09:16 on 8 November. Verified: one `MainActivity`, all 2,342 bookings unchanged, profiles unchanged, old Continue watching list set aside.
## The Continue watching sync issue (audit A3)
**What changed in 0.108.104:**
- Continue watching only records programmes watched in Catch Up, not live viewing.
- On first start, each TV sets aside its old lists, which were filled by live viewing, as `continue-<profile>.json.before-catchup-only`.
**The problem:**
1. **Version mismatch (temporary):** upstairs is still on 0.108.103, so it keeps adding live viewing to its Continue watching lists. Every 2 minutes while Orbit is open on both TVs, Rooms sync merges those lists into downstairs (`Rooms.kt:107-113`, union of both rooms keeping the newest mark). Live-viewing entries will reappear downstairs.
2. **No record of removals (lasting, in both versions):**
- Removing a programme from Continue watching on one TV isn't sent to the other. The other TV's copy brings it back at the next sync.
- The same applies, more weakly, to resetting Taste: only the last hour of events is re-sent, so the effect is limited.
**Impact:**
- No data loss.
- Continue watching downstairs may show programmes you watched live upstairs until upstairs is upgraded.
- Removals may not stick while both TVs are on.
**After the upstairs upgrade:**
- Upstairs sets aside its own old lists.
- Any live-viewing marks that already synced to downstairs stay there until removed, or until they leave Catch Up on their own. Catch Up cards only show while the programme is still in Catch Up, so they age out within the Catch Up window.
**Fix proposed for review (not started):**
- Removal records for Continue watching marks, in the same way profiles already have them.
- Taste's "reset at" time honoured by the merge.
- A format flag in the sync data, so TVs on different versions don't mix list formats.
Test: room A removes, room B still holds the mark, and after the merge neither has it.
## Upgrade plan (same procedure as downstairs, already proven today)
### Prepared and verified now
- `apks/orbit-tv-0.108.104.apk`: checksum OK, signed with the Orbit certificate (SHA-256 `042f9637…558e1`).
- `apks/orbit-tv-0.108.103.apk`, the rollback copy: checksum OK. It is byte-identical to the copy pulled from downstairs before today's install.
### On the day (after Paul approves), in order
1. **Connect.** Find the port with `adb mdns services` (wireless debugging on upstairs), then `adb connect`.
2. **Confirm the version.** It should report 0.108.103. If not, stop and re-plan.
3. **Pull the rollback copy** of the installed APK (`pm path`) and check its SHA-256 matches `orbit-tv-0.108.103.apk`.
4. **Before snapshot:** `INSTALL_SNAPSHOT do=snapshot` (retry if it reports "failed"), pull it to `backups/upstairs-install-0.108.104-<time>/before`, then `do=clear`.
5. **Arm rollback:** `do=rollback version=0.108.103`.
6. **Install:** `sha256sum -c`, then `install -r`, then `cmd package compile -m speed -f tv.orbit.classic`.
7. **Launch:** `am start`, wait 25 s.
8. **Single-copy check:** `dumpsys activity activities | grep -c 'Hist.*MainActivity'` must be **1**.
9. **After snapshot:** pull it.
10. **Compare:**
- bookings: every pre-existing entry identical
- decisions, history, tickets, choices, learning, yours, profiles: hashes unchanged
- Taste events unchanged
- `continue-*.json` moved to `.before-catchup-only` (expected)
11. **Prune** to the last 3 upstairs backups.
### Rollback, if any check fails: a gap found while preparing this
What exists today:
- A verified copy of the previous APK.
- A full `before` snapshot on the PC.
- An on-box copy of the schedules (`schedule-rollback-0.108.103`, made by step 5).
What doesn't:
- **A way to put the old version back while keeping the data.** Android 14 retail builds refuse an APK downgrade (`adb install -r -d`) for a non-debuggable app. The only route back to 0.108.103 is to uninstall, which deletes Orbit's data, and reinstall.
- **A tool to restore data.** The snapshot receiver only copies data out (`InstallSnapshot.kt`: "It only ever copies"). So after an uninstall, the snapshot can't currently be put back.
**What this means in practice:**
- A bad build can be fixed forward: build 0.108.105 with the fix and install it over the top. This keeps all data.
- A true "go back with data" path doesn't exist yet. That has been true for every install so far.
**Proposed, small and for review:** a `restore` command in the same adb-only receiver (DUMP permission), which copies a pulled snapshot back into place. It would be tested on downstairs with a throwaway change before we ever need it in earnest. Until it exists, the safety net is fix-forward plus the PC snapshot.
Downstairs keeps working on its own in the meantime.
### After the install
Leave both TVs on for one sync cycle (2 minutes), then:
- check downstairs still shows one `MainActivity`
- check its Continue watching has no new live-viewing entries