OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/dbus/fake_cryptohome_client.h" | 5 #include "chromeos/dbus/fake_cryptohome_client.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
17 #include "chromeos/chromeos_paths.h" | 17 #include "chromeos/chromeos_paths.h" |
| 18 #include "chromeos/cryptohome/attestation.pb.h" |
18 #include "chromeos/dbus/cryptohome/key.pb.h" | 19 #include "chromeos/dbus/cryptohome/key.pb.h" |
19 #include "chromeos/dbus/cryptohome/rpc.pb.h" | 20 #include "chromeos/dbus/cryptohome/rpc.pb.h" |
20 #include "third_party/cros_system_api/dbus/service_constants.h" | 21 #include "third_party/cros_system_api/dbus/service_constants.h" |
21 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h" | 22 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h" |
22 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream.h" | 23 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream.h" |
23 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite
.h" | 24 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite
.h" |
24 | 25 |
25 namespace chromeos { | 26 namespace chromeos { |
26 | 27 |
| 28 // Signature nonces are twenty bytes. This matches the attestation code. |
| 29 const std::string FakeCryptohomeClient::kTwentyBytesNonce{ |
| 30 "+addtwentybytesnonce"}; |
| 31 const std::string FakeCryptohomeClient::kSignature{"signed"}; |
| 32 |
27 FakeCryptohomeClient::FakeCryptohomeClient() | 33 FakeCryptohomeClient::FakeCryptohomeClient() |
28 : service_is_available_(true), | 34 : service_is_available_(true), |
29 async_call_id_(1), | 35 async_call_id_(1), |
30 unmount_result_(true), | 36 unmount_result_(true), |
31 system_salt_(GetStubSystemSalt()), | 37 system_salt_(GetStubSystemSalt()), |
32 weak_ptr_factory_(this) { | 38 weak_ptr_factory_(this) { |
33 base::FilePath cache_path; | 39 base::FilePath cache_path; |
34 locked_ = PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, &cache_path) && | 40 locked_ = PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, &cache_path) && |
35 base::PathExists(cache_path); | 41 base::PathExists(cache_path); |
36 } | 42 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 79 |
74 bool FakeCryptohomeClient::Unmount(bool* success) { | 80 bool FakeCryptohomeClient::Unmount(bool* success) { |
75 *success = unmount_result_; | 81 *success = unmount_result_; |
76 return true; | 82 return true; |
77 } | 83 } |
78 | 84 |
79 void FakeCryptohomeClient::AsyncCheckKey( | 85 void FakeCryptohomeClient::AsyncCheckKey( |
80 const cryptohome::Identification& cryptohome_id, | 86 const cryptohome::Identification& cryptohome_id, |
81 const std::string& key, | 87 const std::string& key, |
82 const AsyncMethodCallback& callback) { | 88 const AsyncMethodCallback& callback) { |
83 ReturnAsyncMethodResult(callback, false); | 89 ReturnAsyncMethodResult(callback); |
84 } | 90 } |
85 | 91 |
86 void FakeCryptohomeClient::AsyncMigrateKey( | 92 void FakeCryptohomeClient::AsyncMigrateKey( |
87 const cryptohome::Identification& cryptohome_id, | 93 const cryptohome::Identification& cryptohome_id, |
88 const std::string& from_key, | 94 const std::string& from_key, |
89 const std::string& to_key, | 95 const std::string& to_key, |
90 const AsyncMethodCallback& callback) { | 96 const AsyncMethodCallback& callback) { |
91 ReturnAsyncMethodResult(callback, false); | 97 ReturnAsyncMethodResult(callback); |
92 } | 98 } |
93 | 99 |
94 void FakeCryptohomeClient::AsyncRemove( | 100 void FakeCryptohomeClient::AsyncRemove( |
95 const cryptohome::Identification& cryptohome_id, | 101 const cryptohome::Identification& cryptohome_id, |
96 const AsyncMethodCallback& callback) { | 102 const AsyncMethodCallback& callback) { |
97 ReturnAsyncMethodResult(callback, false); | 103 ReturnAsyncMethodResult(callback); |
98 } | 104 } |
99 | 105 |
100 void FakeCryptohomeClient::RenameCryptohome( | 106 void FakeCryptohomeClient::RenameCryptohome( |
101 const cryptohome::Identification& cryptohome_id_from, | 107 const cryptohome::Identification& cryptohome_id_from, |
102 const cryptohome::Identification& cryptohome_id_to, | 108 const cryptohome::Identification& cryptohome_id_to, |
103 const ProtobufMethodCallback& callback) { | 109 const ProtobufMethodCallback& callback) { |
104 cryptohome::BaseReply reply; | 110 cryptohome::BaseReply reply; |
105 ReturnProtobufMethodCallback(reply, callback); | 111 ReturnProtobufMethodCallback(reply, callback); |
106 } | 112 } |
107 | 113 |
(...skipping 28 matching lines...) Expand all Loading... |
136 std::string FakeCryptohomeClient::BlockingGetSanitizedUsername( | 142 std::string FakeCryptohomeClient::BlockingGetSanitizedUsername( |
137 const cryptohome::Identification& cryptohome_id) { | 143 const cryptohome::Identification& cryptohome_id) { |
138 return GetStubSanitizedUsername(cryptohome_id); | 144 return GetStubSanitizedUsername(cryptohome_id); |
139 } | 145 } |
140 | 146 |
141 void FakeCryptohomeClient::AsyncMount( | 147 void FakeCryptohomeClient::AsyncMount( |
142 const cryptohome::Identification& cryptohome_id, | 148 const cryptohome::Identification& cryptohome_id, |
143 const std::string& key, | 149 const std::string& key, |
144 int flags, | 150 int flags, |
145 const AsyncMethodCallback& callback) { | 151 const AsyncMethodCallback& callback) { |
146 ReturnAsyncMethodResult(callback, false); | 152 ReturnAsyncMethodResult(callback); |
147 } | 153 } |
148 | 154 |
149 void FakeCryptohomeClient::AsyncAddKey( | 155 void FakeCryptohomeClient::AsyncAddKey( |
150 const cryptohome::Identification& cryptohome_id, | 156 const cryptohome::Identification& cryptohome_id, |
151 const std::string& key, | 157 const std::string& key, |
152 const std::string& new_key, | 158 const std::string& new_key, |
153 const AsyncMethodCallback& callback) { | 159 const AsyncMethodCallback& callback) { |
154 ReturnAsyncMethodResult(callback, false); | 160 ReturnAsyncMethodResult(callback); |
155 } | 161 } |
156 | 162 |
157 void FakeCryptohomeClient::AsyncMountGuest( | 163 void FakeCryptohomeClient::AsyncMountGuest( |
158 const AsyncMethodCallback& callback) { | 164 const AsyncMethodCallback& callback) { |
159 ReturnAsyncMethodResult(callback, false); | 165 ReturnAsyncMethodResult(callback); |
160 } | 166 } |
161 | 167 |
162 void FakeCryptohomeClient::AsyncMountPublic( | 168 void FakeCryptohomeClient::AsyncMountPublic( |
163 const cryptohome::Identification& public_mount_id, | 169 const cryptohome::Identification& public_mount_id, |
164 int flags, | 170 int flags, |
165 const AsyncMethodCallback& callback) { | 171 const AsyncMethodCallback& callback) { |
166 ReturnAsyncMethodResult(callback, false); | 172 ReturnAsyncMethodResult(callback); |
167 } | 173 } |
168 | 174 |
169 void FakeCryptohomeClient::TpmIsReady( | 175 void FakeCryptohomeClient::TpmIsReady( |
170 const BoolDBusMethodCallback& callback) { | 176 const BoolDBusMethodCallback& callback) { |
171 base::ThreadTaskRunnerHandle::Get()->PostTask( | 177 base::ThreadTaskRunnerHandle::Get()->PostTask( |
172 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); | 178 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); |
173 } | 179 } |
174 | 180 |
175 void FakeCryptohomeClient::TpmIsEnabled( | 181 void FakeCryptohomeClient::TpmIsEnabled( |
176 const BoolDBusMethodCallback& callback) { | 182 const BoolDBusMethodCallback& callback) { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 | 365 |
360 void FakeCryptohomeClient::TpmAttestationIsEnrolled( | 366 void FakeCryptohomeClient::TpmAttestationIsEnrolled( |
361 const BoolDBusMethodCallback& callback) { | 367 const BoolDBusMethodCallback& callback) { |
362 base::ThreadTaskRunnerHandle::Get()->PostTask( | 368 base::ThreadTaskRunnerHandle::Get()->PostTask( |
363 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); | 369 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); |
364 } | 370 } |
365 | 371 |
366 void FakeCryptohomeClient::AsyncTpmAttestationCreateEnrollRequest( | 372 void FakeCryptohomeClient::AsyncTpmAttestationCreateEnrollRequest( |
367 chromeos::attestation::PrivacyCAType pca_type, | 373 chromeos::attestation::PrivacyCAType pca_type, |
368 const AsyncMethodCallback& callback) { | 374 const AsyncMethodCallback& callback) { |
369 ReturnAsyncMethodResult(callback, true); | 375 ReturnAsyncMethodData(callback, std::string()); |
370 } | 376 } |
371 | 377 |
372 void FakeCryptohomeClient::AsyncTpmAttestationEnroll( | 378 void FakeCryptohomeClient::AsyncTpmAttestationEnroll( |
373 chromeos::attestation::PrivacyCAType pca_type, | 379 chromeos::attestation::PrivacyCAType pca_type, |
374 const std::string& pca_response, | 380 const std::string& pca_response, |
375 const AsyncMethodCallback& callback) { | 381 const AsyncMethodCallback& callback) { |
376 ReturnAsyncMethodResult(callback, false); | 382 ReturnAsyncMethodResult(callback); |
377 } | 383 } |
378 | 384 |
379 void FakeCryptohomeClient::AsyncTpmAttestationCreateCertRequest( | 385 void FakeCryptohomeClient::AsyncTpmAttestationCreateCertRequest( |
380 chromeos::attestation::PrivacyCAType pca_type, | 386 chromeos::attestation::PrivacyCAType pca_type, |
381 attestation::AttestationCertificateProfile certificate_profile, | 387 attestation::AttestationCertificateProfile certificate_profile, |
382 const cryptohome::Identification& cryptohome_id, | 388 const cryptohome::Identification& cryptohome_id, |
383 const std::string& request_origin, | 389 const std::string& request_origin, |
384 const AsyncMethodCallback& callback) { | 390 const AsyncMethodCallback& callback) { |
385 ReturnAsyncMethodResult(callback, true); | 391 ReturnAsyncMethodData(callback, std::string()); |
386 } | 392 } |
387 | 393 |
388 void FakeCryptohomeClient::AsyncTpmAttestationFinishCertRequest( | 394 void FakeCryptohomeClient::AsyncTpmAttestationFinishCertRequest( |
389 const std::string& pca_response, | 395 const std::string& pca_response, |
390 attestation::AttestationKeyType key_type, | 396 attestation::AttestationKeyType key_type, |
391 const cryptohome::Identification& cryptohome_id, | 397 const cryptohome::Identification& cryptohome_id, |
392 const std::string& key_name, | 398 const std::string& key_name, |
393 const AsyncMethodCallback& callback) { | 399 const AsyncMethodCallback& callback) { |
394 ReturnAsyncMethodResult(callback, true); | 400 ReturnAsyncMethodData(callback, std::string()); |
395 } | 401 } |
396 | 402 |
397 void FakeCryptohomeClient::TpmAttestationDoesKeyExist( | 403 void FakeCryptohomeClient::TpmAttestationDoesKeyExist( |
398 attestation::AttestationKeyType key_type, | 404 attestation::AttestationKeyType key_type, |
399 const cryptohome::Identification& cryptohome_id, | 405 const cryptohome::Identification& cryptohome_id, |
400 const std::string& key_name, | 406 const std::string& key_name, |
401 const BoolDBusMethodCallback& callback) { | 407 const BoolDBusMethodCallback& callback) { |
402 base::ThreadTaskRunnerHandle::Get()->PostTask( | 408 base::ThreadTaskRunnerHandle::Get()->PostTask( |
403 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); | 409 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); |
404 } | 410 } |
(...skipping 16 matching lines...) Expand all Loading... |
421 base::ThreadTaskRunnerHandle::Get()->PostTask( | 427 base::ThreadTaskRunnerHandle::Get()->PostTask( |
422 FROM_HERE, | 428 FROM_HERE, |
423 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string())); | 429 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string())); |
424 } | 430 } |
425 | 431 |
426 void FakeCryptohomeClient::TpmAttestationRegisterKey( | 432 void FakeCryptohomeClient::TpmAttestationRegisterKey( |
427 attestation::AttestationKeyType key_type, | 433 attestation::AttestationKeyType key_type, |
428 const cryptohome::Identification& cryptohome_id, | 434 const cryptohome::Identification& cryptohome_id, |
429 const std::string& key_name, | 435 const std::string& key_name, |
430 const AsyncMethodCallback& callback) { | 436 const AsyncMethodCallback& callback) { |
431 ReturnAsyncMethodResult(callback, true); | 437 ReturnAsyncMethodData(callback, std::string()); |
432 } | 438 } |
433 | 439 |
434 void FakeCryptohomeClient::TpmAttestationSignEnterpriseChallenge( | 440 void FakeCryptohomeClient::TpmAttestationSignEnterpriseChallenge( |
435 attestation::AttestationKeyType key_type, | 441 attestation::AttestationKeyType key_type, |
436 const cryptohome::Identification& cryptohome_id, | 442 const cryptohome::Identification& cryptohome_id, |
437 const std::string& key_name, | 443 const std::string& key_name, |
438 const std::string& domain, | 444 const std::string& domain, |
439 const std::string& device_id, | 445 const std::string& device_id, |
440 attestation::AttestationChallengeOptions options, | 446 attestation::AttestationChallengeOptions options, |
441 const std::string& challenge, | 447 const std::string& challenge, |
442 const AsyncMethodCallback& callback) { | 448 const AsyncMethodCallback& callback) { |
443 ReturnAsyncMethodResult(callback, true); | 449 ReturnAsyncMethodData(callback, std::string()); |
444 } | 450 } |
445 | 451 |
446 void FakeCryptohomeClient::TpmAttestationSignSimpleChallenge( | 452 void FakeCryptohomeClient::TpmAttestationSignSimpleChallenge( |
447 attestation::AttestationKeyType key_type, | 453 attestation::AttestationKeyType key_type, |
448 const cryptohome::Identification& cryptohome_id, | 454 const cryptohome::Identification& cryptohome_id, |
449 const std::string& key_name, | 455 const std::string& key_name, |
450 const std::string& challenge, | 456 const std::string& challenge, |
451 const AsyncMethodCallback& callback) { | 457 const AsyncMethodCallback& callback) { |
452 ReturnAsyncMethodResult(callback, true); | 458 cryptohome::SignedData signed_data; |
| 459 signed_data.set_data(challenge + kTwentyBytesNonce); |
| 460 signed_data.set_signature(kSignature); |
| 461 ReturnAsyncMethodData(callback, signed_data.SerializeAsString()); |
453 } | 462 } |
454 | 463 |
455 void FakeCryptohomeClient::TpmAttestationGetKeyPayload( | 464 void FakeCryptohomeClient::TpmAttestationGetKeyPayload( |
456 attestation::AttestationKeyType key_type, | 465 attestation::AttestationKeyType key_type, |
457 const cryptohome::Identification& cryptohome_id, | 466 const cryptohome::Identification& cryptohome_id, |
458 const std::string& key_name, | 467 const std::string& key_name, |
459 const DataMethodCallback& callback) { | 468 const DataMethodCallback& callback) { |
460 base::ThreadTaskRunnerHandle::Get()->PostTask( | 469 base::ThreadTaskRunnerHandle::Get()->PostTask( |
461 FROM_HERE, | 470 FROM_HERE, |
462 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string())); | 471 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string())); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 } | 590 } |
582 | 591 |
583 void FakeCryptohomeClient::ReturnProtobufMethodCallback( | 592 void FakeCryptohomeClient::ReturnProtobufMethodCallback( |
584 const cryptohome::BaseReply& reply, | 593 const cryptohome::BaseReply& reply, |
585 const ProtobufMethodCallback& callback) { | 594 const ProtobufMethodCallback& callback) { |
586 base::ThreadTaskRunnerHandle::Get()->PostTask( | 595 base::ThreadTaskRunnerHandle::Get()->PostTask( |
587 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true, reply)); | 596 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true, reply)); |
588 } | 597 } |
589 | 598 |
590 void FakeCryptohomeClient::ReturnAsyncMethodResult( | 599 void FakeCryptohomeClient::ReturnAsyncMethodResult( |
591 const AsyncMethodCallback& callback, | 600 const AsyncMethodCallback& callback) { |
592 bool returns_data) { | |
593 base::ThreadTaskRunnerHandle::Get()->PostTask( | 601 base::ThreadTaskRunnerHandle::Get()->PostTask( |
594 FROM_HERE, | 602 FROM_HERE, |
595 base::Bind(&FakeCryptohomeClient::ReturnAsyncMethodResultInternal, | 603 base::Bind(&FakeCryptohomeClient::ReturnAsyncMethodResultInternal, |
596 weak_ptr_factory_.GetWeakPtr(), callback, returns_data)); | 604 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 605 } |
| 606 |
| 607 void FakeCryptohomeClient::ReturnAsyncMethodData( |
| 608 const AsyncMethodCallback& callback, |
| 609 const std::string& data) { |
| 610 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 611 FROM_HERE, |
| 612 base::Bind(&FakeCryptohomeClient::ReturnAsyncMethodDataInternal, |
| 613 weak_ptr_factory_.GetWeakPtr(), callback, data)); |
597 } | 614 } |
598 | 615 |
599 void FakeCryptohomeClient::ReturnAsyncMethodResultInternal( | 616 void FakeCryptohomeClient::ReturnAsyncMethodResultInternal( |
600 const AsyncMethodCallback& callback, | 617 const AsyncMethodCallback& callback) { |
601 bool returns_data) { | |
602 callback.Run(async_call_id_); | 618 callback.Run(async_call_id_); |
603 if (!returns_data && !async_call_status_handler_.is_null()) { | 619 if (!async_call_status_handler_.is_null()) { |
604 base::ThreadTaskRunnerHandle::Get()->PostTask( | 620 base::ThreadTaskRunnerHandle::Get()->PostTask( |
605 FROM_HERE, base::Bind(async_call_status_handler_, async_call_id_, true, | 621 FROM_HERE, base::Bind(async_call_status_handler_, async_call_id_, true, |
606 cryptohome::MOUNT_ERROR_NONE)); | 622 cryptohome::MOUNT_ERROR_NONE)); |
607 } else if (returns_data && !async_call_status_data_handler_.is_null()) { | |
608 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
609 FROM_HERE, base::Bind(async_call_status_data_handler_, async_call_id_, | |
610 true, std::string())); | |
611 } | 623 } |
612 ++async_call_id_; | 624 ++async_call_id_; |
613 } | 625 } |
| 626 |
| 627 void FakeCryptohomeClient::ReturnAsyncMethodDataInternal( |
| 628 const AsyncMethodCallback& callback, |
| 629 const std::string& data) { |
| 630 callback.Run(async_call_id_); |
| 631 if (!async_call_status_data_handler_.is_null()) { |
| 632 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 633 FROM_HERE, base::Bind(async_call_status_data_handler_, async_call_id_, |
| 634 true, data)); |
| 635 } |
| 636 ++async_call_id_; |
| 637 } |
614 | 638 |
615 } // namespace chromeos | 639 } // namespace chromeos |
OLD | NEW |