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 #include "chromeos/tpm/tpm_token_info_getter.h" | 5 #include "chromeos/tpm/tpm_token_info_getter.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "chromeos/cryptohome/cryptohome_parameters.h" |
11 #include "chromeos/dbus/cryptohome_client.h" | 12 #include "chromeos/dbus/cryptohome_client.h" |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 const int64_t kInitialRequestDelayMs = 100; | 16 const int64_t kInitialRequestDelayMs = 100; |
16 const int64_t kMaxRequestDelayMs = 300000; // 5 minutes | 17 const int64_t kMaxRequestDelayMs = 300000; // 5 minutes |
17 | 18 |
18 // Calculates the delay before running next attempt to initiatialize the TPM | 19 // Calculates the delay before running next attempt to initiatialize the TPM |
19 // token, if |last_delay| was the last or initial delay. | 20 // token, if |last_delay| was the last or initial delay. |
20 base::TimeDelta GetNextRequestDelayMs(base::TimeDelta last_delay) { | 21 base::TimeDelta GetNextRequestDelayMs(base::TimeDelta last_delay) { |
(...skipping 15 matching lines...) Expand all Loading... |
36 | 37 |
37 TPMTokenInfo::TPMTokenInfo() | 38 TPMTokenInfo::TPMTokenInfo() |
38 : tpm_is_enabled(false), | 39 : tpm_is_enabled(false), |
39 token_slot_id(-1) { | 40 token_slot_id(-1) { |
40 } | 41 } |
41 | 42 |
42 TPMTokenInfo::~TPMTokenInfo() {} | 43 TPMTokenInfo::~TPMTokenInfo() {} |
43 | 44 |
44 // static | 45 // static |
45 scoped_ptr<TPMTokenInfoGetter> TPMTokenInfoGetter::CreateForUserToken( | 46 scoped_ptr<TPMTokenInfoGetter> TPMTokenInfoGetter::CreateForUserToken( |
46 const std::string& user_id, | 47 const AccountId& account_id, |
47 CryptohomeClient* cryptohome_client, | 48 CryptohomeClient* cryptohome_client, |
48 const scoped_refptr<base::TaskRunner>& delayed_task_runner) { | 49 const scoped_refptr<base::TaskRunner>& delayed_task_runner) { |
49 CHECK(!user_id.empty()); | 50 CHECK(account_id.is_valid()); |
50 return scoped_ptr<TPMTokenInfoGetter>( | 51 return scoped_ptr<TPMTokenInfoGetter>(new TPMTokenInfoGetter( |
51 new TPMTokenInfoGetter( | 52 TYPE_USER, account_id, cryptohome_client, delayed_task_runner)); |
52 TYPE_USER, user_id, cryptohome_client, delayed_task_runner)); | |
53 } | 53 } |
54 | 54 |
55 // static | 55 // static |
56 scoped_ptr<TPMTokenInfoGetter> TPMTokenInfoGetter::CreateForSystemToken( | 56 scoped_ptr<TPMTokenInfoGetter> TPMTokenInfoGetter::CreateForSystemToken( |
57 CryptohomeClient* cryptohome_client, | 57 CryptohomeClient* cryptohome_client, |
58 const scoped_refptr<base::TaskRunner>& delayed_task_runner) { | 58 const scoped_refptr<base::TaskRunner>& delayed_task_runner) { |
59 return scoped_ptr<TPMTokenInfoGetter>( | 59 return scoped_ptr<TPMTokenInfoGetter>(new TPMTokenInfoGetter( |
60 new TPMTokenInfoGetter( | 60 TYPE_SYSTEM, EmptyAccountId(), cryptohome_client, delayed_task_runner)); |
61 TYPE_SYSTEM, std::string(), cryptohome_client, delayed_task_runner)); | |
62 } | 61 } |
63 | 62 |
64 TPMTokenInfoGetter::~TPMTokenInfoGetter() {} | 63 TPMTokenInfoGetter::~TPMTokenInfoGetter() {} |
65 | 64 |
66 void TPMTokenInfoGetter::Start(const TPMTokenInfoCallback& callback) { | 65 void TPMTokenInfoGetter::Start(const TPMTokenInfoCallback& callback) { |
67 CHECK(state_ == STATE_INITIAL); | 66 CHECK(state_ == STATE_INITIAL); |
68 CHECK(!callback.is_null()); | 67 CHECK(!callback.is_null()); |
69 | 68 |
70 callback_ = callback; | 69 callback_ = callback; |
71 | 70 |
72 state_ = STATE_STARTED; | 71 state_ = STATE_STARTED; |
73 Continue(); | 72 Continue(); |
74 } | 73 } |
75 | 74 |
76 TPMTokenInfoGetter::TPMTokenInfoGetter( | 75 TPMTokenInfoGetter::TPMTokenInfoGetter( |
77 TPMTokenInfoGetter::Type type, | 76 TPMTokenInfoGetter::Type type, |
78 const std::string& user_id, | 77 const AccountId& account_id, |
79 CryptohomeClient* cryptohome_client, | 78 CryptohomeClient* cryptohome_client, |
80 const scoped_refptr<base::TaskRunner>& delayed_task_runner) | 79 const scoped_refptr<base::TaskRunner>& delayed_task_runner) |
81 : delayed_task_runner_(delayed_task_runner), | 80 : delayed_task_runner_(delayed_task_runner), |
82 type_(type), | 81 type_(type), |
83 state_(TPMTokenInfoGetter::STATE_INITIAL), | 82 state_(TPMTokenInfoGetter::STATE_INITIAL), |
84 user_id_(user_id), | 83 account_id_(account_id), |
85 tpm_request_delay_( | 84 tpm_request_delay_( |
86 base::TimeDelta::FromMilliseconds(kInitialRequestDelayMs)), | 85 base::TimeDelta::FromMilliseconds(kInitialRequestDelayMs)), |
87 cryptohome_client_(cryptohome_client), | 86 cryptohome_client_(cryptohome_client), |
88 weak_factory_(this) { | 87 weak_factory_(this) {} |
89 } | |
90 | 88 |
91 void TPMTokenInfoGetter::Continue() { | 89 void TPMTokenInfoGetter::Continue() { |
92 switch (state_) { | 90 switch (state_) { |
93 case STATE_INITIAL: | 91 case STATE_INITIAL: |
94 NOTREACHED(); | 92 NOTREACHED(); |
95 break; | 93 break; |
96 case STATE_STARTED: | 94 case STATE_STARTED: |
97 cryptohome_client_->TpmIsEnabled( | 95 cryptohome_client_->TpmIsEnabled( |
98 base::Bind(&TPMTokenInfoGetter::OnTpmIsEnabled, | 96 base::Bind(&TPMTokenInfoGetter::OnTpmIsEnabled, |
99 weak_factory_.GetWeakPtr())); | 97 weak_factory_.GetWeakPtr())); |
100 break; | 98 break; |
101 case STATE_TPM_ENABLED: | 99 case STATE_TPM_ENABLED: |
102 if (type_ == TYPE_SYSTEM) { | 100 if (type_ == TYPE_SYSTEM) { |
103 cryptohome_client_->Pkcs11GetTpmTokenInfo( | 101 cryptohome_client_->Pkcs11GetTpmTokenInfo( |
104 base::Bind(&TPMTokenInfoGetter::OnPkcs11GetTpmTokenInfo, | 102 base::Bind(&TPMTokenInfoGetter::OnPkcs11GetTpmTokenInfo, |
105 weak_factory_.GetWeakPtr())); | 103 weak_factory_.GetWeakPtr())); |
106 } else { // if (type_ == TYPE_USER) | 104 } else { // if (type_ == TYPE_USER) |
107 cryptohome_client_->Pkcs11GetTpmTokenInfoForUser( | 105 cryptohome_client_->Pkcs11GetTpmTokenInfoForUser( |
108 user_id_, | 106 cryptohome::Identification(account_id_), |
109 base::Bind(&TPMTokenInfoGetter::OnPkcs11GetTpmTokenInfo, | 107 base::Bind(&TPMTokenInfoGetter::OnPkcs11GetTpmTokenInfo, |
110 weak_factory_.GetWeakPtr())); | 108 weak_factory_.GetWeakPtr())); |
111 } | 109 } |
112 break; | 110 break; |
113 case STATE_DONE: | 111 case STATE_DONE: |
114 NOTREACHED(); | 112 NOTREACHED(); |
115 } | 113 } |
116 } | 114 } |
117 | 115 |
118 void TPMTokenInfoGetter::RetryLater() { | 116 void TPMTokenInfoGetter::RetryLater() { |
119 delayed_task_runner_->PostDelayedTask( | 117 delayed_task_runner_->PostDelayedTask( |
120 FROM_HERE, | 118 FROM_HERE, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 TPMTokenInfo token_info; | 153 TPMTokenInfo token_info; |
156 token_info.tpm_is_enabled = true; | 154 token_info.tpm_is_enabled = true; |
157 token_info.token_name = token_name; | 155 token_info.token_name = token_name; |
158 token_info.user_pin = user_pin; | 156 token_info.user_pin = user_pin; |
159 token_info.token_slot_id = token_slot_id; | 157 token_info.token_slot_id = token_slot_id; |
160 | 158 |
161 callback_.Run(token_info); | 159 callback_.Run(token_info); |
162 } | 160 } |
163 | 161 |
164 } // namespace chromeos | 162 } // namespace chromeos |
OLD | NEW |