Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/cryptauth/cryptauth_device_manager.h" | 5 #include "components/cryptauth/cryptauth_device_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdexcept> | 8 #include <stdexcept> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 || !seed.has_start_time_millis() | 61 || !seed.has_start_time_millis() |
| 62 || !seed.has_end_time_millis()) { | 62 || !seed.has_end_time_millis()) { |
| 63 PA_LOG(WARNING) << "Unable to serialize BeaconSeed due to missing data; " | 63 PA_LOG(WARNING) << "Unable to serialize BeaconSeed due to missing data; " |
| 64 << "skipping."; | 64 << "skipping."; |
| 65 continue; | 65 continue; |
| 66 } | 66 } |
| 67 | 67 |
| 68 std::unique_ptr<base::DictionaryValue> beacon_seed_value( | 68 std::unique_ptr<base::DictionaryValue> beacon_seed_value( |
| 69 new base::DictionaryValue()); | 69 new base::DictionaryValue()); |
| 70 | 70 |
| 71 // Note: Seed data is already base-64 encoded, so there is no need to | 71 // Note that the beacon seeds' data is stored in Base64Url form because |
|
Kyle Horimoto
2017/01/04 18:42:29
nit: |BeaconSeed|s'
| |
| 72 // convert it. | 72 // dictionary values must be valid UTF8 strings. |
| 73 beacon_seed_value->SetString(kExternalDeviceKeyBeaconSeedData, seed.data()); | 73 std::string seed_data_b64; |
| 74 base::Base64UrlEncode(seed.data(), | |
| 75 base::Base64UrlEncodePolicy::INCLUDE_PADDING, | |
| 76 &seed_data_b64); | |
| 77 beacon_seed_value->SetString(kExternalDeviceKeyBeaconSeedData, | |
| 78 seed_data_b64); | |
| 74 | 79 |
| 75 // Set the timestamps as string representations of their numeric value | 80 // Set the timestamps as string representations of their numeric value |
| 76 // since there is no notion of a base::LongValue. | 81 // since there is no notion of a base::LongValue. |
| 77 beacon_seed_value->SetString( | 82 beacon_seed_value->SetString( |
| 78 kExternalDeviceKeyBeaconSeedStartMs, | 83 kExternalDeviceKeyBeaconSeedStartMs, |
| 79 std::to_string(seed.start_time_millis())); | 84 std::to_string(seed.start_time_millis())); |
| 80 beacon_seed_value->SetString( | 85 beacon_seed_value->SetString( |
| 81 kExternalDeviceKeyBeaconSeedEndMs, | 86 kExternalDeviceKeyBeaconSeedEndMs, |
| 82 std::to_string(seed.end_time_millis())); | 87 std::to_string(seed.end_time_millis())); |
| 83 | 88 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 const base::ListValue& beacon_seeds, | 166 const base::ListValue& beacon_seeds, |
| 162 cryptauth::ExternalDeviceInfo& external_device) { | 167 cryptauth::ExternalDeviceInfo& external_device) { |
| 163 for (size_t i = 0; i < beacon_seeds.GetSize(); i++) { | 168 for (size_t i = 0; i < beacon_seeds.GetSize(); i++) { |
| 164 const base::DictionaryValue* seed_dictionary = nullptr; | 169 const base::DictionaryValue* seed_dictionary = nullptr; |
| 165 if (!beacon_seeds.GetDictionary(i, &seed_dictionary)) { | 170 if (!beacon_seeds.GetDictionary(i, &seed_dictionary)) { |
| 166 PA_LOG(WARNING) << "Unable to retrieve BeaconSeed dictionary; " | 171 PA_LOG(WARNING) << "Unable to retrieve BeaconSeed dictionary; " |
| 167 << "skipping."; | 172 << "skipping."; |
| 168 continue; | 173 continue; |
| 169 } | 174 } |
| 170 | 175 |
| 171 std::string data, start_time_millis_str, end_time_millis_str; | 176 std::string seed_data_b64, start_time_millis_str, end_time_millis_str; |
| 172 if (!seed_dictionary->GetString(kExternalDeviceKeyBeaconSeedData, &data) | 177 if (!seed_dictionary->GetString(kExternalDeviceKeyBeaconSeedData, |
| 173 || !seed_dictionary->GetString( | 178 &seed_data_b64) || |
| 174 kExternalDeviceKeyBeaconSeedStartMs, | 179 !seed_dictionary->GetString(kExternalDeviceKeyBeaconSeedStartMs, |
| 175 &start_time_millis_str) | 180 &start_time_millis_str) || |
| 176 || !seed_dictionary->GetString( | 181 !seed_dictionary->GetString(kExternalDeviceKeyBeaconSeedEndMs, |
| 177 kExternalDeviceKeyBeaconSeedEndMs, | 182 &end_time_millis_str)) { |
| 178 &end_time_millis_str)) { | |
| 179 PA_LOG(WARNING) << "Unable to deserialize BeaconSeed due to missing " | 183 PA_LOG(WARNING) << "Unable to deserialize BeaconSeed due to missing " |
| 180 << "data; skipping."; | 184 << "data; skipping."; |
| 181 continue; | 185 continue; |
| 182 } | 186 } |
| 183 | 187 |
| 188 // Seed data is returned as raw data, not in Base64 encoding. | |
| 189 std::string seed_data; | |
| 190 if (!base::Base64UrlDecode(seed_data_b64, | |
| 191 base::Base64UrlDecodePolicy::REQUIRE_PADDING, | |
| 192 &seed_data)) { | |
| 193 PA_LOG(WARNING) << "Decoding seed data failed."; | |
| 194 continue; | |
| 195 } | |
| 196 | |
| 184 int64_t start_time_millis, end_time_millis; | 197 int64_t start_time_millis, end_time_millis; |
| 185 if (!base::StringToInt64(start_time_millis_str, &start_time_millis) | 198 if (!base::StringToInt64(start_time_millis_str, &start_time_millis) |
| 186 || !base::StringToInt64(end_time_millis_str, &end_time_millis)) { | 199 || !base::StringToInt64(end_time_millis_str, &end_time_millis)) { |
| 187 PA_LOG(WARNING) << "Unable to convert stored timestamp to int64_t: " | 200 PA_LOG(WARNING) << "Unable to convert stored timestamp to int64_t: " |
| 188 << start_time_millis_str << " or " << end_time_millis_str; | 201 << start_time_millis_str << " or " << end_time_millis_str; |
| 189 continue; | 202 continue; |
| 190 } | 203 } |
| 191 | 204 |
| 192 cryptauth::BeaconSeed* seed = external_device.add_beacon_seeds(); | 205 cryptauth::BeaconSeed* seed = external_device.add_beacon_seeds(); |
| 193 seed->set_data(data); | 206 seed->set_data(seed_data); |
| 194 seed->set_start_time_millis(start_time_millis); | 207 seed->set_start_time_millis(start_time_millis); |
| 195 seed->set_end_time_millis(end_time_millis); | 208 seed->set_end_time_millis(end_time_millis); |
| 196 } | 209 } |
| 197 } | 210 } |
| 198 | 211 |
| 199 // Converts an unlock key dictionary stored in user prefs to an | 212 // Converts an unlock key dictionary stored in user prefs to an |
| 200 // ExternalDeviceInfo proto. Returns true if the dictionary is valid, and the | 213 // ExternalDeviceInfo proto. Returns true if the dictionary is valid, and the |
| 201 // parsed proto is written to |external_device|. | 214 // parsed proto is written to |external_device|. |
| 202 bool DictionaryToUnlockKey(const base::DictionaryValue& dictionary, | 215 bool DictionaryToUnlockKey(const base::DictionaryValue& dictionary, |
| 203 cryptauth::ExternalDeviceInfo* external_device) { | 216 cryptauth::ExternalDeviceInfo* external_device) { |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 507 request.set_invocation_reason(invocation_reason); | 520 request.set_invocation_reason(invocation_reason); |
| 508 request.set_allow_stale_read(is_sync_speculative); | 521 request.set_allow_stale_read(is_sync_speculative); |
| 509 cryptauth_client_->GetMyDevices( | 522 cryptauth_client_->GetMyDevices( |
| 510 request, base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesSuccess, | 523 request, base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesSuccess, |
| 511 weak_ptr_factory_.GetWeakPtr()), | 524 weak_ptr_factory_.GetWeakPtr()), |
| 512 base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesFailure, | 525 base::Bind(&CryptAuthDeviceManager::OnGetMyDevicesFailure, |
| 513 weak_ptr_factory_.GetWeakPtr())); | 526 weak_ptr_factory_.GetWeakPtr())); |
| 514 } | 527 } |
| 515 | 528 |
| 516 } // namespace cryptauth | 529 } // namespace cryptauth |
| OLD | NEW |