| 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 <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" |
| (...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 | 876 |
| 877 proxy_->CallMethod(&method_call, | 877 proxy_->CallMethod(&method_call, |
| 878 kTpmDBusTimeoutMs , | 878 kTpmDBusTimeoutMs , |
| 879 base::Bind(&CryptohomeClientImpl::OnBaseReplyMethod, | 879 base::Bind(&CryptohomeClientImpl::OnBaseReplyMethod, |
| 880 weak_ptr_factory_.GetWeakPtr(), | 880 weak_ptr_factory_.GetWeakPtr(), |
| 881 callback)); | 881 callback)); |
| 882 } | 882 } |
| 883 | 883 |
| 884 void GetBootAttribute(const cryptohome::GetBootAttributeRequest& request, | 884 void GetBootAttribute(const cryptohome::GetBootAttributeRequest& request, |
| 885 const ProtobufMethodCallback& callback) override { | 885 const ProtobufMethodCallback& callback) override { |
| 886 const char* method_name = cryptohome::kCryptohomeGetBootAttribute; | 886 CallCryptohomeMethod(cryptohome::kCryptohomeGetBootAttribute, request, |
| 887 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, method_name); | 887 callback); |
| 888 | |
| 889 dbus::MessageWriter writer(&method_call); | |
| 890 writer.AppendProtoAsArrayOfBytes(request); | |
| 891 | |
| 892 proxy_->CallMethod(&method_call, | |
| 893 kTpmDBusTimeoutMs , | |
| 894 base::Bind(&CryptohomeClientImpl::OnBaseReplyMethod, | |
| 895 weak_ptr_factory_.GetWeakPtr(), | |
| 896 callback)); | |
| 897 } | 888 } |
| 898 | 889 |
| 899 void SetBootAttribute(const cryptohome::SetBootAttributeRequest& request, | 890 void SetBootAttribute(const cryptohome::SetBootAttributeRequest& request, |
| 900 const ProtobufMethodCallback& callback) override { | 891 const ProtobufMethodCallback& callback) override { |
| 901 const char* method_name = cryptohome::kCryptohomeSetBootAttribute; | 892 CallCryptohomeMethod(cryptohome::kCryptohomeSetBootAttribute, request, |
| 902 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, method_name); | 893 callback); |
| 903 | |
| 904 dbus::MessageWriter writer(&method_call); | |
| 905 writer.AppendProtoAsArrayOfBytes(request); | |
| 906 | |
| 907 proxy_->CallMethod(&method_call, | |
| 908 kTpmDBusTimeoutMs , | |
| 909 base::Bind(&CryptohomeClientImpl::OnBaseReplyMethod, | |
| 910 weak_ptr_factory_.GetWeakPtr(), | |
| 911 callback)); | |
| 912 } | 894 } |
| 913 | 895 |
| 914 void FlushAndSignBootAttributes( | 896 void FlushAndSignBootAttributes( |
| 915 const cryptohome::FlushAndSignBootAttributesRequest& request, | 897 const cryptohome::FlushAndSignBootAttributesRequest& request, |
| 916 const ProtobufMethodCallback& callback) override { | 898 const ProtobufMethodCallback& callback) override { |
| 917 const char* method_name = cryptohome::kCryptohomeFlushAndSignBootAttributes; | 899 CallCryptohomeMethod(cryptohome::kCryptohomeFlushAndSignBootAttributes, |
| 918 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, method_name); | 900 request, callback); |
| 901 } |
| 919 | 902 |
| 920 dbus::MessageWriter writer(&method_call); | 903 void RemoveFirmwareManagementParametersFromTpm( |
| 921 writer.AppendProtoAsArrayOfBytes(request); | 904 const cryptohome::RemoveFirmwareManagementParametersRequest& request, |
| 905 const ProtobufMethodCallback& callback) override { |
| 906 CallCryptohomeMethod( |
| 907 cryptohome::kCryptohomeRemoveFirmwareManagementParameters, request, |
| 908 callback); |
| 909 } |
| 922 | 910 |
| 923 proxy_->CallMethod(&method_call, | 911 void SetFirmwareManagementParametersInTpm( |
| 924 kTpmDBusTimeoutMs , | 912 const cryptohome::SetFirmwareManagementParametersRequest& request, |
| 925 base::Bind(&CryptohomeClientImpl::OnBaseReplyMethod, | 913 const ProtobufMethodCallback& callback) override { |
| 926 weak_ptr_factory_.GetWeakPtr(), | 914 CallCryptohomeMethod(cryptohome::kCryptohomeSetFirmwareManagementParameters, |
| 927 callback)); | 915 request, callback); |
| 928 } | 916 } |
| 929 | 917 |
| 930 protected: | 918 protected: |
| 931 void Init(dbus::Bus* bus) override { | 919 void Init(dbus::Bus* bus) override { |
| 932 proxy_ = bus->GetObjectProxy( | 920 proxy_ = bus->GetObjectProxy( |
| 933 cryptohome::kCryptohomeServiceName, | 921 cryptohome::kCryptohomeServiceName, |
| 934 dbus::ObjectPath(cryptohome::kCryptohomeServicePath)); | 922 dbus::ObjectPath(cryptohome::kCryptohomeServicePath)); |
| 935 | 923 |
| 936 blocking_method_caller_.reset(new BlockingMethodCaller(bus, proxy_)); | 924 blocking_method_caller_.reset(new BlockingMethodCaller(bus, proxy_)); |
| 937 | 925 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 } | 1176 } |
| 1189 | 1177 |
| 1190 // Handles the result of signal connection setup. | 1178 // Handles the result of signal connection setup. |
| 1191 void OnSignalConnected(const std::string& interface, | 1179 void OnSignalConnected(const std::string& interface, |
| 1192 const std::string& signal, | 1180 const std::string& signal, |
| 1193 bool succeeded) { | 1181 bool succeeded) { |
| 1194 LOG_IF(ERROR, !succeeded) << "Connect to " << interface << " " << | 1182 LOG_IF(ERROR, !succeeded) << "Connect to " << interface << " " << |
| 1195 signal << " failed."; | 1183 signal << " failed."; |
| 1196 } | 1184 } |
| 1197 | 1185 |
| 1186 // Makes an asynchronous D-Bus call, using cryptohome interface. |method_name| |
| 1187 // is the name of the method to be called. |request| is the specific request |
| 1188 // for the method, including the data required to be sent. |callback| is |
| 1189 // invoked when the response is received. |
| 1190 void CallCryptohomeMethod(const std::string& method_name, |
| 1191 const google::protobuf::MessageLite& request, |
| 1192 const ProtobufMethodCallback& callback) { |
| 1193 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, method_name); |
| 1194 |
| 1195 dbus::MessageWriter writer(&method_call); |
| 1196 writer.AppendProtoAsArrayOfBytes(request); |
| 1197 |
| 1198 proxy_->CallMethod(&method_call, kTpmDBusTimeoutMs, |
| 1199 base::Bind(&CryptohomeClientImpl::OnBaseReplyMethod, |
| 1200 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 1201 } |
| 1202 |
| 1198 dbus::ObjectProxy* proxy_; | 1203 dbus::ObjectProxy* proxy_; |
| 1199 std::unique_ptr<BlockingMethodCaller> blocking_method_caller_; | 1204 std::unique_ptr<BlockingMethodCaller> blocking_method_caller_; |
| 1200 AsyncCallStatusHandler async_call_status_handler_; | 1205 AsyncCallStatusHandler async_call_status_handler_; |
| 1201 AsyncCallStatusWithDataHandler async_call_status_data_handler_; | 1206 AsyncCallStatusWithDataHandler async_call_status_data_handler_; |
| 1202 LowDiskSpaceHandler low_disk_space_handler_; | 1207 LowDiskSpaceHandler low_disk_space_handler_; |
| 1203 | 1208 |
| 1204 // Note: This should remain the last member so it'll be destroyed and | 1209 // Note: This should remain the last member so it'll be destroyed and |
| 1205 // invalidate its weak pointers before any other members are destroyed. | 1210 // invalidate its weak pointers before any other members are destroyed. |
| 1206 base::WeakPtrFactory<CryptohomeClientImpl> weak_ptr_factory_; | 1211 base::WeakPtrFactory<CryptohomeClientImpl> weak_ptr_factory_; |
| 1207 | 1212 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1222 return new CryptohomeClientImpl(); | 1227 return new CryptohomeClientImpl(); |
| 1223 } | 1228 } |
| 1224 | 1229 |
| 1225 // static | 1230 // static |
| 1226 std::string CryptohomeClient::GetStubSanitizedUsername( | 1231 std::string CryptohomeClient::GetStubSanitizedUsername( |
| 1227 const cryptohome::Identification& cryptohome_id) { | 1232 const cryptohome::Identification& cryptohome_id) { |
| 1228 return cryptohome_id.id() + kUserIdStubHashSuffix; | 1233 return cryptohome_id.id() + kUserIdStubHashSuffix; |
| 1229 } | 1234 } |
| 1230 | 1235 |
| 1231 } // namespace chromeos | 1236 } // namespace chromeos |
| OLD | NEW |