Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(307)

Unified Diff: components/cryptauth/cryptauth_device_manager.cc

Issue 2611913002: Tweak CryptauthDeviceManager to store fetched BeaconSeed data in Base64URL encoding, and retrieve i… (Closed)
Patch Set: Fixing a comment. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/cryptauth/cryptauth_device_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cryptauth/cryptauth_device_manager.cc
diff --git a/components/cryptauth/cryptauth_device_manager.cc b/components/cryptauth/cryptauth_device_manager.cc
index 3597043786193c30dedcaf71eff49a40a69ea973..f2e6b55e9f6e31844934ee6f6d26208f05029a99 100644
--- a/components/cryptauth/cryptauth_device_manager.cc
+++ b/components/cryptauth/cryptauth_device_manager.cc
@@ -68,9 +68,14 @@ std::unique_ptr<base::ListValue> BeaconSeedsToListValue(
std::unique_ptr<base::DictionaryValue> beacon_seed_value(
new base::DictionaryValue());
- // Note: Seed data is already base-64 encoded, so there is no need to
- // convert it.
- beacon_seed_value->SetString(kExternalDeviceKeyBeaconSeedData, seed.data());
+ // Note that the |BeaconSeed|s' data is stored in Base64Url encoding because
+ // dictionary values must be valid UTF8 strings.
+ std::string seed_data_b64;
+ base::Base64UrlEncode(seed.data(),
+ base::Base64UrlEncodePolicy::INCLUDE_PADDING,
+ &seed_data_b64);
+ beacon_seed_value->SetString(kExternalDeviceKeyBeaconSeedData,
+ seed_data_b64);
// Set the timestamps as string representations of their numeric value
// since there is no notion of a base::LongValue.
@@ -168,19 +173,27 @@ void AddBeaconSeedsToExternalDevice(
continue;
}
- std::string data, start_time_millis_str, end_time_millis_str;
- if (!seed_dictionary->GetString(kExternalDeviceKeyBeaconSeedData, &data)
- || !seed_dictionary->GetString(
- kExternalDeviceKeyBeaconSeedStartMs,
- &start_time_millis_str)
- || !seed_dictionary->GetString(
- kExternalDeviceKeyBeaconSeedEndMs,
- &end_time_millis_str)) {
+ std::string seed_data_b64, start_time_millis_str, end_time_millis_str;
+ if (!seed_dictionary->GetString(kExternalDeviceKeyBeaconSeedData,
+ &seed_data_b64) ||
+ !seed_dictionary->GetString(kExternalDeviceKeyBeaconSeedStartMs,
+ &start_time_millis_str) ||
+ !seed_dictionary->GetString(kExternalDeviceKeyBeaconSeedEndMs,
+ &end_time_millis_str)) {
PA_LOG(WARNING) << "Unable to deserialize BeaconSeed due to missing "
<< "data; skipping.";
continue;
}
+ // Seed data is returned as raw data, not in Base64 encoding.
+ std::string seed_data;
+ if (!base::Base64UrlDecode(seed_data_b64,
+ base::Base64UrlDecodePolicy::REQUIRE_PADDING,
+ &seed_data)) {
+ PA_LOG(WARNING) << "Decoding seed data failed.";
+ continue;
+ }
+
int64_t start_time_millis, end_time_millis;
if (!base::StringToInt64(start_time_millis_str, &start_time_millis)
|| !base::StringToInt64(end_time_millis_str, &end_time_millis)) {
@@ -190,7 +203,7 @@ void AddBeaconSeedsToExternalDevice(
}
cryptauth::BeaconSeed* seed = external_device.add_beacon_seeds();
- seed->set_data(data);
+ seed->set_data(seed_data);
seed->set_start_time_millis(start_time_millis);
seed->set_end_time_millis(end_time_millis);
}
« no previous file with comments | « no previous file | components/cryptauth/cryptauth_device_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698