Repository navigation
feat: prove the private key when taking a device over - #123
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
takeOverDevice,EnrolAsyncbuildstakeover:<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 askeySignature. This matchestakeoverStatementandsignedWithKeyin Fellowship'sdevices.ts.uid(sub, oruser_idif there is nosub) andauth_timecome 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.keyProved: false. A signature the server rejects comes back asfellowship_key_mismatch, which Link already answers by enrolling as new.EnrolmentRequest.TakeOverPrivateKey(PKCS#8 PEM), set byMessageBackup.AimedAtHeldDevicefrom the held backup. It is only used to sign, and never sent.EnrolmentRequest.ToStringnow prints only the platform, label and takeover device id. Before, the default record printing would also have shownPassword.Follow-up
Piece 4b in Fellowship makes the signature required once this release is out.
Fixtures/takeover-signature-vector.jsonis 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'scrypto.verifyusingsignedWithKey'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 theauth_timeor device id changes. The private key appears in no request. A token with onlyuser_idstill 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.ToStringprints 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.