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

Side by Side Diff: tpm_init.cc

Issue 3048029: Initial version of tpm_init, a library for taking ownership of the TPM. (Closed) Base URL: ssh://git@chromiumos-git/tpm_init.git
Patch Set: Minor fix to the error code check from TakeOwnership. Created 10 years, 4 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 | « tpm_init.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
(Empty)
1 // Copyright (c) 2009-2010 The Chromium OS 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 // Contains the implementation of class TpmInit
6
7 #include "tpm_init.h"
8
9 #include <base/logging.h>
10 #include <base/time.h>
11
12 #include "tpm.h"
13
14 namespace tpm_init {
15
16 // TpmInitTask is a private class used to handle asynchronous initialization of
17 // the TPM.
18 class TpmInitTask : public PlatformThread::Delegate {
19 public:
20 TpmInitTask();
21 virtual ~TpmInitTask();
22
23 void Init();
24
25 virtual void ThreadMain();
26
27 bool IsTpmReady();
28 bool IsTpmEnabled();
29 bool GetTpmPassword(chromeos::Blob* password);
30 long GetInitializationMillis();
31
32 private:
33 scoped_ptr<tpm_init::Tpm> default_tpm_;
34 tpm_init::Tpm* tpm_;
35 bool initialize_status_;
36 bool task_done_;
37 long initialization_time_;
38 };
39
40 TpmInit::TpmInit()
41 : tpm_init_(new TpmInitTask()) {
42 }
43
44 TpmInit::~TpmInit() {
45 }
46
47 bool TpmInit::StartInitializeTpm() {
48 tpm_init_->Init();
49 if (!PlatformThread::CreateNonJoinable(0, tpm_init_.get())) {
50 LOG(ERROR) << "Unable to create TPM initialization background thread.";
51 return false;
52 }
53 return true;
54 }
55
56 bool TpmInit::IsTpmReady() {
57 return tpm_init_->IsTpmReady();
58 }
59
60 bool TpmInit::IsTpmEnabled() {
61 return tpm_init_->IsTpmEnabled();
62 }
63
64 bool TpmInit::GetTpmPassword(chromeos::Blob* password) {
65 return tpm_init_->GetTpmPassword(password);
66 }
67
68 long TpmInit::GetInitializationMillis() {
69 return tpm_init_->GetInitializationMillis();
70 }
71
72 TpmInitTask::TpmInitTask()
73 : default_tpm_(new tpm_init::Tpm()),
74 tpm_(default_tpm_.get()),
75 initialize_status_(false),
76 task_done_(false),
77 initialization_time_(-1) {
78 }
79
80 TpmInitTask::~TpmInitTask() {
81 }
82
83 void TpmInitTask::Init() {
84 tpm_->Init();
85 }
86
87 void TpmInitTask::ThreadMain() {
88 base::TimeTicks start = base::TimeTicks::Now();
89 initialize_status_ = tpm_->InitializeTpm();
90 base::TimeDelta delta = (base::TimeTicks::Now() - start);
91 initialization_time_ = delta.InMilliseconds();
92 if (initialize_status_) {
93 LOG(ERROR) << "TPM initialization took " << initialization_time_ << "ms";
94 }
95 task_done_ = true;
96 }
97
98 bool TpmInitTask::IsTpmReady() {
99 // The TPM is not "ready" if the init call has not completed. It may be in
100 // the middle of taking ownership.
101 if (!task_done_) {
102 return false;
103 }
104 // If initialize_status_ is true, then the TPM went through a full succesful
105 // ownership cycle in InitializeTpm()
106 if (initialize_status_) {
107 return true;
108 }
109 // If we get here, then the call to InitializeTpm() is complete and it
110 // returned false. That merely means that it did not successfully take
111 // ownership, which is the common case after ownership is established on OOBE.
112 // In that case, the TPM is ready if it is enabled and owned.
113 return (tpm_->IsEnabled() && tpm_->IsOwned());
114 }
115
116 bool TpmInitTask::IsTpmEnabled() {
117 return tpm_->IsEnabled();
118 }
119
120 bool TpmInitTask::GetTpmPassword(chromeos::Blob* password) {
121 return tpm_->GetOwnerPassword(password);
122 }
123
124 long TpmInitTask::GetInitializationMillis() {
125 return initialization_time_;
126 }
127
128 } // namespace tpm_init
OLDNEW
« no previous file with comments | « tpm_init.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698