Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: chromeos/dbus/cryptohome_client.cc

Issue 13818032: Added dbus bindings for new cryptohomed attestation APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chromeos/dbus/cryptohome_client.h ('k') | chromeos/dbus/mock_cryptohome_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/message_loop.h" 8 #include "base/message_loop.h"
9 #include "chromeos/cryptohome/async_method_caller.h" 9 #include "chromeos/cryptohome/async_method_caller.h"
10 #include "chromeos/dbus/blocking_method_caller.h" 10 #include "chromeos/dbus/blocking_method_caller.h"
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 const std::string& challenge, 523 const std::string& challenge,
524 const AsyncMethodCallback& callback) OVERRIDE { 524 const AsyncMethodCallback& callback) OVERRIDE {
525 dbus::MethodCall method_call( 525 dbus::MethodCall method_call(
526 cryptohome::kCryptohomeInterface, 526 cryptohome::kCryptohomeInterface,
527 cryptohome::kCryptohomeTpmAttestationSignEnterpriseChallenge); 527 cryptohome::kCryptohomeTpmAttestationSignEnterpriseChallenge);
528 dbus::MessageWriter writer(&method_call); 528 dbus::MessageWriter writer(&method_call);
529 bool is_user_specific = (key_type == USER_KEY); 529 bool is_user_specific = (key_type == USER_KEY);
530 writer.AppendBool(is_user_specific); 530 writer.AppendBool(is_user_specific);
531 writer.AppendString(key_name); 531 writer.AppendString(key_name);
532 writer.AppendString(domain); 532 writer.AppendString(domain);
533 writer.AppendString(device_id); 533 writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(device_id.data()),
534 device_id.size());
534 bool include_signed_public_key = (options & INCLUDE_SIGNED_PUBLIC_KEY); 535 bool include_signed_public_key = (options & INCLUDE_SIGNED_PUBLIC_KEY);
535 writer.AppendBool(include_signed_public_key); 536 writer.AppendBool(include_signed_public_key);
536 writer.AppendString(challenge); 537 writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(challenge.data()),
538 challenge.size());
537 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 539 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
538 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, 540 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall,
539 weak_ptr_factory_.GetWeakPtr(), 541 weak_ptr_factory_.GetWeakPtr(),
540 callback)); 542 callback));
541 } 543 }
542 544
543 // CryptohomeClient override. 545 // CryptohomeClient override.
544 virtual void TpmAttestationSignSimpleChallenge( 546 virtual void TpmAttestationSignSimpleChallenge(
545 AttestationKeyType key_type, 547 AttestationKeyType key_type,
546 const std::string& key_name, 548 const std::string& key_name,
547 const std::string& challenge, 549 const std::string& challenge,
548 const AsyncMethodCallback& callback) OVERRIDE { 550 const AsyncMethodCallback& callback) OVERRIDE {
549 dbus::MethodCall method_call( 551 dbus::MethodCall method_call(
550 cryptohome::kCryptohomeInterface, 552 cryptohome::kCryptohomeInterface,
551 cryptohome::kCryptohomeTpmAttestationSignEnterpriseChallenge); 553 cryptohome::kCryptohomeTpmAttestationSignEnterpriseChallenge);
552 dbus::MessageWriter writer(&method_call); 554 dbus::MessageWriter writer(&method_call);
553 bool is_user_specific = (key_type == USER_KEY); 555 bool is_user_specific = (key_type == USER_KEY);
554 writer.AppendBool(is_user_specific); 556 writer.AppendBool(is_user_specific);
555 writer.AppendString(key_name); 557 writer.AppendString(key_name);
556 writer.AppendString(challenge); 558 writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(challenge.data()),
559 challenge.size());
557 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 560 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
558 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, 561 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall,
559 weak_ptr_factory_.GetWeakPtr(), 562 weak_ptr_factory_.GetWeakPtr(),
560 callback)); 563 callback));
561 } 564 }
562 565
566 // CryptohomeClient override.
567 virtual void TpmAttestationGetKeyPayload(
568 AttestationKeyType key_type,
569 const std::string& key_name,
570 const DataMethodCallback& callback) OVERRIDE {
571 dbus::MethodCall method_call(
572 cryptohome::kCryptohomeInterface,
573 cryptohome::kCryptohomeTpmAttestationGetKeyPayload);
574 dbus::MessageWriter writer(&method_call);
575 bool is_user_specific = (key_type == USER_KEY);
576 writer.AppendBool(is_user_specific);
577 writer.AppendString(key_name);
578 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
579 base::Bind(&CryptohomeClientImpl::OnDataMethod,
580 weak_ptr_factory_.GetWeakPtr(),
581 callback));
582 }
583
584 // CryptohomeClient override.
585 virtual void TpmAttestationSetKeyPayload(
586 AttestationKeyType key_type,
587 const std::string& key_name,
588 const std::string& payload,
589 const BoolDBusMethodCallback& callback) OVERRIDE {
590 dbus::MethodCall method_call(
591 cryptohome::kCryptohomeInterface,
592 cryptohome::kCryptohomeTpmAttestationSetKeyPayload);
593 dbus::MessageWriter writer(&method_call);
594 bool is_user_specific = (key_type == USER_KEY);
595 writer.AppendBool(is_user_specific);
596 writer.AppendString(key_name);
597 writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(payload.data()),
598 payload.size());
599 CallBoolMethod(&method_call, callback);
600 }
601
563 private: 602 private:
564 // Handles the result of AsyncXXX methods. 603 // Handles the result of AsyncXXX methods.
565 void OnAsyncMethodCall(const AsyncMethodCallback& callback, 604 void OnAsyncMethodCall(const AsyncMethodCallback& callback,
566 dbus::Response* response) { 605 dbus::Response* response) {
567 if (!response) 606 if (!response)
568 return; 607 return;
569 dbus::MessageReader reader(response); 608 dbus::MessageReader reader(response);
570 int async_id = 0; 609 int async_id = 0;
571 if (!reader.PopInt32(&async_id)) { 610 if (!reader.PopInt32(&async_id)) {
572 LOG(ERROR) << "Invalid response: " << response->ToString(); 611 LOG(ERROR) << "Invalid response: " << response->ToString();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 } 686 }
648 687
649 // Handles responses for methods with a bool result and data. 688 // Handles responses for methods with a bool result and data.
650 void OnDataMethod(const DataMethodCallback& callback, 689 void OnDataMethod(const DataMethodCallback& callback,
651 dbus::Response* response) { 690 dbus::Response* response) {
652 if (!response) { 691 if (!response) {
653 callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string()); 692 callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string());
654 return; 693 return;
655 } 694 }
656 dbus::MessageReader reader(response); 695 dbus::MessageReader reader(response);
696 uint8* data_buffer = NULL;
697 size_t data_length = 0;
657 bool result = false; 698 bool result = false;
658 if (!reader.PopBool(&result)) { 699 if (!reader.PopArrayOfBytes(&data_buffer, &data_length) ||
700 !reader.PopBool(&result)) {
659 callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string()); 701 callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string());
660 return; 702 return;
661 } 703 }
662 std::string data; 704 std::string data(reinterpret_cast<char*>(data_buffer), data_length);
663 if (!reader.PopString(&data)) {
664 callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string());
665 return;
666 }
667 callback.Run(DBUS_METHOD_CALL_SUCCESS, result, data); 705 callback.Run(DBUS_METHOD_CALL_SUCCESS, result, data);
668 } 706 }
669 707
670 // Handles responses for Pkcs11GetTpmtTokenInfo. 708 // Handles responses for Pkcs11GetTpmtTokenInfo.
671 void OnPkcs11GetTpmTokenInfo(const Pkcs11GetTpmTokenInfoCallback& callback, 709 void OnPkcs11GetTpmTokenInfo(const Pkcs11GetTpmTokenInfoCallback& callback,
672 dbus::Response* response) { 710 dbus::Response* response) {
673 if (!response) { 711 if (!response) {
674 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string(), std::string()); 712 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string(), std::string());
675 return; 713 return;
676 } 714 }
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 1101
1064 // CryptohomeClient override. 1102 // CryptohomeClient override.
1065 virtual void TpmAttestationSignSimpleChallenge( 1103 virtual void TpmAttestationSignSimpleChallenge(
1066 AttestationKeyType key_type, 1104 AttestationKeyType key_type,
1067 const std::string& key_name, 1105 const std::string& key_name,
1068 const std::string& challenge, 1106 const std::string& challenge,
1069 const AsyncMethodCallback& callback) OVERRIDE { 1107 const AsyncMethodCallback& callback) OVERRIDE {
1070 ReturnAsyncMethodResult(callback, true); 1108 ReturnAsyncMethodResult(callback, true);
1071 } 1109 }
1072 1110
1111 virtual void TpmAttestationGetKeyPayload(
1112 AttestationKeyType key_type,
1113 const std::string& key_name,
1114 const DataMethodCallback& callback) OVERRIDE {
1115 MessageLoop::current()->PostTask(
1116 FROM_HERE,
1117 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string()));
1118 }
1119
1120 virtual void TpmAttestationSetKeyPayload(
1121 AttestationKeyType key_type,
1122 const std::string& key_name,
1123 const std::string& payload,
1124 const BoolDBusMethodCallback& callback) OVERRIDE {
1125 MessageLoop::current()->PostTask(
1126 FROM_HERE,
1127 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false));
1128 }
1129
1130
1073 private: 1131 private:
1074 // Posts tasks which return fake results to the UI thread. 1132 // Posts tasks which return fake results to the UI thread.
1075 void ReturnAsyncMethodResult(const AsyncMethodCallback& callback, 1133 void ReturnAsyncMethodResult(const AsyncMethodCallback& callback,
1076 bool returns_data) { 1134 bool returns_data) {
1077 MessageLoop::current()->PostTask( 1135 MessageLoop::current()->PostTask(
1078 FROM_HERE, 1136 FROM_HERE,
1079 base::Bind(&CryptohomeClientStubImpl::ReturnAsyncMethodResultInternal, 1137 base::Bind(&CryptohomeClientStubImpl::ReturnAsyncMethodResultInternal,
1080 weak_ptr_factory_.GetWeakPtr(), 1138 weak_ptr_factory_.GetWeakPtr(),
1081 callback, 1139 callback,
1082 returns_data)); 1140 returns_data));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 // static 1185 // static
1128 CryptohomeClient* CryptohomeClient::Create(DBusClientImplementationType type, 1186 CryptohomeClient* CryptohomeClient::Create(DBusClientImplementationType type,
1129 dbus::Bus* bus) { 1187 dbus::Bus* bus) {
1130 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 1188 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
1131 return new CryptohomeClientImpl(bus); 1189 return new CryptohomeClientImpl(bus);
1132 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); 1190 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
1133 return new CryptohomeClientStubImpl(); 1191 return new CryptohomeClientStubImpl();
1134 } 1192 }
1135 1193
1136 } // namespace chromeos 1194 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/cryptohome_client.h ('k') | chromeos/dbus/mock_cryptohome_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698