OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chromeos/cryptohome/cryptohome_parameters.h" | 5 #include "chromeos/cryptohome/cryptohome_parameters.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "chromeos/dbus/cryptohome/key.pb.h" | 10 #include "chromeos/dbus/cryptohome/key.pb.h" |
| 11 #include "components/signin/core/account_id/account_id.h" |
| 12 #include "components/user_manager/known_user.h" |
11 | 13 |
12 namespace cryptohome { | 14 namespace cryptohome { |
| 15 namespace { |
13 | 16 |
14 Identification::Identification(const std::string& user_id) : user_id(user_id) { | 17 // Subsystem name for GaiaId migration status. |
| 18 const char kCryptohome[] = "cryptohome"; |
| 19 |
| 20 const std::string GetCryptohomeId(const AccountId& account_id) { |
| 21 // Guest/kiosk/managed/public accounts have empty GaiaId. Default to email. |
| 22 if (account_id.GetGaiaId().empty()) |
| 23 return account_id.GetUserEmail(); // Migrated |
| 24 |
| 25 if (GetGaiaIdMigrationStatus(account_id)) |
| 26 return account_id.GetGaiaIdKey(); |
| 27 |
| 28 return account_id.GetUserEmail(); // Migrated |
| 29 } |
| 30 |
| 31 } // anonymous namespace |
| 32 |
| 33 Identification::Identification() {} |
| 34 |
| 35 Identification::Identification(const AccountId& account_id) |
| 36 : id_(GetCryptohomeId(account_id)) {} |
| 37 |
| 38 Identification::Identification(const std::string& id) : id_(id) {} |
| 39 |
| 40 Identification Identification::FromString(const std::string& id) { |
| 41 return Identification(id); |
15 } | 42 } |
16 | 43 |
17 bool Identification::operator==(const Identification& other) const { | 44 bool Identification::operator==(const Identification& other) const { |
18 return user_id == other.user_id; | 45 return id_ == other.id_; |
| 46 } |
| 47 |
| 48 bool Identification::operator<(const Identification& right) const { |
| 49 return id_ < right.id_; |
| 50 } |
| 51 |
| 52 AccountId Identification::GetAccountId() const { |
| 53 const std::vector<AccountId> known_account_ids = |
| 54 user_manager::known_user::GetKnownAccountIds(); |
| 55 |
| 56 // A LOT of tests start with --login_user <user>, and not registing this user |
| 57 // before. So we might have "known_user" entry without gaia_id. |
| 58 for (const AccountId& known_id : known_account_ids) { |
| 59 if (!known_id.GetGaiaId().empty() && known_id.GetGaiaIdKey() == id_) { |
| 60 return known_id; |
| 61 } |
| 62 } |
| 63 |
| 64 for (const AccountId& known_id : known_account_ids) { |
| 65 if (known_id.GetUserEmail() == id_) { |
| 66 return known_id; |
| 67 } |
| 68 } |
| 69 |
| 70 return user_manager::known_user::GetAccountId(id_, |
| 71 std::string() /* gaia_id */); |
19 } | 72 } |
20 | 73 |
21 KeyDefinition::AuthorizationData::Secret::Secret() : encrypt(false), | 74 KeyDefinition::AuthorizationData::Secret::Secret() : encrypt(false), |
22 sign(false), | 75 sign(false), |
23 wrapped(false) { | 76 wrapped(false) { |
24 } | 77 } |
25 | 78 |
26 KeyDefinition::AuthorizationData::Secret::Secret( | 79 KeyDefinition::AuthorizationData::Secret::Secret( |
27 bool encrypt, | 80 bool encrypt, |
28 bool sign, | 81 bool sign, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 MountParameters::MountParameters(bool ephemeral) : ephemeral(ephemeral) { | 229 MountParameters::MountParameters(bool ephemeral) : ephemeral(ephemeral) { |
177 } | 230 } |
178 | 231 |
179 bool MountParameters::operator==(const MountParameters& other) const { | 232 bool MountParameters::operator==(const MountParameters& other) const { |
180 return ephemeral == other.ephemeral && create_keys == other.create_keys; | 233 return ephemeral == other.ephemeral && create_keys == other.create_keys; |
181 } | 234 } |
182 | 235 |
183 MountParameters::~MountParameters() { | 236 MountParameters::~MountParameters() { |
184 } | 237 } |
185 | 238 |
| 239 bool GetGaiaIdMigrationStatus(const AccountId& account_id) { |
| 240 return user_manager::known_user::GetGaiaIdMigrationStatus(account_id, |
| 241 kCryptohome); |
| 242 } |
| 243 |
| 244 void SetGaiaIdMigrationStatusDone(const AccountId& account_id) { |
| 245 user_manager::known_user::SetGaiaIdMigrationStatusDone(account_id, |
| 246 kCryptohome); |
| 247 } |
| 248 |
186 } // namespace cryptohome | 249 } // namespace cryptohome |
| 250 |
| 251 namespace BASE_HASH_NAMESPACE { |
| 252 |
| 253 std::size_t hash<cryptohome::Identification>::operator()( |
| 254 const cryptohome::Identification& cryptohome_id) const { |
| 255 return hash<std::string>()(cryptohome_id.id()); |
| 256 } |
| 257 |
| 258 } // namespace BASE_HASH_NAMESPACE |
OLD | NEW |