Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/browser/chromeos/login/managed/supervised_user_authentication.cc

Issue 221813006: Various supervised user password fixes - 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: upload once again Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 std::string raw_result(out_bytes, out_bytes + sizeof(out_bytes)); 95 std::string raw_result(out_bytes, out_bytes + sizeof(out_bytes));
96 96
97 std::string result; 97 std::string result;
98 base::Base64Encode(raw_result, &result); 98 base::Base64Encode(raw_result, &result);
99 return result; 99 return result;
100 } 100 }
101 101
102 base::DictionaryValue* LoadPasswordData(base::FilePath profile_dir) { 102 base::DictionaryValue* LoadPasswordData(base::FilePath profile_dir) {
103 JSONFileValueSerializer serializer(profile_dir.Append(kPasswordUpdateFile)); 103 JSONFileValueSerializer serializer(profile_dir.Append(kPasswordUpdateFile));
104 std::string error_message; 104 std::string error_message;
105 int error_code; 105 int error_code = JSONFileValueSerializer::JSON_NO_ERROR;
106 scoped_ptr<base::Value> value( 106 scoped_ptr<base::Value> value(
107 serializer.Deserialize(&error_code, &error_message)); 107 serializer.Deserialize(&error_code, &error_message));
108 if (JSONFileValueSerializer::JSON_NO_ERROR != error_code) { 108 if (JSONFileValueSerializer::JSON_NO_ERROR != error_code) {
109 LOG(ERROR) << "Could not deserialize password data, error = " << error_code
110 << " / " << error_message;
109 return NULL; 111 return NULL;
110 } 112 }
111 base::DictionaryValue* result; 113 base::DictionaryValue* result;
112 if (!value->GetAsDictionary(&result)) { 114 if (!value->GetAsDictionary(&result)) {
115 NOTREACHED();
Bernhard Bauer 2014/04/02 14:05:28 In general, having a NOTREACHED() is an indication
Denis Kuznetsov (DE-MUC) 2014/04/02 14:48:51 Done.
113 return NULL; 116 return NULL;
114 } 117 }
115 value.Pass(); 118 // Ignore unused result warning.
Nikita (slow) 2014/04/02 14:18:20 nit: Add empty line before, place comment into {}
Denis Kuznetsov (DE-MUC) 2014/04/02 14:48:51 Done.
119 if (value.release()) {
Bernhard Bauer 2014/04/02 14:05:28 base/macros.h has ignore_result().
Denis Kuznetsov (DE-MUC) 2014/04/02 14:48:51 Done.
120 }
116 return result; 121 return result;
117 } 122 }
118 123
119 void OnPasswordDataLoaded( 124 void OnPasswordDataLoaded(
120 const SupervisedUserAuthentication::PasswordDataCallback& success_callback, 125 const SupervisedUserAuthentication::PasswordDataCallback& success_callback,
121 const base::Closure& failure_callback, 126 const base::Closure& failure_callback,
122 base::DictionaryValue* value) { 127 base::DictionaryValue* value) {
123 if (!value) { 128 if (!value) {
124 failure_callback.Run(); 129 failure_callback.Run();
125 return; 130 return;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 password_data->SetStringWithoutPathExpansion(kSalt, salt); 211 password_data->SetStringWithoutPathExpansion(kSalt, salt);
207 int revision = kMinPasswordRevision; 212 int revision = kMinPasswordRevision;
208 password_data->SetIntegerWithoutPathExpansion(kPasswordRevision, revision); 213 password_data->SetIntegerWithoutPathExpansion(kPasswordRevision, revision);
209 std::string salted_password = 214 std::string salted_password =
210 BuildPasswordForHashWithSaltSchema(salt, password); 215 BuildPasswordForHashWithSaltSchema(salt, password);
211 std::string base64_signature_key = BuildRawHMACKey(); 216 std::string base64_signature_key = BuildRawHMACKey();
212 std::string base64_signature = 217 std::string base64_signature =
213 BuildPasswordSignature(salted_password, revision, base64_signature_key); 218 BuildPasswordSignature(salted_password, revision, base64_signature_key);
214 password_data->SetStringWithoutPathExpansion(kEncryptedPassword, 219 password_data->SetStringWithoutPathExpansion(kEncryptedPassword,
215 salted_password); 220 salted_password);
221 password_data->SetStringWithoutPathExpansion(kPasswordSignature,
222 base64_signature);
216 223
217 extra_data->SetStringWithoutPathExpansion(kPasswordEncryptionKey, 224 extra_data->SetStringWithoutPathExpansion(kPasswordEncryptionKey,
218 BuildRawHMACKey()); 225 BuildRawHMACKey());
219 extra_data->SetStringWithoutPathExpansion(kPasswordSignatureKey, 226 extra_data->SetStringWithoutPathExpansion(kPasswordSignatureKey,
220 base64_signature_key); 227 base64_signature_key);
221 return true; 228 return true;
222 } 229 }
223 NOTREACHED(); 230 NOTREACHED();
224 return false; 231 return false;
225 } 232 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 if (holder.GetIntegerWithoutPathExpansion(kSchemaVersion, 266 if (holder.GetIntegerWithoutPathExpansion(kSchemaVersion,
260 &schema_version_index)) { 267 &schema_version_index)) {
261 schema_version = static_cast<Schema>(schema_version_index); 268 schema_version = static_cast<Schema>(schema_version_index);
262 } 269 }
263 return schema_version; 270 return schema_version;
264 } 271 }
265 272
266 bool SupervisedUserAuthentication::NeedPasswordChange( 273 bool SupervisedUserAuthentication::NeedPasswordChange(
267 const std::string& user_id, 274 const std::string& user_id,
268 const base::DictionaryValue* password_data) { 275 const base::DictionaryValue* password_data) {
269
270 base::DictionaryValue local; 276 base::DictionaryValue local;
271 owner_->GetPasswordInformation(user_id, &local); 277 owner_->GetPasswordInformation(user_id, &local);
272 int local_schema = SCHEMA_PLAIN; 278 int local_schema = SCHEMA_PLAIN;
273 int local_revision = kMinPasswordRevision; 279 int local_revision = kMinPasswordRevision;
274 int updated_schema = SCHEMA_PLAIN; 280 int updated_schema = SCHEMA_PLAIN;
275 int updated_revision = kMinPasswordRevision; 281 int updated_revision = kMinPasswordRevision;
276 local.GetIntegerWithoutPathExpansion(kSchemaVersion, &local_schema); 282 local.GetIntegerWithoutPathExpansion(kSchemaVersion, &local_schema);
277 local.GetIntegerWithoutPathExpansion(kPasswordRevision, &local_revision); 283 local.GetIntegerWithoutPathExpansion(kPasswordRevision, &local_revision);
278 password_data->GetIntegerWithoutPathExpansion(kSchemaVersion, 284 password_data->GetIntegerWithoutPathExpansion(kSchemaVersion,
279 &updated_schema); 285 &updated_schema);
280 password_data->GetIntegerWithoutPathExpansion(kPasswordRevision, 286 password_data->GetIntegerWithoutPathExpansion(kPasswordRevision,
281 &updated_revision); 287 &updated_revision);
288 LOG(ERROR) << "-----5";
Bernhard Bauer 2014/04/02 14:05:28 Please remove.
Denis Kuznetsov (DE-MUC) 2014/04/02 14:48:51 Done.
282 if (updated_schema > local_schema) 289 if (updated_schema > local_schema)
283 return true; 290 return true;
284 DCHECK_EQ(updated_schema, local_schema); 291 DCHECK_EQ(updated_schema, local_schema);
285 return updated_revision > local_revision; 292 return updated_revision > local_revision;
286 } 293 }
287 294
288 void SupervisedUserAuthentication::ScheduleSupervisedPasswordChange( 295 void SupervisedUserAuthentication::ScheduleSupervisedPasswordChange(
289 const std::string& supervised_user_id, 296 const std::string& supervised_user_id,
290 const base::DictionaryValue* password_data) { 297 const base::DictionaryValue* password_data) {
291 const User* user = UserManager::Get()->FindUser(supervised_user_id); 298 const User* user = UserManager::Get()->FindUser(supervised_user_id);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 333
327 bool SupervisedUserAuthentication::HasIncompleteKey( 334 bool SupervisedUserAuthentication::HasIncompleteKey(
328 const std::string& user_id) { 335 const std::string& user_id) {
329 base::DictionaryValue holder; 336 base::DictionaryValue holder;
330 owner_->GetPasswordInformation(user_id, &holder); 337 owner_->GetPasswordInformation(user_id, &holder);
331 bool incomplete_key = false; 338 bool incomplete_key = false;
332 holder.GetBoolean(kHasIncompleteKey, &incomplete_key); 339 holder.GetBoolean(kHasIncompleteKey, &incomplete_key);
333 return incomplete_key; 340 return incomplete_key;
334 } 341 }
335 342
336 void SupervisedUserAuthentication::MarkKeyIncomplete( 343 void SupervisedUserAuthentication::MarkKeyIncomplete(const std::string& user_id,
337 const std::string& user_id) { 344 bool incomplete) {
338 base::DictionaryValue holder; 345 base::DictionaryValue holder;
339 owner_->GetPasswordInformation(user_id, &holder); 346 owner_->GetPasswordInformation(user_id, &holder);
340 holder.SetBoolean(kHasIncompleteKey, true); 347 holder.SetBoolean(kHasIncompleteKey, incomplete);
341 owner_->SetPasswordInformation(user_id, &holder); 348 owner_->SetPasswordInformation(user_id, &holder);
342 } 349 }
343 350
344 void SupervisedUserAuthentication::LoadPasswordUpdateData( 351 void SupervisedUserAuthentication::LoadPasswordUpdateData(
345 const std::string& user_id, 352 const std::string& user_id,
346 const PasswordDataCallback& success_callback, 353 const PasswordDataCallback& success_callback,
347 const base::Closure& failure_callback) { 354 const base::Closure& failure_callback) {
348 const User* user = UserManager::Get()->FindUser(user_id); 355 const User* user = UserManager::Get()->FindUser(user_id);
349 base::FilePath profile_path = 356 base::FilePath profile_path =
350 ProfileHelper::GetProfilePathByUserIdHash(user->username_hash()); 357 ProfileHelper::GetProfilePathByUserIdHash(user->username_hash());
351 PostTaskAndReplyWithResult( 358 PostTaskAndReplyWithResult(
352 content::BrowserThread::GetBlockingPool(), 359 content::BrowserThread::GetBlockingPool(),
353 FROM_HERE, 360 FROM_HERE,
354 base::Bind(&LoadPasswordData, profile_path), 361 base::Bind(&LoadPasswordData, profile_path),
355 base::Bind(&OnPasswordDataLoaded, success_callback, failure_callback)); 362 base::Bind(&OnPasswordDataLoaded, success_callback, failure_callback));
356 } 363 }
357 364
358 } // namespace chromeos 365 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698