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 <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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 async_call_status_handler_.Reset(); | 61 async_call_status_handler_.Reset(); |
| 62 async_call_status_data_handler_.Reset(); | 62 async_call_status_data_handler_.Reset(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 // CryptohomeClient override. | 65 // CryptohomeClient override. |
| 66 void SetLowDiskSpaceHandler(const LowDiskSpaceHandler& handler) override { | 66 void SetLowDiskSpaceHandler(const LowDiskSpaceHandler& handler) override { |
| 67 low_disk_space_handler_ = handler; | 67 low_disk_space_handler_ = handler; |
| 68 } | 68 } |
| 69 | 69 |
| 70 // CryptohomeClient override. | 70 // CryptohomeClient override. |
| 71 void SetDircryptoMigrationProgressHandler( | |
| 72 const DircryptoMigrationProgessHandler& handler) override { | |
| 73 dircrypto_migration_progress_handler_ = handler; | |
| 74 } | |
| 75 | |
| 76 // CryptohomeClient override. | |
| 71 void WaitForServiceToBeAvailable( | 77 void WaitForServiceToBeAvailable( |
| 72 const WaitForServiceToBeAvailableCallback& callback) override { | 78 const WaitForServiceToBeAvailableCallback& callback) override { |
| 73 proxy_->WaitForServiceToBeAvailable(callback); | 79 proxy_->WaitForServiceToBeAvailable(callback); |
| 74 } | 80 } |
| 75 | 81 |
| 76 // CryptohomeClient override. | 82 // CryptohomeClient override. |
| 77 void IsMounted(const BoolDBusMethodCallback& callback) override { | 83 void IsMounted(const BoolDBusMethodCallback& callback) override { |
| 78 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, | 84 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, |
| 79 cryptohome::kCryptohomeIsMounted); | 85 cryptohome::kCryptohomeIsMounted); |
| 80 CallBoolMethod(&method_call, callback); | 86 CallBoolMethod(&method_call, callback); |
| (...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 920 dbus::MessageWriter writer(&method_call); | 926 dbus::MessageWriter writer(&method_call); |
| 921 writer.AppendProtoAsArrayOfBytes(request); | 927 writer.AppendProtoAsArrayOfBytes(request); |
| 922 | 928 |
| 923 proxy_->CallMethod(&method_call, | 929 proxy_->CallMethod(&method_call, |
| 924 kTpmDBusTimeoutMs , | 930 kTpmDBusTimeoutMs , |
| 925 base::Bind(&CryptohomeClientImpl::OnBaseReplyMethod, | 931 base::Bind(&CryptohomeClientImpl::OnBaseReplyMethod, |
| 926 weak_ptr_factory_.GetWeakPtr(), | 932 weak_ptr_factory_.GetWeakPtr(), |
| 927 callback)); | 933 callback)); |
| 928 } | 934 } |
| 929 | 935 |
| 936 void MigrateToDircrypto(const cryptohome::Identification& cryptohome_id, | |
| 937 const cryptohome::AuthorizationRequest& auth, | |
| 938 const ProtobufMethodCallback& callback) override { | |
| 939 const char* method_name = cryptohome::kCryptohomeMigrateToDircrypto; | |
|
Daniel Erat
2017/03/14 15:37:36
nit: just inline this in the next statement? it do
kinaba
2017/03/15 08:17:30
Done.
| |
| 940 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, method_name); | |
| 941 | |
| 942 cryptohome::AccountIdentifier id_proto; | |
| 943 FillIdentificationProtobuf(cryptohome_id, &id_proto); | |
| 944 | |
| 945 dbus::MessageWriter writer(&method_call); | |
| 946 writer.AppendProtoAsArrayOfBytes(id_proto); | |
| 947 writer.AppendProtoAsArrayOfBytes(auth); | |
| 948 | |
| 949 proxy_->CallMethod(&method_call, kTpmDBusTimeoutMs, | |
|
Daniel Erat
2017/03/14 15:37:36
is this dependent on the TPM, or does it make sens
kinaba
2017/03/15 08:17:30
Good catch. Done
| |
| 950 base::Bind(&CryptohomeClientImpl::OnBaseReplyMethod, | |
| 951 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 952 } | |
| 953 | |
| 930 protected: | 954 protected: |
| 931 void Init(dbus::Bus* bus) override { | 955 void Init(dbus::Bus* bus) override { |
| 932 proxy_ = bus->GetObjectProxy( | 956 proxy_ = bus->GetObjectProxy( |
| 933 cryptohome::kCryptohomeServiceName, | 957 cryptohome::kCryptohomeServiceName, |
| 934 dbus::ObjectPath(cryptohome::kCryptohomeServicePath)); | 958 dbus::ObjectPath(cryptohome::kCryptohomeServicePath)); |
| 935 | 959 |
| 936 blocking_method_caller_.reset(new BlockingMethodCaller(bus, proxy_)); | 960 blocking_method_caller_.reset(new BlockingMethodCaller(bus, proxy_)); |
| 937 | 961 |
| 938 proxy_->ConnectToSignal(cryptohome::kCryptohomeInterface, | 962 proxy_->ConnectToSignal(cryptohome::kCryptohomeInterface, |
| 939 cryptohome::kSignalAsyncCallStatus, | 963 cryptohome::kSignalAsyncCallStatus, |
| 940 base::Bind(&CryptohomeClientImpl::OnAsyncCallStatus, | 964 base::Bind(&CryptohomeClientImpl::OnAsyncCallStatus, |
| 941 weak_ptr_factory_.GetWeakPtr()), | 965 weak_ptr_factory_.GetWeakPtr()), |
| 942 base::Bind(&CryptohomeClientImpl::OnSignalConnected, | 966 base::Bind(&CryptohomeClientImpl::OnSignalConnected, |
| 943 weak_ptr_factory_.GetWeakPtr())); | 967 weak_ptr_factory_.GetWeakPtr())); |
| 944 proxy_->ConnectToSignal( | 968 proxy_->ConnectToSignal( |
| 945 cryptohome::kCryptohomeInterface, | 969 cryptohome::kCryptohomeInterface, |
| 946 cryptohome::kSignalAsyncCallStatusWithData, | 970 cryptohome::kSignalAsyncCallStatusWithData, |
| 947 base::Bind(&CryptohomeClientImpl::OnAsyncCallStatusWithData, | 971 base::Bind(&CryptohomeClientImpl::OnAsyncCallStatusWithData, |
| 948 weak_ptr_factory_.GetWeakPtr()), | 972 weak_ptr_factory_.GetWeakPtr()), |
| 949 base::Bind(&CryptohomeClientImpl::OnSignalConnected, | 973 base::Bind(&CryptohomeClientImpl::OnSignalConnected, |
| 950 weak_ptr_factory_.GetWeakPtr())); | 974 weak_ptr_factory_.GetWeakPtr())); |
| 951 proxy_->ConnectToSignal(cryptohome::kCryptohomeInterface, | 975 proxy_->ConnectToSignal(cryptohome::kCryptohomeInterface, |
| 952 cryptohome::kSignalLowDiskSpace, | 976 cryptohome::kSignalLowDiskSpace, |
| 953 base::Bind(&CryptohomeClientImpl::OnLowDiskSpace, | 977 base::Bind(&CryptohomeClientImpl::OnLowDiskSpace, |
| 954 weak_ptr_factory_.GetWeakPtr()), | 978 weak_ptr_factory_.GetWeakPtr()), |
| 955 base::Bind(&CryptohomeClientImpl::OnSignalConnected, | 979 base::Bind(&CryptohomeClientImpl::OnSignalConnected, |
| 956 weak_ptr_factory_.GetWeakPtr())); | 980 weak_ptr_factory_.GetWeakPtr())); |
| 981 proxy_->ConnectToSignal( | |
| 982 cryptohome::kCryptohomeInterface, | |
| 983 cryptohome::kSignalDircryptoMigrationProgress, | |
| 984 base::Bind(&CryptohomeClientImpl::OnDircryptoMigrationProgress, | |
| 985 weak_ptr_factory_.GetWeakPtr()), | |
| 986 base::Bind(&CryptohomeClientImpl::OnSignalConnected, | |
| 987 weak_ptr_factory_.GetWeakPtr())); | |
| 957 } | 988 } |
| 958 | 989 |
| 959 private: | 990 private: |
| 960 // Handles the result of AsyncXXX methods. | 991 // Handles the result of AsyncXXX methods. |
| 961 void OnAsyncMethodCall(const AsyncMethodCallback& callback, | 992 void OnAsyncMethodCall(const AsyncMethodCallback& callback, |
| 962 dbus::Response* response) { | 993 dbus::Response* response) { |
| 963 if (!response) { | 994 if (!response) { |
| 964 callback.Run(kNotReadyAsyncId); | 995 callback.Run(kNotReadyAsyncId); |
| 965 return; | 996 return; |
| 966 } | 997 } |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1180 dbus::MessageReader reader(signal); | 1211 dbus::MessageReader reader(signal); |
| 1181 uint64_t disk_free_bytes = 0; | 1212 uint64_t disk_free_bytes = 0; |
| 1182 if (!reader.PopUint64(&disk_free_bytes)) { | 1213 if (!reader.PopUint64(&disk_free_bytes)) { |
| 1183 LOG(ERROR) << "Invalid signal: " << signal->ToString(); | 1214 LOG(ERROR) << "Invalid signal: " << signal->ToString(); |
| 1184 return; | 1215 return; |
| 1185 } | 1216 } |
| 1186 if (!low_disk_space_handler_.is_null()) | 1217 if (!low_disk_space_handler_.is_null()) |
| 1187 low_disk_space_handler_.Run(disk_free_bytes); | 1218 low_disk_space_handler_.Run(disk_free_bytes); |
| 1188 } | 1219 } |
| 1189 | 1220 |
| 1221 // Handles DircryptoMigrationProgess signal. | |
| 1222 void OnDircryptoMigrationProgress(dbus::Signal* signal) { | |
| 1223 dbus::MessageReader reader(signal); | |
| 1224 uint64_t current = 0, total = 0; | |
| 1225 if (!reader.PopUint64(¤t)) { | |
| 1226 LOG(ERROR) << "Invalid signal: " << signal->ToString(); | |
| 1227 return; | |
| 1228 } | |
| 1229 if (!reader.PopUint64(&total)) { | |
|
Daniel Erat
2017/03/14 15:37:36
just merge these:
if (!reader.PopUint64(¤
kinaba
2017/03/15 08:17:30
Done.
| |
| 1230 LOG(ERROR) << "Invalid signal: " << signal->ToString(); | |
| 1231 return; | |
| 1232 } | |
| 1233 if (!dircrypto_migration_progress_handler_.is_null()) | |
|
Daniel Erat
2017/03/14 15:37:36
move this check to the top of the method? it doesn
kinaba
2017/03/15 08:17:30
Done.
| |
| 1234 dircrypto_migration_progress_handler_.Run(current, total); | |
| 1235 } | |
| 1236 | |
| 1190 // Handles the result of signal connection setup. | 1237 // Handles the result of signal connection setup. |
| 1191 void OnSignalConnected(const std::string& interface, | 1238 void OnSignalConnected(const std::string& interface, |
| 1192 const std::string& signal, | 1239 const std::string& signal, |
| 1193 bool succeeded) { | 1240 bool succeeded) { |
| 1194 LOG_IF(ERROR, !succeeded) << "Connect to " << interface << " " << | 1241 LOG_IF(ERROR, !succeeded) << "Connect to " << interface << " " << |
| 1195 signal << " failed."; | 1242 signal << " failed."; |
| 1196 } | 1243 } |
| 1197 | 1244 |
| 1198 dbus::ObjectProxy* proxy_; | 1245 dbus::ObjectProxy* proxy_; |
| 1199 std::unique_ptr<BlockingMethodCaller> blocking_method_caller_; | 1246 std::unique_ptr<BlockingMethodCaller> blocking_method_caller_; |
| 1200 AsyncCallStatusHandler async_call_status_handler_; | 1247 AsyncCallStatusHandler async_call_status_handler_; |
| 1201 AsyncCallStatusWithDataHandler async_call_status_data_handler_; | 1248 AsyncCallStatusWithDataHandler async_call_status_data_handler_; |
| 1202 LowDiskSpaceHandler low_disk_space_handler_; | 1249 LowDiskSpaceHandler low_disk_space_handler_; |
| 1250 DircryptoMigrationProgessHandler dircrypto_migration_progress_handler_; | |
| 1203 | 1251 |
| 1204 // Note: This should remain the last member so it'll be destroyed and | 1252 // Note: This should remain the last member so it'll be destroyed and |
| 1205 // invalidate its weak pointers before any other members are destroyed. | 1253 // invalidate its weak pointers before any other members are destroyed. |
| 1206 base::WeakPtrFactory<CryptohomeClientImpl> weak_ptr_factory_; | 1254 base::WeakPtrFactory<CryptohomeClientImpl> weak_ptr_factory_; |
| 1207 | 1255 |
| 1208 DISALLOW_COPY_AND_ASSIGN(CryptohomeClientImpl); | 1256 DISALLOW_COPY_AND_ASSIGN(CryptohomeClientImpl); |
| 1209 }; | 1257 }; |
| 1210 | 1258 |
| 1211 } // namespace | 1259 } // namespace |
| 1212 | 1260 |
| 1213 //////////////////////////////////////////////////////////////////////////////// | 1261 //////////////////////////////////////////////////////////////////////////////// |
| 1214 // CryptohomeClient | 1262 // CryptohomeClient |
| 1215 | 1263 |
| 1216 CryptohomeClient::CryptohomeClient() {} | 1264 CryptohomeClient::CryptohomeClient() {} |
| 1217 | 1265 |
| 1218 CryptohomeClient::~CryptohomeClient() {} | 1266 CryptohomeClient::~CryptohomeClient() {} |
| 1219 | 1267 |
| 1220 // static | 1268 // static |
| 1221 CryptohomeClient* CryptohomeClient::Create() { | 1269 CryptohomeClient* CryptohomeClient::Create() { |
| 1222 return new CryptohomeClientImpl(); | 1270 return new CryptohomeClientImpl(); |
| 1223 } | 1271 } |
| 1224 | 1272 |
| 1225 // static | 1273 // static |
| 1226 std::string CryptohomeClient::GetStubSanitizedUsername( | 1274 std::string CryptohomeClient::GetStubSanitizedUsername( |
| 1227 const cryptohome::Identification& cryptohome_id) { | 1275 const cryptohome::Identification& cryptohome_id) { |
| 1228 return cryptohome_id.id() + kUserIdStubHashSuffix; | 1276 return cryptohome_id.id() + kUserIdStubHashSuffix; |
| 1229 } | 1277 } |
| 1230 | 1278 |
| 1231 } // namespace chromeos | 1279 } // namespace chromeos |
| OLD | NEW |