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