OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/cros/cryptohome_library.h" | 5 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/hash_tables.h" | 8 #include "base/hash_tables.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
12 #include "content/browser/browser_thread.h" | 12 #include "content/browser/browser_thread.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 const char kStubSystemSalt[] = "stub_system_salt"; | 15 const char kStubSystemSalt[] = "stub_system_salt"; |
16 } | 16 } |
17 | 17 |
18 namespace chromeos { | 18 namespace chromeos { |
19 | 19 |
20 // This class handles the interaction with the ChromeOS cryptohome library APIs. | 20 // This class handles the interaction with the ChromeOS cryptohome library APIs. |
21 class CryptohomeLibraryImpl : public CryptohomeLibrary { | 21 class CryptohomeLibraryImpl : public CryptohomeLibrary { |
22 public: | 22 public: |
23 CryptohomeLibraryImpl() { | 23 CryptohomeLibraryImpl() {} |
24 if (CrosLibrary::Get()->EnsureLoaded()) | |
25 Init(); | |
26 } | |
27 virtual ~CryptohomeLibraryImpl() {} | 24 virtual ~CryptohomeLibraryImpl() {} |
28 | 25 |
29 bool CheckKey(const std::string& user_email, const std::string& passhash) { | 26 virtual void Init() OVERRIDE { |
| 27 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
| 28 cryptohome_connection_ = chromeos::CryptohomeMonitorSession(&Handler, this); |
| 29 } |
| 30 |
| 31 virtual bool CheckKey( |
| 32 const std::string& user_email, const std::string& passhash) OVERRIDE { |
30 return chromeos::CryptohomeCheckKey(user_email.c_str(), passhash.c_str()); | 33 return chromeos::CryptohomeCheckKey(user_email.c_str(), passhash.c_str()); |
31 } | 34 } |
32 | 35 |
33 bool AsyncCheckKey(const std::string& user_email, | 36 virtual bool AsyncCheckKey(const std::string& user_email, |
34 const std::string& passhash, | 37 const std::string& passhash, |
35 Delegate* d) { | 38 Delegate* d) OVERRIDE { |
36 return CacheCallback( | 39 return CacheCallback( |
37 chromeos::CryptohomeAsyncCheckKey(user_email.c_str(), passhash.c_str()), | 40 chromeos::CryptohomeAsyncCheckKey(user_email.c_str(), passhash.c_str()), |
38 d, | 41 d, |
39 "Couldn't initiate async check of user's key."); | 42 "Couldn't initiate async check of user's key."); |
40 } | 43 } |
41 | 44 |
42 bool MigrateKey(const std::string& user_email, | 45 virtual bool MigrateKey(const std::string& user_email, |
43 const std::string& old_hash, | 46 const std::string& old_hash, |
44 const std::string& new_hash) { | 47 const std::string& new_hash) OVERRIDE { |
45 return chromeos::CryptohomeMigrateKey(user_email.c_str(), | 48 return chromeos::CryptohomeMigrateKey(user_email.c_str(), |
46 old_hash.c_str(), | 49 old_hash.c_str(), |
47 new_hash.c_str()); | 50 new_hash.c_str()); |
48 } | 51 } |
49 | 52 |
50 bool AsyncMigrateKey(const std::string& user_email, | 53 virtual bool AsyncMigrateKey(const std::string& user_email, |
51 const std::string& old_hash, | 54 const std::string& old_hash, |
52 const std::string& new_hash, | 55 const std::string& new_hash, |
53 Delegate* d) { | 56 Delegate* d) OVERRIDE { |
54 return CacheCallback( | 57 return CacheCallback( |
55 chromeos::CryptohomeAsyncMigrateKey(user_email.c_str(), | 58 chromeos::CryptohomeAsyncMigrateKey(user_email.c_str(), |
56 old_hash.c_str(), | 59 old_hash.c_str(), |
57 new_hash.c_str()), | 60 new_hash.c_str()), |
58 d, | 61 d, |
59 "Couldn't initiate aync migration of user's key"); | 62 "Couldn't initiate aync migration of user's key"); |
60 } | 63 } |
61 | 64 |
62 bool Mount(const std::string& user_email, | 65 virtual bool Mount(const std::string& user_email, |
63 const std::string& passhash, | 66 const std::string& passhash, |
64 int* error_code) { | 67 int* error_code) OVERRIDE { |
65 return chromeos::CryptohomeMountAllowFail(user_email.c_str(), | 68 return chromeos::CryptohomeMountAllowFail(user_email.c_str(), |
66 passhash.c_str(), | 69 passhash.c_str(), |
67 error_code); | 70 error_code); |
68 } | 71 } |
69 | 72 |
70 bool AsyncMount(const std::string& user_email, | 73 virtual bool AsyncMount(const std::string& user_email, |
71 const std::string& passhash, | 74 const std::string& passhash, |
72 const bool create_if_missing, | 75 const bool create_if_missing, |
73 Delegate* d) { | 76 Delegate* d) OVERRIDE { |
74 return CacheCallback( | 77 return CacheCallback( |
75 chromeos::CryptohomeAsyncMountSafe(user_email.c_str(), | 78 chromeos::CryptohomeAsyncMountSafe(user_email.c_str(), |
76 passhash.c_str(), | 79 passhash.c_str(), |
77 create_if_missing, | 80 create_if_missing, |
78 false, | 81 false, |
79 NULL), | 82 NULL), |
80 d, | 83 d, |
81 "Couldn't initiate async mount of cryptohome."); | 84 "Couldn't initiate async mount of cryptohome."); |
82 } | 85 } |
83 | 86 |
84 bool MountForBwsi(int* error_code) { | 87 virtual bool MountForBwsi(int* error_code) OVERRIDE { |
85 return chromeos::CryptohomeMountGuest(error_code); | 88 return chromeos::CryptohomeMountGuest(error_code); |
86 } | 89 } |
87 | 90 |
88 bool AsyncMountForBwsi(Delegate* d) { | 91 virtual bool AsyncMountForBwsi(Delegate* d) OVERRIDE { |
89 return CacheCallback(chromeos::CryptohomeAsyncMountGuest(), | 92 return CacheCallback(chromeos::CryptohomeAsyncMountGuest(), |
90 d, | 93 d, |
91 "Couldn't initiate async mount of cryptohome."); | 94 "Couldn't initiate async mount of cryptohome."); |
92 } | 95 } |
93 | 96 |
94 bool Unmount() { | 97 virtual bool Unmount() OVERRIDE { |
95 return chromeos::CryptohomeUnmount(); | 98 return chromeos::CryptohomeUnmount(); |
96 } | 99 } |
97 | 100 |
98 bool Remove(const std::string& user_email) { | 101 virtual bool Remove(const std::string& user_email) OVERRIDE { |
99 return chromeos::CryptohomeRemove(user_email.c_str()); | 102 return chromeos::CryptohomeRemove(user_email.c_str()); |
100 } | 103 } |
101 | 104 |
102 bool AsyncRemove(const std::string& user_email, Delegate* d) { | 105 virtual bool AsyncRemove( |
| 106 const std::string& user_email, Delegate* d) OVERRIDE { |
103 return CacheCallback( | 107 return CacheCallback( |
104 chromeos::CryptohomeAsyncRemove(user_email.c_str()), | 108 chromeos::CryptohomeAsyncRemove(user_email.c_str()), |
105 d, | 109 d, |
106 "Couldn't initiate async removal of cryptohome."); | 110 "Couldn't initiate async removal of cryptohome."); |
107 } | 111 } |
108 | 112 |
109 bool IsMounted() { | 113 virtual bool IsMounted() OVERRIDE { |
110 return chromeos::CryptohomeIsMounted(); | 114 return chromeos::CryptohomeIsMounted(); |
111 } | 115 } |
112 | 116 |
113 CryptohomeBlob GetSystemSalt() { | 117 virtual CryptohomeBlob GetSystemSalt() OVERRIDE { |
114 CryptohomeBlob system_salt; | 118 CryptohomeBlob system_salt; |
115 char* salt_buf; | 119 char* salt_buf; |
116 int salt_len; | 120 int salt_len; |
117 bool result = chromeos::CryptohomeGetSystemSaltSafe(&salt_buf, &salt_len); | 121 bool result = chromeos::CryptohomeGetSystemSaltSafe(&salt_buf, &salt_len); |
118 if (result) { | 122 if (result) { |
119 system_salt.resize(salt_len); | 123 system_salt.resize(salt_len); |
120 if ((int)system_salt.size() == salt_len) { | 124 if ((int)system_salt.size() == salt_len) { |
121 memcpy(&system_salt[0], static_cast<const void*>(salt_buf), | 125 memcpy(&system_salt[0], static_cast<const void*>(salt_buf), |
122 salt_len); | 126 salt_len); |
123 } else { | 127 } else { |
124 system_salt.clear(); | 128 system_salt.clear(); |
125 } | 129 } |
126 } | 130 } |
127 return system_salt; | 131 return system_salt; |
128 } | 132 } |
129 | 133 |
130 bool AsyncDoAutomaticFreeDiskSpaceControl(Delegate* d) { | 134 virtual bool AsyncDoAutomaticFreeDiskSpaceControl(Delegate* d) OVERRIDE { |
131 return CacheCallback( | 135 return CacheCallback( |
132 chromeos::CryptohomeAsyncDoAutomaticFreeDiskSpaceControl(), | 136 chromeos::CryptohomeAsyncDoAutomaticFreeDiskSpaceControl(), |
133 d, | 137 d, |
134 "Couldn't do automatic free disk space control."); | 138 "Couldn't do automatic free disk space control."); |
135 } | 139 } |
136 | 140 |
137 bool AsyncSetOwnerUser(const std::string& username, Delegate* d) { | 141 virtual bool AsyncSetOwnerUser( |
| 142 const std::string& username, Delegate* d) OVERRIDE { |
138 return CacheCallback( | 143 return CacheCallback( |
139 chromeos::CryptohomeAsyncSetOwnerUser(username.c_str()), | 144 chromeos::CryptohomeAsyncSetOwnerUser(username.c_str()), |
140 d, | 145 d, |
141 "Couldn't do set owner user in Cryptohomed."); | 146 "Couldn't do set owner user in Cryptohomed."); |
142 } | 147 } |
143 | 148 |
144 bool TpmIsReady() { | 149 virtual bool TpmIsReady() OVERRIDE { |
145 return chromeos::CryptohomeTpmIsReady(); | 150 return chromeos::CryptohomeTpmIsReady(); |
146 } | 151 } |
147 | 152 |
148 bool TpmIsEnabled() { | 153 virtual bool TpmIsEnabled() OVERRIDE { |
149 return chromeos::CryptohomeTpmIsEnabled(); | 154 return chromeos::CryptohomeTpmIsEnabled(); |
150 } | 155 } |
151 | 156 |
152 bool TpmIsOwned() { | 157 virtual bool TpmIsOwned() OVERRIDE { |
153 return chromeos::CryptohomeTpmIsOwned(); | 158 return chromeos::CryptohomeTpmIsOwned(); |
154 } | 159 } |
155 | 160 |
156 bool TpmIsBeingOwned() { | 161 virtual bool TpmIsBeingOwned() OVERRIDE { |
157 return chromeos::CryptohomeTpmIsBeingOwned(); | 162 return chromeos::CryptohomeTpmIsBeingOwned(); |
158 } | 163 } |
159 | 164 |
160 bool TpmGetPassword(std::string* password) { | 165 virtual bool TpmGetPassword(std::string* password) OVERRIDE { |
161 char *password_buf; | 166 char *password_buf; |
162 bool result = chromeos::CryptohomeTpmGetPasswordSafe(&password_buf); | 167 bool result = chromeos::CryptohomeTpmGetPasswordSafe(&password_buf); |
163 *password = password_buf; | 168 *password = password_buf; |
164 chromeos::CryptohomeFreeString(password_buf); | 169 chromeos::CryptohomeFreeString(password_buf); |
165 return result; | 170 return result; |
166 } | 171 } |
167 | 172 |
168 void TpmCanAttemptOwnership() { | 173 virtual void TpmCanAttemptOwnership() OVERRIDE { |
169 chromeos::CryptohomeTpmCanAttemptOwnership(); | 174 chromeos::CryptohomeTpmCanAttemptOwnership(); |
170 } | 175 } |
171 | 176 |
172 void TpmClearStoredPassword() { | 177 virtual void TpmClearStoredPassword() OVERRIDE { |
173 chromeos::CryptohomeTpmClearStoredPassword(); | 178 chromeos::CryptohomeTpmClearStoredPassword(); |
174 } | 179 } |
175 | 180 |
176 bool InstallAttributesGet(const std::string& name, std::string* value) { | 181 virtual bool InstallAttributesGet( |
| 182 const std::string& name, std::string* value) OVERRIDE { |
177 char* local_value; | 183 char* local_value; |
178 bool done = | 184 bool done = |
179 chromeos::CryptohomeInstallAttributesGet(name.c_str(), &local_value); | 185 chromeos::CryptohomeInstallAttributesGet(name.c_str(), &local_value); |
180 if (done) { | 186 if (done) { |
181 *value = local_value; | 187 *value = local_value; |
182 chromeos::CryptohomeFreeString(local_value); | 188 chromeos::CryptohomeFreeString(local_value); |
183 } | 189 } |
184 return done; | 190 return done; |
185 } | 191 } |
186 | 192 |
187 bool InstallAttributesSet(const std::string& name, const std::string& value) { | 193 virtual bool InstallAttributesSet( |
| 194 const std::string& name, const std::string& value) OVERRIDE { |
188 return chromeos::CryptohomeInstallAttributesSet(name.c_str(), | 195 return chromeos::CryptohomeInstallAttributesSet(name.c_str(), |
189 value.c_str()); | 196 value.c_str()); |
190 } | 197 } |
191 | 198 |
192 int InstallAttributesCount() { | 199 virtual int InstallAttributesCount() OVERRIDE { |
193 return chromeos::CryptohomeInstallAttributesCount(); | 200 return chromeos::CryptohomeInstallAttributesCount(); |
194 } | 201 } |
195 | 202 |
196 bool InstallAttributesFinalize() { | 203 virtual bool InstallAttributesFinalize() OVERRIDE { |
197 return chromeos::CryptohomeInstallAttributesFinalize(); | 204 return chromeos::CryptohomeInstallAttributesFinalize(); |
198 } | 205 } |
199 | 206 |
200 bool InstallAttributesIsReady() { | 207 virtual bool InstallAttributesIsReady() OVERRIDE { |
201 return chromeos::CryptohomeInstallAttributesIsReady(); | 208 return chromeos::CryptohomeInstallAttributesIsReady(); |
202 } | 209 } |
203 | 210 |
204 bool InstallAttributesIsSecure() { | 211 virtual bool InstallAttributesIsSecure() OVERRIDE { |
205 return chromeos::CryptohomeInstallAttributesIsSecure(); | 212 return chromeos::CryptohomeInstallAttributesIsSecure(); |
206 } | 213 } |
207 | 214 |
208 bool InstallAttributesIsInvalid() { | 215 virtual bool InstallAttributesIsInvalid() OVERRIDE { |
209 return chromeos::CryptohomeInstallAttributesIsInvalid(); | 216 return chromeos::CryptohomeInstallAttributesIsInvalid(); |
210 } | 217 } |
211 | 218 |
212 bool InstallAttributesIsFirstInstall() { | 219 virtual bool InstallAttributesIsFirstInstall() OVERRIDE { |
213 return chromeos::CryptohomeInstallAttributesIsFirstInstall(); | 220 return chromeos::CryptohomeInstallAttributesIsFirstInstall(); |
214 } | 221 } |
215 | 222 |
216 void Pkcs11GetTpmTokenInfo(std::string* label, std::string* user_pin) { | 223 virtual void Pkcs11GetTpmTokenInfo( |
| 224 std::string* label, std::string* user_pin) OVERRIDE { |
217 chromeos::CryptohomePkcs11GetTpmTokenInfo(label, user_pin); | 225 chromeos::CryptohomePkcs11GetTpmTokenInfo(label, user_pin); |
218 } | 226 } |
219 | 227 |
220 bool Pkcs11IsTpmTokenReady() { | 228 virtual bool Pkcs11IsTpmTokenReady() OVERRIDE { |
221 return chromeos::CryptohomePkcs11IsTpmTokenReady(); | 229 return chromeos::CryptohomePkcs11IsTpmTokenReady(); |
222 } | 230 } |
223 | 231 |
224 private: | 232 private: |
225 static void Handler(const chromeos::CryptohomeAsyncCallStatus& event, | 233 static void Handler(const chromeos::CryptohomeAsyncCallStatus& event, |
226 void* cryptohome_library) { | 234 void* cryptohome_library) { |
227 CryptohomeLibraryImpl* library = | 235 CryptohomeLibraryImpl* library = |
228 reinterpret_cast<CryptohomeLibraryImpl*>(cryptohome_library); | 236 reinterpret_cast<CryptohomeLibraryImpl*>(cryptohome_library); |
229 library->Dispatch(event); | 237 library->Dispatch(event); |
230 } | 238 } |
231 | 239 |
232 void Init() { | |
233 cryptohome_connection_ = chromeos::CryptohomeMonitorSession(&Handler, this); | |
234 } | |
235 | |
236 void Dispatch(const chromeos::CryptohomeAsyncCallStatus& event) { | 240 void Dispatch(const chromeos::CryptohomeAsyncCallStatus& event) { |
237 const CallbackMap::iterator callback = callback_map_.find(event.async_id); | 241 const CallbackMap::iterator callback = callback_map_.find(event.async_id); |
238 if (callback == callback_map_.end()) { | 242 if (callback == callback_map_.end()) { |
239 LOG(ERROR) << "Received signal for unknown async_id " << event.async_id; | 243 LOG(ERROR) << "Received signal for unknown async_id " << event.async_id; |
240 return; | 244 return; |
241 } | 245 } |
242 if (callback->second) | 246 if (callback->second) |
243 callback->second->OnComplete(event.return_status, event.return_code); | 247 callback->second->OnComplete(event.return_status, event.return_code); |
244 callback_map_.erase(callback); | 248 callback_map_.erase(callback); |
245 } | 249 } |
(...skipping 15 matching lines...) Expand all Loading... |
261 | 265 |
262 DISALLOW_COPY_AND_ASSIGN(CryptohomeLibraryImpl); | 266 DISALLOW_COPY_AND_ASSIGN(CryptohomeLibraryImpl); |
263 }; | 267 }; |
264 | 268 |
265 class CryptohomeLibraryStubImpl : public CryptohomeLibrary { | 269 class CryptohomeLibraryStubImpl : public CryptohomeLibrary { |
266 public: | 270 public: |
267 CryptohomeLibraryStubImpl() | 271 CryptohomeLibraryStubImpl() |
268 : locked_(false) {} | 272 : locked_(false) {} |
269 virtual ~CryptohomeLibraryStubImpl() {} | 273 virtual ~CryptohomeLibraryStubImpl() {} |
270 | 274 |
271 bool CheckKey(const std::string& user_email, const std::string& passhash) { | 275 virtual void Init() OVERRIDE {} |
| 276 |
| 277 virtual bool CheckKey( |
| 278 const std::string& user_email, const std::string& passhash) OVERRIDE { |
272 return true; | 279 return true; |
273 } | 280 } |
274 | 281 |
275 bool AsyncCheckKey(const std::string& user_email, | 282 virtual bool AsyncCheckKey(const std::string& user_email, |
276 const std::string& passhash, | 283 const std::string& passhash, |
277 Delegate* callback) { | 284 Delegate* callback) OVERRIDE { |
278 BrowserThread::PostTask( | 285 BrowserThread::PostTask( |
279 BrowserThread::UI, FROM_HERE, | 286 BrowserThread::UI, FROM_HERE, |
280 NewRunnableFunction(&DoStubCallback, callback)); | 287 NewRunnableFunction(&DoStubCallback, callback)); |
281 return true; | 288 return true; |
282 } | 289 } |
283 | 290 |
284 bool MigrateKey(const std::string& user_email, | 291 virtual bool MigrateKey(const std::string& user_email, |
285 const std::string& old_hash, | 292 const std::string& old_hash, |
286 const std::string& new_hash) { | 293 const std::string& new_hash) OVERRIDE { |
287 return true; | 294 return true; |
288 } | 295 } |
289 | 296 |
290 bool AsyncMigrateKey(const std::string& user_email, | 297 virtual bool AsyncMigrateKey(const std::string& user_email, |
291 const std::string& old_hash, | 298 const std::string& old_hash, |
292 const std::string& new_hash, | 299 const std::string& new_hash, |
293 Delegate* callback) { | 300 Delegate* callback) OVERRIDE { |
294 BrowserThread::PostTask( | 301 BrowserThread::PostTask( |
295 BrowserThread::UI, FROM_HERE, | 302 BrowserThread::UI, FROM_HERE, |
296 NewRunnableFunction(&DoStubCallback, callback)); | 303 NewRunnableFunction(&DoStubCallback, callback)); |
297 return true; | 304 return true; |
298 } | 305 } |
299 | 306 |
300 bool Mount(const std::string& user_email, | 307 virtual bool Mount(const std::string& user_email, |
301 const std::string& passhash, | 308 const std::string& passhash, |
302 int* error_code) { | 309 int* error_code) OVERRIDE { |
303 // For testing password change. | 310 // For testing password change. |
304 if (user_email == | 311 if (user_email == |
305 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 312 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
306 switches::kLoginUserWithNewPassword)) { | 313 switches::kLoginUserWithNewPassword)) { |
307 *error_code = kCryptohomeMountErrorKeyFailure; | 314 *error_code = kCryptohomeMountErrorKeyFailure; |
308 return false; | 315 return false; |
309 } | 316 } |
310 | 317 |
311 return true; | 318 return true; |
312 } | 319 } |
313 | 320 |
314 bool AsyncMount(const std::string& user_email, | 321 virtual bool AsyncMount(const std::string& user_email, |
315 const std::string& passhash, | 322 const std::string& passhash, |
316 const bool create_if_missing, | 323 const bool create_if_missing, |
317 Delegate* callback) { | 324 Delegate* callback) OVERRIDE { |
318 BrowserThread::PostTask( | 325 BrowserThread::PostTask( |
319 BrowserThread::UI, FROM_HERE, | 326 BrowserThread::UI, FROM_HERE, |
320 NewRunnableFunction(&DoStubCallback, callback)); | 327 NewRunnableFunction(&DoStubCallback, callback)); |
321 return true; | 328 return true; |
322 } | 329 } |
323 | 330 |
324 bool MountForBwsi(int* error_code) { | 331 virtual bool MountForBwsi(int* error_code) OVERRIDE { |
325 return true; | 332 return true; |
326 } | 333 } |
327 | 334 |
328 bool AsyncMountForBwsi(Delegate* callback) { | 335 virtual bool AsyncMountForBwsi(Delegate* callback) OVERRIDE { |
329 BrowserThread::PostTask( | 336 BrowserThread::PostTask( |
330 BrowserThread::UI, FROM_HERE, | 337 BrowserThread::UI, FROM_HERE, |
331 NewRunnableFunction(&DoStubCallback, callback)); | 338 NewRunnableFunction(&DoStubCallback, callback)); |
332 return true; | 339 return true; |
333 } | 340 } |
334 | 341 |
335 bool Unmount() { | 342 virtual bool Unmount() OVERRIDE { |
336 return true; | 343 return true; |
337 } | 344 } |
338 | 345 |
339 bool Remove(const std::string& user_email) { | 346 virtual bool Remove(const std::string& user_email) OVERRIDE { |
340 return true; | 347 return true; |
341 } | 348 } |
342 | 349 |
343 bool AsyncRemove(const std::string& user_email, Delegate* callback) { | 350 virtual bool AsyncRemove( |
| 351 const std::string& user_email, Delegate* callback) OVERRIDE { |
344 BrowserThread::PostTask( | 352 BrowserThread::PostTask( |
345 BrowserThread::UI, FROM_HERE, | 353 BrowserThread::UI, FROM_HERE, |
346 NewRunnableFunction(&DoStubCallback, callback)); | 354 NewRunnableFunction(&DoStubCallback, callback)); |
347 return true; | 355 return true; |
348 } | 356 } |
349 | 357 |
350 bool IsMounted() { | 358 virtual bool IsMounted() OVERRIDE { |
351 return true; | 359 return true; |
352 } | 360 } |
353 | 361 |
354 CryptohomeBlob GetSystemSalt() { | 362 virtual CryptohomeBlob GetSystemSalt() OVERRIDE { |
355 CryptohomeBlob salt = CryptohomeBlob(); | 363 CryptohomeBlob salt = CryptohomeBlob(); |
356 for (size_t i = 0; i < strlen(kStubSystemSalt); i++) | 364 for (size_t i = 0; i < strlen(kStubSystemSalt); i++) |
357 salt.push_back(static_cast<unsigned char>(kStubSystemSalt[i])); | 365 salt.push_back(static_cast<unsigned char>(kStubSystemSalt[i])); |
358 | 366 |
359 return salt; | 367 return salt; |
360 } | 368 } |
361 | 369 |
362 bool AsyncDoAutomaticFreeDiskSpaceControl(Delegate* callback) { | 370 virtual bool AsyncDoAutomaticFreeDiskSpaceControl( |
| 371 Delegate* callback) OVERRIDE { |
363 BrowserThread::PostTask( | 372 BrowserThread::PostTask( |
364 BrowserThread::UI, FROM_HERE, | 373 BrowserThread::UI, FROM_HERE, |
365 NewRunnableFunction(&DoStubCallback, callback)); | 374 NewRunnableFunction(&DoStubCallback, callback)); |
366 return true; | 375 return true; |
367 } | 376 } |
368 | 377 |
369 bool AsyncSetOwnerUser(const std::string& username, Delegate* callback) { | 378 virtual bool AsyncSetOwnerUser( |
| 379 const std::string& username, Delegate* callback) OVERRIDE { |
370 BrowserThread::PostTask( | 380 BrowserThread::PostTask( |
371 BrowserThread::UI, FROM_HERE, | 381 BrowserThread::UI, FROM_HERE, |
372 NewRunnableFunction(&DoStubCallback, callback)); | 382 NewRunnableFunction(&DoStubCallback, callback)); |
373 return true; | 383 return true; |
374 } | 384 } |
375 | 385 |
376 // Tpm begin ready after 20-th call. | 386 // Tpm begin ready after 20-th call. |
377 bool TpmIsReady() { | 387 virtual bool TpmIsReady() OVERRIDE { |
378 static int counter = 0; | 388 static int counter = 0; |
379 return ++counter > 20; | 389 return ++counter > 20; |
380 } | 390 } |
381 | 391 |
382 bool TpmIsEnabled() { | 392 virtual bool TpmIsEnabled() OVERRIDE { |
383 return true; | 393 return true; |
384 } | 394 } |
385 | 395 |
386 bool TpmIsOwned() { | 396 virtual bool TpmIsOwned() OVERRIDE { |
387 return true; | 397 return true; |
388 } | 398 } |
389 | 399 |
390 bool TpmIsBeingOwned() { | 400 virtual bool TpmIsBeingOwned() OVERRIDE { |
391 return true; | 401 return true; |
392 } | 402 } |
393 | 403 |
394 bool TpmGetPassword(std::string* password) { | 404 virtual bool TpmGetPassword(std::string* password) OVERRIDE { |
395 *password = "Stub-TPM-password"; | 405 *password = "Stub-TPM-password"; |
396 return true; | 406 return true; |
397 } | 407 } |
398 | 408 |
399 void TpmCanAttemptOwnership() {} | 409 virtual void TpmCanAttemptOwnership() OVERRIDE {} |
400 | 410 |
401 void TpmClearStoredPassword() {} | 411 virtual void TpmClearStoredPassword() OVERRIDE {} |
402 | 412 |
403 bool InstallAttributesGet(const std::string& name, std::string* value) { | 413 virtual bool InstallAttributesGet( |
| 414 const std::string& name, std::string* value) OVERRIDE { |
404 if (install_attrs_.find(name) != install_attrs_.end()) { | 415 if (install_attrs_.find(name) != install_attrs_.end()) { |
405 *value = install_attrs_[name]; | 416 *value = install_attrs_[name]; |
406 return true; | 417 return true; |
407 } | 418 } |
408 return false; | 419 return false; |
409 } | 420 } |
410 | 421 |
411 bool InstallAttributesSet(const std::string& name, const std::string& value) { | 422 virtual bool InstallAttributesSet( |
| 423 const std::string& name, const std::string& value) OVERRIDE { |
412 install_attrs_[name] = value; | 424 install_attrs_[name] = value; |
413 return true; | 425 return true; |
414 } | 426 } |
415 | 427 |
416 int InstallAttributesCount() { | 428 virtual int InstallAttributesCount() OVERRIDE { |
417 return install_attrs_.size(); | 429 return install_attrs_.size(); |
418 } | 430 } |
419 | 431 |
420 bool InstallAttributesFinalize() { | 432 virtual bool InstallAttributesFinalize() OVERRIDE { |
421 locked_ = true; | 433 locked_ = true; |
422 return true; | 434 return true; |
423 } | 435 } |
424 | 436 |
425 bool InstallAttributesIsReady() { | 437 virtual bool InstallAttributesIsReady() OVERRIDE { |
426 return true; | 438 return true; |
427 } | 439 } |
428 | 440 |
429 bool InstallAttributesIsSecure() { | 441 virtual bool InstallAttributesIsSecure() OVERRIDE { |
430 return false; | 442 return false; |
431 } | 443 } |
432 | 444 |
433 bool InstallAttributesIsInvalid() { | 445 virtual bool InstallAttributesIsInvalid() OVERRIDE { |
434 return false; | 446 return false; |
435 } | 447 } |
436 | 448 |
437 bool InstallAttributesIsFirstInstall() { | 449 virtual bool InstallAttributesIsFirstInstall() OVERRIDE { |
438 return !locked_; | 450 return !locked_; |
439 } | 451 } |
440 | 452 |
441 void Pkcs11GetTpmTokenInfo(std::string* label, | 453 virtual void Pkcs11GetTpmTokenInfo(std::string* label, |
442 std::string* user_pin) { | 454 std::string* user_pin) OVERRIDE { |
443 *label = "Stub TPM Token"; | 455 *label = "Stub TPM Token"; |
444 *user_pin = "012345"; | 456 *user_pin = "012345"; |
445 } | 457 } |
446 | 458 |
447 bool Pkcs11IsTpmTokenReady() { return true; } | 459 virtual bool Pkcs11IsTpmTokenReady() OVERRIDE { return true; } |
448 | 460 |
449 private: | 461 private: |
450 static void DoStubCallback(Delegate* callback) { | 462 static void DoStubCallback(Delegate* callback) { |
451 if (callback) | 463 if (callback) |
452 callback->OnComplete(true, kCryptohomeMountErrorNone); | 464 callback->OnComplete(true, kCryptohomeMountErrorNone); |
453 } | 465 } |
454 | 466 |
455 std::map<std::string, std::string> install_attrs_; | 467 std::map<std::string, std::string> install_attrs_; |
456 bool locked_; | 468 bool locked_; |
457 DISALLOW_COPY_AND_ASSIGN(CryptohomeLibraryStubImpl); | 469 DISALLOW_COPY_AND_ASSIGN(CryptohomeLibraryStubImpl); |
458 }; | 470 }; |
459 | 471 |
460 CryptohomeLibrary::CryptohomeLibrary() {} | 472 CryptohomeLibrary::CryptohomeLibrary() {} |
461 CryptohomeLibrary::~CryptohomeLibrary() {} | 473 CryptohomeLibrary::~CryptohomeLibrary() {} |
462 | 474 |
463 // static | 475 // static |
464 CryptohomeLibrary* CryptohomeLibrary::GetImpl(bool stub) { | 476 CryptohomeLibrary* CryptohomeLibrary::GetImpl(bool stub) { |
| 477 CryptohomeLibrary* impl; |
465 if (stub) | 478 if (stub) |
466 return new CryptohomeLibraryStubImpl(); | 479 impl = new CryptohomeLibraryStubImpl(); |
467 else | 480 else |
468 return new CryptohomeLibraryImpl(); | 481 impl = new CryptohomeLibraryImpl(); |
| 482 impl->Init(); |
| 483 return impl; |
469 } | 484 } |
470 | 485 |
471 } // namespace chromeos | 486 } // namespace chromeos |
OLD | NEW |