Files
stitch/docs/SIGNING.md
T

136 lines
6.6 KiB
Markdown

# The Stitch signing key
> **Short version:** a proper release key now exists at `~/.stitch-release-key/`. **Back that folder up
> off this machine today.** Nothing uses it yet — builds still use the old debug key on purpose, because
> switching keys forces an uninstall. The switch happens once, deliberately, in the order below.
---
## Why any of this matters
Android refuses to install an app over one signed with a different key. It is a security rule and there
is no way around it. So the key a release is signed with decides whether a future update can install
over your phone's copy of Stitch, or whether you have to uninstall first — which erases your API key,
wake phrase, notes, memories and reminders.
Until now, every Stitch release has been signed with **this machine's Android debug key**
(`~/.android/debug.keystore`). That worked, but it is the wrong key for something you rely on:
- It is a throwaway key the Android tools generate automatically, and any tool can regenerate it.
- It expires. Debug keys are valid for 30 years from creation, but they are not treated as durable.
- If this machine is ever reinstalled and that file is lost, you can never update Stitch again without
uninstalling it first.
## The new key
| | |
|---|---|
| Location | `~/.stitch-release-key/stitch-release.jks` |
| Password file | `~/.stitch-release-key/keystore.properties` (permissions `600`) |
| Alias | `stitch` |
| Algorithm | RSA 4096, SHA384withRSA |
| Valid until | 16 September 2056 |
| SHA-256 | `79:43:B9:19:BA:DC:EC:CE:F7:C3:67:84:D6:E8:26:8E:7A:54:74:66:06:11:20:37:34:D6:37:9B:21:54:EE:9C` |
The password was randomly generated and is stored beside the keystore. That is a deliberate trade-off
for a personal, single-user, sideloaded app: the folder is `700`, both files are `600`, and the real
risk here is losing the key, not someone stealing it off your own machine.
### Back it up now
The whole folder, somewhere that is not this machine — an encrypted drive, a password manager's file
attachment, or private cloud storage:
```sh
tar czf stitch-release-key-backup.tar.gz -C ~ .stitch-release-key
```
If you lose it, every future Stitch update requires an uninstall. The key cannot be regenerated —
a new key with identical details is still a different key to Android.
### Keeping it in Bitwarden (free plan works)
Free Bitwarden accounts can't attach files, so the key file goes in as text inside a **Secure Note**.
It is 4,360 bytes, about 5,800 characters as text, well under a note's 10,000-character limit.
In a terminal on this machine (your own terminal, so the password doesn't end up in a chat log):
```sh
cat ~/.stitch-release-key/keystore.properties # the passwords and alias
base64 -w0 ~/.stitch-release-key/stitch-release.jks # the key file, as one long line of text
```
In Bitwarden: **New → Secure note**, name it `Stitch release signing key`, and add:
| Field (type) | Value |
|---|---|
| `storePassword` (hidden) | from `keystore.properties` |
| `keyPassword` (hidden) | from `keystore.properties` |
| `keyAlias` (text) | `stitch` |
| `jks-base64` (hidden) | the whole base64 line |
| `sha256` (text) | `91ce998bf62f677b43de1890b4953f0576ed1ebc328eefde301517c58d5164cd` |
**To restore** on a new machine: paste the base64 line into a file, then
```sh
mkdir -p ~/.stitch-release-key && chmod 700 ~/.stitch-release-key
base64 -d pasted.txt > ~/.stitch-release-key/stitch-release.jks
sha256sum ~/.stitch-release-key/stitch-release.jks # must equal the sha256 field above
```
and recreate `keystore.properties` from the two passwords and the alias (same four lines as today:
`storeFile`, `storePassword`, `keyAlias`, `keyPassword`; `storeFile` is the full path to the `.jks`).
## How the build uses it
It does not, yet. In `app/build.gradle.kts`:
```kotlin
val useReleaseKey = project.hasProperty("releaseKey") && releaseKeyProps.exists()
```
- `./gradlew assembleRelease` → **debug key** (unchanged; installs over your current Stitch)
- `./gradlew assembleRelease -PreleaseKey` → **release key** (will NOT install over your current Stitch)
Verify either one without building:
```sh
./gradlew :app:signingReport # Store: ~/.android/debug.keystore
./gradlew :app:signingReport -PreleaseKey # Store: ~/.stitch-release-key/stitch-release.jks
```
## The cutover — do these in order
Doing this out of order loses your data. That is the entire reason the backup feature was built first.
1. **Back up the key folder** off this machine (above).
2. On the phone: **Settings → Backup & restore → Save a backup.** Choose a passphrase, write it down,
and put the file somewhere that is not the phone.
3. **Check the backup is real** — open the file and confirm it is a few KB of JSON with
`"format": "stitch-backup"` at the top. An empty or missing file means stop.
4. Build the changeover release: `./gradlew assembleRelease -PreleaseKey`, copy to `dist/`, verify the
version with `aapt dump badging`.
5. On the phone: **uninstall Stitch.** Everything is erased at this point — this is the moment the
backup exists for.
6. Install the new APK.
7. **Settings → Backup & restore → Restore from a backup**, pick the file, type the passphrase.
8. Close and reopen Stitch.
9. Re-grant the special permissions — accessibility (Phone control), notification access, Do Not
Disturb and "modify system settings". **Android does not restore these**, and no app can grant them.
The backup cannot help here; it is a one-off cost of the changeover.
10. Check: does the wake phrase still wake it? Does the AI provider still answer? Are your notes and
reminders there?
11. From then on, always build with `-PreleaseKey`, and updates install over the top as before.
Until step 4 happens, keep building **without** the flag.
## If something goes wrong
| Problem | What to do |
|---|---|
| "App not installed" when installing the new APK | The old Stitch is still there. Uninstall it first (step 5) |
| Restore says the passphrase is wrong | AES-GCM cannot tell a wrong passphrase from a damaged file. Re-copy the file from wherever you stored it and try again. There is no recovery without the passphrase |
| Restored, but the AI provider doesn't work | The API key restores, but check Settings → AI & provider → Test connection. If the key looks empty, paste it again |
| Restored, but the wake phrase never triggers | The fingerprints restore, but the listening service needs a restart — close and reopen Stitch. If it still misses you, retrain (5 recordings) |
| On-device model gone | Expected. Model files are gigabytes and are not in the backup. Download it again in Settings → On-device model |