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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/hash_tables.h" | 9 #include "base/hash_tables.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 class CryptohomeLibraryImpl : public CryptohomeLibrary { | 24 class CryptohomeLibraryImpl : public CryptohomeLibrary { |
25 public: | 25 public: |
26 CryptohomeLibraryImpl() {} | 26 CryptohomeLibraryImpl() {} |
27 virtual ~CryptohomeLibraryImpl() {} | 27 virtual ~CryptohomeLibraryImpl() {} |
28 | 28 |
29 virtual void Init() OVERRIDE { | 29 virtual void Init() OVERRIDE { |
30 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 30 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
31 cryptohome_connection_ = chromeos::CryptohomeMonitorSession(&Handler, this); | 31 cryptohome_connection_ = chromeos::CryptohomeMonitorSession(&Handler, this); |
32 } | 32 } |
33 | 33 |
34 virtual bool CheckKey( | |
35 const std::string& user_email, const std::string& passhash) OVERRIDE { | |
36 return chromeos::CryptohomeCheckKey(user_email.c_str(), passhash.c_str()); | |
37 } | |
38 | |
39 virtual bool AsyncCheckKey(const std::string& user_email, | 34 virtual bool AsyncCheckKey(const std::string& user_email, |
40 const std::string& passhash, | 35 const std::string& passhash, |
41 Delegate* d) OVERRIDE { | 36 Delegate* d) OVERRIDE { |
42 return CacheCallback( | 37 return CacheCallback( |
43 chromeos::CryptohomeAsyncCheckKey(user_email.c_str(), passhash.c_str()), | 38 chromeos::CryptohomeAsyncCheckKey(user_email.c_str(), passhash.c_str()), |
44 d, | 39 d, |
45 "Couldn't initiate async check of user's key."); | 40 "Couldn't initiate async check of user's key."); |
46 } | 41 } |
47 | 42 |
48 virtual bool MigrateKey(const std::string& user_email, | |
49 const std::string& old_hash, | |
50 const std::string& new_hash) OVERRIDE { | |
51 return chromeos::CryptohomeMigrateKey(user_email.c_str(), | |
52 old_hash.c_str(), | |
53 new_hash.c_str()); | |
54 } | |
55 | |
56 virtual bool AsyncMigrateKey(const std::string& user_email, | 43 virtual bool AsyncMigrateKey(const std::string& user_email, |
57 const std::string& old_hash, | 44 const std::string& old_hash, |
58 const std::string& new_hash, | 45 const std::string& new_hash, |
59 Delegate* d) OVERRIDE { | 46 Delegate* d) OVERRIDE { |
60 return CacheCallback( | 47 return CacheCallback( |
61 chromeos::CryptohomeAsyncMigrateKey(user_email.c_str(), | 48 chromeos::CryptohomeAsyncMigrateKey(user_email.c_str(), |
62 old_hash.c_str(), | 49 old_hash.c_str(), |
63 new_hash.c_str()), | 50 new_hash.c_str()), |
64 d, | 51 d, |
65 "Couldn't initiate aync migration of user's key"); | 52 "Couldn't initiate aync migration of user's key"); |
66 } | 53 } |
67 | 54 |
68 virtual bool Mount(const std::string& user_email, | |
69 const std::string& passhash, | |
70 int* error_code) OVERRIDE { | |
71 return chromeos::CryptohomeMountAllowFail(user_email.c_str(), | |
72 passhash.c_str(), | |
73 error_code); | |
74 } | |
75 | |
76 virtual bool AsyncMount(const std::string& user_email, | 55 virtual bool AsyncMount(const std::string& user_email, |
77 const std::string& passhash, | 56 const std::string& passhash, |
78 const bool create_if_missing, | 57 const bool create_if_missing, |
79 Delegate* d) OVERRIDE { | 58 Delegate* d) OVERRIDE { |
80 return CacheCallback( | 59 return CacheCallback( |
81 chromeos::CryptohomeAsyncMountSafe(user_email.c_str(), | 60 chromeos::CryptohomeAsyncMountSafe(user_email.c_str(), |
82 passhash.c_str(), | 61 passhash.c_str(), |
83 create_if_missing, | 62 create_if_missing, |
84 false, | 63 false, |
85 NULL), | 64 NULL), |
86 d, | 65 d, |
87 "Couldn't initiate async mount of cryptohome."); | 66 "Couldn't initiate async mount of cryptohome."); |
88 } | 67 } |
89 | 68 |
90 virtual bool MountForBwsi(int* error_code) OVERRIDE { | |
91 return chromeos::CryptohomeMountGuest(error_code); | |
92 } | |
93 | |
94 virtual bool AsyncMountForBwsi(Delegate* d) OVERRIDE { | 69 virtual bool AsyncMountForBwsi(Delegate* d) OVERRIDE { |
95 return CacheCallback(chromeos::CryptohomeAsyncMountGuest(), | 70 return CacheCallback(chromeos::CryptohomeAsyncMountGuest(), |
96 d, | 71 d, |
97 "Couldn't initiate async mount of cryptohome."); | 72 "Couldn't initiate async mount of cryptohome."); |
98 } | 73 } |
99 | 74 |
100 virtual bool Unmount() OVERRIDE { | |
101 return chromeos::CryptohomeUnmount(); | |
102 } | |
103 | |
104 virtual bool Remove(const std::string& user_email) OVERRIDE { | |
105 return chromeos::CryptohomeRemove(user_email.c_str()); | |
106 } | |
107 | |
108 virtual bool AsyncRemove( | 75 virtual bool AsyncRemove( |
109 const std::string& user_email, Delegate* d) OVERRIDE { | 76 const std::string& user_email, Delegate* d) OVERRIDE { |
110 return CacheCallback( | 77 return CacheCallback( |
111 chromeos::CryptohomeAsyncRemove(user_email.c_str()), | 78 chromeos::CryptohomeAsyncRemove(user_email.c_str()), |
112 d, | 79 d, |
113 "Couldn't initiate async removal of cryptohome."); | 80 "Couldn't initiate async removal of cryptohome."); |
114 } | 81 } |
115 | 82 |
116 virtual bool IsMounted() OVERRIDE { | 83 virtual bool IsMounted() OVERRIDE { |
117 return chromeos::CryptohomeIsMounted(); | 84 return chromeos::CryptohomeIsMounted(); |
118 } | 85 } |
119 | 86 |
120 virtual CryptohomeBlob GetSystemSalt() OVERRIDE { | 87 virtual CryptohomeBlob GetSystemSalt() OVERRIDE { |
121 CryptohomeBlob system_salt; | 88 CryptohomeBlob system_salt; |
122 char* salt_buf; | 89 char* salt_buf; |
123 int salt_len; | 90 int salt_len; |
124 bool result = chromeos::CryptohomeGetSystemSaltSafe(&salt_buf, &salt_len); | 91 bool result = chromeos::CryptohomeGetSystemSaltSafe(&salt_buf, &salt_len); |
125 if (result) { | 92 if (result) { |
126 system_salt.resize(salt_len); | 93 system_salt.resize(salt_len); |
127 if ((int)system_salt.size() == salt_len) { | 94 if ((int)system_salt.size() == salt_len) { |
128 memcpy(&system_salt[0], static_cast<const void*>(salt_buf), | 95 memcpy(&system_salt[0], static_cast<const void*>(salt_buf), |
129 salt_len); | 96 salt_len); |
130 } else { | 97 } else { |
131 system_salt.clear(); | 98 system_salt.clear(); |
132 } | 99 } |
133 } | 100 } |
134 return system_salt; | 101 return system_salt; |
135 } | 102 } |
136 | 103 |
137 virtual bool AsyncDoAutomaticFreeDiskSpaceControl(Delegate* d) OVERRIDE { | |
138 return CacheCallback( | |
139 chromeos::CryptohomeAsyncDoAutomaticFreeDiskSpaceControl(), | |
140 d, | |
141 "Couldn't do automatic free disk space control."); | |
142 } | |
143 | |
144 virtual bool AsyncSetOwnerUser( | 104 virtual bool AsyncSetOwnerUser( |
145 const std::string& username, Delegate* d) OVERRIDE { | 105 const std::string& username, Delegate* d) OVERRIDE { |
146 return CacheCallback( | 106 return CacheCallback( |
147 chromeos::CryptohomeAsyncSetOwnerUser(username.c_str()), | 107 chromeos::CryptohomeAsyncSetOwnerUser(username.c_str()), |
148 d, | 108 d, |
149 "Couldn't do set owner user in Cryptohomed."); | 109 "Couldn't do set owner user in Cryptohomed."); |
150 } | 110 } |
151 | 111 |
152 virtual bool TpmIsReady() OVERRIDE { | 112 virtual bool TpmIsReady() OVERRIDE { |
153 return chromeos::CryptohomeTpmIsReady(); | 113 return chromeos::CryptohomeTpmIsReady(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } | 152 } |
193 return done; | 153 return done; |
194 } | 154 } |
195 | 155 |
196 virtual bool InstallAttributesSet( | 156 virtual bool InstallAttributesSet( |
197 const std::string& name, const std::string& value) OVERRIDE { | 157 const std::string& name, const std::string& value) OVERRIDE { |
198 return chromeos::CryptohomeInstallAttributesSet(name.c_str(), | 158 return chromeos::CryptohomeInstallAttributesSet(name.c_str(), |
199 value.c_str()); | 159 value.c_str()); |
200 } | 160 } |
201 | 161 |
202 virtual int InstallAttributesCount() OVERRIDE { | |
203 return chromeos::CryptohomeInstallAttributesCount(); | |
204 } | |
205 | |
206 virtual bool InstallAttributesFinalize() OVERRIDE { | 162 virtual bool InstallAttributesFinalize() OVERRIDE { |
207 return chromeos::CryptohomeInstallAttributesFinalize(); | 163 return chromeos::CryptohomeInstallAttributesFinalize(); |
208 } | 164 } |
209 | 165 |
210 virtual bool InstallAttributesIsReady() OVERRIDE { | 166 virtual bool InstallAttributesIsReady() OVERRIDE { |
211 return chromeos::CryptohomeInstallAttributesIsReady(); | 167 return chromeos::CryptohomeInstallAttributesIsReady(); |
212 } | 168 } |
213 | 169 |
214 virtual bool InstallAttributesIsSecure() OVERRIDE { | |
215 return chromeos::CryptohomeInstallAttributesIsSecure(); | |
216 } | |
217 | |
218 virtual bool InstallAttributesIsInvalid() OVERRIDE { | 170 virtual bool InstallAttributesIsInvalid() OVERRIDE { |
219 return chromeos::CryptohomeInstallAttributesIsInvalid(); | 171 return chromeos::CryptohomeInstallAttributesIsInvalid(); |
220 } | 172 } |
221 | 173 |
222 virtual bool InstallAttributesIsFirstInstall() OVERRIDE { | 174 virtual bool InstallAttributesIsFirstInstall() OVERRIDE { |
223 return chromeos::CryptohomeInstallAttributesIsFirstInstall(); | 175 return chromeos::CryptohomeInstallAttributesIsFirstInstall(); |
224 } | 176 } |
225 | 177 |
226 virtual void Pkcs11GetTpmTokenInfo( | 178 virtual void Pkcs11GetTpmTokenInfo( |
227 std::string* label, std::string* user_pin) OVERRIDE { | 179 std::string* label, std::string* user_pin) OVERRIDE { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 }; | 222 }; |
271 | 223 |
272 class CryptohomeLibraryStubImpl : public CryptohomeLibrary { | 224 class CryptohomeLibraryStubImpl : public CryptohomeLibrary { |
273 public: | 225 public: |
274 CryptohomeLibraryStubImpl() | 226 CryptohomeLibraryStubImpl() |
275 : locked_(false) {} | 227 : locked_(false) {} |
276 virtual ~CryptohomeLibraryStubImpl() {} | 228 virtual ~CryptohomeLibraryStubImpl() {} |
277 | 229 |
278 virtual void Init() OVERRIDE {} | 230 virtual void Init() OVERRIDE {} |
279 | 231 |
280 virtual bool CheckKey( | |
281 const std::string& user_email, const std::string& passhash) OVERRIDE { | |
282 return true; | |
283 } | |
284 | |
285 virtual bool AsyncCheckKey(const std::string& user_email, | 232 virtual bool AsyncCheckKey(const std::string& user_email, |
286 const std::string& passhash, | 233 const std::string& passhash, |
287 Delegate* callback) OVERRIDE { | 234 Delegate* callback) OVERRIDE { |
288 BrowserThread::PostTask( | 235 BrowserThread::PostTask( |
289 BrowserThread::UI, FROM_HERE, | 236 BrowserThread::UI, FROM_HERE, |
290 base::Bind(&DoStubCallback, callback)); | 237 base::Bind(&DoStubCallback, callback)); |
291 return true; | 238 return true; |
292 } | 239 } |
293 | 240 |
294 virtual bool MigrateKey(const std::string& user_email, | |
295 const std::string& old_hash, | |
296 const std::string& new_hash) OVERRIDE { | |
297 return true; | |
298 } | |
299 | |
300 virtual bool AsyncMigrateKey(const std::string& user_email, | 241 virtual bool AsyncMigrateKey(const std::string& user_email, |
301 const std::string& old_hash, | 242 const std::string& old_hash, |
302 const std::string& new_hash, | 243 const std::string& new_hash, |
303 Delegate* callback) OVERRIDE { | 244 Delegate* callback) OVERRIDE { |
304 BrowserThread::PostTask( | 245 BrowserThread::PostTask( |
305 BrowserThread::UI, FROM_HERE, | 246 BrowserThread::UI, FROM_HERE, |
306 base::Bind(&DoStubCallback, callback)); | 247 base::Bind(&DoStubCallback, callback)); |
307 return true; | 248 return true; |
308 } | 249 } |
309 | 250 |
310 virtual bool Mount(const std::string& user_email, | |
311 const std::string& passhash, | |
312 int* error_code) OVERRIDE { | |
313 // For testing password change. | |
314 if (user_email == | |
315 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
316 switches::kLoginUserWithNewPassword)) { | |
317 *error_code = kCryptohomeMountErrorKeyFailure; | |
318 return false; | |
319 } | |
320 | |
321 return true; | |
322 } | |
323 | |
324 virtual bool AsyncMount(const std::string& user_email, | 251 virtual bool AsyncMount(const std::string& user_email, |
325 const std::string& passhash, | 252 const std::string& passhash, |
326 const bool create_if_missing, | 253 const bool create_if_missing, |
327 Delegate* callback) OVERRIDE { | 254 Delegate* callback) OVERRIDE { |
328 BrowserThread::PostTask( | 255 BrowserThread::PostTask( |
329 BrowserThread::UI, FROM_HERE, | 256 BrowserThread::UI, FROM_HERE, |
330 base::Bind(&DoStubCallback, callback)); | 257 base::Bind(&DoStubCallback, callback)); |
331 return true; | 258 return true; |
332 } | 259 } |
333 | 260 |
334 virtual bool MountForBwsi(int* error_code) OVERRIDE { | |
335 return true; | |
336 } | |
337 | |
338 virtual bool AsyncMountForBwsi(Delegate* callback) OVERRIDE { | 261 virtual bool AsyncMountForBwsi(Delegate* callback) OVERRIDE { |
339 BrowserThread::PostTask( | 262 BrowserThread::PostTask( |
340 BrowserThread::UI, FROM_HERE, | 263 BrowserThread::UI, FROM_HERE, |
341 base::Bind(&DoStubCallback, callback)); | 264 base::Bind(&DoStubCallback, callback)); |
342 return true; | 265 return true; |
343 } | 266 } |
344 | 267 |
345 virtual bool Unmount() OVERRIDE { | |
346 return true; | |
347 } | |
348 | |
349 virtual bool Remove(const std::string& user_email) OVERRIDE { | |
350 return true; | |
351 } | |
352 | |
353 virtual bool AsyncRemove( | 268 virtual bool AsyncRemove( |
354 const std::string& user_email, Delegate* callback) OVERRIDE { | 269 const std::string& user_email, Delegate* callback) OVERRIDE { |
355 BrowserThread::PostTask( | 270 BrowserThread::PostTask( |
356 BrowserThread::UI, FROM_HERE, | 271 BrowserThread::UI, FROM_HERE, |
357 base::Bind(&DoStubCallback, callback)); | 272 base::Bind(&DoStubCallback, callback)); |
358 return true; | 273 return true; |
359 } | 274 } |
360 | 275 |
361 virtual bool IsMounted() OVERRIDE { | 276 virtual bool IsMounted() OVERRIDE { |
362 return true; | 277 return true; |
363 } | 278 } |
364 | 279 |
365 virtual CryptohomeBlob GetSystemSalt() OVERRIDE { | 280 virtual CryptohomeBlob GetSystemSalt() OVERRIDE { |
366 CryptohomeBlob salt = CryptohomeBlob(); | 281 CryptohomeBlob salt = CryptohomeBlob(); |
367 for (size_t i = 0; i < strlen(kStubSystemSalt); i++) | 282 for (size_t i = 0; i < strlen(kStubSystemSalt); i++) |
368 salt.push_back(static_cast<unsigned char>(kStubSystemSalt[i])); | 283 salt.push_back(static_cast<unsigned char>(kStubSystemSalt[i])); |
369 | 284 |
370 return salt; | 285 return salt; |
371 } | 286 } |
372 | 287 |
373 virtual bool AsyncDoAutomaticFreeDiskSpaceControl( | |
374 Delegate* callback) OVERRIDE { | |
375 BrowserThread::PostTask( | |
376 BrowserThread::UI, FROM_HERE, | |
377 base::Bind(&DoStubCallback, callback)); | |
378 return true; | |
379 } | |
380 | |
381 virtual bool AsyncSetOwnerUser( | 288 virtual bool AsyncSetOwnerUser( |
382 const std::string& username, Delegate* callback) OVERRIDE { | 289 const std::string& username, Delegate* callback) OVERRIDE { |
383 BrowserThread::PostTask( | 290 BrowserThread::PostTask( |
384 BrowserThread::UI, FROM_HERE, | 291 BrowserThread::UI, FROM_HERE, |
385 base::Bind(&DoStubCallback, callback)); | 292 base::Bind(&DoStubCallback, callback)); |
386 return true; | 293 return true; |
387 } | 294 } |
388 | 295 |
389 // Tpm begin ready after 20-th call. | 296 // Tpm begin ready after 20-th call. |
390 virtual bool TpmIsReady() OVERRIDE { | 297 virtual bool TpmIsReady() OVERRIDE { |
(...skipping 30 matching lines...) Expand all Loading... |
421 } | 328 } |
422 return false; | 329 return false; |
423 } | 330 } |
424 | 331 |
425 virtual bool InstallAttributesSet( | 332 virtual bool InstallAttributesSet( |
426 const std::string& name, const std::string& value) OVERRIDE { | 333 const std::string& name, const std::string& value) OVERRIDE { |
427 install_attrs_[name] = value; | 334 install_attrs_[name] = value; |
428 return true; | 335 return true; |
429 } | 336 } |
430 | 337 |
431 virtual int InstallAttributesCount() OVERRIDE { | |
432 return install_attrs_.size(); | |
433 } | |
434 | |
435 virtual bool InstallAttributesFinalize() OVERRIDE { | 338 virtual bool InstallAttributesFinalize() OVERRIDE { |
436 locked_ = true; | 339 locked_ = true; |
437 return true; | 340 return true; |
438 } | 341 } |
439 | 342 |
440 virtual bool InstallAttributesIsReady() OVERRIDE { | 343 virtual bool InstallAttributesIsReady() OVERRIDE { |
441 return true; | 344 return true; |
442 } | 345 } |
443 | 346 |
444 virtual bool InstallAttributesIsSecure() OVERRIDE { | |
445 return false; | |
446 } | |
447 | |
448 virtual bool InstallAttributesIsInvalid() OVERRIDE { | 347 virtual bool InstallAttributesIsInvalid() OVERRIDE { |
449 return false; | 348 return false; |
450 } | 349 } |
451 | 350 |
452 virtual bool InstallAttributesIsFirstInstall() OVERRIDE { | 351 virtual bool InstallAttributesIsFirstInstall() OVERRIDE { |
453 return !locked_; | 352 return !locked_; |
454 } | 353 } |
455 | 354 |
456 virtual void Pkcs11GetTpmTokenInfo(std::string* label, | 355 virtual void Pkcs11GetTpmTokenInfo(std::string* label, |
457 std::string* user_pin) OVERRIDE { | 356 std::string* user_pin) OVERRIDE { |
(...skipping 22 matching lines...) Expand all Loading... |
480 CryptohomeLibrary* impl; | 379 CryptohomeLibrary* impl; |
481 if (stub) | 380 if (stub) |
482 impl = new CryptohomeLibraryStubImpl(); | 381 impl = new CryptohomeLibraryStubImpl(); |
483 else | 382 else |
484 impl = new CryptohomeLibraryImpl(); | 383 impl = new CryptohomeLibraryImpl(); |
485 impl->Init(); | 384 impl->Init(); |
486 return impl; | 385 return impl; |
487 } | 386 } |
488 | 387 |
489 } // namespace chromeos | 388 } // namespace chromeos |
OLD | NEW |