| 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 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_TOKEN_ENCRYPTOR_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_TOKEN_ENCRYPTOR_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_TOKEN_ENCRYPTOR_H_ | 6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_TOKEN_ENCRYPTOR_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 explicit CryptohomeTokenEncryptor(const std::string& system_salt); | 40 explicit CryptohomeTokenEncryptor(const std::string& system_salt); |
| 41 ~CryptohomeTokenEncryptor() override; | 41 ~CryptohomeTokenEncryptor() override; |
| 42 | 42 |
| 43 // TokenEncryptor overrides: | 43 // TokenEncryptor overrides: |
| 44 std::string EncryptWithSystemSalt(const std::string& token) override; | 44 std::string EncryptWithSystemSalt(const std::string& token) override; |
| 45 std::string DecryptWithSystemSalt( | 45 std::string DecryptWithSystemSalt( |
| 46 const std::string& encrypted_token_hex) override; | 46 const std::string& encrypted_token_hex) override; |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 // Converts |passphrase| to a SymmetricKey using the given |salt|. | 49 // Converts |passphrase| to a SymmetricKey using the given |salt|. |
| 50 crypto::SymmetricKey* PassphraseToKey(const std::string& passphrase, | 50 std::unique_ptr<crypto::SymmetricKey> PassphraseToKey( |
| 51 const std::string& salt); | 51 const std::string& passphrase, |
| 52 const std::string& salt); |
| 52 | 53 |
| 53 // Encrypts (AES) the token given |key| and |salt|. | 54 // Encrypts (AES) the token given |key| and |salt|. |
| 54 std::string EncryptTokenWithKey(crypto::SymmetricKey* key, | 55 std::string EncryptTokenWithKey(crypto::SymmetricKey* key, |
| 55 const std::string& salt, | 56 const std::string& salt, |
| 56 const std::string& token); | 57 const std::string& token); |
| 57 | 58 |
| 58 // Decrypts (AES) hex encoded encrypted token given |key| and |salt|. | 59 // Decrypts (AES) hex encoded encrypted token given |key| and |salt|. |
| 59 std::string DecryptTokenWithKey(crypto::SymmetricKey* key, | 60 std::string DecryptTokenWithKey(crypto::SymmetricKey* key, |
| 60 const std::string& salt, | 61 const std::string& salt, |
| 61 const std::string& encrypted_token_hex); | 62 const std::string& encrypted_token_hex); |
| 62 | 63 |
| 63 // The cached system salt passed to the constructor, originally coming | 64 // The cached system salt passed to the constructor, originally coming |
| 64 // from cryptohome daemon. | 65 // from cryptohome daemon. |
| 65 std::string system_salt_; | 66 std::string system_salt_; |
| 66 | 67 |
| 67 // A key based on the system salt. Useful for encrypting device-level | 68 // A key based on the system salt. Useful for encrypting device-level |
| 68 // data for which we have no additional credentials. | 69 // data for which we have no additional credentials. |
| 69 std::unique_ptr<crypto::SymmetricKey> system_salt_key_; | 70 std::unique_ptr<crypto::SymmetricKey> system_salt_key_; |
| 70 | 71 |
| 71 DISALLOW_COPY_AND_ASSIGN(CryptohomeTokenEncryptor); | 72 DISALLOW_COPY_AND_ASSIGN(CryptohomeTokenEncryptor); |
| 72 }; | 73 }; |
| 73 | 74 |
| 74 } // namespace chromeos | 75 } // namespace chromeos |
| 75 | 76 |
| 76 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_TOKEN_ENCRYPTOR_H_ | 77 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_TOKEN_ENCRYPTOR_H_ |
| OLD | NEW |