Skip to content

feat: prove the private key when taking a device over - #123

Merged
crazeydave merged 1 commit into
mainfrom
claude/gallant-carson-3f5237
Nov 29, 2026
Merged

crazeydave merged 1 commit into
mainfrom
claude/gallant-carson-3f5237

Conversation

@crazeydave

Copy link
Copy Markdown
Contributor

Stage 5, piece 4a. The Functions side is bleedingdeacons/fellowship#75, which is deployed and already accepts keySignature.

Why

Restoring a backup on a new phone takes its old device over with takeOverDevice. The Function only checked that the public key matched the device's. Every sender is handed that public key, so the check proved nothing. Now the phone also proves it holds the private key.

What changes

  • The signature. Before calling takeOverDevice, EnrolAsync builds takeover:<deviceId>:<uid>:<auth_time> and signs its UTF-8 bytes with the backup's private key: RSA-PSS, SHA-256, salt as long as the hash (RSASignaturePadding.Pss). It sends the base64 as keySignature. This matches takeoverStatement and signedWithKey in Fellowship's devices.ts.
    • uid (sub, or user_id if there is no sub) and auth_time come from the identity sign-in's ID token, the one sent with the call, not from the device. A signature therefore can't be reused for another sign-in. The token is only decoded here; Firebase verifies it.
    • If the key or the token can't be read, no signature is sent and a warning is logged, without the key or the token. Fellowship still accepts that, and records it as keyProved: false. A signature the server rejects comes back as fellowship_key_mismatch, which Link already answers by enrolling as new.
  • EnrolmentRequest.TakeOverPrivateKey (PKCS#8 PEM), set by MessageBackup.AimedAtHeldDevice from the held backup. It is only used to sign, and never sent.
  • EnrolmentRequest.ToString now prints only the platform, label and takeover device id. Before, the default record printing would also have shown Password.

Follow-up

Piece 4b in Fellowship makes the signature required once this release is out. Fixtures/takeover-signature-vector.json is one public key, statement and signature made by .NET, for 4b's emulator tests to verify. It holds no private key. I've already checked it verifies with Node's crypto.verify using signedWithKey's settings.

Tests

  • FirebaseFellowshipClientTests: the signature verifies against the backup's public key for exactly that statement. It fails if the uid is swapped for the device's, or if the auth_time or device id changes. The private key appears in no request. A token with only user_id still works. An enrolment with no takeover sends no signature. A key or token that can't be read takes over without a signature. A refused signature enrols as new. ToString prints neither secret. The cross-check vector verifies.
  • MessageBackupTests: the held backup's private key is passed through. A held key that can't be read leaves the request alone, so the phone enrols as new.
  • Local runs: Tests 680/680, Specs 229 passed and 43 skipped as before. The app project is unchanged, so no Android build was run.
  • Not tried against /amber or on a phone yet.

Restoring a backup on a new phone takes its old device over. The server
only checked that the public key matched, and every sender is handed the
public key, so that proved nothing. Link now signs
takeover:<deviceId>:<uid>:<auth_time> with the backup's private key and
sends it as keySignature. uid and auth_time come from the identity
sign-in's ID token, so a signature can't be reused for another sign-in.

If the key or the token can't be read, no signature is sent and the
takeover goes ahead unproven, which Fellowship still accepts for now.
EnrolmentRequest.ToString no longer prints the password or the key.
@crazeydave
crazeydave merged commit 6b6aa29 into main Nov 29, 2026
10 checks passed
@crazeydave
crazeydave deleted the claude/gallant-carson-3f5237 branch November 29, 2026 02:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant