| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/cryptohome_client.h" | 5 #include "chromeos/dbus/cryptohome_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 pca_response.size()); | 457 pca_response.size()); |
| 458 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 458 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 459 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, | 459 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, |
| 460 weak_ptr_factory_.GetWeakPtr(), | 460 weak_ptr_factory_.GetWeakPtr(), |
| 461 callback)); | 461 callback)); |
| 462 } | 462 } |
| 463 | 463 |
| 464 // CryptohomeClient override. | 464 // CryptohomeClient override. |
| 465 virtual void AsyncTpmAttestationCreateCertRequest( | 465 virtual void AsyncTpmAttestationCreateCertRequest( |
| 466 attestation::AttestationCertificateProfile certificate_profile, | 466 attestation::AttestationCertificateProfile certificate_profile, |
| 467 const std::string& user_email, | 467 const std::string& user_id, |
| 468 const std::string& request_origin, | 468 const std::string& request_origin, |
| 469 const AsyncMethodCallback& callback) OVERRIDE { | 469 const AsyncMethodCallback& callback) OVERRIDE { |
| 470 dbus::MethodCall method_call( | 470 dbus::MethodCall method_call( |
| 471 cryptohome::kCryptohomeInterface, | 471 cryptohome::kCryptohomeInterface, |
| 472 cryptohome::kCryptohomeAsyncTpmAttestationCreateCertRequestByProfile); | 472 cryptohome::kCryptohomeAsyncTpmAttestationCreateCertRequestByProfile); |
| 473 dbus::MessageWriter writer(&method_call); | 473 dbus::MessageWriter writer(&method_call); |
| 474 writer.AppendInt32(certificate_profile); | 474 writer.AppendInt32(certificate_profile); |
| 475 writer.AppendString(user_email); | 475 writer.AppendString(user_id); |
| 476 writer.AppendString(request_origin); | 476 writer.AppendString(request_origin); |
| 477 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 477 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 478 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, | 478 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, |
| 479 weak_ptr_factory_.GetWeakPtr(), | 479 weak_ptr_factory_.GetWeakPtr(), |
| 480 callback)); | 480 callback)); |
| 481 } | 481 } |
| 482 | 482 |
| 483 // CryptohomeClient override. | 483 // CryptohomeClient override. |
| 484 virtual void AsyncTpmAttestationFinishCertRequest( | 484 virtual void AsyncTpmAttestationFinishCertRequest( |
| 485 const std::string& pca_response, | 485 const std::string& pca_response, |
| 486 attestation::AttestationKeyType key_type, | 486 attestation::AttestationKeyType key_type, |
| 487 const std::string& user_id, |
| 487 const std::string& key_name, | 488 const std::string& key_name, |
| 488 const AsyncMethodCallback& callback) OVERRIDE { | 489 const AsyncMethodCallback& callback) OVERRIDE { |
| 489 dbus::MethodCall method_call( | 490 dbus::MethodCall method_call( |
| 490 cryptohome::kCryptohomeInterface, | 491 cryptohome::kCryptohomeInterface, |
| 491 cryptohome::kCryptohomeAsyncTpmAttestationFinishCertRequestOld); | 492 cryptohome::kCryptohomeAsyncTpmAttestationFinishCertRequest); |
| 492 dbus::MessageWriter writer(&method_call); | 493 dbus::MessageWriter writer(&method_call); |
| 493 writer.AppendArrayOfBytes( | 494 writer.AppendArrayOfBytes( |
| 494 reinterpret_cast<const uint8*>(pca_response.data()), | 495 reinterpret_cast<const uint8*>(pca_response.data()), |
| 495 pca_response.size()); | 496 pca_response.size()); |
| 496 bool is_user_specific = (key_type == attestation::KEY_USER); | 497 bool is_user_specific = (key_type == attestation::KEY_USER); |
| 497 writer.AppendBool(is_user_specific); | 498 writer.AppendBool(is_user_specific); |
| 499 writer.AppendString(user_id); |
| 498 writer.AppendString(key_name); | 500 writer.AppendString(key_name); |
| 499 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 501 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 500 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, | 502 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, |
| 501 weak_ptr_factory_.GetWeakPtr(), | 503 weak_ptr_factory_.GetWeakPtr(), |
| 502 callback)); | 504 callback)); |
| 503 } | 505 } |
| 504 | 506 |
| 505 // CryptohomeClient override. | 507 // CryptohomeClient override. |
| 506 virtual void TpmAttestationDoesKeyExist( | 508 virtual void TpmAttestationDoesKeyExist( |
| 507 attestation::AttestationKeyType key_type, | 509 attestation::AttestationKeyType key_type, |
| 510 const std::string& user_id, |
| 508 const std::string& key_name, | 511 const std::string& key_name, |
| 509 const BoolDBusMethodCallback& callback) OVERRIDE { | 512 const BoolDBusMethodCallback& callback) OVERRIDE { |
| 510 dbus::MethodCall method_call( | 513 dbus::MethodCall method_call( |
| 511 cryptohome::kCryptohomeInterface, | 514 cryptohome::kCryptohomeInterface, |
| 512 cryptohome::kCryptohomeTpmAttestationDoesKeyExistOld); | 515 cryptohome::kCryptohomeTpmAttestationDoesKeyExist); |
| 513 dbus::MessageWriter writer(&method_call); | 516 dbus::MessageWriter writer(&method_call); |
| 514 bool is_user_specific = (key_type == attestation::KEY_USER); | 517 bool is_user_specific = (key_type == attestation::KEY_USER); |
| 515 writer.AppendBool(is_user_specific); | 518 writer.AppendBool(is_user_specific); |
| 519 writer.AppendString(user_id); |
| 516 writer.AppendString(key_name); | 520 writer.AppendString(key_name); |
| 517 CallBoolMethod(&method_call, callback); | 521 CallBoolMethod(&method_call, callback); |
| 518 } | 522 } |
| 519 | 523 |
| 520 // CryptohomeClient override. | 524 // CryptohomeClient override. |
| 521 virtual void TpmAttestationGetCertificate( | 525 virtual void TpmAttestationGetCertificate( |
| 522 attestation::AttestationKeyType key_type, | 526 attestation::AttestationKeyType key_type, |
| 527 const std::string& user_id, |
| 523 const std::string& key_name, | 528 const std::string& key_name, |
| 524 const DataMethodCallback& callback) OVERRIDE { | 529 const DataMethodCallback& callback) OVERRIDE { |
| 525 dbus::MethodCall method_call( | 530 dbus::MethodCall method_call( |
| 526 cryptohome::kCryptohomeInterface, | 531 cryptohome::kCryptohomeInterface, |
| 527 cryptohome::kCryptohomeTpmAttestationGetCertificateOld); | 532 cryptohome::kCryptohomeTpmAttestationGetCertificate); |
| 528 dbus::MessageWriter writer(&method_call); | 533 dbus::MessageWriter writer(&method_call); |
| 529 bool is_user_specific = (key_type == attestation::KEY_USER); | 534 bool is_user_specific = (key_type == attestation::KEY_USER); |
| 530 writer.AppendBool(is_user_specific); | 535 writer.AppendBool(is_user_specific); |
| 536 writer.AppendString(user_id); |
| 531 writer.AppendString(key_name); | 537 writer.AppendString(key_name); |
| 532 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 538 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 533 base::Bind(&CryptohomeClientImpl::OnDataMethod, | 539 base::Bind(&CryptohomeClientImpl::OnDataMethod, |
| 534 weak_ptr_factory_.GetWeakPtr(), | 540 weak_ptr_factory_.GetWeakPtr(), |
| 535 callback)); | 541 callback)); |
| 536 } | 542 } |
| 537 | 543 |
| 538 // CryptohomeClient override. | 544 // CryptohomeClient override. |
| 539 virtual void TpmAttestationGetPublicKey( | 545 virtual void TpmAttestationGetPublicKey( |
| 540 attestation::AttestationKeyType key_type, | 546 attestation::AttestationKeyType key_type, |
| 547 const std::string& user_id, |
| 541 const std::string& key_name, | 548 const std::string& key_name, |
| 542 const DataMethodCallback& callback) OVERRIDE { | 549 const DataMethodCallback& callback) OVERRIDE { |
| 543 dbus::MethodCall method_call( | 550 dbus::MethodCall method_call( |
| 544 cryptohome::kCryptohomeInterface, | 551 cryptohome::kCryptohomeInterface, |
| 545 cryptohome::kCryptohomeTpmAttestationGetPublicKeyOld); | 552 cryptohome::kCryptohomeTpmAttestationGetPublicKey); |
| 546 dbus::MessageWriter writer(&method_call); | 553 dbus::MessageWriter writer(&method_call); |
| 547 bool is_user_specific = (key_type == attestation::KEY_USER); | 554 bool is_user_specific = (key_type == attestation::KEY_USER); |
| 548 writer.AppendBool(is_user_specific); | 555 writer.AppendBool(is_user_specific); |
| 556 writer.AppendString(user_id); |
| 549 writer.AppendString(key_name); | 557 writer.AppendString(key_name); |
| 550 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 558 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 551 base::Bind(&CryptohomeClientImpl::OnDataMethod, | 559 base::Bind(&CryptohomeClientImpl::OnDataMethod, |
| 552 weak_ptr_factory_.GetWeakPtr(), | 560 weak_ptr_factory_.GetWeakPtr(), |
| 553 callback)); | 561 callback)); |
| 554 } | 562 } |
| 555 | 563 |
| 556 // CryptohomeClient override. | 564 // CryptohomeClient override. |
| 557 virtual void TpmAttestationRegisterKey( | 565 virtual void TpmAttestationRegisterKey( |
| 558 attestation::AttestationKeyType key_type, | 566 attestation::AttestationKeyType key_type, |
| 567 const std::string& user_id, |
| 559 const std::string& key_name, | 568 const std::string& key_name, |
| 560 const AsyncMethodCallback& callback) OVERRIDE { | 569 const AsyncMethodCallback& callback) OVERRIDE { |
| 561 dbus::MethodCall method_call( | 570 dbus::MethodCall method_call( |
| 562 cryptohome::kCryptohomeInterface, | 571 cryptohome::kCryptohomeInterface, |
| 563 cryptohome::kCryptohomeTpmAttestationRegisterKeyOld); | 572 cryptohome::kCryptohomeTpmAttestationRegisterKey); |
| 564 dbus::MessageWriter writer(&method_call); | 573 dbus::MessageWriter writer(&method_call); |
| 565 bool is_user_specific = (key_type == attestation::KEY_USER); | 574 bool is_user_specific = (key_type == attestation::KEY_USER); |
| 566 writer.AppendBool(is_user_specific); | 575 writer.AppendBool(is_user_specific); |
| 576 writer.AppendString(user_id); |
| 567 writer.AppendString(key_name); | 577 writer.AppendString(key_name); |
| 568 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 578 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 569 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, | 579 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, |
| 570 weak_ptr_factory_.GetWeakPtr(), | 580 weak_ptr_factory_.GetWeakPtr(), |
| 571 callback)); | 581 callback)); |
| 572 } | 582 } |
| 573 | 583 |
| 574 // CryptohomeClient override. | 584 // CryptohomeClient override. |
| 575 virtual void TpmAttestationSignEnterpriseChallenge( | 585 virtual void TpmAttestationSignEnterpriseChallenge( |
| 576 attestation::AttestationKeyType key_type, | 586 attestation::AttestationKeyType key_type, |
| 587 const std::string& user_id, |
| 577 const std::string& key_name, | 588 const std::string& key_name, |
| 578 const std::string& domain, | 589 const std::string& domain, |
| 579 const std::string& device_id, | 590 const std::string& device_id, |
| 580 attestation::AttestationChallengeOptions options, | 591 attestation::AttestationChallengeOptions options, |
| 581 const std::string& challenge, | 592 const std::string& challenge, |
| 582 const AsyncMethodCallback& callback) OVERRIDE { | 593 const AsyncMethodCallback& callback) OVERRIDE { |
| 583 dbus::MethodCall method_call( | 594 dbus::MethodCall method_call( |
| 584 cryptohome::kCryptohomeInterface, | 595 cryptohome::kCryptohomeInterface, |
| 585 cryptohome::kCryptohomeTpmAttestationSignEnterpriseChallengeOld); | 596 cryptohome::kCryptohomeTpmAttestationSignEnterpriseChallenge); |
| 586 dbus::MessageWriter writer(&method_call); | 597 dbus::MessageWriter writer(&method_call); |
| 587 bool is_user_specific = (key_type == attestation::KEY_USER); | 598 bool is_user_specific = (key_type == attestation::KEY_USER); |
| 588 writer.AppendBool(is_user_specific); | 599 writer.AppendBool(is_user_specific); |
| 600 writer.AppendString(user_id); |
| 589 writer.AppendString(key_name); | 601 writer.AppendString(key_name); |
| 590 writer.AppendString(domain); | 602 writer.AppendString(domain); |
| 591 writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(device_id.data()), | 603 writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(device_id.data()), |
| 592 device_id.size()); | 604 device_id.size()); |
| 593 bool include_signed_public_key = | 605 bool include_signed_public_key = |
| 594 (options & attestation::CHALLENGE_INCLUDE_SIGNED_PUBLIC_KEY); | 606 (options & attestation::CHALLENGE_INCLUDE_SIGNED_PUBLIC_KEY); |
| 595 writer.AppendBool(include_signed_public_key); | 607 writer.AppendBool(include_signed_public_key); |
| 596 writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(challenge.data()), | 608 writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(challenge.data()), |
| 597 challenge.size()); | 609 challenge.size()); |
| 598 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 610 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 599 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, | 611 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, |
| 600 weak_ptr_factory_.GetWeakPtr(), | 612 weak_ptr_factory_.GetWeakPtr(), |
| 601 callback)); | 613 callback)); |
| 602 } | 614 } |
| 603 | 615 |
| 604 // CryptohomeClient override. | 616 // CryptohomeClient override. |
| 605 virtual void TpmAttestationSignSimpleChallenge( | 617 virtual void TpmAttestationSignSimpleChallenge( |
| 606 attestation::AttestationKeyType key_type, | 618 attestation::AttestationKeyType key_type, |
| 619 const std::string& user_id, |
| 607 const std::string& key_name, | 620 const std::string& key_name, |
| 608 const std::string& challenge, | 621 const std::string& challenge, |
| 609 const AsyncMethodCallback& callback) OVERRIDE { | 622 const AsyncMethodCallback& callback) OVERRIDE { |
| 610 dbus::MethodCall method_call( | 623 dbus::MethodCall method_call( |
| 611 cryptohome::kCryptohomeInterface, | 624 cryptohome::kCryptohomeInterface, |
| 612 cryptohome::kCryptohomeTpmAttestationSignSimpleChallengeOld); | 625 cryptohome::kCryptohomeTpmAttestationSignSimpleChallenge); |
| 613 dbus::MessageWriter writer(&method_call); | 626 dbus::MessageWriter writer(&method_call); |
| 614 bool is_user_specific = (key_type == attestation::KEY_USER); | 627 bool is_user_specific = (key_type == attestation::KEY_USER); |
| 615 writer.AppendBool(is_user_specific); | 628 writer.AppendBool(is_user_specific); |
| 629 writer.AppendString(user_id); |
| 616 writer.AppendString(key_name); | 630 writer.AppendString(key_name); |
| 617 writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(challenge.data()), | 631 writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(challenge.data()), |
| 618 challenge.size()); | 632 challenge.size()); |
| 619 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 633 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 620 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, | 634 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, |
| 621 weak_ptr_factory_.GetWeakPtr(), | 635 weak_ptr_factory_.GetWeakPtr(), |
| 622 callback)); | 636 callback)); |
| 623 } | 637 } |
| 624 | 638 |
| 625 // CryptohomeClient override. | 639 // CryptohomeClient override. |
| 626 virtual void TpmAttestationGetKeyPayload( | 640 virtual void TpmAttestationGetKeyPayload( |
| 627 attestation::AttestationKeyType key_type, | 641 attestation::AttestationKeyType key_type, |
| 642 const std::string& user_id, |
| 628 const std::string& key_name, | 643 const std::string& key_name, |
| 629 const DataMethodCallback& callback) OVERRIDE { | 644 const DataMethodCallback& callback) OVERRIDE { |
| 630 dbus::MethodCall method_call( | 645 dbus::MethodCall method_call( |
| 631 cryptohome::kCryptohomeInterface, | 646 cryptohome::kCryptohomeInterface, |
| 632 cryptohome::kCryptohomeTpmAttestationGetKeyPayloadOld); | 647 cryptohome::kCryptohomeTpmAttestationGetKeyPayload); |
| 633 dbus::MessageWriter writer(&method_call); | 648 dbus::MessageWriter writer(&method_call); |
| 634 bool is_user_specific = (key_type == attestation::KEY_USER); | 649 bool is_user_specific = (key_type == attestation::KEY_USER); |
| 635 writer.AppendBool(is_user_specific); | 650 writer.AppendBool(is_user_specific); |
| 651 writer.AppendString(user_id); |
| 636 writer.AppendString(key_name); | 652 writer.AppendString(key_name); |
| 637 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 653 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 638 base::Bind(&CryptohomeClientImpl::OnDataMethod, | 654 base::Bind(&CryptohomeClientImpl::OnDataMethod, |
| 639 weak_ptr_factory_.GetWeakPtr(), | 655 weak_ptr_factory_.GetWeakPtr(), |
| 640 callback)); | 656 callback)); |
| 641 } | 657 } |
| 642 | 658 |
| 643 // CryptohomeClient override. | 659 // CryptohomeClient override. |
| 644 virtual void TpmAttestationSetKeyPayload( | 660 virtual void TpmAttestationSetKeyPayload( |
| 645 attestation::AttestationKeyType key_type, | 661 attestation::AttestationKeyType key_type, |
| 662 const std::string& user_id, |
| 646 const std::string& key_name, | 663 const std::string& key_name, |
| 647 const std::string& payload, | 664 const std::string& payload, |
| 648 const BoolDBusMethodCallback& callback) OVERRIDE { | 665 const BoolDBusMethodCallback& callback) OVERRIDE { |
| 649 dbus::MethodCall method_call( | 666 dbus::MethodCall method_call( |
| 650 cryptohome::kCryptohomeInterface, | 667 cryptohome::kCryptohomeInterface, |
| 651 cryptohome::kCryptohomeTpmAttestationSetKeyPayloadOld); | 668 cryptohome::kCryptohomeTpmAttestationSetKeyPayload); |
| 652 dbus::MessageWriter writer(&method_call); | 669 dbus::MessageWriter writer(&method_call); |
| 653 bool is_user_specific = (key_type == attestation::KEY_USER); | 670 bool is_user_specific = (key_type == attestation::KEY_USER); |
| 654 writer.AppendBool(is_user_specific); | 671 writer.AppendBool(is_user_specific); |
| 672 writer.AppendString(user_id); |
| 655 writer.AppendString(key_name); | 673 writer.AppendString(key_name); |
| 656 writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(payload.data()), | 674 writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(payload.data()), |
| 657 payload.size()); | 675 payload.size()); |
| 658 CallBoolMethod(&method_call, callback); | 676 CallBoolMethod(&method_call, callback); |
| 659 } | 677 } |
| 660 | 678 |
| 661 protected: | 679 protected: |
| 662 virtual void Init(dbus::Bus* bus) OVERRIDE { | 680 virtual void Init(dbus::Bus* bus) OVERRIDE { |
| 663 proxy_ = bus->GetObjectProxy( | 681 proxy_ = bus->GetObjectProxy( |
| 664 cryptohome::kCryptohomeServiceName, | 682 cryptohome::kCryptohomeServiceName, |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 return new FakeCryptohomeClient(); | 919 return new FakeCryptohomeClient(); |
| 902 } | 920 } |
| 903 | 921 |
| 904 // static | 922 // static |
| 905 std::string CryptohomeClient::GetStubSanitizedUsername( | 923 std::string CryptohomeClient::GetStubSanitizedUsername( |
| 906 const std::string& username) { | 924 const std::string& username) { |
| 907 return username + kUserIdStubHashSuffix; | 925 return username + kUserIdStubHashSuffix; |
| 908 } | 926 } |
| 909 | 927 |
| 910 } // namespace chromeos | 928 } // namespace chromeos |
| OLD | NEW |