OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROMEOS_CRYPTOHOME_CRYPTOHOME_LIBRARY_H_ | 5 #ifndef CHROMEOS_CRYPTOHOME_CRYPTOHOME_LIBRARY_H_ |
6 #define CHROMEOS_CRYPTOHOME_CRYPTOHOME_LIBRARY_H_ | 6 #define CHROMEOS_CRYPTOHOME_CRYPTOHOME_LIBRARY_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "chromeos/chromeos_export.h" | 11 #include "chromeos/chromeos_export.h" |
12 | 12 |
13 namespace chromeos { | 13 namespace chromeos { |
14 | 14 |
15 // This interface defines the interaction with the ChromeOS cryptohome library | 15 // This interface defines the interaction with the ChromeOS cryptohome library |
16 // APIs. | 16 // APIs. |
17 class CHROMEOS_EXPORT CryptohomeLibrary { | 17 class CHROMEOS_EXPORT CryptohomeLibrary { |
satorux1
2013/10/04 06:44:01
BTW, now this class just manages the system salt.
| |
18 public: | 18 public: |
19 // Manage an explicitly initialized global instance. | 19 // Manage an explicitly initialized global instance. |
20 static void Initialize(); | 20 static void Initialize(); |
21 static bool IsInitialized(); | 21 static bool IsInitialized(); |
22 static void Shutdown(); | 22 static void Shutdown(); |
23 static CryptohomeLibrary* Get(); | 23 static CryptohomeLibrary* Get(); |
24 | 24 |
25 // Sets up Get() to return |impl| for testing (e.g. with a mock | 25 // Sets up Get() to return |impl| for testing (e.g. with a mock |
26 // implementation). Call SetForTest(NULL) when |impl| is deleted. | 26 // implementation). Call SetForTest(NULL) when |impl| is deleted. |
27 static void SetForTest(CryptohomeLibrary* impl); | 27 static void SetForTest(CryptohomeLibrary* impl); |
28 | 28 |
29 // Returns a CryptohomeLibrary instance for testing. Does not set or affect | 29 // Returns a CryptohomeLibrary instance for testing. Does not set or affect |
30 // the global instance. | 30 // the global instance. |
31 static CryptohomeLibrary* GetTestImpl(); | 31 static CryptohomeLibrary* GetTestImpl(); |
32 | 32 |
33 // Public so that result of GetTestImpl can be destroyed. | 33 // Public so that result of GetTestImpl can be destroyed. |
34 virtual ~CryptohomeLibrary(); | 34 virtual ~CryptohomeLibrary(); |
35 | 35 |
36 // Returns system hash in hex encoded ascii format. Note: this may return | 36 // Returns system hash in hex encoded ascii format. Note: this may return |
37 // an empty string (e.g. if cryptohome is not running). It is up to the | 37 // an empty string (e.g. if cryptohome is not running). It is up to the |
38 // calling function to try again after a delay if desired. | 38 // calling function to try again after a delay if desired. |
39 // | |
40 // TODO(hashimoto): Make it asynchronous. crbug.com/141009. | |
39 virtual std::string GetSystemSalt() = 0; | 41 virtual std::string GetSystemSalt() = 0; |
40 | 42 |
41 // Encrypts |token| with the system salt key (stable for the lifetime | 43 // Returns system hash in hex encoded ascii format, cached by a prior call |
42 // of the device). Useful to avoid storing plain text in place like | 44 // to GetSystemSalt(). Note: this may return an empty string (e.g. if |
43 // Local State. | 45 // GetSystemSalt() is not yet called). |
44 virtual std::string EncryptWithSystemSalt(const std::string& token) = 0; | 46 virtual std::string GetCachedSystemSalt() = 0; |
45 | |
46 // Decrypts |token| with the system salt key (stable for the lifetime | |
47 // of the device). | |
48 virtual std::string DecryptWithSystemSalt( | |
49 const std::string& encrypted_token_hex) = 0; | |
50 | 47 |
51 protected: | 48 protected: |
52 CryptohomeLibrary(); | 49 CryptohomeLibrary(); |
53 | 50 |
54 private: | 51 private: |
55 DISALLOW_COPY_AND_ASSIGN(CryptohomeLibrary); | 52 DISALLOW_COPY_AND_ASSIGN(CryptohomeLibrary); |
56 }; | 53 }; |
57 | 54 |
58 } // namespace chromeos | 55 } // namespace chromeos |
59 | 56 |
60 #endif // CHROMEOS_CRYPTOHOME_CRYPTOHOME_LIBRARY_H_ | 57 #endif // CHROMEOS_CRYPTOHOME_CRYPTOHOME_LIBRARY_H_ |
OLD | NEW |