Skip to content

feat: prove WebRTC key bundles with OpenPubkey and Google sign-in - #9656

Draft
pjwerneck wants to merge 2 commits into
pjwerneck/webrtc-signaling-serverfrom
pjwerneck/webrtc-openpubkey
Draft

pjwerneck wants to merge 2 commits into
pjwerneck/webrtc-signaling-serverfrom
pjwerneck/webrtc-openpubkey

Conversation

@pjwerneck

Copy link
Copy Markdown
Collaborator

Summary

Stacked on #9654: the base branch is pjwerneck/webrtc-signaling-server.

  • When a user logs in with webrtc=True for the first time on a machine, Firebase previously sent a sign-in link to the email. Now the login prints the address of a Google consent page. The user signs in with the Google account of the email, then pastes the address of the http://localhost page that does not load. One consent gives the Firebase session and a Google ID token whose nonce commits to the key bundle of the user.
  • User-facing change: a WebRTC login now needs a Google account for the email. It still needs no Google Drive. The login, login_do and login_ds APIs do not change. The plan of feat: sync over WebRTC with Firebase signaling and no Google login (WIP) #9654 had "no Google account in WebRTC mode"; this PR changes that.
  • When a WebRTC login runs again on the same machine, it asks nothing. It asks for a new consent when the keys changed, or when Google no longer lists the key that signed the token. The login loads or creates the key file before the consent, and it refuses a Google account of another email.
  • When a client published its key bundle in WebRTC mode, it previously wrote the bundle at keys/{email}, and peers kept any value they found there. Now keys/{email} holds a key record: the bundle, the pk_token, nonce_rnd, and sig. sig is an Ed25519 signature over the pk_token by the identity key of the bundle.
  • The pk_token is the Google ID token with a GQ signature in place of Google's RSA signature, as in OpenPubkey. The GQ signature proves that Google signed the token, but Firebase does not accept the token as a sign-in. So a client publishes its record at once. A client never replaces a published record that holds other keys.
  • When a client reads the bundle of a peer, it previously kept it unchecked. Now GoogleOpenPubkeyAttestor checks the GQ signature with Google's keys, the issuer, the audience, the email and email_verified, the nonce, and sig. A bundle that fails a check is not kept, and the error names the check.
  • When a bundle fails its check, the other peers sync all the same. sync() raises UnprovenKeyBundleError at the end of its pass, with any background WebRTC error. add_peer and approve_peer_request finish the peering, then raise. A login prints the peers and returns the client.
  • New: syft/sync/connections/webrtc/firebase/gq.py makes and checks GQ signatures for RS256 tokens. database.rules.json accepts only a record with the four string fields at keys/{email}. infra/firebase/README.md has the console steps for the sign-in with Google.
  • syft now declares pyjwt>=2.8.0 and cryptography>=38.0.3. Both were already installed through google-auth[pyjwt].

Guidelines

High level

  • 🟢 Split: the login, the key record, the attestor and the publication serve one flow. In that flow, a peer proves that its key bundle belongs to its email.
  • 🟢 Size: this PR proves each WebRTC key bundle with a Google-signed token before a peer uses the bundle.

Mid level

  • 🟢 User-facing code
  • 🟢 Error handling
  • 🟢 State versioning
  • 🟢 Function structure
  • 🟢 Tests

Low level

  • 🟢 Naming
  • 🟢 Code style

Security

  • Before, a peer kept the first bundle it read at keys/{email}, so the admins of the project could swap a bundle. Now a peer keeps a bundle only if a Google-signed token commits to it, and the identity key of the bundle signed that token. An admin cannot make Google's signature, so an admin cannot swap a bundle.
  • A test on the real project showed that Firebase accepts a bare Google ID token as a sign-in, until the token expires. Every signed-in user can read keys/. So the published pk_token has a GQ signature, a zero-knowledge proof of Google's signature. Firebase refuses it as a sign-in.
  • The raw Google ID token stays in memory. The attestation file holds the GQ form, and only the user can read it.
  • The audience must be the OAuth client of the sign-in of the project, so tokens that Google issued to other apps are refused.
  • Limit: when Google no longer lists the key that signed a pk_token, new peers cannot check that record until its owner logs in again. Bundles that peers already kept stay in use. infra/firebase/README.md explains this.
  • Admins can still delete records, which stops new peering. They cannot make a peer use a swapped bundle.

Testing

  • The unit tests for GQ signatures are in tests/unit/webrtc/test_gq.py. A GQ token proves the signature of the issuer, and PyJWT refuses it as an RS256 token. Another payload, a truncated signature, or a token of another signer is refused.
  • Unit tests for the attestor (tests/unit/webrtc/test_key_attestation.py): one test for each failed check, plus an expired token and a token issued ahead of the local clock, which are accepted. Other unit tests cover the attestation file, the peering config, and an unproven peer bundle in sync, login and add_peer.
  • The emulator tests in tests/integration/webrtc/ cover the login with a stand-in for Google, and the keys/ rules. They also cover a bundle that a project admin swaps, a record published at once, and a record of other keys that is not replaced. The job flow of a DO and a DS runs from end to end.
  • For each check of the attestor and the GQ verifier, a test fails when the check is removed.
  • On the real project, createAuthUri puts our nonce in the Google ID token. In a live test on two machines, a DO with a Google Workspace account and a DS with a Gmail account logged in with encryption=True. Both records went out at once. Their GQ signatures passed the attestor against Google's real keys. Each side kept the bundle of the other, and an encrypted job ran.
  • The new rules are deployed to webrtc-transport-for-pysyft. The clients of feat: sync over WebRTC with Firebase signaling and no Google login (WIP) #9654 write a bundle string at keys/{email}, so these rules refuse their add_peer there.
  • Not tested yet: a login on Colab.

Asana task

https://app.asana.com/1/1185126988600652/project/1220031667339032/task/1219404478719095

A WebRTC login now signs in with Google through Firebase Auth, in place of
the emailed link. One consent gives the Firebase session and the pk_token, a
Google ID token whose nonce commits to the key bundle of the user. keys/{email}
holds the bundle, the pk_token, nonce_rnd and a signature by the identity key
of the bundle. A peer checks all of them before it pins a bundle, so the
admins of the project cannot swap one.

Firebase accepts a pk_token as a sign-in until it expires, so a client
publishes its record one hour after the consent. A record of other keys is
never replaced. A peer whose record fails its check is skipped, and sync
raises the failure at its end. syft now declares pyjwt>=2.9.0 and
cryptography.
A Google ID token signs anyone in to Firebase until it expires. So a key
record that held it waited one hour before it went out. The client now
replaces Google's RSA signature with a GQ signature, a zero-knowledge proof
that Google signed the token. Peers check the proof with Google's key, but
Firebase refuses the token as a sign-in. So a client publishes its record at
once, and the raw ID token never reaches disk.

A peer record fails its check, for example once Google retires the key that
signed it. Login now prints such peers and returns the client. add_peer and
approve_peer_request finish the peering before they raise. sync() raises
background WebRTC errors with the bundle errors, so neither hides the other.
syft pins pyjwt>=2.8.0.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant