| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROMEOS_TPM_TOKEN_INFO_GETTER_H_ | |
| 6 #define CHROMEOS_TPM_TOKEN_INFO_GETTER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/time/time.h" | |
| 14 #include "chromeos/chromeos_export.h" | |
| 15 #include "chromeos/dbus/dbus_method_call_status.h" | |
| 16 | |
| 17 namespace base { | |
| 18 class TaskRunner; | |
| 19 } | |
| 20 | |
| 21 namespace chromeos { | |
| 22 class CryptohomeClient; | |
| 23 } | |
| 24 | |
| 25 namespace chromeos { | |
| 26 | |
| 27 // Information retrieved from cryptohome by TPMTokenInfoGetter. | |
| 28 // For invalid token |token_name| and |user_pin| will be empty, while | |
| 29 // |token_slot_id| will be set to -1. | |
| 30 struct TPMTokenInfo { | |
| 31 // Default constructor creates token info for disabled TPM. | |
| 32 TPMTokenInfo(); | |
| 33 ~TPMTokenInfo(); | |
| 34 | |
| 35 bool tpm_is_enabled; | |
| 36 std::string token_name; | |
| 37 std::string user_pin; | |
| 38 int token_slot_id; | |
| 39 }; | |
| 40 | |
| 41 // Class for getting a user or the system TPM token info from cryptohome during | |
| 42 // TPM token loading. | |
| 43 class CHROMEOS_EXPORT TPMTokenInfoGetter { | |
| 44 public: | |
| 45 using TPMTokenInfoCallback = base::Callback<void(const TPMTokenInfo& info)>; | |
| 46 | |
| 47 // Factory method for TPMTokenInfoGetter for a user token. | |
| 48 static scoped_ptr<TPMTokenInfoGetter> CreateForUserToken( | |
| 49 const std::string& user_id, | |
| 50 CryptohomeClient* cryptohome_client, | |
| 51 const scoped_refptr<base::TaskRunner>& delayed_task_runner); | |
| 52 | |
| 53 // Factory method for TPMTokenGetter for the system token. | |
| 54 static scoped_ptr<TPMTokenInfoGetter> CreateForSystemToken( | |
| 55 CryptohomeClient* cryptohome_client, | |
| 56 const scoped_refptr<base::TaskRunner>& delayed_task_runner); | |
| 57 | |
| 58 ~TPMTokenInfoGetter(); | |
| 59 | |
| 60 // Starts getting TPM token info. Should be called at most once. | |
| 61 // |callback| will be called when all the info is fetched. | |
| 62 // The object may get deleted before |callback| is called, which is equivalent | |
| 63 // to cancelling the info getting (in which case |callback| will never get | |
| 64 // called). | |
| 65 void Start(const TPMTokenInfoCallback& callback); | |
| 66 | |
| 67 private: | |
| 68 enum Type { | |
| 69 TYPE_SYSTEM, | |
| 70 TYPE_USER | |
| 71 }; | |
| 72 | |
| 73 enum State { | |
| 74 STATE_INITIAL, | |
| 75 STATE_STARTED, | |
| 76 STATE_TPM_ENABLED, | |
| 77 STATE_DONE | |
| 78 }; | |
| 79 | |
| 80 TPMTokenInfoGetter( | |
| 81 Type type, | |
| 82 const std::string& user_id, | |
| 83 CryptohomeClient* cryptohome_client, | |
| 84 const scoped_refptr<base::TaskRunner>& delayed_task_runner); | |
| 85 | |
| 86 // Continues TPM token info getting procedure by starting the task associated | |
| 87 // with the current TPMTokenInfoGetter state. | |
| 88 void Continue(); | |
| 89 | |
| 90 // If token initialization step fails (e.g. if tpm token is not yet ready) | |
| 91 // schedules the initialization step retry attempt after a timeout. | |
| 92 void RetryLater(); | |
| 93 | |
| 94 // Cryptohome methods callbacks. | |
| 95 void OnTpmIsEnabled(DBusMethodCallStatus call_status, | |
| 96 bool tpm_is_enabled); | |
| 97 void OnPkcs11GetTpmTokenInfo(DBusMethodCallStatus call_status, | |
| 98 const std::string& token_name, | |
| 99 const std::string& user_pin, | |
| 100 int token_slot_id); | |
| 101 | |
| 102 // The task runner used to run delayed tasks when retrying failed Cryptohome | |
| 103 // calls. | |
| 104 scoped_refptr<base::TaskRunner> delayed_task_runner_; | |
| 105 | |
| 106 Type type_; | |
| 107 State state_; | |
| 108 | |
| 109 // The user id associated with the TPMTokenInfoGetter. Empty for system token. | |
| 110 std::string user_id_; | |
| 111 | |
| 112 TPMTokenInfoCallback callback_; | |
| 113 | |
| 114 // The current request delay before the next attempt to initialize the | |
| 115 // TPM. Will be adapted after each attempt. | |
| 116 base::TimeDelta tpm_request_delay_; | |
| 117 | |
| 118 CryptohomeClient* cryptohome_client_; | |
| 119 | |
| 120 base::WeakPtrFactory<TPMTokenInfoGetter> weak_factory_; | |
| 121 | |
| 122 DISALLOW_COPY_AND_ASSIGN(TPMTokenInfoGetter); | |
| 123 }; | |
| 124 | |
| 125 } // namespace chromeos | |
| 126 | |
| 127 #endif // CHROMEOS_TPM_TOKEN_INFO_GETTER_H_ | |
| OLD | NEW |