# Signed updates (/docs/updates/signing)



With signed updates, a compromised server, a leaked API token or a mistake on our side still can't push code to your users: apps only install updates signed with **your** private key, and Liftbay only ever holds the public certificate.

Signing works with all three clients: expo-updates, hot-updater and CodePush.

## Set up [#set-up]

Run this once in your app's folder:

```sh
npx liftbay update signing init
```

<Steps>
  <Step>
    It creates an RSA 2048 key pair and a self-signed code signing certificate (valid 10 years), the same kind `expo-updates codesigning:generate` makes.
  </Step>

  <Step>
    The **private key** goes to `keys/liftbay-private-key.pem`, readable only by you, and `keys/` is added to `.gitignore`. The **certificate** goes to `certs/liftbay-certificate.pem`; commit it.
  </Step>

  <Step>
    The certificate is registered with Liftbay, with a signature proving you hold the private key.
  </Step>

  <Step>
    `app.json` gets `"codeSigningCertificate": "./certs/liftbay-certificate.pem"` in the Liftbay plugin options, so expo-updates embeds the certificate in your app.
  </Step>

  <Step>
    Optionally, every channel is set to **signed updates only**.
  </Step>
</Steps>

Then **rebuild your apps once**: the certificate is part of the binary.

<Callout type="warn" title="Back up the private key">
  Keep a copy of `keys/liftbay-private-key.pem` somewhere safe, like a password manager. If it's lost, you need a new key and a new build of your apps; Liftbay can't recover it because it never has it.
</Callout>

## Publish [#publish]

`liftbay update publish` signs automatically when it finds the key:

| Source                         | Use                                        |
| ------------------------------ | ------------------------------------------ |
| `--private-key <file>`         | An explicit path                           |
| `LIFTBAY_UPDATE_PRIVATE_KEY`   | CI: the PEM itself as a secret (or a path) |
| `keys/liftbay-private-key.pem` | The default written by `signing init`      |

Publishing becomes two steps, done for you by the CLI: Liftbay prepares the exact bytes each client will verify, your machine signs them, and Liftbay checks every signature against the certificate before the release goes live. A signature made with any other key is rejected, so a wrong key can never ship.

## What gets signed [#what-gets-signed]

| Client          | Signed bytes                                                                     | How the app checks                                                                                          |
| --------------- | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| expo-updates    | The manifest JSON, and the `noUpdateAvailable` / `rollBackToEmbedded` directives | `expo-signature` header, verified with the embedded certificate                                             |
| hot-updater 1.x | The SHA-256 of the bundle manifest, and of each file                             | `manifestFileHash: "sig:…"` and each file's `signature` in the manifest, verified with the app's public key |
| hot-updater 0.x | The SHA-256 of the bundle zip                                                    | `fileHash: "sig:…"`, verified with the app's public key                                                     |
| CodePush        | A JWT with the package hash                                                      | `CodePush/.codepushrelease` in the package, verified with the app's public key                              |

Asset files are covered too: their hashes are in the signed manifest or package.

## Signed updates only [#signed-updates-only]

On a channel set to **signed updates only** (dashboard: the channel's **Signed updates** card), unsigned publishes are refused and only signed releases are served. Apps that send `expo-expect-signature` only ever receive signed releases, on any channel.

Apps built before signing was set up don't check signatures, so they keep receiving signed releases normally.

## hot-updater and CodePush [#hot-updater-and-codepush]

`signing init` also writes the public key to `certs/liftbay-public-key.pem`. Add it to your app's native config:

| Client      | iOS (`Info.plist`)       | Android                                                                                             |
| ----------- | ------------------------ | --------------------------------------------------------------------------------------------------- |
| hot-updater | `HOT_UPDATER_PUBLIC_KEY` | `<meta-data android:name="com.hotupdater.PUBLIC_KEY" android:value="…" />` in `AndroidManifest.xml` |
| CodePush    | `CodePushPublicKey`      | `CodePushPublicKey` string resource (`moduleConfig="true"`)                                         |

## Replace or remove the key [#replace-or-remove-the-key]

* `liftbay update signing init --force` creates a new key and certificate. Apps built with the old certificate reject updates signed with the new key until they're rebuilt.
* Removing the certificate (`DELETE /updates/signing` in the API) turns off signed-only on every channel. Apps built with the certificate keep rejecting unsigned updates until rebuilt without it.
