Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Constellation/STAR encryption for P3A #14399

Merged
merged 32 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
421f611
Add P3A STAR functionality
DJAndries Jun 7, 2022
0481c4d
Add nitro enclave attestation functionality, update rust deps
DJAndries Jul 20, 2022
46a2379
Compare TLS cert of randomness requests to cert approved by attestati…
DJAndries Jul 22, 2022
08d672e
Split up STAR randomness manager, misc fixes, add logging
DJAndries Jul 26, 2022
ce82819
Add unit tests for COSE parsing and P3A log stores, small log store fix
DJAndries Jul 27, 2022
a85bc9c
Add P3A message manager & star unit tests, misc fixes
DJAndries Jul 28, 2022
02b1173
Update Rust deps, fix nested star panics + example
DJAndries Aug 1, 2022
164af6d
Include only major/minor version numbers in P3A message, update crypt…
DJAndries Oct 26, 2022
8539a90
Remove nested star cargo config, use make_unique when possible
DJAndries Nov 1, 2022
b24be12
Add iOS P3A STAR switches, use make_unique where possible
DJAndries Nov 7, 2022
3fff570
Rename "nested_star" to "constellation"
DJAndries Nov 23, 2022
bb1e797
Update ECDSA related patches
DJAndries Nov 23, 2022
b1118a6
Update rust dependencies, update json parser unit test case
DJAndries Nov 23, 2022
0612953
Add comments for Nitro attestation serial number validation disabling…
DJAndries Nov 29, 2022
3074f0e
Add feature for STAR which is disabled by default, for the purpose of…
DJAndries Dec 8, 2022
df1d8c6
Update copyright notices
DJAndries Dec 8, 2022
c1d1884
Update rust deps and ECDSA related patch, fix presubmit errors
DJAndries Jan 4, 2023
95e72b2
Updating constellation dep, fix rebase issues
DJAndries Jan 25, 2023
3e9279a
Constellation updates from PR feedback
DJAndries Feb 1, 2023
73a101c
Misc Constellation/P3A enhancements from PR feedback
DJAndries Feb 3, 2023
38143b2
Remove BraveP3A prefix from P3A classes, renamed 'brave' namespace to…
DJAndries Feb 4, 2023
de174ee
Replace P3A unique_ptr reset calls with std::make_unique or setting t…
DJAndries Feb 4, 2023
300bfe8
Fix P3A slow unit test, fix P3A iOS build
DJAndries Feb 7, 2023
3a2ba29
Update Constellation crate, fix presubmit errors/rebase glitches
DJAndries Feb 18, 2023
94816f1
P3A STAR feedback iteration/misc changes
DJAndries Mar 8, 2023
1f939ce
Reduce brave_p3a_enabled buildflag usage, check for existence of p3a …
DJAndries Mar 16, 2023
d182e27
Replace nitro_utils-related crypto patches with chromium_src overrides
DJAndries Mar 27, 2023
ef7b8fe
Use WeakPtr in StarRandomnessMeta attestation verification callback
DJAndries Mar 29, 2023
a836ffd
Constellation feedback updates, revert Rust transitive dependency upd…
DJAndries Mar 31, 2023
128b6f4
Move constellation crate dependency DEPS, misc P3A constellation feed…
DJAndries Mar 31, 2023
9e5680d
Rename all "star" references to "constellation", with exception of th…
DJAndries Apr 3, 2023
e548e0e
Update constellation, update constellation unit tests for invalid res…
DJAndries Apr 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ patches/**/*.patchinfo
/third_party/argon2/src
/third_party/ethash/src
/third_party/bitcoin-core/src
/third_party/constellation/crate
/third_party/playlist_component/src
/third_party/rapidjson/src
/third_party/rust/cxx
Expand Down
1 change: 1 addition & 0 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ deps = {
'dep_type': 'cipd',
},
"third_party/playlist_component/src": "https://github.com/brave/playlist-component.git@5434730bf7342f1ba5c057f1640882bb38604a85",
"third_party/constellation/crate": "https://github.com/brave/constellation.git@b6b8396abd98cc87a187e051c32a291c9faa43f7",
}

recursedeps = [
Expand Down
12 changes: 6 additions & 6 deletions browser/brave_browser_main_extra_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "base/metrics/histogram_macros.h"
#include "brave/browser/brave_browser_process_impl.h"
#include "brave/components/brave_shields/browser/brave_shields_p3a.h"
#include "brave/components/p3a/brave_p3a_service.h"
#include "brave/components/p3a/buildflags.h"
#include "brave/components/p3a/p3a_service.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/prefs/pref_service.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
Expand Down Expand Up @@ -72,11 +72,11 @@ void BraveBrowserMainExtraParts::PostBrowserStart() {

void BraveBrowserMainExtraParts::PreMainMessageLoopRun() {
// Disabled on mobile platforms, see for instance issues/6176
#if BUILDFLAG(BRAVE_P3A_ENABLED)
// TODO(iefremov): Maybe find a better place for this initialization.
g_brave_browser_process->brave_p3a_service()->Init(
g_browser_process->shared_url_loader_factory());
#endif // BUILDFLAG(BRAVE_P3A_ENABLED)
if (g_brave_browser_process->p3a_service() != nullptr) {
// TODO(iefremov): Maybe find a better place for this initialization.
g_brave_browser_process->p3a_service()->Init(
g_browser_process->shared_url_loader_factory());
}

RecordInitialP3AValues();

Expand Down
7 changes: 5 additions & 2 deletions browser/brave_browser_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

namespace brave {
class BraveReferralsService;
class BraveP3AService;
class BraveFarblingService;
class URLSanitizerComponentInstaller;
} // namespace brave
Expand Down Expand Up @@ -67,6 +66,10 @@ namespace ntp_background_images {
class NTPBackgroundImagesService;
} // namespace ntp_background_images

namespace p3a {
class P3AService;
} // namespace p3a

namespace tor {
class BraveTorClientUpdater;
class BraveTorPluggableTransportUpdater;
Expand Down Expand Up @@ -112,7 +115,7 @@ class BraveBrowserProcess {
#if BUILDFLAG(ENABLE_IPFS)
virtual ipfs::BraveIpfsClientUpdater* ipfs_client_updater() = 0;
#endif
virtual brave::BraveP3AService* brave_p3a_service() = 0;
virtual p3a::P3AService* p3a_service() = 0;
virtual brave::BraveReferralsService* brave_referrals_service() = 0;
virtual brave_stats::BraveStatsUpdater* brave_stats_updater() = 0;
virtual brave_ads::BraveStatsHelper* ads_brave_stats_helper() = 0;
Expand Down
28 changes: 17 additions & 11 deletions browser/brave_browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@
#include "brave/components/https_upgrade_exceptions/browser/https_upgrade_exceptions_service.h"
#include "brave/components/misc_metrics/menu_metrics.h"
#include "brave/components/ntp_background_images/browser/ntp_background_images_service.h"
#include "brave/components/p3a/brave_p3a_service.h"
#include "brave/components/p3a/buildflags.h"
#include "brave/components/p3a/histograms_braveizer.h"
#include "brave/components/p3a/p3a_config.h"
#include "brave/components/p3a/p3a_service.h"
#include "brave/services/network/public/cpp/system_request_handler.h"
#include "build/build_config.h"
#include "chrome/browser/component_updater/component_updater_utils.h"
Expand Down Expand Up @@ -119,11 +120,11 @@ BraveBrowserProcessImpl::BraveBrowserProcessImpl(StartupData* startup_data)
brave_referrals_service();

// Disabled on mobile platforms, see for instance issues/6176
#if BUILDFLAG(BRAVE_P3A_ENABLED)
// Create P3A Service early to catch more histograms. The full initialization
// should be started once browser process impl is ready.
brave_p3a_service();
histogram_braveizer_ = brave::HistogramsBraveizer::Create();
p3a_service();
#if BUILDFLAG(BRAVE_P3A_ENABLED)
histogram_braveizer_ = p3a::HistogramsBraveizer::Create();
#endif // BUILDFLAG(BRAVE_P3A_ENABLED)

// initialize ads stats helper
Expand Down Expand Up @@ -361,15 +362,20 @@ void BraveBrowserProcessImpl::OnTorEnabledChanged() {
}
#endif

brave::BraveP3AService* BraveBrowserProcessImpl::brave_p3a_service() {
if (brave_p3a_service_) {
return brave_p3a_service_.get();
p3a::P3AService* BraveBrowserProcessImpl::p3a_service() {
#if BUILDFLAG(BRAVE_P3A_ENABLED)
if (p3a_service_) {
return p3a_service_.get();
}
brave_p3a_service_ = base::MakeRefCounted<brave::BraveP3AService>(
p3a_service_ = base::MakeRefCounted<p3a::P3AService>(
local_state(), brave::GetChannelName(),
local_state()->GetString(kWeekOfInstallation));
brave_p3a_service()->InitCallbacks();
return brave_p3a_service_.get();
local_state()->GetString(kWeekOfInstallation),
p3a::P3AConfig::LoadFromCommandLine());
p3a_service()->InitCallbacks();
return p3a_service_.get();
#else
return nullptr;
#endif // BUILDFLAG(BRAVE_P3A_ENABLED)
}

brave::BraveReferralsService*
Expand Down
13 changes: 8 additions & 5 deletions browser/brave_browser_process_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

namespace brave {
class BraveReferralsService;
class BraveP3AService;
class HistogramsBraveizer;
class BraveFarblingService;
} // namespace brave

Expand Down Expand Up @@ -64,6 +62,11 @@ namespace ntp_background_images {
class NTPBackgroundImagesService;
} // namespace ntp_background_images

namespace p3a {
class HistogramsBraveizer;
class P3AService;
} // namespace p3a

namespace tor {
class BraveTorClientUpdater;
class BraveTorPluggableTransportUpdater;
Expand Down Expand Up @@ -118,7 +121,7 @@ class BraveBrowserProcessImpl : public BraveBrowserProcess,
#if BUILDFLAG(ENABLE_IPFS)
ipfs::BraveIpfsClientUpdater* ipfs_client_updater() override;
#endif
brave::BraveP3AService* brave_p3a_service() override;
p3a::P3AService* p3a_service() override;
brave::BraveReferralsService* brave_referrals_service() override;
brave_stats::BraveStatsUpdater* brave_stats_updater() override;
brave_ads::BraveStatsHelper* ads_brave_stats_helper() override;
Expand Down Expand Up @@ -187,8 +190,8 @@ class BraveBrowserProcessImpl : public BraveBrowserProcess,
#if BUILDFLAG(ENABLE_IPFS)
std::unique_ptr<ipfs::BraveIpfsClientUpdater> ipfs_client_updater_;
#endif
scoped_refptr<brave::BraveP3AService> brave_p3a_service_;
scoped_refptr<brave::HistogramsBraveizer> histogram_braveizer_;
scoped_refptr<p3a::P3AService> p3a_service_;
scoped_refptr<p3a::HistogramsBraveizer> histogram_braveizer_;
std::unique_ptr<ntp_background_images::NTPBackgroundImagesService>
ntp_background_images_service_;
std::unique_ptr<brave_ads::ResourceComponent> resource_component_;
Expand Down
16 changes: 6 additions & 10 deletions browser/brave_local_state_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
#include "brave/components/misc_metrics/page_metrics_service.h"
#include "brave/components/ntp_background_images/browser/ntp_background_images_service.h"
#include "brave/components/ntp_background_images/browser/view_counter_service.h"
#include "brave/components/p3a/brave_p3a_service.h"
#include "brave/components/p3a/buildflags.h"
#include "brave/components/p3a/p3a_service.h"
#include "brave/components/skus/browser/skus_utils.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "build/build_config.h"
Expand Down Expand Up @@ -90,18 +89,15 @@ void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
metrics::prefs::kMetricsReportingEnabled,
base::Value(GetDefaultPrefValueForMetricsReporting()));

#if BUILDFLAG(BRAVE_P3A_ENABLED)
brave::BraveP3AService::RegisterPrefs(registry,
p3a::P3AService::RegisterPrefs(registry,
#if !BUILDFLAG(IS_ANDROID)
first_run::IsChromeFirstRun());
first_run::IsChromeFirstRun());
bridiver marked this conversation as resolved.
Show resolved Hide resolved
#else
// BraveP3AService::RegisterPrefs
// doesn't use this arg on Android
false);
// BraveP3AService::RegisterPrefs
// doesn't use this arg on Android
false);
#endif // !BUILDFLAG(IS_ANDROID)

#endif // BUILDFLAG(BRAVE_P3A_ENABLED)

brave_shields::RegisterShieldsP3ALocalPrefs(registry);
#if !BUILDFLAG(IS_ANDROID)
BraveNewTabMessageHandler::RegisterLocalStatePrefs(registry);
Expand Down
12 changes: 6 additions & 6 deletions browser/infobars/brave_confirm_p3a_infobar_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ void BraveConfirmP3AInfoBarDelegate::Create(
// - P3A is disabled
// - notice has already been acknowledged
if (local_state) {
if (!local_state->GetBoolean(brave::kP3AEnabled) ||
local_state->GetBoolean(brave::kP3ANoticeAcknowledged)) {
local_state->SetBoolean(brave::kP3ANoticeAcknowledged, true);
if (!local_state->GetBoolean(p3a::kP3AEnabled) ||
local_state->GetBoolean(p3a::kP3ANoticeAcknowledged)) {
local_state->SetBoolean(p3a::kP3ANoticeAcknowledged, true);
return;
}
}
Expand Down Expand Up @@ -64,7 +64,7 @@ bool BraveConfirmP3AInfoBarDelegate::ShouldExpire(
void BraveConfirmP3AInfoBarDelegate::InfoBarDismissed() {
// Mark notice as acknowledged when infobar is dismissed
if (local_state_) {
local_state_->SetBoolean(brave::kP3ANoticeAcknowledged, true);
local_state_->SetBoolean(p3a::kP3ANoticeAcknowledged, true);
}
}

Expand Down Expand Up @@ -98,7 +98,7 @@ GURL BraveConfirmP3AInfoBarDelegate::GetLinkURL() const {
bool BraveConfirmP3AInfoBarDelegate::Accept() {
// Mark notice as acknowledged when infobar is dismissed
if (local_state_) {
local_state_->SetBoolean(brave::kP3ANoticeAcknowledged, true);
local_state_->SetBoolean(p3a::kP3ANoticeAcknowledged, true);
}
return true;
}
Expand All @@ -107,7 +107,7 @@ bool BraveConfirmP3AInfoBarDelegate::Cancel() {
// OK button is "Disable"
// Clicking should disable P3A
if (local_state_) {
local_state_->SetBoolean(brave::kP3AEnabled, false);
local_state_->SetBoolean(p3a::kP3AEnabled, false);
}
return true;
}
29 changes: 18 additions & 11 deletions browser/ntp_background/ntp_p3a_helper_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "brave/components/brave_ads/browser/ads_service.h"
#include "brave/components/p3a/brave_p3a_service.h"
#include "brave/components/p3a/metric_log_type.h"
#include "brave/components/p3a/p3a_service.h"
#include "brave/components/p3a_utils/bucket.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
Expand Down Expand Up @@ -50,16 +50,16 @@ constexpr base::TimeDelta kLandingTime = base::Seconds(10);
} // namespace

NTPP3AHelperImpl::NTPP3AHelperImpl(PrefService* local_state,
brave::BraveP3AService* p3a_service,
p3a::P3AService* p3a_service,
brave_ads::AdsService* ads_service)
: local_state_(local_state),
p3a_service_(p3a_service),
ads_service_(ads_service) {
DCHECK(local_state);
DCHECK(p3a_service);
metric_sent_subscription_ =
p3a_service->RegisterMetricSentCallback(base::BindRepeating(
&NTPP3AHelperImpl::OnP3AMetricSent, base::Unretained(this)));
p3a_service->RegisterMetricCycledCallback(base::BindRepeating(
&NTPP3AHelperImpl::OnP3AMetricCycled, base::Unretained(this)));
DJAndries marked this conversation as resolved.
Show resolved Hide resolved
rotation_subscription_ =
p3a_service->RegisterRotationCallback(base::BindRepeating(
&NTPP3AHelperImpl::OnP3ARotation, base::Unretained(this)));
Expand Down Expand Up @@ -94,8 +94,9 @@ void NTPP3AHelperImpl::SetLastTabURL(const GURL& url) {
last_tab_hostname_ = url.host();
}

void NTPP3AHelperImpl::OnP3ARotation(brave::MetricLogType log_type) {
if (log_type != brave::MetricLogType::kExpress) {
void NTPP3AHelperImpl::OnP3ARotation(p3a::MetricLogType log_type,
bool is_star) {
if (log_type != p3a::MetricLogType::kExpress || is_star) {
return;
}
ScopedDictPrefUpdate update(local_state_, kNewTabPageEventCountDictPref);
Expand Down Expand Up @@ -134,16 +135,22 @@ void NTPP3AHelperImpl::OnP3ARotation(brave::MetricLogType log_type) {
if ((ads_service_ != nullptr && !ads_service_->IsEnabled()) ||
total_active_creatives > 0) {
p3a_service_->RegisterDynamicMetric(creative_total_histogram_name,
brave::MetricLogType::kExpress);
p3a::MetricLogType::kExpress);
p3a_utils::RecordToHistogramBucket(creative_total_histogram_name.c_str(),
kCountBuckets, total_active_creatives);
} else {
p3a_service_->RemoveDynamicMetric(creative_total_histogram_name);
}
}

void NTPP3AHelperImpl::OnP3AMetricSent(const std::string& histogram_name) {
if (!base::StartsWith(histogram_name, brave::kCreativeMetricPrefix)) {
void NTPP3AHelperImpl::OnP3AMetricCycled(const std::string& histogram_name,
bool is_star) {
if (is_star) {
// TODO(djandries): Monitor both STAR and JSON metric cycles once STAR is
// supported for express metrics
return;
}
if (!base::StartsWith(histogram_name, p3a::kCreativeMetricPrefix)) {
return;
}

Expand Down Expand Up @@ -195,7 +202,7 @@ std::string NTPP3AHelperImpl::BuildHistogramName(
const std::string& creative_instance_id,
const std::string& event_type) {
return base::StrCat(
{brave::kCreativeMetricPrefix, creative_instance_id, ".", event_type});
{p3a::kCreativeMetricPrefix, creative_instance_id, ".", event_type});
}

void NTPP3AHelperImpl::UpdateMetricCount(
Expand All @@ -205,7 +212,7 @@ void NTPP3AHelperImpl::UpdateMetricCount(
BuildHistogramName(creative_instance_id, event_type);

p3a_service_->RegisterDynamicMetric(histogram_name,
brave::MetricLogType::kExpress);
p3a::MetricLogType::kExpress);

ScopedDictPrefUpdate update(local_state_, kNewTabPageEventCountDictPref);
base::Value::Dict& update_dict = update.Get();
Expand Down
18 changes: 10 additions & 8 deletions browser/ntp_background/ntp_p3a_helper_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
class PrefRegistrySimple;
class PrefService;

namespace brave {
class BraveP3AService;
namespace p3a {
class P3AService;
enum class MetricLogType;
} // namespace brave
} // namespace p3a

namespace brave_ads {
class AdsService;
Expand All @@ -31,7 +31,7 @@ namespace ntp_background_images {
class NTPP3AHelperImpl : public NTPP3AHelper {
public:
NTPP3AHelperImpl(PrefService* local_state,
brave::BraveP3AService* p3a_service,
p3a::P3AService* p3a_service,
brave_ads::AdsService* ads_service);
~NTPP3AHelperImpl() override;

Expand All @@ -44,9 +44,11 @@ class NTPP3AHelperImpl : public NTPP3AHelper {

void SetLastTabURL(const GURL& url) override;

void OnP3ARotation(brave::MetricLogType log_type);

void OnP3AMetricSent(const std::string& histogram_name);
// See BraveP3AService::RegisterDynamicMetric and
// BraveP3AService::RegisterMetricCycledCallback header comments for more
// info.
void OnP3ARotation(p3a::MetricLogType log_type, bool is_star);
void OnP3AMetricCycled(const std::string& histogram_name, bool is_star);
DJAndries marked this conversation as resolved.
Show resolved Hide resolved

private:
std::string BuildHistogramName(const std::string& creative_instance_id,
Expand All @@ -61,7 +63,7 @@ class NTPP3AHelperImpl : public NTPP3AHelper {
const std::string& expected_hostname);

raw_ptr<PrefService> local_state_;
raw_ptr<brave::BraveP3AService> p3a_service_;
raw_ptr<p3a::P3AService> p3a_service_;
raw_ptr<const brave_ads::AdsService> ads_service_;

absl::optional<std::string> last_tab_hostname_;
Expand Down
Loading