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 "chromeos/login/auth/key.h" | 5 #include "chromeos/login/auth/key.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // reversed. | 87 // reversed. |
88 secret_ = base::ToLowerASCII(base::HexEncode( | 88 secret_ = base::ToLowerASCII(base::HexEncode( |
89 reinterpret_cast<const void*>(hash), sizeof(hash) / 2)); | 89 reinterpret_cast<const void*>(hash), sizeof(hash) / 2)); |
90 break; | 90 break; |
91 } | 91 } |
92 case KEY_TYPE_SALTED_PBKDF2_AES256_1234: { | 92 case KEY_TYPE_SALTED_PBKDF2_AES256_1234: { |
93 std::unique_ptr<crypto::SymmetricKey> key( | 93 std::unique_ptr<crypto::SymmetricKey> key( |
94 crypto::SymmetricKey::DeriveKeyFromPassword( | 94 crypto::SymmetricKey::DeriveKeyFromPassword( |
95 crypto::SymmetricKey::AES, secret_, salt, kNumIterations, | 95 crypto::SymmetricKey::AES, secret_, salt, kNumIterations, |
96 kKeySizeInBits)); | 96 kKeySizeInBits)); |
97 std::string raw_secret; | 97 base::Base64Encode(key->key(), &secret_); |
98 key->GetRawKey(&raw_secret); | |
99 base::Base64Encode(raw_secret, &secret_); | |
100 break; | 98 break; |
101 } | 99 } |
102 case KEY_TYPE_SALTED_SHA256: | 100 case KEY_TYPE_SALTED_SHA256: |
103 base::Base64Encode(crypto::SHA256HashString(salt + secret_), &secret_); | 101 base::Base64Encode(crypto::SHA256HashString(salt + secret_), &secret_); |
104 break; | 102 break; |
105 | 103 |
106 default: | 104 default: |
107 // The resulting key will be sent to cryptohomed. It should always be | 105 // The resulting key will be sent to cryptohomed. It should always be |
108 // hashed. If hashing fails, crash instead of sending a plain-text key. | 106 // hashed. If hashing fails, crash instead of sending a plain-text key. |
109 CHECK(false); | 107 CHECK(false); |
110 return; | 108 return; |
111 } | 109 } |
112 | 110 |
113 key_type_ = target_key_type; | 111 key_type_ = target_key_type; |
114 salt_ = salt; | 112 salt_ = salt; |
115 } | 113 } |
116 | 114 |
117 } // namespace chromeos | 115 } // namespace chromeos |
OLD | NEW |