NaCl docs: add sanitizers to GSoC ideas
[chromium-blink-merge.git] / chrome / browser / chromeos / settings / token_encryptor.h
blob057d34479b2ea04c519c8301f799ea8a842c7c56
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_TOKEN_ENCRYPTOR_H_
6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_TOKEN_ENCRYPTOR_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
13 namespace crypto {
14 class SymmetricKey;
17 namespace chromeos {
19 // Interface class for classes that encrypt and decrypt tokens using the
20 // system salt.
21 class TokenEncryptor {
22 public:
23 virtual ~TokenEncryptor() {}
25 // Encrypts |token| with the system salt key (stable for the lifetime
26 // of the device). Useful to avoid storing plain text in place like
27 // Local State.
28 virtual std::string EncryptWithSystemSalt(const std::string& token) = 0;
30 // Decrypts |token| with the system salt key (stable for the lifetime
31 // of the device).
32 virtual std::string DecryptWithSystemSalt(
33 const std::string& encrypted_token_hex) = 0;
36 // TokenEncryptor based on the system salt from cryptohome daemon. This
37 // implementation is used in production.
38 class CryptohomeTokenEncryptor : public TokenEncryptor {
39 public:
40 explicit CryptohomeTokenEncryptor(const std::string& system_salt);
41 ~CryptohomeTokenEncryptor() override;
43 // TokenEncryptor overrides:
44 std::string EncryptWithSystemSalt(const std::string& token) override;
45 std::string DecryptWithSystemSalt(
46 const std::string& encrypted_token_hex) override;
48 private:
49 // Converts |passphrase| to a SymmetricKey using the given |salt|.
50 crypto::SymmetricKey* PassphraseToKey(const std::string& passphrase,
51 const std::string& salt);
53 // Encrypts (AES) the token given |key| and |salt|.
54 std::string EncryptTokenWithKey(crypto::SymmetricKey* key,
55 const std::string& salt,
56 const std::string& token);
58 // Decrypts (AES) hex encoded encrypted token given |key| and |salt|.
59 std::string DecryptTokenWithKey(crypto::SymmetricKey* key,
60 const std::string& salt,
61 const std::string& encrypted_token_hex);
63 // The cached system salt passed to the constructor, originally coming
64 // from cryptohome daemon.
65 std::string system_salt_;
67 // A key based on the system salt. Useful for encrypting device-level
68 // data for which we have no additional credentials.
69 scoped_ptr<crypto::SymmetricKey> system_salt_key_;
71 DISALLOW_COPY_AND_ASSIGN(CryptohomeTokenEncryptor);
74 } // namespace chromeos
76 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_TOKEN_ENCRYPTOR_H_