Patch Signing
Patch signing makes your app check that every patch it downloads carries a signature matching a public key built into your release, and refuse any patch that doesn’t. Someone who can tamper with your users’ network traffic can’t produce that signature, so they can’t push code to your app.
Starting with Shorebird CLI 1.6.132, every new release is signed by default, with a key Shorebird manages for your organization. There are three modes:
| Mode | How you choose it | Who holds the private key |
|---|---|---|
| Managed (default) | shorebird release with no key flags | Shorebird, in Google Cloud KMS |
| Self-managed | --public-key-path or --public-key-cmd on release, a private key on patch | You |
| Unsigned | --no-patch-signing on release | No one: patches aren’t signed at all |
The mode is fixed when you release each platform, because the public key is built into the release. To change it, make a new release. There are no changes to your code in any mode.
Releases made with an older CLI, without a key, are unsigned. Patches to them stay unsigned and keep installing. To protect an app made that way, update the CLI and make a new release; you don’t need to change your Flutter version.
Managed signing
Section titled “Managed signing”Managed signing is the default. To turn it on for an app, update the Shorebird CLI and make a new release:
The release summary shows which key the release uses:
Patch as usual with shorebird patch. Shorebird signs each patch for you.
How it works
Section titled “How it works”- Shorebird creates a signing key for your organization in
Google Cloud KMS the first time
shorebird releaseneeds one. The private key never leaves KMS: Cloud KMS doesn’t let anyone export it, including Shorebird. shorebird releasefetches the organization’s public key from Shorebird and builds it into the release, the same way--public-key-pathdoes.shorebird patchbuilds the patch with the same public key, so it matches the release. When the patch is uploaded, Shorebird’s servers sign it with the matching private key. A patch to a managed release is never published unsigned: if it can’t be signed, the upload fails.- Each release keeps the key it was built with, and every patch to it is signed with that key.
- Your app verifies signatures exactly as it does for self-managed keys. See Test and verify signed patch.
Patching a managed release takes no key flags. If you pass --public-key-path,
--public-key-cmd, --private-key-path, or --sign-cmd, shorebird patch
stops before uploading and names the flags to remove. A CLI older than 1.6.132
can’t patch a managed release; it tells you to run shorebird upgrade.
If shorebird release can’t get the signing key from Shorebird, the release
fails rather than going out unsigned. Run it again. If you can’t wait, you can
turn signing off for that release, but it stays unsigned
for good: every patch to it is unsigned, and only a new release turns signing
back on.
What managed signing protects against
Section titled “What managed signing protects against”Managed signing protects against anyone between your users and Shorebird. It doesn’t protect against someone who controls Shorebird itself. If you need that, use self-managed signing.
| An attacker who… | Managed | Self-managed | Unsigned |
|---|---|---|---|
| Controls your users’ network, including with a fraudulent TLS certificate | Protected | Protected | Not protected |
| Can change patch files in storage or on the CDN, but not Shorebird’s API | Protected | Protected | Protected |
| Compromises Shorebird’s servers or signing service | Not protected | Protected | Not protected |
| Compromises Google Cloud | Not protected | Protected, unless your key is in Google Cloud | Not protected |
| Has your Shorebird credentials (an account, API key, or CI token) and publishes a patch | Not protected | Protected, unless they have your private key | Not protected |
Unsigned apps are protected in the second row because your app already rejects a patch whose contents don’t match the hash Shorebird’s API returned for it. Signing adds protection when the attacker can also change what the API returns, as in the first row.
In short, managed signing moves your app’s trust from the network and every certificate authority your app trusts to Shorebird and Google. Self-managed signing removes Shorebird and Google from it too.
Switch to your own key
Section titled “Switch to your own key”To move an app from managed signing to your own key, make a new release with
--public-key-path or --public-key-cmd, as in
Self-managed signing. Releases you made with managed
signing keep receiving signed patches. Managed keys can’t be exported, so you
can’t take your existing managed key with you.
Turn signing off
Section titled “Turn signing off”You can release without signing, though it leaves your app open to the attacks above:
Patches to that release are unsigned, as before 1.6.132. You can’t combine
--no-patch-signing with --public-key-path or --public-key-cmd.
Self-managed signing
Section titled “Self-managed signing”With self-managed signing, you sign patches with your own key, so no one, including Shorebird, can change the content of your patches without your private key.
Signing works in two parts. First, shorebird release takes a
--public-key-path or --public-key-cmd argument to embed your public key in
your released application. The
Shorebird updater only loads patches
signed with the corresponding private key.
Second, when you build your patch with shorebird patch, you pass
--private-key-path or --sign-cmd to sign your patch with your private key.
This is required for a release created with your public key.
You will need an RSA key pair. Shorebird supports RSA keys in PEM format, both PKCS#1 and PKCS#8.
Generate keys
Section titled “Generate keys”If you do not already have an RSA key pair you’d like to use, you can generate a
pair with openssl:
The above operation will generate a public/private key pair in private.pem and
a public key in public.pem. The file containing the private key should be
stored securely and kept secret. While the private key is not itself sufficient
to make an update to your application (someone would also need access to your
Shorebird credentials), it should not be checked into public source control.
Key storage
Section titled “Key storage”If you don’t want to store keys yourself, use managed signing. If you are using self-managed keys, using a cloud key management service instead of just storing keys on disk is highly recommended. If for any reason you were to lose your private key, there is no way to create a patch for an application containing the corresponding public key. Even Shorebird is not able to create a patch for your application without your private key. In such a case, you would need to make and distribute a new release of your application to send patches to it.
Shorebird does support command-based signing for integration with cloud key management services (HashiCorp Vault, GCP Cloud KMS, AWS KMS, Azure Key Vault), hardware security modules (HSMs), and secrets managers (1Password, etc.). Please ensure you are using at least v1.6.81 or greater to use this feature.
See Cloud KMS Examples below for integration examples with popular services.
Create a signed release
Section titled “Create a signed release”To create a release that requires signed patches, run the following command:
This will include the public key in the release artifact produced by
shorebird release and cause the released app to require signed patches.
Create a signed patch
Section titled “Create a signed patch”To create a signed patch, run the following command:
This tells Shorebird to sign the patch with the key pair you provided.
Patch a release signed with your own key
Section titled “Patch a release signed with your own key”If shorebird patch stops before building with exit code 64 and this message,
the release embeds your public key but the patch command didn’t pass a key pair:
Run the patch again with the same public key the release used and its private key, as in Create a signed patch.
Shorebird 1.6.135 and newer make this check for releases built with Shorebird 1.6.132 or newer. For older releases, or with an older CLI, nothing stops the patch, and devices on the release refuse it because it has no valid signature (see Fallback behavior).
Test and verify signed patch
Section titled “Test and verify signed patch”This works the same for managed and self-managed signing. You can verify that
the patch is properly signed using shorebird preview. On the first launch, you
should see something like the following in your app logs:
If you close and relaunch your app, you should see this message telling you that the patch’s signature was verified:
If the patch is missing a signature, or fails signature verification for any reason, Shorebird will not load it, and will instead use any previously installed and verifiable patch (if there is one) or the unpatched release version of your app.
With self-managed signing, you can also test the missing signature behavior
(managed releases refuse these patches before they’re published). Create a patch
without a private key and notice that shorebird preview rejects it. Similarly,
you can create a patch with a different private key to do the same.
Fallback behavior
Section titled “Fallback behavior”Releases that contain a public key will reject all unsigned patches. If a patch is missing a signature or its signature is invalid, Shorebird will reject this patch at boot time. It will instead boot from the last known good patch (if still on disk) or the release build of the app. This will not cause your app to crash.
Trade-offs
Section titled “Trade-offs”Signature verification, managed or self-managed, adds a small overhead at app
launch. During testing this has been observed to be under 50ms with a
medium-sized app on a 5-year-old Android phone. This overhead increases with
application size. For very large apps, if this overhead shows up on your
benchmarks, you can set patch_verification: install_only in shorebird.yaml
to verify signatures only when patches are installed rather than on every
launch.
Cloud KMS examples
Section titled “Cloud KMS examples”The following examples show how to integrate Shorebird patch signing with
popular key management services using --public-key-cmd and --sign-cmd.