| 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/signin/local_auth.h" | 5 #include "chrome/browser/signin/local_auth.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "components/encryptor/encryptor.h" | 17 #include "components/encryptor/os_crypt.h" |
| 18 #include "components/user_prefs/pref_registry_syncable.h" | 18 #include "components/user_prefs/pref_registry_syncable.h" |
| 19 #include "crypto/random.h" | 19 #include "crypto/random.h" |
| 20 #include "crypto/secure_util.h" | 20 #include "crypto/secure_util.h" |
| 21 #include "crypto/symmetric_key.h" | 21 #include "crypto/symmetric_key.h" |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // WARNING: Changing these values will make it impossible to do off-line | 25 // WARNING: Changing these values will make it impossible to do off-line |
| 26 // authentication until the next successful on-line authentication. To change | 26 // authentication until the next successful on-line authentication. To change |
| 27 // these safely, change the "encoding" version below and make verification | 27 // these safely, change the "encoding" version below and make verification |
| (...skipping 27 matching lines...) Expand all Loading... |
| 55 | 55 |
| 56 return password_hash; | 56 return password_hash; |
| 57 } | 57 } |
| 58 | 58 |
| 59 std::string EncodePasswordHashRecord(const std::string& record, | 59 std::string EncodePasswordHashRecord(const std::string& record, |
| 60 char encoding) { | 60 char encoding) { |
| 61 DCHECK_EQ(kHash1Encoding, encoding); // Currently support only one method. | 61 DCHECK_EQ(kHash1Encoding, encoding); // Currently support only one method. |
| 62 | 62 |
| 63 // Encrypt the hash using the OS account-password protection (if available). | 63 // Encrypt the hash using the OS account-password protection (if available). |
| 64 std::string encoded; | 64 std::string encoded; |
| 65 const bool success = Encryptor::EncryptString(record, &encoded); | 65 const bool success = OSCrypt::EncryptString(record, &encoded); |
| 66 DCHECK(success); | 66 DCHECK(success); |
| 67 | 67 |
| 68 // Convert binary record to text for preference database. | 68 // Convert binary record to text for preference database. |
| 69 std::string encoded64; | 69 std::string encoded64; |
| 70 base::Base64Encode(encoded, &encoded64); | 70 base::Base64Encode(encoded, &encoded64); |
| 71 | 71 |
| 72 // Stuff the "encoding" value into the first byte. | 72 // Stuff the "encoding" value into the first byte. |
| 73 encoded64.insert(0, &encoding, sizeof(encoding)); | 73 encoded64.insert(0, &encoding, sizeof(encoding)); |
| 74 | 74 |
| 75 return encoded64; | 75 return encoded64; |
| 76 } | 76 } |
| 77 | 77 |
| 78 bool DecodePasswordHashRecord(const std::string& encoded, | 78 bool DecodePasswordHashRecord(const std::string& encoded, |
| 79 std::string* decoded, | 79 std::string* decoded, |
| 80 char* encoding) { | 80 char* encoding) { |
| 81 // Extract the "encoding" value from the first byte and validate. | 81 // Extract the "encoding" value from the first byte and validate. |
| 82 if (encoded.length() < 1) | 82 if (encoded.length() < 1) |
| 83 return false; | 83 return false; |
| 84 *encoding = encoded[0]; | 84 *encoding = encoded[0]; |
| 85 if (*encoding != kHash1Encoding) | 85 if (*encoding != kHash1Encoding) |
| 86 return false; | 86 return false; |
| 87 | 87 |
| 88 // Stored record is base64; convert to binary. | 88 // Stored record is base64; convert to binary. |
| 89 std::string unbase64; | 89 std::string unbase64; |
| 90 if (!base::Base64Decode(encoded.substr(1), &unbase64)) | 90 if (!base::Base64Decode(encoded.substr(1), &unbase64)) |
| 91 return false; | 91 return false; |
| 92 | 92 |
| 93 // Decrypt the record using the OS account-password protection (if available). | 93 // Decrypt the record using the OS account-password protection (if available). |
| 94 return Encryptor::DecryptString(unbase64, decoded); | 94 return OSCrypt::DecryptString(unbase64, decoded); |
| 95 } | 95 } |
| 96 | 96 |
| 97 } // namespace | 97 } // namespace |
| 98 | 98 |
| 99 namespace chrome { | 99 namespace chrome { |
| 100 | 100 |
| 101 void RegisterLocalAuthPrefs(user_prefs::PrefRegistrySyncable* registry) { | 101 void RegisterLocalAuthPrefs(user_prefs::PrefRegistrySyncable* registry) { |
| 102 registry->RegisterStringPref( | 102 registry->RegisterStringPref( |
| 103 prefs::kGoogleServicesPasswordHash, | 103 prefs::kGoogleServicesPasswordHash, |
| 104 std::string(), | 104 std::string(), |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 g_browser_process->profile_manager()->GetProfileInfoCache(); | 192 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 193 size_t info_index = info.GetIndexOfProfileWithPath(profile->GetPath()); | 193 size_t info_index = info.GetIndexOfProfileWithPath(profile->GetPath()); |
| 194 if (info_index == std::string::npos) { | 194 if (info_index == std::string::npos) { |
| 195 NOTREACHED(); // This should never happen but fail safely if it does. | 195 NOTREACHED(); // This should never happen but fail safely if it does. |
| 196 return false; | 196 return false; |
| 197 } | 197 } |
| 198 return ValidateLocalAuthCredentials(info_index, password); | 198 return ValidateLocalAuthCredentials(info_index, password); |
| 199 } | 199 } |
| 200 | 200 |
| 201 } // namespace chrome | 201 } // namespace chrome |
| OLD | NEW |