| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/managed/supervised_user_authentication.h
" | 5 #include "chrome/browser/chromeos/login/managed/supervised_user_authentication.h
" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
| 10 #include "base/macros.h" |
| 10 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 14 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "chrome/browser/chromeos/login/managed/locally_managed_user_constants.h
" | 15 #include "chrome/browser/chromeos/login/managed/locally_managed_user_constants.h
" |
| 15 #include "chrome/browser/chromeos/login/supervised_user_manager.h" | 16 #include "chrome/browser/chromeos/login/supervised_user_manager.h" |
| 16 #include "chrome/browser/chromeos/login/user.h" | 17 #include "chrome/browser/chromeos/login/user.h" |
| 17 #include "chrome/browser/chromeos/login/user_manager.h" | 18 #include "chrome/browser/chromeos/login/user_manager.h" |
| 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 19 #include "chromeos/chromeos_switches.h" | 20 #include "chromeos/chromeos_switches.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 std::string raw_result(out_bytes, out_bytes + sizeof(out_bytes)); | 96 std::string raw_result(out_bytes, out_bytes + sizeof(out_bytes)); |
| 96 | 97 |
| 97 std::string result; | 98 std::string result; |
| 98 base::Base64Encode(raw_result, &result); | 99 base::Base64Encode(raw_result, &result); |
| 99 return result; | 100 return result; |
| 100 } | 101 } |
| 101 | 102 |
| 102 base::DictionaryValue* LoadPasswordData(base::FilePath profile_dir) { | 103 base::DictionaryValue* LoadPasswordData(base::FilePath profile_dir) { |
| 103 JSONFileValueSerializer serializer(profile_dir.Append(kPasswordUpdateFile)); | 104 JSONFileValueSerializer serializer(profile_dir.Append(kPasswordUpdateFile)); |
| 104 std::string error_message; | 105 std::string error_message; |
| 105 int error_code; | 106 int error_code = JSONFileValueSerializer::JSON_NO_ERROR; |
| 106 scoped_ptr<base::Value> value( | 107 scoped_ptr<base::Value> value( |
| 107 serializer.Deserialize(&error_code, &error_message)); | 108 serializer.Deserialize(&error_code, &error_message)); |
| 108 if (JSONFileValueSerializer::JSON_NO_ERROR != error_code) { | 109 if (JSONFileValueSerializer::JSON_NO_ERROR != error_code) { |
| 110 LOG(ERROR) << "Could not deserialize password data, error = " << error_code |
| 111 << " / " << error_message; |
| 109 return NULL; | 112 return NULL; |
| 110 } | 113 } |
| 111 base::DictionaryValue* result; | 114 base::DictionaryValue* result; |
| 112 if (!value->GetAsDictionary(&result)) { | 115 if (!value->GetAsDictionary(&result)) { |
| 116 LOG(ERROR) << "Stored password data is not a dictionary"; |
| 113 return NULL; | 117 return NULL; |
| 114 } | 118 } |
| 115 value.Pass(); | 119 ignore_result(value.release()); |
| 116 return result; | 120 return result; |
| 117 } | 121 } |
| 118 | 122 |
| 119 void OnPasswordDataLoaded( | 123 void OnPasswordDataLoaded( |
| 120 const SupervisedUserAuthentication::PasswordDataCallback& success_callback, | 124 const SupervisedUserAuthentication::PasswordDataCallback& success_callback, |
| 121 const base::Closure& failure_callback, | 125 const base::Closure& failure_callback, |
| 122 base::DictionaryValue* value) { | 126 base::DictionaryValue* value) { |
| 123 if (!value) { | 127 if (!value) { |
| 124 failure_callback.Run(); | 128 failure_callback.Run(); |
| 125 return; | 129 return; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 password_data->SetStringWithoutPathExpansion(kSalt, salt); | 210 password_data->SetStringWithoutPathExpansion(kSalt, salt); |
| 207 int revision = kMinPasswordRevision; | 211 int revision = kMinPasswordRevision; |
| 208 password_data->SetIntegerWithoutPathExpansion(kPasswordRevision, revision); | 212 password_data->SetIntegerWithoutPathExpansion(kPasswordRevision, revision); |
| 209 std::string salted_password = | 213 std::string salted_password = |
| 210 BuildPasswordForHashWithSaltSchema(salt, password); | 214 BuildPasswordForHashWithSaltSchema(salt, password); |
| 211 std::string base64_signature_key = BuildRawHMACKey(); | 215 std::string base64_signature_key = BuildRawHMACKey(); |
| 212 std::string base64_signature = | 216 std::string base64_signature = |
| 213 BuildPasswordSignature(salted_password, revision, base64_signature_key); | 217 BuildPasswordSignature(salted_password, revision, base64_signature_key); |
| 214 password_data->SetStringWithoutPathExpansion(kEncryptedPassword, | 218 password_data->SetStringWithoutPathExpansion(kEncryptedPassword, |
| 215 salted_password); | 219 salted_password); |
| 220 password_data->SetStringWithoutPathExpansion(kPasswordSignature, |
| 221 base64_signature); |
| 216 | 222 |
| 217 extra_data->SetStringWithoutPathExpansion(kPasswordEncryptionKey, | 223 extra_data->SetStringWithoutPathExpansion(kPasswordEncryptionKey, |
| 218 BuildRawHMACKey()); | 224 BuildRawHMACKey()); |
| 219 extra_data->SetStringWithoutPathExpansion(kPasswordSignatureKey, | 225 extra_data->SetStringWithoutPathExpansion(kPasswordSignatureKey, |
| 220 base64_signature_key); | 226 base64_signature_key); |
| 221 return true; | 227 return true; |
| 222 } | 228 } |
| 223 NOTREACHED(); | 229 NOTREACHED(); |
| 224 return false; | 230 return false; |
| 225 } | 231 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 if (holder.GetIntegerWithoutPathExpansion(kSchemaVersion, | 265 if (holder.GetIntegerWithoutPathExpansion(kSchemaVersion, |
| 260 &schema_version_index)) { | 266 &schema_version_index)) { |
| 261 schema_version = static_cast<Schema>(schema_version_index); | 267 schema_version = static_cast<Schema>(schema_version_index); |
| 262 } | 268 } |
| 263 return schema_version; | 269 return schema_version; |
| 264 } | 270 } |
| 265 | 271 |
| 266 bool SupervisedUserAuthentication::NeedPasswordChange( | 272 bool SupervisedUserAuthentication::NeedPasswordChange( |
| 267 const std::string& user_id, | 273 const std::string& user_id, |
| 268 const base::DictionaryValue* password_data) { | 274 const base::DictionaryValue* password_data) { |
| 269 | |
| 270 base::DictionaryValue local; | 275 base::DictionaryValue local; |
| 271 owner_->GetPasswordInformation(user_id, &local); | 276 owner_->GetPasswordInformation(user_id, &local); |
| 272 int local_schema = SCHEMA_PLAIN; | 277 int local_schema = SCHEMA_PLAIN; |
| 273 int local_revision = kMinPasswordRevision; | 278 int local_revision = kMinPasswordRevision; |
| 274 int updated_schema = SCHEMA_PLAIN; | 279 int updated_schema = SCHEMA_PLAIN; |
| 275 int updated_revision = kMinPasswordRevision; | 280 int updated_revision = kMinPasswordRevision; |
| 276 local.GetIntegerWithoutPathExpansion(kSchemaVersion, &local_schema); | 281 local.GetIntegerWithoutPathExpansion(kSchemaVersion, &local_schema); |
| 277 local.GetIntegerWithoutPathExpansion(kPasswordRevision, &local_revision); | 282 local.GetIntegerWithoutPathExpansion(kPasswordRevision, &local_revision); |
| 278 password_data->GetIntegerWithoutPathExpansion(kSchemaVersion, | 283 password_data->GetIntegerWithoutPathExpansion(kSchemaVersion, |
| 279 &updated_schema); | 284 &updated_schema); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 331 |
| 327 bool SupervisedUserAuthentication::HasIncompleteKey( | 332 bool SupervisedUserAuthentication::HasIncompleteKey( |
| 328 const std::string& user_id) { | 333 const std::string& user_id) { |
| 329 base::DictionaryValue holder; | 334 base::DictionaryValue holder; |
| 330 owner_->GetPasswordInformation(user_id, &holder); | 335 owner_->GetPasswordInformation(user_id, &holder); |
| 331 bool incomplete_key = false; | 336 bool incomplete_key = false; |
| 332 holder.GetBoolean(kHasIncompleteKey, &incomplete_key); | 337 holder.GetBoolean(kHasIncompleteKey, &incomplete_key); |
| 333 return incomplete_key; | 338 return incomplete_key; |
| 334 } | 339 } |
| 335 | 340 |
| 336 void SupervisedUserAuthentication::MarkKeyIncomplete( | 341 void SupervisedUserAuthentication::MarkKeyIncomplete(const std::string& user_id, |
| 337 const std::string& user_id) { | 342 bool incomplete) { |
| 338 base::DictionaryValue holder; | 343 base::DictionaryValue holder; |
| 339 owner_->GetPasswordInformation(user_id, &holder); | 344 owner_->GetPasswordInformation(user_id, &holder); |
| 340 holder.SetBoolean(kHasIncompleteKey, true); | 345 holder.SetBoolean(kHasIncompleteKey, incomplete); |
| 341 owner_->SetPasswordInformation(user_id, &holder); | 346 owner_->SetPasswordInformation(user_id, &holder); |
| 342 } | 347 } |
| 343 | 348 |
| 344 void SupervisedUserAuthentication::LoadPasswordUpdateData( | 349 void SupervisedUserAuthentication::LoadPasswordUpdateData( |
| 345 const std::string& user_id, | 350 const std::string& user_id, |
| 346 const PasswordDataCallback& success_callback, | 351 const PasswordDataCallback& success_callback, |
| 347 const base::Closure& failure_callback) { | 352 const base::Closure& failure_callback) { |
| 348 const User* user = UserManager::Get()->FindUser(user_id); | 353 const User* user = UserManager::Get()->FindUser(user_id); |
| 349 base::FilePath profile_path = | 354 base::FilePath profile_path = |
| 350 ProfileHelper::GetProfilePathByUserIdHash(user->username_hash()); | 355 ProfileHelper::GetProfilePathByUserIdHash(user->username_hash()); |
| 351 PostTaskAndReplyWithResult( | 356 PostTaskAndReplyWithResult( |
| 352 content::BrowserThread::GetBlockingPool(), | 357 content::BrowserThread::GetBlockingPool(), |
| 353 FROM_HERE, | 358 FROM_HERE, |
| 354 base::Bind(&LoadPasswordData, profile_path), | 359 base::Bind(&LoadPasswordData, profile_path), |
| 355 base::Bind(&OnPasswordDataLoaded, success_callback, failure_callback)); | 360 base::Bind(&OnPasswordDataLoaded, success_callback, failure_callback)); |
| 356 } | 361 } |
| 357 | 362 |
| 358 } // namespace chromeos | 363 } // namespace chromeos |
| OLD | NEW |