Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: chromeos/tpm_token_loader.cc

Issue 567553002: TPMTokenLoader: Report both the disabled and enabled state of the TPM. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@nss_util_deadcode
Patch Set: Addressed nit. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/tpm_token_loader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_token_loader.h" 5 #include "chromeos/tpm_token_loader.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 const scoped_refptr<base::SequencedTaskRunner>& crypto_task_runner) { 99 const scoped_refptr<base::SequencedTaskRunner>& crypto_task_runner) {
100 crypto_task_runner_ = crypto_task_runner; 100 crypto_task_runner_ = crypto_task_runner;
101 MaybeStartTokenInitialization(); 101 MaybeStartTokenInitialization();
102 } 102 }
103 103
104 TPMTokenLoader::~TPMTokenLoader() { 104 TPMTokenLoader::~TPMTokenLoader() {
105 if (!initialized_for_test_ && LoginState::IsInitialized()) 105 if (!initialized_for_test_ && LoginState::IsInitialized())
106 LoginState::Get()->RemoveObserver(this); 106 LoginState::Get()->RemoveObserver(this);
107 } 107 }
108 108
109 void TPMTokenLoader::AddObserver(TPMTokenLoader::Observer* observer) { 109 TPMTokenLoader::TPMTokenStatus TPMTokenLoader::IsTPMTokenEnabled(
110 observers_.AddObserver(observer); 110 const TPMReadyCallback& callback) {
111 if (tpm_token_state_ == TPM_TOKEN_INITIALIZED)
112 return TPM_TOKEN_STATUS_ENABLED;
113 if (!IsTPMLoadingEnabled() || tpm_token_state_ == TPM_DISABLED)
114 return TPM_TOKEN_STATUS_DISABLED;
115 // Status is not known yet.
116 if (!callback.is_null())
117 tpm_ready_callback_list_.push_back(callback);
118 return TPM_TOKEN_STATUS_UNDETERMINED;
111 } 119 }
112 120
113 void TPMTokenLoader::RemoveObserver(TPMTokenLoader::Observer* observer) { 121 bool TPMTokenLoader::IsTPMLoadingEnabled() const {
114 observers_.RemoveObserver(observer); 122 // TPM loading is enabled on non-ChromeOS environments, e.g. when running
115 } 123 // tests on Linux.
116 124 // Treat TPM as disabled for guest users since they do not store certs.
117 bool TPMTokenLoader::IsTPMTokenReady() const { 125 return initialized_for_test_ || (base::SysInfo::IsRunningOnChromeOS() &&
118 return tpm_token_state_ == TPM_DISABLED || 126 LoginState::Get()->IsGuestSessionUser());
119 tpm_token_state_ == TPM_TOKEN_INITIALIZED;
120 } 127 }
121 128
122 void TPMTokenLoader::MaybeStartTokenInitialization() { 129 void TPMTokenLoader::MaybeStartTokenInitialization() {
123 CHECK(thread_checker_.CalledOnValidThread()); 130 CHECK(thread_checker_.CalledOnValidThread());
124 131
125 // This is the entry point to the TPM token initialization process, 132 // This is the entry point to the TPM token initialization process,
126 // which we should do at most once. 133 // which we should do at most once.
127 if (tpm_token_state_ != TPM_STATE_UNKNOWN || !crypto_task_runner_.get()) 134 if (tpm_token_state_ != TPM_STATE_UNKNOWN || !crypto_task_runner_.get())
128 return; 135 return;
129 136
130 if (!LoginState::IsInitialized()) 137 if (!LoginState::IsInitialized())
131 return; 138 return;
132 139
133 bool start_initialization = LoginState::Get()->IsUserLoggedIn(); 140 bool start_initialization = LoginState::Get()->IsUserLoggedIn();
134 141
135 VLOG(1) << "StartTokenInitialization: " << start_initialization; 142 VLOG(1) << "StartTokenInitialization: " << start_initialization;
136 if (!start_initialization) 143 if (!start_initialization)
137 return; 144 return;
138 145
139 if (!base::SysInfo::IsRunningOnChromeOS()) 146 if (!IsTPMLoadingEnabled())
140 tpm_token_state_ = TPM_DISABLED;
141
142 // Treat TPM as disabled for guest users since they do not store certs.
143 if (LoginState::Get()->IsGuestSessionUser())
144 tpm_token_state_ = TPM_DISABLED; 147 tpm_token_state_ = TPM_DISABLED;
145 148
146 ContinueTokenInitialization(); 149 ContinueTokenInitialization();
147 150
148 DCHECK_NE(tpm_token_state_, TPM_STATE_UNKNOWN); 151 DCHECK_NE(tpm_token_state_, TPM_STATE_UNKNOWN);
149 } 152 }
150 153
151 void TPMTokenLoader::ContinueTokenInitialization() { 154 void TPMTokenLoader::ContinueTokenInitialization() {
152 CHECK(thread_checker_.CalledOnValidThread()); 155 CHECK(thread_checker_.CalledOnValidThread());
153 VLOG(1) << "ContinueTokenInitialization: " << tpm_token_state_; 156 VLOG(1) << "ContinueTokenInitialization: " << tpm_token_state_;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 236
234 if (call_status == DBUS_METHOD_CALL_SUCCESS && tpm_is_enabled) 237 if (call_status == DBUS_METHOD_CALL_SUCCESS && tpm_is_enabled)
235 tpm_token_state_ = TPM_ENABLED; 238 tpm_token_state_ = TPM_ENABLED;
236 else 239 else
237 tpm_token_state_ = TPM_DISABLED; 240 tpm_token_state_ = TPM_DISABLED;
238 241
239 ContinueTokenInitialization(); 242 ContinueTokenInitialization();
240 } 243 }
241 244
242 void TPMTokenLoader::OnPkcs11IsTpmTokenReady(DBusMethodCallStatus call_status, 245 void TPMTokenLoader::OnPkcs11IsTpmTokenReady(DBusMethodCallStatus call_status,
243 bool is_tpm_token_ready) { 246 bool is_tpm_token_ready) {
244 VLOG(1) << "OnPkcs11IsTpmTokenReady: " << is_tpm_token_ready; 247 VLOG(1) << "OnPkcs11IsTpmTokenReady: " << is_tpm_token_ready;
245 248
246 if (call_status == DBUS_METHOD_CALL_FAILURE || !is_tpm_token_ready) { 249 if (call_status == DBUS_METHOD_CALL_FAILURE || !is_tpm_token_ready) {
247 RetryTokenInitializationLater(); 250 RetryTokenInitializationLater();
248 return; 251 return;
249 } 252 }
250 253
251 tpm_token_state_ = TPM_TOKEN_READY; 254 tpm_token_state_ = TPM_TOKEN_READY;
252 ContinueTokenInitialization(); 255 ContinueTokenInitialization();
253 } 256 }
(...skipping 20 matching lines...) Expand all
274 VLOG(1) << "OnTPMTokenInitialized: " << success; 277 VLOG(1) << "OnTPMTokenInitialized: " << success;
275 if (!success) { 278 if (!success) {
276 RetryTokenInitializationLater(); 279 RetryTokenInitializationLater();
277 return; 280 return;
278 } 281 }
279 tpm_token_state_ = TPM_TOKEN_INITIALIZED; 282 tpm_token_state_ = TPM_TOKEN_INITIALIZED;
280 ContinueTokenInitialization(); 283 ContinueTokenInitialization();
281 } 284 }
282 285
283 void TPMTokenLoader::NotifyTPMTokenReady() { 286 void TPMTokenLoader::NotifyTPMTokenReady() {
284 FOR_EACH_OBSERVER(Observer, observers_, OnTPMTokenReady()); 287 DCHECK(tpm_token_state_ == TPM_DISABLED ||
288 tpm_token_state_ == TPM_TOKEN_INITIALIZED);
289 bool tpm_status = tpm_token_state_ == TPM_TOKEN_INITIALIZED;
290 for (TPMReadyCallbackList::iterator i = tpm_ready_callback_list_.begin();
291 i != tpm_ready_callback_list_.end();
292 ++i) {
293 i->Run(tpm_status);
294 }
295 tpm_ready_callback_list_.clear();
285 } 296 }
286 297
287 void TPMTokenLoader::LoggedInStateChanged() { 298 void TPMTokenLoader::LoggedInStateChanged() {
288 VLOG(1) << "LoggedInStateChanged"; 299 VLOG(1) << "LoggedInStateChanged";
289 MaybeStartTokenInitialization(); 300 MaybeStartTokenInitialization();
290 } 301 }
291 302
292 } // namespace chromeos 303 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/tpm_token_loader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698