Add Constellation/STAR encryption for P3A by DJAndries · Pull Request #14399 · brave/brave-core (original) (raw)

Resolves brave/brave-browser#24338

Submitter Checklist:

Reviewer Checklist:

After-merge Checklist:

Test Plan:

Please test in a version that includes #18340 or #18410.

Access https://star-randsrv.bsg.brave.software/info and note the currentEpoch value.

Perform this first test without a MITM proxy (Nitro Enclave attestation will not work without proxy).

  1. Start browser with a fresh profile and the following flags: --enable-features="BraveP3AConstellation" --p3a-star-randomness-host=https://star-randsrv.bsg.bravesoftware.com --p3a-constellation-upload-url=https://collector.bsg.bravesoftware.com/
  2. Access local state, validate the following details: brave.p3a.approved_cert_fp should contain a value prefixed with sha256/, brave.p3a.current_epoch should contain the value noted above, brave.p3a.current_pk should contain a long string, brave.p3a.next_epoch_time should contain a numerical timestamp value, p3a.logs_constellation_prep should exist with the typical list of metrics/values/etc.
  3. Wait five minutes and reload local state page. p3a.constellation_logs.{epoch number} should contain a list of metrics with the name as the key, and the encrypted base-64 value as the value. A new log should appear in the list every minute. Verify that the relevant metrics in the p3a.logs_constellation_prep list indicate being sent.
  4. Quit the browser and add the following flag when restarting --p3a-fake-star-epoch=. Add one to the current epoch and append the value to the flag.
  5. Access local state, validate that the metrics still exist in p3a.constellation_logs.{original epoch number}.
  6. Wait five minutes and refresh the local state page. The Constellation logs object should contain less metric than before (because the encrypted metrics were uploaded to our server and no longer need to be stored).
  7. Repeat steps 0 - 2. Repeat step 3 with an epoch value that is 5 or more epochs ahead of the current epoch value. Access local state and ensure the metrics in p3a.constellation_logs.{original epoch number} do not exist (due to expiry).

Perform this second test using a MITM proxy, and add the --p3a-disable-star-attestation flag.

  1. Start browser with a fresh profile and using the flags mentioned in step 0 from the first test.
  2. Ensure that an /info request is sent to the randomness server.
  3. Wait a few minutes, ensure that /randomness requests are sent to the randomness server. Ensure that the number of metrics existing in the Constellation logs (in local state) matches the number of randomness requests sent. Ensure no requests are sent to the upload url.
  4. Quit the browser and relaunch, ensure that the info request is not sent (server info should be cached).
  5. Add the fake STAR epoch flag and relaunch the browser, add one to the current epoch like above.
  6. An /info request should be sent. Encrypted metrics should be uploaded to the upload URL after a few minutes. Randomness requests should fail since the current fake epoch is not valid.

Ensure JSON metrics are sent as usual with or without the Constellation feature enabled.