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

Side by Side Diff: tpm_init.cc

Issue 3437016: Add better handling of a TPM clear. (Closed) Base URL: http://git.chromium.org/git/tpm_init.git
Patch Set: Remove unnecessary include. Created 10 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 | Annotate | Revision Log
« 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
1 // Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. 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 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 // Contains the implementation of class TpmInit 5 // Contains the implementation of class TpmInit
6 6
7 #include "tpm_init.h" 7 #include "tpm_init.h"
8 8
9 #include <base/logging.h> 9 #include <base/logging.h>
10 #include <base/time.h> 10 #include <base/time.h>
11 11
12 #include "tpm.h" 12 #include "tpm.h"
13 13
14 namespace tpm_init { 14 namespace tpm_init {
15 15
16 // TpmInitTask is a private class used to handle asynchronous initialization of 16 // TpmInitTask is a private class used to handle asynchronous initialization of
17 // the TPM. 17 // the TPM.
18 class TpmInitTask : public PlatformThread::Delegate { 18 class TpmInitTask : public PlatformThread::Delegate {
19 public: 19 public:
20 TpmInitTask(); 20 TpmInitTask();
21 virtual ~TpmInitTask(); 21 virtual ~TpmInitTask();
22 22
23 void Init(); 23 void Init(TpmInit::TpmInitCallback* notify_callback);
24 24
25 virtual void ThreadMain(); 25 virtual void ThreadMain();
26 26
27 bool IsTpmReady(); 27 bool IsTpmReady();
28 bool IsTpmEnabled(); 28 bool IsTpmEnabled();
29 bool IsTpmOwned(); 29 bool IsTpmOwned();
30 bool IsTpmBeingOwned(); 30 bool IsTpmBeingOwned();
31 bool GetTpmPassword(chromeos::Blob* password); 31 bool GetTpmPassword(chromeos::Blob* password);
32 long GetInitializationMillis(); 32 long GetInitializationMillis();
33 bool GetRandomData(int length, chromeos::Blob* data); 33 bool GetRandomData(int length, chromeos::Blob* data);
34 34
35 private: 35 private:
36 scoped_ptr<tpm_init::Tpm> default_tpm_; 36 scoped_ptr<tpm_init::Tpm> default_tpm_;
37 tpm_init::Tpm* tpm_; 37 tpm_init::Tpm* tpm_;
38 bool initialize_status_; 38 bool initialize_took_ownership_;
39 bool task_done_; 39 bool task_done_;
40 long initialization_time_; 40 long initialization_time_;
41 TpmInit::TpmInitCallback* notify_callback_;
41 }; 42 };
42 43
43 TpmInit::TpmInit() 44 TpmInit::TpmInit()
44 : tpm_init_(new TpmInitTask()) { 45 : tpm_init_task_(new TpmInitTask()),
46 notify_callback_(NULL) {
45 } 47 }
46 48
47 TpmInit::~TpmInit() { 49 TpmInit::~TpmInit() {
48 } 50 }
49 51
52 void TpmInit::Init(TpmInitCallback* notify_callback) {
53 notify_callback_ = notify_callback;
54 }
55
50 bool TpmInit::GetRandomData(int length, chromeos::Blob* data) { 56 bool TpmInit::GetRandomData(int length, chromeos::Blob* data) {
51 return tpm_init_->GetRandomData(length, data); 57 return tpm_init_task_->GetRandomData(length, data);
52 } 58 }
53 59
54 bool TpmInit::StartInitializeTpm() { 60 bool TpmInit::StartInitializeTpm() {
55 tpm_init_->Init(); 61 tpm_init_task_->Init(notify_callback_);
56 if (!PlatformThread::CreateNonJoinable(0, tpm_init_.get())) { 62 if (!PlatformThread::CreateNonJoinable(0, tpm_init_task_.get())) {
57 LOG(ERROR) << "Unable to create TPM initialization background thread."; 63 LOG(ERROR) << "Unable to create TPM initialization background thread.";
58 return false; 64 return false;
59 } 65 }
60 return true; 66 return true;
61 } 67 }
62 68
63 bool TpmInit::IsTpmReady() { 69 bool TpmInit::IsTpmReady() {
64 return tpm_init_->IsTpmReady(); 70 return tpm_init_task_->IsTpmReady();
65 } 71 }
66 72
67 bool TpmInit::IsTpmEnabled() { 73 bool TpmInit::IsTpmEnabled() {
68 return tpm_init_->IsTpmEnabled(); 74 return tpm_init_task_->IsTpmEnabled();
69 } 75 }
70 76
71 bool TpmInit::IsTpmOwned() { 77 bool TpmInit::IsTpmOwned() {
72 return tpm_init_->IsTpmOwned(); 78 return tpm_init_task_->IsTpmOwned();
73 } 79 }
74 80
75 bool TpmInit::IsTpmBeingOwned() { 81 bool TpmInit::IsTpmBeingOwned() {
76 return tpm_init_->IsTpmBeingOwned(); 82 return tpm_init_task_->IsTpmBeingOwned();
77 } 83 }
78 84
79 bool TpmInit::GetTpmPassword(chromeos::Blob* password) { 85 bool TpmInit::GetTpmPassword(chromeos::Blob* password) {
80 return tpm_init_->GetTpmPassword(password); 86 return tpm_init_task_->GetTpmPassword(password);
81 } 87 }
82 88
83 long TpmInit::GetInitializationMillis() { 89 long TpmInit::GetInitializationMillis() {
84 return tpm_init_->GetInitializationMillis(); 90 return tpm_init_task_->GetInitializationMillis();
85 } 91 }
86 92
87 TpmInitTask::TpmInitTask() 93 TpmInitTask::TpmInitTask()
88 : default_tpm_(new tpm_init::Tpm()), 94 : default_tpm_(new tpm_init::Tpm()),
89 tpm_(default_tpm_.get()), 95 tpm_(default_tpm_.get()),
90 initialize_status_(false), 96 initialize_took_ownership_(false),
91 task_done_(false), 97 task_done_(false),
92 initialization_time_(-1) { 98 initialization_time_(-1),
99 notify_callback_(NULL) {
93 } 100 }
94 101
95 TpmInitTask::~TpmInitTask() { 102 TpmInitTask::~TpmInitTask() {
96 } 103 }
97 104
98 void TpmInitTask::Init() { 105 void TpmInitTask::Init(TpmInit::TpmInitCallback* notify_callback) {
106 notify_callback_ = notify_callback;
99 tpm_->Init(); 107 tpm_->Init();
100 } 108 }
101 109
102 void TpmInitTask::ThreadMain() { 110 void TpmInitTask::ThreadMain() {
103 base::TimeTicks start = base::TimeTicks::Now(); 111 base::TimeTicks start = base::TimeTicks::Now();
104 initialize_status_ = tpm_->InitializeTpm(); 112 bool initialize_result = tpm_->InitializeTpm(&initialize_took_ownership_);
105 base::TimeDelta delta = (base::TimeTicks::Now() - start); 113 base::TimeDelta delta = (base::TimeTicks::Now() - start);
106 initialization_time_ = delta.InMilliseconds(); 114 initialization_time_ = delta.InMilliseconds();
107 if (initialize_status_) { 115 if (initialize_took_ownership_) {
108 LOG(ERROR) << "TPM initialization took " << initialization_time_ << "ms"; 116 LOG(ERROR) << "TPM initialization took " << initialization_time_ << "ms";
109 } 117 }
110 task_done_ = true; 118 task_done_ = true;
119 if (notify_callback_) {
120 notify_callback_->InitializeTpmComplete(initialize_result,
121 initialize_took_ownership_);
122 }
111 } 123 }
112 124
113 bool TpmInitTask::IsTpmReady() { 125 bool TpmInitTask::IsTpmReady() {
114 // The TPM is not "ready" if the init call has not completed. It may be in 126 // The TPM is not "ready" if the init call has not completed. It may be in
115 // the middle of taking ownership. 127 // the middle of taking ownership.
116 if (!task_done_) { 128 if (!task_done_) {
117 return false; 129 return false;
118 } 130 }
119 // If initialize_status_ is true, then the TPM went through a full succesful 131 // If initialize_took_ownership_ is true, then the TPM went through a full
120 // ownership cycle in InitializeTpm() 132 // succesful ownership cycle in InitializeTpm()
121 if (initialize_status_) { 133 if (initialize_took_ownership_) {
122 return true; 134 return true;
123 } 135 }
124 // If we get here, then the call to InitializeTpm() is complete and it 136 // If we get here, then the call to InitializeTpm() is complete and it
125 // returned false. That merely means that it did not successfully take 137 // returned false. That merely means that it did not successfully take
126 // ownership, which is the common case after ownership is established on OOBE. 138 // ownership, which is the common case after ownership is established on OOBE.
127 // In that case, the TPM is ready if it is enabled and owned. 139 // In that case, the TPM is ready if it is enabled and owned.
128 return (tpm_->IsEnabled() && tpm_->IsOwned()); 140 return (tpm_->IsEnabled() && tpm_->IsOwned());
129 } 141 }
130 142
131 bool TpmInitTask::IsTpmEnabled() { 143 bool TpmInitTask::IsTpmEnabled() {
(...skipping 14 matching lines...) Expand all
146 158
147 long TpmInitTask::GetInitializationMillis() { 159 long TpmInitTask::GetInitializationMillis() {
148 return initialization_time_; 160 return initialization_time_;
149 } 161 }
150 162
151 bool TpmInitTask::GetRandomData(int length, chromeos::Blob* data) { 163 bool TpmInitTask::GetRandomData(int length, chromeos::Blob* data) {
152 return tpm_->GetRandomData(length, data); 164 return tpm_->GetRandomData(length, data);
153 } 165 }
154 166
155 } // namespace tpm_init 167 } // 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