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 #ifndef CHROMEOS_TPM_TPM_TOKEN_INFO_GETTER_H_ | 5 #ifndef CHROMEOS_TPM_TPM_TOKEN_INFO_GETTER_H_ |
6 #define CHROMEOS_TPM_TPM_TOKEN_INFO_GETTER_H_ | 6 #define CHROMEOS_TPM_TPM_TOKEN_INFO_GETTER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "chromeos/chromeos_export.h" | 15 #include "chromeos/chromeos_export.h" |
16 #include "chromeos/dbus/dbus_method_call_status.h" | 16 #include "chromeos/dbus/dbus_method_call_status.h" |
| 17 #include "components/signin/core/account_id/account_id.h" |
17 | 18 |
18 namespace base { | 19 namespace base { |
19 class TaskRunner; | 20 class TaskRunner; |
20 } | 21 } |
21 | 22 |
22 namespace chromeos { | 23 namespace chromeos { |
23 class CryptohomeClient; | 24 class CryptohomeClient; |
24 } | 25 } |
25 | 26 |
26 namespace chromeos { | 27 namespace chromeos { |
(...skipping 13 matching lines...) Expand all Loading... |
40 }; | 41 }; |
41 | 42 |
42 // Class for getting a user or the system TPM token info from cryptohome during | 43 // Class for getting a user or the system TPM token info from cryptohome during |
43 // TPM token loading. | 44 // TPM token loading. |
44 class CHROMEOS_EXPORT TPMTokenInfoGetter { | 45 class CHROMEOS_EXPORT TPMTokenInfoGetter { |
45 public: | 46 public: |
46 using TPMTokenInfoCallback = base::Callback<void(const TPMTokenInfo& info)>; | 47 using TPMTokenInfoCallback = base::Callback<void(const TPMTokenInfo& info)>; |
47 | 48 |
48 // Factory method for TPMTokenInfoGetter for a user token. | 49 // Factory method for TPMTokenInfoGetter for a user token. |
49 static scoped_ptr<TPMTokenInfoGetter> CreateForUserToken( | 50 static scoped_ptr<TPMTokenInfoGetter> CreateForUserToken( |
50 const std::string& user_id, | 51 const AccountId& account_id, |
51 CryptohomeClient* cryptohome_client, | 52 CryptohomeClient* cryptohome_client, |
52 const scoped_refptr<base::TaskRunner>& delayed_task_runner); | 53 const scoped_refptr<base::TaskRunner>& delayed_task_runner); |
53 | 54 |
54 // Factory method for TPMTokenGetter for the system token. | 55 // Factory method for TPMTokenGetter for the system token. |
55 static scoped_ptr<TPMTokenInfoGetter> CreateForSystemToken( | 56 static scoped_ptr<TPMTokenInfoGetter> CreateForSystemToken( |
56 CryptohomeClient* cryptohome_client, | 57 CryptohomeClient* cryptohome_client, |
57 const scoped_refptr<base::TaskRunner>& delayed_task_runner); | 58 const scoped_refptr<base::TaskRunner>& delayed_task_runner); |
58 | 59 |
59 ~TPMTokenInfoGetter(); | 60 ~TPMTokenInfoGetter(); |
60 | 61 |
(...skipping 12 matching lines...) Expand all Loading... |
73 | 74 |
74 enum State { | 75 enum State { |
75 STATE_INITIAL, | 76 STATE_INITIAL, |
76 STATE_STARTED, | 77 STATE_STARTED, |
77 STATE_TPM_ENABLED, | 78 STATE_TPM_ENABLED, |
78 STATE_DONE | 79 STATE_DONE |
79 }; | 80 }; |
80 | 81 |
81 TPMTokenInfoGetter( | 82 TPMTokenInfoGetter( |
82 Type type, | 83 Type type, |
83 const std::string& user_id, | 84 const AccountId& account_id, |
84 CryptohomeClient* cryptohome_client, | 85 CryptohomeClient* cryptohome_client, |
85 const scoped_refptr<base::TaskRunner>& delayed_task_runner); | 86 const scoped_refptr<base::TaskRunner>& delayed_task_runner); |
86 | 87 |
87 // Continues TPM token info getting procedure by starting the task associated | 88 // Continues TPM token info getting procedure by starting the task associated |
88 // with the current TPMTokenInfoGetter state. | 89 // with the current TPMTokenInfoGetter state. |
89 void Continue(); | 90 void Continue(); |
90 | 91 |
91 // If token initialization step fails (e.g. if tpm token is not yet ready) | 92 // If token initialization step fails (e.g. if tpm token is not yet ready) |
92 // schedules the initialization step retry attempt after a timeout. | 93 // schedules the initialization step retry attempt after a timeout. |
93 void RetryLater(); | 94 void RetryLater(); |
94 | 95 |
95 // Cryptohome methods callbacks. | 96 // Cryptohome methods callbacks. |
96 void OnTpmIsEnabled(DBusMethodCallStatus call_status, | 97 void OnTpmIsEnabled(DBusMethodCallStatus call_status, |
97 bool tpm_is_enabled); | 98 bool tpm_is_enabled); |
98 void OnPkcs11GetTpmTokenInfo(DBusMethodCallStatus call_status, | 99 void OnPkcs11GetTpmTokenInfo(DBusMethodCallStatus call_status, |
99 const std::string& token_name, | 100 const std::string& token_name, |
100 const std::string& user_pin, | 101 const std::string& user_pin, |
101 int token_slot_id); | 102 int token_slot_id); |
102 | 103 |
103 // The task runner used to run delayed tasks when retrying failed Cryptohome | 104 // The task runner used to run delayed tasks when retrying failed Cryptohome |
104 // calls. | 105 // calls. |
105 scoped_refptr<base::TaskRunner> delayed_task_runner_; | 106 scoped_refptr<base::TaskRunner> delayed_task_runner_; |
106 | 107 |
107 Type type_; | 108 Type type_; |
108 State state_; | 109 State state_; |
109 | 110 |
110 // The user id associated with the TPMTokenInfoGetter. Empty for system token. | 111 // The account id associated with the TPMTokenInfoGetter. Empty for system |
111 std::string user_id_; | 112 // token. |
| 113 AccountId account_id_; |
112 | 114 |
113 TPMTokenInfoCallback callback_; | 115 TPMTokenInfoCallback callback_; |
114 | 116 |
115 // The current request delay before the next attempt to initialize the | 117 // The current request delay before the next attempt to initialize the |
116 // TPM. Will be adapted after each attempt. | 118 // TPM. Will be adapted after each attempt. |
117 base::TimeDelta tpm_request_delay_; | 119 base::TimeDelta tpm_request_delay_; |
118 | 120 |
119 CryptohomeClient* cryptohome_client_; | 121 CryptohomeClient* cryptohome_client_; |
120 | 122 |
121 base::WeakPtrFactory<TPMTokenInfoGetter> weak_factory_; | 123 base::WeakPtrFactory<TPMTokenInfoGetter> weak_factory_; |
122 | 124 |
123 DISALLOW_COPY_AND_ASSIGN(TPMTokenInfoGetter); | 125 DISALLOW_COPY_AND_ASSIGN(TPMTokenInfoGetter); |
124 }; | 126 }; |
125 | 127 |
126 } // namespace chromeos | 128 } // namespace chromeos |
127 | 129 |
128 #endif // CHROMEOS_TPM_TPM_TOKEN_INFO_GETTER_H_ | 130 #endif // CHROMEOS_TPM_TPM_TOKEN_INFO_GETTER_H_ |
OLD | NEW |