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

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

Issue 26407002: Add support for the Pkcs11GetTpmTokenInfoForUser cryptohome call. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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/fake_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/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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 cryptohome::kCryptohomePkcs11GetTpmTokenInfo); 323 cryptohome::kCryptohomePkcs11GetTpmTokenInfo);
324 proxy_->CallMethod( 324 proxy_->CallMethod(
325 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 325 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
326 base::Bind( 326 base::Bind(
327 &CryptohomeClientImpl::OnPkcs11GetTpmTokenInfo, 327 &CryptohomeClientImpl::OnPkcs11GetTpmTokenInfo,
328 weak_ptr_factory_.GetWeakPtr(), 328 weak_ptr_factory_.GetWeakPtr(),
329 callback)); 329 callback));
330 } 330 }
331 331
332 // CryptohomeClient override. 332 // CryptohomeClient override.
333 virtual void Pkcs11GetTpmTokenInfoForUser(
334 const std::string& user_email,
335 const Pkcs11GetTpmTokenInfoCallback& callback) OVERRIDE {
336 dbus::MethodCall method_call(
337 cryptohome::kCryptohomeInterface,
338 cryptohome::kCryptohomePkcs11GetTpmTokenInfoForUser);
339 dbus::MessageWriter writer(&method_call);
340 writer.AppendString(user_email);
341 proxy_->CallMethod(
342 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
343 base::Bind(
344 &CryptohomeClientImpl::OnPkcs11GetTpmTokenInfoForUser,
345 weak_ptr_factory_.GetWeakPtr(),
346 callback));
347 }
348
349 // CryptohomeClient override.
333 virtual bool InstallAttributesGet(const std::string& name, 350 virtual bool InstallAttributesGet(const std::string& name,
334 std::vector<uint8>* value, 351 std::vector<uint8>* value,
335 bool* successful) OVERRIDE { 352 bool* successful) OVERRIDE {
336 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, 353 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface,
337 cryptohome::kCryptohomeInstallAttributesGet); 354 cryptohome::kCryptohomeInstallAttributesGet);
338 dbus::MessageWriter writer(&method_call); 355 dbus::MessageWriter writer(&method_call);
339 writer.AppendString(name); 356 writer.AppendString(name);
340 scoped_ptr<dbus::Response> response( 357 scoped_ptr<dbus::Response> response(
341 blocking_method_caller_->CallMethodAndBlock(&method_call)); 358 blocking_method_caller_->CallMethodAndBlock(&method_call));
342 if (!response.get()) 359 if (!response.get())
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 void OnBoolMethod(const BoolDBusMethodCallback& callback, 739 void OnBoolMethod(const BoolDBusMethodCallback& callback,
723 dbus::Response* response) { 740 dbus::Response* response) {
724 if (!response) { 741 if (!response) {
725 callback.Run(DBUS_METHOD_CALL_FAILURE, false); 742 callback.Run(DBUS_METHOD_CALL_FAILURE, false);
726 return; 743 return;
727 } 744 }
728 dbus::MessageReader reader(response); 745 dbus::MessageReader reader(response);
729 bool result = false; 746 bool result = false;
730 if (!reader.PopBool(&result)) { 747 if (!reader.PopBool(&result)) {
731 callback.Run(DBUS_METHOD_CALL_FAILURE, false); 748 callback.Run(DBUS_METHOD_CALL_FAILURE, false);
749 LOG(ERROR) << "Invalid response: " << response->ToString();
732 return; 750 return;
733 } 751 }
734 callback.Run(DBUS_METHOD_CALL_SUCCESS, result); 752 callback.Run(DBUS_METHOD_CALL_SUCCESS, result);
735 } 753 }
736 754
737 // Handles responses for methods with a string value result. 755 // Handles responses for methods with a string value result.
738 void OnStringMethod(const StringDBusMethodCallback& callback, 756 void OnStringMethod(const StringDBusMethodCallback& callback,
739 dbus::Response* response) { 757 dbus::Response* response) {
740 if (!response) { 758 if (!response) {
741 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string()); 759 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string());
(...skipping 21 matching lines...) Expand all
763 bool result = false; 781 bool result = false;
764 if (!reader.PopArrayOfBytes(&data_buffer, &data_length) || 782 if (!reader.PopArrayOfBytes(&data_buffer, &data_length) ||
765 !reader.PopBool(&result)) { 783 !reader.PopBool(&result)) {
766 callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string()); 784 callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string());
767 return; 785 return;
768 } 786 }
769 std::string data(reinterpret_cast<char*>(data_buffer), data_length); 787 std::string data(reinterpret_cast<char*>(data_buffer), data_length);
770 callback.Run(DBUS_METHOD_CALL_SUCCESS, result, data); 788 callback.Run(DBUS_METHOD_CALL_SUCCESS, result, data);
771 } 789 }
772 790
773 // Handles responses for Pkcs11GetTpmtTokenInfo. 791 // Handles responses for Pkcs11GetTpmTokenInfo.
774 void OnPkcs11GetTpmTokenInfo(const Pkcs11GetTpmTokenInfoCallback& callback, 792 void OnPkcs11GetTpmTokenInfo(const Pkcs11GetTpmTokenInfoCallback& callback,
775 dbus::Response* response) { 793 dbus::Response* response) {
776 if (!response) { 794 if (!response) {
777 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string(), std::string()); 795 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string(), std::string(), -1);
778 return; 796 return;
779 } 797 }
780 dbus::MessageReader reader(response); 798 dbus::MessageReader reader(response);
781 std::string label; 799 std::string label;
782 std::string user_pin; 800 std::string user_pin;
783 if (!reader.PopString(&label) || !reader.PopString(&user_pin)) { 801 if (!reader.PopString(&label) || !reader.PopString(&user_pin)) {
784 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string(), std::string()); 802 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string(), std::string(), -1);
803 LOG(ERROR) << "Invalid response: " << response->ToString();
785 return; 804 return;
786 } 805 }
787 callback.Run(DBUS_METHOD_CALL_SUCCESS, label, user_pin); 806 const int kDefaultSlot = 0;
807 callback.Run(DBUS_METHOD_CALL_SUCCESS, label, user_pin, kDefaultSlot);
808 }
809
810 // Handles responses for Pkcs11GetTpmTokenInfoForUser.
811 void OnPkcs11GetTpmTokenInfoForUser(
812 const Pkcs11GetTpmTokenInfoCallback& callback,
813 dbus::Response* response) {
814 if (!response) {
815 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string(), std::string(), -1);
816 return;
817 }
818 dbus::MessageReader reader(response);
819 std::string label;
820 std::string user_pin;
821 int slot = 0;
822 if (!reader.PopString(&label) || !reader.PopString(&user_pin) ||
823 !reader.PopInt32(&slot)) {
824 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string(), std::string(), -1);
825 LOG(ERROR) << "Invalid response: " << response->ToString();
826 return;
827 }
828 callback.Run(DBUS_METHOD_CALL_SUCCESS, label, user_pin, slot);
788 } 829 }
789 830
790 // Handles AsyncCallStatus signal. 831 // Handles AsyncCallStatus signal.
791 void OnAsyncCallStatus(dbus::Signal* signal) { 832 void OnAsyncCallStatus(dbus::Signal* signal) {
792 dbus::MessageReader reader(signal); 833 dbus::MessageReader reader(signal);
793 int async_id = 0; 834 int async_id = 0;
794 bool return_status = false; 835 bool return_status = false;
795 int return_code = 0; 836 int return_code = 0;
796 if (!reader.PopInt32(&async_id) || 837 if (!reader.PopInt32(&async_id) ||
797 !reader.PopBool(&return_status) || 838 !reader.PopBool(&return_status) ||
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 return new FakeCryptohomeClient(); 901 return new FakeCryptohomeClient();
861 } 902 }
862 903
863 // static 904 // static
864 std::string CryptohomeClient::GetStubSanitizedUsername( 905 std::string CryptohomeClient::GetStubSanitizedUsername(
865 const std::string& username) { 906 const std::string& username) {
866 return username + kUserIdStubHashSuffix; 907 return username + kUserIdStubHashSuffix;
867 } 908 }
868 909
869 } // namespace chromeos 910 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/cryptohome_client.h ('k') | chromeos/dbus/fake_cryptohome_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698