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 22 matching lines...) Expand all Loading... |
33 // Size of key signature. | 33 // Size of key signature. |
34 const unsigned kHMACKeySizeInBits = 256; | 34 const unsigned kHMACKeySizeInBits = 256; |
35 const int kSignatureLength = 32; | 35 const int kSignatureLength = 32; |
36 | 36 |
37 // Size of master key (in bytes). | 37 // Size of master key (in bytes). |
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 StringToLowerASCII(base::HexEncode( | 43 return base::StringToLowerASCII(base::HexEncode( |
44 reinterpret_cast<const void*>(result), | 44 reinterpret_cast<const void*>(result), |
45 sizeof(result))); | 45 sizeof(result))); |
46 } | 46 } |
47 | 47 |
48 std::string BuildRawHMACKey() { | 48 std::string BuildRawHMACKey() { |
49 scoped_ptr<crypto::SymmetricKey> key(crypto::SymmetricKey::GenerateRandomKey( | 49 scoped_ptr<crypto::SymmetricKey> key(crypto::SymmetricKey::GenerateRandomKey( |
50 crypto::SymmetricKey::AES, kHMACKeySizeInBits)); | 50 crypto::SymmetricKey::AES, kHMACKeySizeInBits)); |
51 std::string raw_result, result; | 51 std::string raw_result, result; |
52 key->GetRawKey(&raw_result); | 52 key->GetRawKey(&raw_result); |
53 base::Base64Encode(raw_result, &result); | 53 base::Base64Encode(raw_result, &result); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 base64_signature_key); | 156 base64_signature_key); |
157 return true; | 157 return true; |
158 } | 158 } |
159 NOTREACHED(); | 159 NOTREACHED(); |
160 return false; | 160 return false; |
161 } | 161 } |
162 | 162 |
163 std::string SupervisedUserAuthentication::GenerateMasterKey() { | 163 std::string SupervisedUserAuthentication::GenerateMasterKey() { |
164 char master_key_bytes[kMasterKeySize]; | 164 char master_key_bytes[kMasterKeySize]; |
165 crypto::RandBytes(&master_key_bytes, sizeof(master_key_bytes)); | 165 crypto::RandBytes(&master_key_bytes, sizeof(master_key_bytes)); |
166 return StringToLowerASCII( | 166 return base::StringToLowerASCII( |
167 base::HexEncode(reinterpret_cast<const void*>(master_key_bytes), | 167 base::HexEncode(reinterpret_cast<const void*>(master_key_bytes), |
168 sizeof(master_key_bytes))); | 168 sizeof(master_key_bytes))); |
169 } | 169 } |
170 | 170 |
171 void SupervisedUserAuthentication::StorePasswordData( | 171 void SupervisedUserAuthentication::StorePasswordData( |
172 const std::string& user_id, | 172 const std::string& user_id, |
173 const base::DictionaryValue& password_data) { | 173 const base::DictionaryValue& password_data) { |
174 base::DictionaryValue holder; | 174 base::DictionaryValue holder; |
175 owner_->GetPasswordInformation(user_id, &holder); | 175 owner_->GetPasswordInformation(user_id, &holder); |
176 const base::Value* value; | 176 const base::Value* value; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 LOG(FATAL) << "HMAC::Sign failed"; | 313 LOG(FATAL) << "HMAC::Sign failed"; |
314 | 314 |
315 std::string raw_result(out_bytes, out_bytes + sizeof(out_bytes)); | 315 std::string raw_result(out_bytes, out_bytes + sizeof(out_bytes)); |
316 | 316 |
317 std::string result; | 317 std::string result; |
318 base::Base64Encode(raw_result, &result); | 318 base::Base64Encode(raw_result, &result); |
319 return result; | 319 return result; |
320 } | 320 } |
321 | 321 |
322 } // namespace chromeos | 322 } // namespace chromeos |
OLD | NEW |