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/login/auth/extended_authenticator_impl.h" | 5 #include "chromeos/login/auth/extended_authenticator_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "chromeos/cryptohome/async_method_caller.h" | 10 #include "chromeos/cryptohome/async_method_caller.h" |
11 #include "chromeos/cryptohome/cryptohome_parameters.h" | 11 #include "chromeos/cryptohome/cryptohome_parameters.h" |
12 #include "chromeos/cryptohome/homedir_methods.h" | 12 #include "chromeos/cryptohome/homedir_methods.h" |
13 #include "chromeos/cryptohome/system_salt_getter.h" | 13 #include "chromeos/cryptohome/system_salt_getter.h" |
14 #include "chromeos/dbus/cryptohome_client.h" | 14 #include "chromeos/dbus/cryptohome_client.h" |
15 #include "chromeos/dbus/dbus_thread_manager.h" | 15 #include "chromeos/dbus/dbus_thread_manager.h" |
16 #include "chromeos/login/auth/auth_status_consumer.h" | 16 #include "chromeos/login/auth/auth_status_consumer.h" |
17 #include "chromeos/login/auth/key.h" | 17 #include "chromeos/login/auth/key.h" |
18 #include "chromeos/login/auth/user_context.h" | 18 #include "chromeos/login/auth/user_context.h" |
19 #include "chromeos/login_event_recorder.h" | 19 #include "chromeos/login_event_recorder.h" |
| 20 #include "components/signin/core/account_id/account_id.h" |
20 #include "crypto/sha2.h" | 21 #include "crypto/sha2.h" |
21 #include "google_apis/gaia/gaia_auth_util.h" | 22 #include "google_apis/gaia/gaia_auth_util.h" |
22 | 23 |
23 namespace chromeos { | 24 namespace chromeos { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 void RecordStartMarker(const std::string& marker) { | 28 void RecordStartMarker(const std::string& marker) { |
28 std::string full_marker = "Cryptohome-"; | 29 std::string full_marker = "Cryptohome-"; |
29 full_marker.append(marker); | 30 full_marker.append(marker); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 const ResultCallback& success_callback) { | 85 const ResultCallback& success_callback) { |
85 RecordStartMarker("MountEx"); | 86 RecordStartMarker("MountEx"); |
86 | 87 |
87 std::string canonicalized = gaia::CanonicalizeEmail(user_id); | 88 std::string canonicalized = gaia::CanonicalizeEmail(user_id); |
88 cryptohome::Identification id(canonicalized); | 89 cryptohome::Identification id(canonicalized); |
89 cryptohome::Authorization auth(keys.front()); | 90 cryptohome::Authorization auth(keys.front()); |
90 cryptohome::MountParameters mount(false); | 91 cryptohome::MountParameters mount(false); |
91 for (size_t i = 0; i < keys.size(); i++) { | 92 for (size_t i = 0; i < keys.size(); i++) { |
92 mount.create_keys.push_back(keys[i]); | 93 mount.create_keys.push_back(keys[i]); |
93 } | 94 } |
94 UserContext context(user_id); | 95 UserContext context(AccountId::FromUserEmail(user_id)); |
95 Key key(keys.front().secret); | 96 Key key(keys.front().secret); |
96 key.SetLabel(keys.front().label); | 97 key.SetLabel(keys.front().label); |
97 context.SetKey(key); | 98 context.SetKey(key); |
98 | 99 |
99 cryptohome::HomedirMethods::GetInstance()->MountEx( | 100 cryptohome::HomedirMethods::GetInstance()->MountEx( |
100 id, | 101 id, |
101 auth, | 102 auth, |
102 mount, | 103 mount, |
103 base::Bind(&ExtendedAuthenticatorImpl::OnMountComplete, | 104 base::Bind(&ExtendedAuthenticatorImpl::OnMountComplete, |
104 this, | 105 this, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 it->Run(); | 180 it->Run(); |
180 } | 181 } |
181 system_salt_callbacks_.clear(); | 182 system_salt_callbacks_.clear(); |
182 } | 183 } |
183 | 184 |
184 void ExtendedAuthenticatorImpl::DoAuthenticateToMount( | 185 void ExtendedAuthenticatorImpl::DoAuthenticateToMount( |
185 const ResultCallback& success_callback, | 186 const ResultCallback& success_callback, |
186 const UserContext& user_context) { | 187 const UserContext& user_context) { |
187 RecordStartMarker("MountEx"); | 188 RecordStartMarker("MountEx"); |
188 | 189 |
189 std::string canonicalized = gaia::CanonicalizeEmail(user_context.GetUserID()); | 190 const std::string canonicalized = |
| 191 gaia::CanonicalizeEmail(user_context.GetAccountId().GetUserEmail()); |
190 cryptohome::Identification id(canonicalized); | 192 cryptohome::Identification id(canonicalized); |
191 const Key* const key = user_context.GetKey(); | 193 const Key* const key = user_context.GetKey(); |
192 cryptohome::Authorization auth(key->GetSecret(), key->GetLabel()); | 194 cryptohome::Authorization auth(key->GetSecret(), key->GetLabel()); |
193 cryptohome::MountParameters mount(false); | 195 cryptohome::MountParameters mount(false); |
194 | 196 |
195 cryptohome::HomedirMethods::GetInstance()->MountEx( | 197 cryptohome::HomedirMethods::GetInstance()->MountEx( |
196 id, | 198 id, |
197 auth, | 199 auth, |
198 mount, | 200 mount, |
199 base::Bind(&ExtendedAuthenticatorImpl::OnMountComplete, | 201 base::Bind(&ExtendedAuthenticatorImpl::OnMountComplete, |
200 this, | 202 this, |
201 "MountEx", | 203 "MountEx", |
202 user_context, | 204 user_context, |
203 success_callback)); | 205 success_callback)); |
204 } | 206 } |
205 | 207 |
206 void ExtendedAuthenticatorImpl::DoAuthenticateToCheck( | 208 void ExtendedAuthenticatorImpl::DoAuthenticateToCheck( |
207 const base::Closure& success_callback, | 209 const base::Closure& success_callback, |
208 const UserContext& user_context) { | 210 const UserContext& user_context) { |
209 RecordStartMarker("CheckKeyEx"); | 211 RecordStartMarker("CheckKeyEx"); |
210 | 212 |
211 std::string canonicalized = gaia::CanonicalizeEmail(user_context.GetUserID()); | 213 const std::string canonicalized = |
| 214 gaia::CanonicalizeEmail(user_context.GetAccountId().GetUserEmail()); |
212 cryptohome::Identification id(canonicalized); | 215 cryptohome::Identification id(canonicalized); |
213 const Key* const key = user_context.GetKey(); | 216 const Key* const key = user_context.GetKey(); |
214 cryptohome::Authorization auth(key->GetSecret(), key->GetLabel()); | 217 cryptohome::Authorization auth(key->GetSecret(), key->GetLabel()); |
215 | 218 |
216 cryptohome::HomedirMethods::GetInstance()->CheckKeyEx( | 219 cryptohome::HomedirMethods::GetInstance()->CheckKeyEx( |
217 id, | 220 id, |
218 auth, | 221 auth, |
219 base::Bind(&ExtendedAuthenticatorImpl::OnOperationComplete, | 222 base::Bind(&ExtendedAuthenticatorImpl::OnOperationComplete, |
220 this, | 223 this, |
221 "CheckKeyEx", | 224 "CheckKeyEx", |
222 user_context, | 225 user_context, |
223 success_callback)); | 226 success_callback)); |
224 } | 227 } |
225 | 228 |
226 void ExtendedAuthenticatorImpl::DoAddKey(const cryptohome::KeyDefinition& key, | 229 void ExtendedAuthenticatorImpl::DoAddKey(const cryptohome::KeyDefinition& key, |
227 bool replace_existing, | 230 bool replace_existing, |
228 const base::Closure& success_callback, | 231 const base::Closure& success_callback, |
229 const UserContext& user_context) { | 232 const UserContext& user_context) { |
230 RecordStartMarker("AddKeyEx"); | 233 RecordStartMarker("AddKeyEx"); |
231 | 234 |
232 std::string canonicalized = gaia::CanonicalizeEmail(user_context.GetUserID()); | 235 const std::string canonicalized = |
| 236 gaia::CanonicalizeEmail(user_context.GetAccountId().GetUserEmail()); |
233 cryptohome::Identification id(canonicalized); | 237 cryptohome::Identification id(canonicalized); |
234 const Key* const auth_key = user_context.GetKey(); | 238 const Key* const auth_key = user_context.GetKey(); |
235 cryptohome::Authorization auth(auth_key->GetSecret(), auth_key->GetLabel()); | 239 cryptohome::Authorization auth(auth_key->GetSecret(), auth_key->GetLabel()); |
236 | 240 |
237 cryptohome::HomedirMethods::GetInstance()->AddKeyEx( | 241 cryptohome::HomedirMethods::GetInstance()->AddKeyEx( |
238 id, | 242 id, |
239 auth, | 243 auth, |
240 key, | 244 key, |
241 replace_existing, | 245 replace_existing, |
242 base::Bind(&ExtendedAuthenticatorImpl::OnOperationComplete, | 246 base::Bind(&ExtendedAuthenticatorImpl::OnOperationComplete, |
243 this, | 247 this, |
244 "AddKeyEx", | 248 "AddKeyEx", |
245 user_context, | 249 user_context, |
246 success_callback)); | 250 success_callback)); |
247 } | 251 } |
248 | 252 |
249 void ExtendedAuthenticatorImpl::DoUpdateKeyAuthorized( | 253 void ExtendedAuthenticatorImpl::DoUpdateKeyAuthorized( |
250 const cryptohome::KeyDefinition& key, | 254 const cryptohome::KeyDefinition& key, |
251 const std::string& signature, | 255 const std::string& signature, |
252 const base::Closure& success_callback, | 256 const base::Closure& success_callback, |
253 const UserContext& user_context) { | 257 const UserContext& user_context) { |
254 RecordStartMarker("UpdateKeyAuthorized"); | 258 RecordStartMarker("UpdateKeyAuthorized"); |
255 | 259 |
256 std::string canonicalized = gaia::CanonicalizeEmail(user_context.GetUserID()); | 260 const std::string canonicalized = |
| 261 gaia::CanonicalizeEmail(user_context.GetAccountId().GetUserEmail()); |
257 cryptohome::Identification id(canonicalized); | 262 cryptohome::Identification id(canonicalized); |
258 const Key* const auth_key = user_context.GetKey(); | 263 const Key* const auth_key = user_context.GetKey(); |
259 cryptohome::Authorization auth(auth_key->GetSecret(), auth_key->GetLabel()); | 264 cryptohome::Authorization auth(auth_key->GetSecret(), auth_key->GetLabel()); |
260 | 265 |
261 cryptohome::HomedirMethods::GetInstance()->UpdateKeyEx( | 266 cryptohome::HomedirMethods::GetInstance()->UpdateKeyEx( |
262 id, | 267 id, |
263 auth, | 268 auth, |
264 key, | 269 key, |
265 signature, | 270 signature, |
266 base::Bind(&ExtendedAuthenticatorImpl::OnOperationComplete, | 271 base::Bind(&ExtendedAuthenticatorImpl::OnOperationComplete, |
267 this, | 272 this, |
268 "UpdateKeyAuthorized", | 273 "UpdateKeyAuthorized", |
269 user_context, | 274 user_context, |
270 success_callback)); | 275 success_callback)); |
271 } | 276 } |
272 | 277 |
273 void ExtendedAuthenticatorImpl::DoRemoveKey(const std::string& key_to_remove, | 278 void ExtendedAuthenticatorImpl::DoRemoveKey(const std::string& key_to_remove, |
274 const base::Closure& success_callback, | 279 const base::Closure& success_callback, |
275 const UserContext& user_context) { | 280 const UserContext& user_context) { |
276 RecordStartMarker("RemoveKeyEx"); | 281 RecordStartMarker("RemoveKeyEx"); |
277 | 282 |
278 std::string canonicalized = gaia::CanonicalizeEmail(user_context.GetUserID()); | 283 const std::string canonicalized = |
| 284 gaia::CanonicalizeEmail(user_context.GetAccountId().GetUserEmail()); |
279 cryptohome::Identification id(canonicalized); | 285 cryptohome::Identification id(canonicalized); |
280 const Key* const auth_key = user_context.GetKey(); | 286 const Key* const auth_key = user_context.GetKey(); |
281 cryptohome::Authorization auth(auth_key->GetSecret(), auth_key->GetLabel()); | 287 cryptohome::Authorization auth(auth_key->GetSecret(), auth_key->GetLabel()); |
282 | 288 |
283 cryptohome::HomedirMethods::GetInstance()->RemoveKeyEx( | 289 cryptohome::HomedirMethods::GetInstance()->RemoveKeyEx( |
284 id, | 290 id, |
285 auth, | 291 auth, |
286 key_to_remove, | 292 key_to_remove, |
287 base::Bind(&ExtendedAuthenticatorImpl::OnOperationComplete, | 293 base::Bind(&ExtendedAuthenticatorImpl::OnOperationComplete, |
288 this, | 294 this, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 if (consumer_) | 362 if (consumer_) |
357 consumer_->OnAuthenticationFailure(state); | 363 consumer_->OnAuthenticationFailure(state); |
358 | 364 |
359 if (old_consumer_) { | 365 if (old_consumer_) { |
360 AuthFailure failure(AuthFailure::UNLOCK_FAILED); | 366 AuthFailure failure(AuthFailure::UNLOCK_FAILED); |
361 old_consumer_->OnAuthFailure(failure); | 367 old_consumer_->OnAuthFailure(failure); |
362 } | 368 } |
363 } | 369 } |
364 | 370 |
365 } // namespace chromeos | 371 } // namespace chromeos |
OLD | NEW |