| 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 "chrome/browser/chromeos/login/supervised/supervised_user_authenticator
.h" | 5 #include "chrome/browser/chromeos/login/supervised/supervised_user_authenticator
.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 "chrome/browser/chromeos/boot_times_recorder.h" | 10 #include "chrome/browser/chromeos/boot_times_recorder.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 scoped_refptr<SupervisedUserAuthenticator> resolver, | 61 scoped_refptr<SupervisedUserAuthenticator> resolver, |
| 62 int flags, | 62 int flags, |
| 63 const std::string& system_salt) { | 63 const std::string& system_salt) { |
| 64 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 64 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 65 chromeos::BootTimesRecorder::Get()->AddLoginTimeMarker( | 65 chromeos::BootTimesRecorder::Get()->AddLoginTimeMarker( |
| 66 "CryptohomeMount-LMU-Start", false); | 66 "CryptohomeMount-LMU-Start", false); |
| 67 | 67 |
| 68 Key key(attempt->password); | 68 Key key(attempt->password); |
| 69 key.Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, system_salt); | 69 key.Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, system_salt); |
| 70 cryptohome::AsyncMethodCaller::GetInstance()->AsyncMount( | 70 cryptohome::AsyncMethodCaller::GetInstance()->AsyncMount( |
| 71 attempt->username, | 71 attempt->user_id, |
| 72 key.GetSecret(), | 72 key.GetSecret(), |
| 73 flags, | 73 flags, |
| 74 base::Bind(&TriggerResolveWithLoginTimeMarker, | 74 base::Bind(&TriggerResolveWithLoginTimeMarker, |
| 75 "CryptohomeMount-LMU-End", | 75 "CryptohomeMount-LMU-End", |
| 76 attempt, | 76 attempt, |
| 77 resolver)); | 77 resolver)); |
| 78 | 78 |
| 79 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername( | 79 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername( |
| 80 attempt->username, | 80 attempt->user_id, |
| 81 base::Bind(&TriggerResolveResult, attempt, resolver)); | 81 base::Bind(&TriggerResolveResult, attempt, resolver)); |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Calls cryptohome's addKey method. | 84 // Calls cryptohome's addKey method. |
| 85 void AddKey(SupervisedUserAuthenticator::AuthAttempt* attempt, | 85 void AddKey(SupervisedUserAuthenticator::AuthAttempt* attempt, |
| 86 scoped_refptr<SupervisedUserAuthenticator> resolver, | 86 scoped_refptr<SupervisedUserAuthenticator> resolver, |
| 87 const std::string& plain_text_master_key, | 87 const std::string& plain_text_master_key, |
| 88 const std::string& system_salt) { | 88 const std::string& system_salt) { |
| 89 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 89 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 90 chromeos::BootTimesRecorder::Get()->AddLoginTimeMarker( | 90 chromeos::BootTimesRecorder::Get()->AddLoginTimeMarker( |
| 91 "CryptohomeAddKey-LMU-Start", false); | 91 "CryptohomeAddKey-LMU-Start", false); |
| 92 | 92 |
| 93 Key user_key(attempt->password); | 93 Key user_key(attempt->password); |
| 94 user_key.Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, system_salt); | 94 user_key.Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, system_salt); |
| 95 Key master_key(plain_text_master_key); | 95 Key master_key(plain_text_master_key); |
| 96 master_key.Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, system_salt); | 96 master_key.Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, system_salt); |
| 97 cryptohome::AsyncMethodCaller::GetInstance()->AsyncAddKey( | 97 cryptohome::AsyncMethodCaller::GetInstance()->AsyncAddKey( |
| 98 attempt->username, | 98 attempt->user_id, |
| 99 user_key.GetSecret(), | 99 user_key.GetSecret(), |
| 100 master_key.GetSecret(), | 100 master_key.GetSecret(), |
| 101 base::Bind(&TriggerResolveWithLoginTimeMarker, | 101 base::Bind(&TriggerResolveWithLoginTimeMarker, |
| 102 "CryptohomeAddKey-LMU-End", | 102 "CryptohomeAddKey-LMU-End", |
| 103 attempt, | 103 attempt, |
| 104 resolver)); | 104 resolver)); |
| 105 } | 105 } |
| 106 | 106 |
| 107 } // namespace | 107 } // namespace |
| 108 | 108 |
| 109 SupervisedUserAuthenticator::SupervisedUserAuthenticator( | 109 SupervisedUserAuthenticator::SupervisedUserAuthenticator( |
| 110 AuthStatusConsumer* consumer) | 110 AuthStatusConsumer* consumer) |
| 111 : consumer_(consumer) {} | 111 : consumer_(consumer) {} |
| 112 | 112 |
| 113 void SupervisedUserAuthenticator::AuthenticateToMount( | 113 void SupervisedUserAuthenticator::AuthenticateToMount( |
| 114 const std::string& username, | 114 const user_manager::UserID& user_id, |
| 115 const std::string& password) { | 115 const std::string& password) { |
| 116 std::string canonicalized = gaia::CanonicalizeEmail(username); | |
| 117 | |
| 118 current_state_.reset(new SupervisedUserAuthenticator::AuthAttempt( | 116 current_state_.reset(new SupervisedUserAuthenticator::AuthAttempt( |
| 119 canonicalized, password, false)); | 117 user_id, password, false)); |
| 120 | 118 |
| 121 SystemSaltGetter::Get()->GetSystemSalt( | 119 SystemSaltGetter::Get()->GetSystemSalt( |
| 122 base::Bind(&Mount, | 120 base::Bind(&Mount, |
| 123 current_state_.get(), | 121 current_state_.get(), |
| 124 scoped_refptr<SupervisedUserAuthenticator>(this), | 122 scoped_refptr<SupervisedUserAuthenticator>(this), |
| 125 cryptohome::MOUNT_FLAGS_NONE)); | 123 cryptohome::MOUNT_FLAGS_NONE)); |
| 126 } | 124 } |
| 127 | 125 |
| 128 void SupervisedUserAuthenticator::AuthenticateToCreate( | 126 void SupervisedUserAuthenticator::AuthenticateToCreate( |
| 129 const std::string& username, | 127 const user_manager::UserID& user_id, |
| 130 const std::string& password) { | 128 const std::string& password) { |
| 131 std::string canonicalized = gaia::CanonicalizeEmail(username); | |
| 132 | |
| 133 current_state_.reset(new SupervisedUserAuthenticator::AuthAttempt( | 129 current_state_.reset(new SupervisedUserAuthenticator::AuthAttempt( |
| 134 canonicalized, password, false)); | 130 user_id, password, false)); |
| 135 | 131 |
| 136 SystemSaltGetter::Get()->GetSystemSalt( | 132 SystemSaltGetter::Get()->GetSystemSalt( |
| 137 base::Bind(&Mount, | 133 base::Bind(&Mount, |
| 138 current_state_.get(), | 134 current_state_.get(), |
| 139 scoped_refptr<SupervisedUserAuthenticator>(this), | 135 scoped_refptr<SupervisedUserAuthenticator>(this), |
| 140 cryptohome::CREATE_IF_MISSING)); | 136 cryptohome::CREATE_IF_MISSING)); |
| 141 } | 137 } |
| 142 | 138 |
| 143 void SupervisedUserAuthenticator::AddMasterKey( | 139 void SupervisedUserAuthenticator::AddMasterKey( |
| 144 const std::string& username, | 140 const user_manager::UserID& user_id, |
| 145 const std::string& password, | 141 const std::string& password, |
| 146 const std::string& master_key) { | 142 const std::string& master_key) { |
| 147 std::string canonicalized = gaia::CanonicalizeEmail(username); | |
| 148 | |
| 149 current_state_.reset(new SupervisedUserAuthenticator::AuthAttempt( | 143 current_state_.reset(new SupervisedUserAuthenticator::AuthAttempt( |
| 150 canonicalized, password, true)); | 144 user_id, password, true)); |
| 151 | 145 |
| 152 SystemSaltGetter::Get()->GetSystemSalt( | 146 SystemSaltGetter::Get()->GetSystemSalt( |
| 153 base::Bind(&AddKey, | 147 base::Bind(&AddKey, |
| 154 current_state_.get(), | 148 current_state_.get(), |
| 155 scoped_refptr<SupervisedUserAuthenticator>(this), | 149 scoped_refptr<SupervisedUserAuthenticator>(this), |
| 156 master_key)); | 150 master_key)); |
| 157 } | 151 } |
| 158 | 152 |
| 159 void SupervisedUserAuthenticator::OnAuthenticationSuccess( | 153 void SupervisedUserAuthenticator::OnAuthenticationSuccess( |
| 160 const std::string& mount_hash, | 154 const std::string& mount_hash, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 return FAILED_MOUNT; | 275 return FAILED_MOUNT; |
| 282 } | 276 } |
| 283 | 277 |
| 284 SupervisedUserAuthenticator::AuthState | 278 SupervisedUserAuthenticator::AuthState |
| 285 SupervisedUserAuthenticator::ResolveCryptohomeSuccessState() { | 279 SupervisedUserAuthenticator::ResolveCryptohomeSuccessState() { |
| 286 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 280 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 287 return SUCCESS; | 281 return SUCCESS; |
| 288 } | 282 } |
| 289 | 283 |
| 290 SupervisedUserAuthenticator::AuthAttempt::AuthAttempt( | 284 SupervisedUserAuthenticator::AuthAttempt::AuthAttempt( |
| 291 const std::string& username, | 285 const user_manager::UserID& user_id, |
| 292 const std::string& password, | 286 const std::string& password, |
| 293 bool add_key_attempt) | 287 bool add_key_attempt) |
| 294 : username(username), | 288 : user_id(user_id), |
| 295 password(password), | 289 password(password), |
| 296 add_key(add_key_attempt), | 290 add_key(add_key_attempt), |
| 297 cryptohome_complete_(false), | 291 cryptohome_complete_(false), |
| 298 cryptohome_outcome_(false), | 292 cryptohome_outcome_(false), |
| 299 hash_obtained_(false), | 293 hash_obtained_(false), |
| 300 cryptohome_code_(cryptohome::MOUNT_ERROR_NONE) {} | 294 cryptohome_code_(cryptohome::MOUNT_ERROR_NONE) {} |
| 301 | 295 |
| 302 SupervisedUserAuthenticator::AuthAttempt::~AuthAttempt() {} | 296 SupervisedUserAuthenticator::AuthAttempt::~AuthAttempt() {} |
| 303 | 297 |
| 304 void SupervisedUserAuthenticator::AuthAttempt::RecordCryptohomeStatus( | 298 void SupervisedUserAuthenticator::AuthAttempt::RecordCryptohomeStatus( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 331 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 338 return hash_obtained_; | 332 return hash_obtained_; |
| 339 } | 333 } |
| 340 | 334 |
| 341 std::string SupervisedUserAuthenticator::AuthAttempt::hash() { | 335 std::string SupervisedUserAuthenticator::AuthAttempt::hash() { |
| 342 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 336 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 343 return hash_; | 337 return hash_; |
| 344 } | 338 } |
| 345 | 339 |
| 346 } // namespace chromeos | 340 } // namespace chromeos |
| OLD | NEW |