| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/cryptohome/homedir_methods.h" | 5 #include "chromeos/cryptohome/homedir_methods.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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 KeyProviderData::Entry* entry = | 88 KeyProviderData::Entry* entry = |
| 89 data->mutable_provider_data()->add_entry(); | 89 data->mutable_provider_data()->add_entry(); |
| 90 entry->set_name(it->name); | 90 entry->set_name(it->name); |
| 91 if (it->number) | 91 if (it->number) |
| 92 entry->set_number(*it->number); | 92 entry->set_number(*it->number); |
| 93 if (it->bytes) | 93 if (it->bytes) |
| 94 entry->set_bytes(*it->bytes); | 94 entry->set_bytes(*it->bytes); |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 // Fill identification protobuffer. | |
| 99 void FillIdentificationProtobuf(const Identification& id, | |
| 100 cryptohome::AccountIdentifier* id_proto) { | |
| 101 id_proto->set_email(id.user_id); | |
| 102 } | |
| 103 | |
| 104 // Fill authorization protobuffer. | 98 // Fill authorization protobuffer. |
| 105 void FillAuthorizationProtobuf(const Authorization& auth, | 99 void FillAuthorizationProtobuf(const Authorization& auth, |
| 106 cryptohome::AuthorizationRequest* auth_proto) { | 100 cryptohome::AuthorizationRequest* auth_proto) { |
| 107 Key* key = auth_proto->mutable_key(); | 101 Key* key = auth_proto->mutable_key(); |
| 108 if (!auth.label.empty()) { | 102 if (!auth.label.empty()) { |
| 109 key->mutable_data()->set_label(auth.label); | 103 key->mutable_data()->set_label(auth.label); |
| 110 } | 104 } |
| 111 key->set_secret(auth.key); | 105 key->set_secret(auth.key); |
| 112 } | 106 } |
| 113 | 107 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 // The implementation of HomedirMethods | 170 // The implementation of HomedirMethods |
| 177 class HomedirMethodsImpl : public HomedirMethods { | 171 class HomedirMethodsImpl : public HomedirMethods { |
| 178 public: | 172 public: |
| 179 HomedirMethodsImpl() : weak_ptr_factory_(this) {} | 173 HomedirMethodsImpl() : weak_ptr_factory_(this) {} |
| 180 | 174 |
| 181 ~HomedirMethodsImpl() override {} | 175 ~HomedirMethodsImpl() override {} |
| 182 | 176 |
| 183 void GetKeyDataEx(const Identification& id, | 177 void GetKeyDataEx(const Identification& id, |
| 184 const std::string& label, | 178 const std::string& label, |
| 185 const GetKeyDataCallback& callback) override { | 179 const GetKeyDataCallback& callback) override { |
| 186 cryptohome::AccountIdentifier id_proto; | |
| 187 cryptohome::AuthorizationRequest kEmptyAuthProto; | 180 cryptohome::AuthorizationRequest kEmptyAuthProto; |
| 188 cryptohome::GetKeyDataRequest request; | 181 cryptohome::GetKeyDataRequest request; |
| 189 | 182 |
| 190 FillIdentificationProtobuf(id, &id_proto); | |
| 191 request.mutable_key()->mutable_data()->set_label(label); | 183 request.mutable_key()->mutable_data()->set_label(label); |
| 192 | 184 |
| 193 DBusThreadManager::Get()->GetCryptohomeClient()->GetKeyDataEx( | 185 DBusThreadManager::Get()->GetCryptohomeClient()->GetKeyDataEx( |
| 194 id_proto, | 186 id, kEmptyAuthProto, request, |
| 195 kEmptyAuthProto, | |
| 196 request, | |
| 197 base::Bind(&HomedirMethodsImpl::OnGetKeyDataExCallback, | 187 base::Bind(&HomedirMethodsImpl::OnGetKeyDataExCallback, |
| 198 weak_ptr_factory_.GetWeakPtr(), | 188 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 199 callback)); | |
| 200 } | 189 } |
| 201 | 190 |
| 202 void CheckKeyEx(const Identification& id, | 191 void CheckKeyEx(const Identification& id, |
| 203 const Authorization& auth, | 192 const Authorization& auth, |
| 204 const Callback& callback) override { | 193 const Callback& callback) override { |
| 205 cryptohome::AccountIdentifier id_proto; | |
| 206 cryptohome::AuthorizationRequest auth_proto; | 194 cryptohome::AuthorizationRequest auth_proto; |
| 207 cryptohome::CheckKeyRequest request; | 195 cryptohome::CheckKeyRequest request; |
| 208 | 196 |
| 209 FillIdentificationProtobuf(id, &id_proto); | |
| 210 FillAuthorizationProtobuf(auth, &auth_proto); | 197 FillAuthorizationProtobuf(auth, &auth_proto); |
| 211 | 198 |
| 212 DBusThreadManager::Get()->GetCryptohomeClient()->CheckKeyEx( | 199 DBusThreadManager::Get()->GetCryptohomeClient()->CheckKeyEx( |
| 213 id_proto, | 200 id, auth_proto, request, |
| 214 auth_proto, | |
| 215 request, | |
| 216 base::Bind(&HomedirMethodsImpl::OnBaseReplyCallback, | 201 base::Bind(&HomedirMethodsImpl::OnBaseReplyCallback, |
| 217 weak_ptr_factory_.GetWeakPtr(), | 202 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 218 callback)); | |
| 219 } | 203 } |
| 220 | 204 |
| 221 void MountEx(const Identification& id, | 205 void MountEx(const Identification& id, |
| 222 const Authorization& auth, | 206 const Authorization& auth, |
| 223 const MountParameters& request, | 207 const MountParameters& request, |
| 224 const MountCallback& callback) override { | 208 const MountCallback& callback) override { |
| 225 cryptohome::AccountIdentifier id_proto; | |
| 226 cryptohome::AuthorizationRequest auth_proto; | 209 cryptohome::AuthorizationRequest auth_proto; |
| 227 cryptohome::MountRequest request_proto; | 210 cryptohome::MountRequest request_proto; |
| 228 | 211 |
| 229 FillIdentificationProtobuf(id, &id_proto); | |
| 230 FillAuthorizationProtobuf(auth, &auth_proto); | 212 FillAuthorizationProtobuf(auth, &auth_proto); |
| 231 | 213 |
| 232 if (request.ephemeral) | 214 if (request.ephemeral) |
| 233 request_proto.set_require_ephemeral(true); | 215 request_proto.set_require_ephemeral(true); |
| 234 | 216 |
| 235 if (!request.create_keys.empty()) { | 217 if (!request.create_keys.empty()) { |
| 236 CreateRequest* create = request_proto.mutable_create(); | 218 CreateRequest* create = request_proto.mutable_create(); |
| 237 for (size_t i = 0; i < request.create_keys.size(); ++i) | 219 for (size_t i = 0; i < request.create_keys.size(); ++i) |
| 238 FillKeyProtobuf(request.create_keys[i], create->add_keys()); | 220 FillKeyProtobuf(request.create_keys[i], create->add_keys()); |
| 239 } | 221 } |
| 240 | 222 |
| 241 DBusThreadManager::Get()->GetCryptohomeClient()->MountEx( | 223 DBusThreadManager::Get()->GetCryptohomeClient()->MountEx( |
| 242 id_proto, | 224 id, auth_proto, request_proto, |
| 243 auth_proto, | |
| 244 request_proto, | |
| 245 base::Bind(&HomedirMethodsImpl::OnMountExCallback, | 225 base::Bind(&HomedirMethodsImpl::OnMountExCallback, |
| 246 weak_ptr_factory_.GetWeakPtr(), | 226 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 247 callback)); | |
| 248 } | 227 } |
| 249 | 228 |
| 250 void AddKeyEx(const Identification& id, | 229 void AddKeyEx(const Identification& id, |
| 251 const Authorization& auth, | 230 const Authorization& auth, |
| 252 const KeyDefinition& new_key, | 231 const KeyDefinition& new_key, |
| 253 bool clobber_if_exists, | 232 bool clobber_if_exists, |
| 254 const Callback& callback) override { | 233 const Callback& callback) override { |
| 255 cryptohome::AccountIdentifier id_proto; | |
| 256 cryptohome::AuthorizationRequest auth_proto; | 234 cryptohome::AuthorizationRequest auth_proto; |
| 257 cryptohome::AddKeyRequest request; | 235 cryptohome::AddKeyRequest request; |
| 258 | 236 |
| 259 FillIdentificationProtobuf(id, &id_proto); | |
| 260 FillAuthorizationProtobuf(auth, &auth_proto); | 237 FillAuthorizationProtobuf(auth, &auth_proto); |
| 261 FillKeyProtobuf(new_key, request.mutable_key()); | 238 FillKeyProtobuf(new_key, request.mutable_key()); |
| 262 request.set_clobber_if_exists(clobber_if_exists); | 239 request.set_clobber_if_exists(clobber_if_exists); |
| 263 | 240 |
| 264 DBusThreadManager::Get()->GetCryptohomeClient()->AddKeyEx( | 241 DBusThreadManager::Get()->GetCryptohomeClient()->AddKeyEx( |
| 265 id_proto, | 242 id, auth_proto, request, |
| 266 auth_proto, | |
| 267 request, | |
| 268 base::Bind(&HomedirMethodsImpl::OnBaseReplyCallback, | 243 base::Bind(&HomedirMethodsImpl::OnBaseReplyCallback, |
| 269 weak_ptr_factory_.GetWeakPtr(), | 244 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 270 callback)); | |
| 271 } | 245 } |
| 272 | 246 |
| 273 void RemoveKeyEx(const Identification& id, | 247 void RemoveKeyEx(const Identification& id, |
| 274 const Authorization& auth, | 248 const Authorization& auth, |
| 275 const std::string& label, | 249 const std::string& label, |
| 276 const Callback& callback) override { | 250 const Callback& callback) override { |
| 277 cryptohome::AccountIdentifier id_proto; | |
| 278 cryptohome::AuthorizationRequest auth_proto; | 251 cryptohome::AuthorizationRequest auth_proto; |
| 279 cryptohome::RemoveKeyRequest request; | 252 cryptohome::RemoveKeyRequest request; |
| 280 | 253 |
| 281 FillIdentificationProtobuf(id, &id_proto); | |
| 282 FillAuthorizationProtobuf(auth, &auth_proto); | 254 FillAuthorizationProtobuf(auth, &auth_proto); |
| 283 request.mutable_key()->mutable_data()->set_label(label); | 255 request.mutable_key()->mutable_data()->set_label(label); |
| 284 | 256 |
| 285 DBusThreadManager::Get()->GetCryptohomeClient()->RemoveKeyEx( | 257 DBusThreadManager::Get()->GetCryptohomeClient()->RemoveKeyEx( |
| 286 id_proto, | 258 id, auth_proto, request, |
| 287 auth_proto, | |
| 288 request, | |
| 289 base::Bind(&HomedirMethodsImpl::OnBaseReplyCallback, | 259 base::Bind(&HomedirMethodsImpl::OnBaseReplyCallback, |
| 290 weak_ptr_factory_.GetWeakPtr(), | 260 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 291 callback)); | |
| 292 } | 261 } |
| 293 | 262 |
| 294 void UpdateKeyEx(const Identification& id, | 263 void UpdateKeyEx(const Identification& id, |
| 295 const Authorization& auth, | 264 const Authorization& auth, |
| 296 const KeyDefinition& new_key, | 265 const KeyDefinition& new_key, |
| 297 const std::string& signature, | 266 const std::string& signature, |
| 298 const Callback& callback) override { | 267 const Callback& callback) override { |
| 299 cryptohome::AccountIdentifier id_proto; | |
| 300 cryptohome::AuthorizationRequest auth_proto; | 268 cryptohome::AuthorizationRequest auth_proto; |
| 301 cryptohome::UpdateKeyRequest pb_update_key; | 269 cryptohome::UpdateKeyRequest pb_update_key; |
| 302 | 270 |
| 303 FillIdentificationProtobuf(id, &id_proto); | |
| 304 FillAuthorizationProtobuf(auth, &auth_proto); | 271 FillAuthorizationProtobuf(auth, &auth_proto); |
| 305 FillKeyProtobuf(new_key, pb_update_key.mutable_changes()); | 272 FillKeyProtobuf(new_key, pb_update_key.mutable_changes()); |
| 306 pb_update_key.set_authorization_signature(signature); | 273 pb_update_key.set_authorization_signature(signature); |
| 307 | 274 |
| 308 DBusThreadManager::Get()->GetCryptohomeClient()->UpdateKeyEx( | 275 DBusThreadManager::Get()->GetCryptohomeClient()->UpdateKeyEx( |
| 309 id_proto, | 276 id, auth_proto, pb_update_key, |
| 310 auth_proto, | |
| 311 pb_update_key, | |
| 312 base::Bind(&HomedirMethodsImpl::OnBaseReplyCallback, | 277 base::Bind(&HomedirMethodsImpl::OnBaseReplyCallback, |
| 313 weak_ptr_factory_.GetWeakPtr(), | 278 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 314 callback)); | 279 } |
| 280 |
| 281 void RenameCryptohome(const Identification& id_from, |
| 282 const Identification& id_to, |
| 283 const Callback& callback) override { |
| 284 DBusThreadManager::Get()->GetCryptohomeClient()->RenameCryptohome( |
| 285 id_from, id_to, base::Bind(&HomedirMethodsImpl::OnBaseReplyCallback, |
| 286 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 315 } | 287 } |
| 316 | 288 |
| 317 private: | 289 private: |
| 318 void OnGetKeyDataExCallback(const GetKeyDataCallback& callback, | 290 void OnGetKeyDataExCallback(const GetKeyDataCallback& callback, |
| 319 chromeos::DBusMethodCallStatus call_status, | 291 chromeos::DBusMethodCallStatus call_status, |
| 320 bool result, | 292 bool result, |
| 321 const BaseReply& reply) { | 293 const BaseReply& reply) { |
| 322 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { | 294 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { |
| 323 callback.Run(false, MOUNT_ERROR_FATAL, std::vector<KeyDefinition>()); | 295 callback.Run(false, MOUNT_ERROR_FATAL, std::vector<KeyDefinition>()); |
| 324 return; | 296 return; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 } | 458 } |
| 487 delete g_homedir_methods; | 459 delete g_homedir_methods; |
| 488 g_homedir_methods = NULL; | 460 g_homedir_methods = NULL; |
| 489 VLOG(1) << "HomedirMethods Shutdown completed"; | 461 VLOG(1) << "HomedirMethods Shutdown completed"; |
| 490 } | 462 } |
| 491 | 463 |
| 492 // static | 464 // static |
| 493 HomedirMethods* HomedirMethods::GetInstance() { return g_homedir_methods; } | 465 HomedirMethods* HomedirMethods::GetInstance() { return g_homedir_methods; } |
| 494 | 466 |
| 495 } // namespace cryptohome | 467 } // namespace cryptohome |
| OLD | NEW |