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.
5 #ifndef CHROMEOS_TPM_TOKEN_INFO_GETTER_H_
6 #define CHROMEOS_TPM_TOKEN_INFO_GETTER_H_
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"
22 class CryptohomeClient
;
27 // Information retrieved from cryptohome by TPMTokenInfoGetter.
29 // Default constructor creates token info for disabled TPM.
34 std::string token_name
;
39 // Class for getting a user or the system TPM token info from cryptohome during
41 class CHROMEOS_EXPORT TPMTokenInfoGetter
{
43 using TPMTokenInfoCallback
= base::Callback
<void(const TPMTokenInfo
& info
)>;
45 // Factory method for TPMTokenInfoGetter for a user token.
46 static scoped_ptr
<TPMTokenInfoGetter
> CreateForUserToken(
47 const std::string
& user_id
,
48 CryptohomeClient
* cryptohome_client
,
49 const scoped_refptr
<base::TaskRunner
>& delayed_task_runner
);
51 // Factory method for TPMTokenGetter for the system token.
52 static scoped_ptr
<TPMTokenInfoGetter
> CreateForSystemToken(
53 CryptohomeClient
* cryptohome_client
,
54 const scoped_refptr
<base::TaskRunner
>& delayed_task_runner
);
56 ~TPMTokenInfoGetter();
58 // Starts getting TPM token info. Should be called at most once.
59 // |callback| will be called when all the info is fetched.
60 // The object may get deleted before |callback| is called, which is equivalent
61 // to cancelling the info getting (in which case |callback| will never get
63 void Start(const TPMTokenInfoCallback
& callback
);
80 const std::string
& user_id
,
81 CryptohomeClient
* cryptohome_client
,
82 const scoped_refptr
<base::TaskRunner
>& delayed_task_runner
);
84 // Continues TPM token info getting procedure by starting the task associated
85 // with the current TPMTokenInfoGetter state.
88 // If token initialization step fails (e.g. if tpm token is not yet ready)
89 // schedules the initialization step retry attempt after a timeout.
92 // Cryptohome methods callbacks.
93 void OnTpmIsEnabled(DBusMethodCallStatus call_status
,
95 void OnPkcs11GetTpmTokenInfo(DBusMethodCallStatus call_status
,
96 const std::string
& token_name
,
97 const std::string
& user_pin
,
100 // The task runner used to run delayed tasks when retrying failed Cryptohome
102 scoped_refptr
<base::TaskRunner
> delayed_task_runner_
;
107 // The user id associated with the TPMTokenInfoGetter. Empty for system token.
108 std::string user_id_
;
110 TPMTokenInfoCallback callback_
;
112 // The current request delay before the next attempt to initialize the
113 // TPM. Will be adapted after each attempt.
114 base::TimeDelta tpm_request_delay_
;
116 CryptohomeClient
* cryptohome_client_
;
118 base::WeakPtrFactory
<TPMTokenInfoGetter
> weak_factory_
;
120 DISALLOW_COPY_AND_ASSIGN(TPMTokenInfoGetter
);
123 } // namespace chromeos
125 #endif // CHROMEOS_TPM_TOKEN_INFO_GETTER_H_