Chromium Code Reviews| 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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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& username, | |
| 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(username); | |
| 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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 return; | 784 return; |
| 768 } | 785 } |
| 769 std::string data(reinterpret_cast<char*>(data_buffer), data_length); | 786 std::string data(reinterpret_cast<char*>(data_buffer), data_length); |
| 770 callback.Run(DBUS_METHOD_CALL_SUCCESS, result, data); | 787 callback.Run(DBUS_METHOD_CALL_SUCCESS, result, data); |
| 771 } | 788 } |
| 772 | 789 |
| 773 // Handles responses for Pkcs11GetTpmtTokenInfo. | 790 // Handles responses for Pkcs11GetTpmtTokenInfo. |
| 774 void OnPkcs11GetTpmTokenInfo(const Pkcs11GetTpmTokenInfoCallback& callback, | 791 void OnPkcs11GetTpmTokenInfo(const Pkcs11GetTpmTokenInfoCallback& callback, |
| 775 dbus::Response* response) { | 792 dbus::Response* response) { |
| 776 if (!response) { | 793 if (!response) { |
| 777 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string(), std::string()); | 794 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string(), std::string(), -1); |
| 778 return; | 795 return; |
| 779 } | 796 } |
| 780 dbus::MessageReader reader(response); | 797 dbus::MessageReader reader(response); |
| 781 std::string label; | 798 std::string label; |
| 782 std::string user_pin; | 799 std::string user_pin; |
| 783 if (!reader.PopString(&label) || !reader.PopString(&user_pin)) { | 800 if (!reader.PopString(&label) || !reader.PopString(&user_pin)) { |
| 784 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string(), std::string()); | 801 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string(), std::string(), -1); |
| 785 return; | 802 return; |
| 786 } | 803 } |
| 787 callback.Run(DBUS_METHOD_CALL_SUCCESS, label, user_pin); | 804 const int kDefaultSlot = 0; |
| 805 callback.Run(DBUS_METHOD_CALL_SUCCESS, label, user_pin, kDefaultSlot); | |
| 806 } | |
| 807 | |
| 808 void OnPkcs11GetTpmTokenInfoForUser( | |
| 809 const Pkcs11GetTpmTokenInfoCallback& callback, | |
| 810 dbus::Response* response) { | |
| 811 if (!response) { | |
| 812 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string(), std::string(), -1); | |
| 813 return; | |
| 814 } | |
| 815 dbus::MessageReader reader(response); | |
| 816 std::string label; | |
| 817 std::string user_pin; | |
| 818 int slot = 0; | |
| 819 if (!reader.PopString(&label) || !reader.PopString(&user_pin) || | |
| 820 !reader.PopInt32(&slot)) { | |
|
satorux1
2013/10/08 04:29:33
might want to add:
LOG(ERROR) << "Invalid respo
Darren Krahn
2013/10/08 17:06:41
Done. Some responses may be sensitive but I added
| |
| 821 callback.Run(DBUS_METHOD_CALL_FAILURE, std::string(), std::string(), -1); | |
| 822 return; | |
| 823 } | |
| 824 callback.Run(DBUS_METHOD_CALL_SUCCESS, label, user_pin, slot); | |
| 788 } | 825 } |
| 789 | 826 |
| 790 // Handles AsyncCallStatus signal. | 827 // Handles AsyncCallStatus signal. |
| 791 void OnAsyncCallStatus(dbus::Signal* signal) { | 828 void OnAsyncCallStatus(dbus::Signal* signal) { |
| 792 dbus::MessageReader reader(signal); | 829 dbus::MessageReader reader(signal); |
| 793 int async_id = 0; | 830 int async_id = 0; |
| 794 bool return_status = false; | 831 bool return_status = false; |
| 795 int return_code = 0; | 832 int return_code = 0; |
| 796 if (!reader.PopInt32(&async_id) || | 833 if (!reader.PopInt32(&async_id) || |
| 797 !reader.PopBool(&return_status) || | 834 !reader.PopBool(&return_status) || |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 860 return new FakeCryptohomeClient(); | 897 return new FakeCryptohomeClient(); |
| 861 } | 898 } |
| 862 | 899 |
| 863 // static | 900 // static |
| 864 std::string CryptohomeClient::GetStubSanitizedUsername( | 901 std::string CryptohomeClient::GetStubSanitizedUsername( |
| 865 const std::string& username) { | 902 const std::string& username) { |
| 866 return username + kUserIdStubHashSuffix; | 903 return username + kUserIdStubHashSuffix; |
| 867 } | 904 } |
| 868 | 905 |
| 869 } // namespace chromeos | 906 } // namespace chromeos |
| OLD | NEW |