| 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_authenticatio
n.h" | 5 #include "chrome/browser/chromeos/login/supervised/supervised_user_authenticatio
n.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 const int kMasterKeySize = 32; | 38 const int kMasterKeySize = 32; |
| 39 | 39 |
| 40 std::string CreateSalt() { | 40 std::string CreateSalt() { |
| 41 char result[kSaltSize]; | 41 char result[kSaltSize]; |
| 42 crypto::RandBytes(&result, sizeof(result)); | 42 crypto::RandBytes(&result, sizeof(result)); |
| 43 return base::ToLowerASCII( | 43 return base::ToLowerASCII( |
| 44 base::HexEncode(reinterpret_cast<const void*>(result), sizeof(result))); | 44 base::HexEncode(reinterpret_cast<const void*>(result), sizeof(result))); |
| 45 } | 45 } |
| 46 | 46 |
| 47 std::string BuildRawHMACKey() { | 47 std::string BuildRawHMACKey() { |
| 48 scoped_ptr<crypto::SymmetricKey> key(crypto::SymmetricKey::GenerateRandomKey( | 48 std::unique_ptr<crypto::SymmetricKey> key( |
| 49 crypto::SymmetricKey::AES, kHMACKeySizeInBits)); | 49 crypto::SymmetricKey::GenerateRandomKey(crypto::SymmetricKey::AES, |
| 50 kHMACKeySizeInBits)); |
| 50 std::string raw_result, result; | 51 std::string raw_result, result; |
| 51 key->GetRawKey(&raw_result); | 52 key->GetRawKey(&raw_result); |
| 52 base::Base64Encode(raw_result, &result); | 53 base::Base64Encode(raw_result, &result); |
| 53 return result; | 54 return result; |
| 54 } | 55 } |
| 55 | 56 |
| 56 base::DictionaryValue* LoadPasswordData(base::FilePath profile_dir) { | 57 base::DictionaryValue* LoadPasswordData(base::FilePath profile_dir) { |
| 57 JSONFileValueDeserializer deserializer( | 58 JSONFileValueDeserializer deserializer( |
| 58 profile_dir.Append(kPasswordUpdateFile)); | 59 profile_dir.Append(kPasswordUpdateFile)); |
| 59 std::string error_message; | 60 std::string error_message; |
| 60 int error_code = JSONFileValueDeserializer::JSON_NO_ERROR; | 61 int error_code = JSONFileValueDeserializer::JSON_NO_ERROR; |
| 61 scoped_ptr<base::Value> value = | 62 std::unique_ptr<base::Value> value = |
| 62 deserializer.Deserialize(&error_code, &error_message); | 63 deserializer.Deserialize(&error_code, &error_message); |
| 63 if (JSONFileValueDeserializer::JSON_NO_ERROR != error_code) { | 64 if (JSONFileValueDeserializer::JSON_NO_ERROR != error_code) { |
| 64 LOG(ERROR) << "Could not deserialize password data, error = " << error_code | 65 LOG(ERROR) << "Could not deserialize password data, error = " << error_code |
| 65 << " / " << error_message; | 66 << " / " << error_message; |
| 66 return NULL; | 67 return NULL; |
| 67 } | 68 } |
| 68 base::DictionaryValue* result; | 69 base::DictionaryValue* result; |
| 69 if (!value->GetAsDictionary(&result)) { | 70 if (!value->GetAsDictionary(&result)) { |
| 70 LOG(ERROR) << "Stored password data is not a dictionary"; | 71 LOG(ERROR) << "Stored password data is not a dictionary"; |
| 71 return NULL; | 72 return NULL; |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 LOG(FATAL) << "HMAC::Sign failed"; | 319 LOG(FATAL) << "HMAC::Sign failed"; |
| 319 | 320 |
| 320 std::string raw_result(out_bytes, out_bytes + sizeof(out_bytes)); | 321 std::string raw_result(out_bytes, out_bytes + sizeof(out_bytes)); |
| 321 | 322 |
| 322 std::string result; | 323 std::string result; |
| 323 base::Base64Encode(raw_result, &result); | 324 base::Base64Encode(raw_result, &result); |
| 324 return result; | 325 return result; |
| 325 } | 326 } |
| 326 | 327 |
| 327 } // namespace chromeos | 328 } // namespace chromeos |
| OLD | NEW |