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> |
| 8 #include <stdint.h> |
| 9 |
7 #include "base/bind.h" | 10 #include "base/bind.h" |
8 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/macros.h" |
9 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
11 #include "chromeos/cryptohome/async_method_caller.h" | 15 #include "chromeos/cryptohome/async_method_caller.h" |
12 #include "chromeos/dbus/blocking_method_caller.h" | 16 #include "chromeos/dbus/blocking_method_caller.h" |
13 #include "chromeos/dbus/cryptohome/key.pb.h" | 17 #include "chromeos/dbus/cryptohome/key.pb.h" |
14 #include "chromeos/dbus/cryptohome/rpc.pb.h" | 18 #include "chromeos/dbus/cryptohome/rpc.pb.h" |
15 #include "dbus/bus.h" | 19 #include "dbus/bus.h" |
16 #include "dbus/message.h" | 20 #include "dbus/message.h" |
17 #include "dbus/object_path.h" | 21 #include "dbus/object_path.h" |
18 #include "dbus/object_proxy.h" | 22 #include "dbus/object_proxy.h" |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 proxy_->CallMethod( | 346 proxy_->CallMethod( |
343 &method_call, kTpmDBusTimeoutMs , | 347 &method_call, kTpmDBusTimeoutMs , |
344 base::Bind( | 348 base::Bind( |
345 &CryptohomeClientImpl::OnPkcs11GetTpmTokenInfoForUser, | 349 &CryptohomeClientImpl::OnPkcs11GetTpmTokenInfoForUser, |
346 weak_ptr_factory_.GetWeakPtr(), | 350 weak_ptr_factory_.GetWeakPtr(), |
347 callback)); | 351 callback)); |
348 } | 352 } |
349 | 353 |
350 // CryptohomeClient override. | 354 // CryptohomeClient override. |
351 bool InstallAttributesGet(const std::string& name, | 355 bool InstallAttributesGet(const std::string& name, |
352 std::vector<uint8>* value, | 356 std::vector<uint8_t>* value, |
353 bool* successful) override { | 357 bool* successful) override { |
354 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, | 358 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, |
355 cryptohome::kCryptohomeInstallAttributesGet); | 359 cryptohome::kCryptohomeInstallAttributesGet); |
356 dbus::MessageWriter writer(&method_call); | 360 dbus::MessageWriter writer(&method_call); |
357 writer.AppendString(name); | 361 writer.AppendString(name); |
358 scoped_ptr<dbus::Response> response( | 362 scoped_ptr<dbus::Response> response( |
359 blocking_method_caller_->CallMethodAndBlock(&method_call)); | 363 blocking_method_caller_->CallMethodAndBlock(&method_call)); |
360 if (!response.get()) | 364 if (!response.get()) |
361 return false; | 365 return false; |
362 dbus::MessageReader reader(response.get()); | 366 dbus::MessageReader reader(response.get()); |
363 const uint8* bytes = NULL; | 367 const uint8_t* bytes = NULL; |
364 size_t length = 0; | 368 size_t length = 0; |
365 if (!reader.PopArrayOfBytes(&bytes, &length) || | 369 if (!reader.PopArrayOfBytes(&bytes, &length) || |
366 !reader.PopBool(successful)) | 370 !reader.PopBool(successful)) |
367 return false; | 371 return false; |
368 value->assign(bytes, bytes + length); | 372 value->assign(bytes, bytes + length); |
369 return true; | 373 return true; |
370 } | 374 } |
371 | 375 |
372 // CryptohomeClient override. | 376 // CryptohomeClient override. |
373 bool InstallAttributesSet(const std::string& name, | 377 bool InstallAttributesSet(const std::string& name, |
374 const std::vector<uint8>& value, | 378 const std::vector<uint8_t>& value, |
375 bool* successful) override { | 379 bool* successful) override { |
376 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, | 380 dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, |
377 cryptohome::kCryptohomeInstallAttributesSet); | 381 cryptohome::kCryptohomeInstallAttributesSet); |
378 dbus::MessageWriter writer(&method_call); | 382 dbus::MessageWriter writer(&method_call); |
379 writer.AppendString(name); | 383 writer.AppendString(name); |
380 writer.AppendArrayOfBytes(value.data(), value.size()); | 384 writer.AppendArrayOfBytes(value.data(), value.size()); |
381 return CallBoolMethodAndBlock(&method_call, successful); | 385 return CallBoolMethodAndBlock(&method_call, successful); |
382 } | 386 } |
383 | 387 |
384 // CryptohomeClient override. | 388 // CryptohomeClient override. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 // CryptohomeClient override. | 454 // CryptohomeClient override. |
451 void AsyncTpmAttestationEnroll(attestation::PrivacyCAType pca_type, | 455 void AsyncTpmAttestationEnroll(attestation::PrivacyCAType pca_type, |
452 const std::string& pca_response, | 456 const std::string& pca_response, |
453 const AsyncMethodCallback& callback) override { | 457 const AsyncMethodCallback& callback) override { |
454 dbus::MethodCall method_call( | 458 dbus::MethodCall method_call( |
455 cryptohome::kCryptohomeInterface, | 459 cryptohome::kCryptohomeInterface, |
456 cryptohome::kCryptohomeAsyncTpmAttestationEnroll); | 460 cryptohome::kCryptohomeAsyncTpmAttestationEnroll); |
457 dbus::MessageWriter writer(&method_call); | 461 dbus::MessageWriter writer(&method_call); |
458 writer.AppendInt32(pca_type); | 462 writer.AppendInt32(pca_type); |
459 writer.AppendArrayOfBytes( | 463 writer.AppendArrayOfBytes( |
460 reinterpret_cast<const uint8*>(pca_response.data()), | 464 reinterpret_cast<const uint8_t*>(pca_response.data()), |
461 pca_response.size()); | 465 pca_response.size()); |
462 proxy_->CallMethod(&method_call, kTpmDBusTimeoutMs , | 466 proxy_->CallMethod(&method_call, kTpmDBusTimeoutMs , |
463 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, | 467 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, |
464 weak_ptr_factory_.GetWeakPtr(), | 468 weak_ptr_factory_.GetWeakPtr(), |
465 callback)); | 469 callback)); |
466 } | 470 } |
467 | 471 |
468 // CryptohomeClient override. | 472 // CryptohomeClient override. |
469 void AsyncTpmAttestationCreateCertRequest( | 473 void AsyncTpmAttestationCreateCertRequest( |
470 attestation::PrivacyCAType pca_type, | 474 attestation::PrivacyCAType pca_type, |
(...skipping 20 matching lines...) Expand all Loading... |
491 const std::string& pca_response, | 495 const std::string& pca_response, |
492 attestation::AttestationKeyType key_type, | 496 attestation::AttestationKeyType key_type, |
493 const std::string& user_id, | 497 const std::string& user_id, |
494 const std::string& key_name, | 498 const std::string& key_name, |
495 const AsyncMethodCallback& callback) override { | 499 const AsyncMethodCallback& callback) override { |
496 dbus::MethodCall method_call( | 500 dbus::MethodCall method_call( |
497 cryptohome::kCryptohomeInterface, | 501 cryptohome::kCryptohomeInterface, |
498 cryptohome::kCryptohomeAsyncTpmAttestationFinishCertRequest); | 502 cryptohome::kCryptohomeAsyncTpmAttestationFinishCertRequest); |
499 dbus::MessageWriter writer(&method_call); | 503 dbus::MessageWriter writer(&method_call); |
500 writer.AppendArrayOfBytes( | 504 writer.AppendArrayOfBytes( |
501 reinterpret_cast<const uint8*>(pca_response.data()), | 505 reinterpret_cast<const uint8_t*>(pca_response.data()), |
502 pca_response.size()); | 506 pca_response.size()); |
503 bool is_user_specific = (key_type == attestation::KEY_USER); | 507 bool is_user_specific = (key_type == attestation::KEY_USER); |
504 writer.AppendBool(is_user_specific); | 508 writer.AppendBool(is_user_specific); |
505 writer.AppendString(user_id); | 509 writer.AppendString(user_id); |
506 writer.AppendString(key_name); | 510 writer.AppendString(key_name); |
507 proxy_->CallMethod(&method_call, kTpmDBusTimeoutMs , | 511 proxy_->CallMethod(&method_call, kTpmDBusTimeoutMs , |
508 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, | 512 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, |
509 weak_ptr_factory_.GetWeakPtr(), | 513 weak_ptr_factory_.GetWeakPtr(), |
510 callback)); | 514 callback)); |
511 } | 515 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 const AsyncMethodCallback& callback) override { | 601 const AsyncMethodCallback& callback) override { |
598 dbus::MethodCall method_call( | 602 dbus::MethodCall method_call( |
599 cryptohome::kCryptohomeInterface, | 603 cryptohome::kCryptohomeInterface, |
600 cryptohome::kCryptohomeTpmAttestationSignEnterpriseChallenge); | 604 cryptohome::kCryptohomeTpmAttestationSignEnterpriseChallenge); |
601 dbus::MessageWriter writer(&method_call); | 605 dbus::MessageWriter writer(&method_call); |
602 bool is_user_specific = (key_type == attestation::KEY_USER); | 606 bool is_user_specific = (key_type == attestation::KEY_USER); |
603 writer.AppendBool(is_user_specific); | 607 writer.AppendBool(is_user_specific); |
604 writer.AppendString(user_id); | 608 writer.AppendString(user_id); |
605 writer.AppendString(key_name); | 609 writer.AppendString(key_name); |
606 writer.AppendString(domain); | 610 writer.AppendString(domain); |
607 writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(device_id.data()), | 611 writer.AppendArrayOfBytes( |
608 device_id.size()); | 612 reinterpret_cast<const uint8_t*>(device_id.data()), device_id.size()); |
609 bool include_signed_public_key = | 613 bool include_signed_public_key = |
610 (options & attestation::CHALLENGE_INCLUDE_SIGNED_PUBLIC_KEY); | 614 (options & attestation::CHALLENGE_INCLUDE_SIGNED_PUBLIC_KEY); |
611 writer.AppendBool(include_signed_public_key); | 615 writer.AppendBool(include_signed_public_key); |
612 writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(challenge.data()), | 616 writer.AppendArrayOfBytes( |
613 challenge.size()); | 617 reinterpret_cast<const uint8_t*>(challenge.data()), challenge.size()); |
614 proxy_->CallMethod(&method_call, kTpmDBusTimeoutMs , | 618 proxy_->CallMethod(&method_call, kTpmDBusTimeoutMs , |
615 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, | 619 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, |
616 weak_ptr_factory_.GetWeakPtr(), | 620 weak_ptr_factory_.GetWeakPtr(), |
617 callback)); | 621 callback)); |
618 } | 622 } |
619 | 623 |
620 // CryptohomeClient override. | 624 // CryptohomeClient override. |
621 void TpmAttestationSignSimpleChallenge( | 625 void TpmAttestationSignSimpleChallenge( |
622 attestation::AttestationKeyType key_type, | 626 attestation::AttestationKeyType key_type, |
623 const std::string& user_id, | 627 const std::string& user_id, |
624 const std::string& key_name, | 628 const std::string& key_name, |
625 const std::string& challenge, | 629 const std::string& challenge, |
626 const AsyncMethodCallback& callback) override { | 630 const AsyncMethodCallback& callback) override { |
627 dbus::MethodCall method_call( | 631 dbus::MethodCall method_call( |
628 cryptohome::kCryptohomeInterface, | 632 cryptohome::kCryptohomeInterface, |
629 cryptohome::kCryptohomeTpmAttestationSignSimpleChallenge); | 633 cryptohome::kCryptohomeTpmAttestationSignSimpleChallenge); |
630 dbus::MessageWriter writer(&method_call); | 634 dbus::MessageWriter writer(&method_call); |
631 bool is_user_specific = (key_type == attestation::KEY_USER); | 635 bool is_user_specific = (key_type == attestation::KEY_USER); |
632 writer.AppendBool(is_user_specific); | 636 writer.AppendBool(is_user_specific); |
633 writer.AppendString(user_id); | 637 writer.AppendString(user_id); |
634 writer.AppendString(key_name); | 638 writer.AppendString(key_name); |
635 writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(challenge.data()), | 639 writer.AppendArrayOfBytes( |
636 challenge.size()); | 640 reinterpret_cast<const uint8_t*>(challenge.data()), challenge.size()); |
637 proxy_->CallMethod(&method_call, kTpmDBusTimeoutMs , | 641 proxy_->CallMethod(&method_call, kTpmDBusTimeoutMs , |
638 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, | 642 base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, |
639 weak_ptr_factory_.GetWeakPtr(), | 643 weak_ptr_factory_.GetWeakPtr(), |
640 callback)); | 644 callback)); |
641 } | 645 } |
642 | 646 |
643 // CryptohomeClient override. | 647 // CryptohomeClient override. |
644 void TpmAttestationGetKeyPayload( | 648 void TpmAttestationGetKeyPayload( |
645 attestation::AttestationKeyType key_type, | 649 attestation::AttestationKeyType key_type, |
646 const std::string& user_id, | 650 const std::string& user_id, |
(...skipping 21 matching lines...) Expand all Loading... |
668 const std::string& payload, | 672 const std::string& payload, |
669 const BoolDBusMethodCallback& callback) override { | 673 const BoolDBusMethodCallback& callback) override { |
670 dbus::MethodCall method_call( | 674 dbus::MethodCall method_call( |
671 cryptohome::kCryptohomeInterface, | 675 cryptohome::kCryptohomeInterface, |
672 cryptohome::kCryptohomeTpmAttestationSetKeyPayload); | 676 cryptohome::kCryptohomeTpmAttestationSetKeyPayload); |
673 dbus::MessageWriter writer(&method_call); | 677 dbus::MessageWriter writer(&method_call); |
674 bool is_user_specific = (key_type == attestation::KEY_USER); | 678 bool is_user_specific = (key_type == attestation::KEY_USER); |
675 writer.AppendBool(is_user_specific); | 679 writer.AppendBool(is_user_specific); |
676 writer.AppendString(user_id); | 680 writer.AppendString(user_id); |
677 writer.AppendString(key_name); | 681 writer.AppendString(key_name); |
678 writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(payload.data()), | 682 writer.AppendArrayOfBytes(reinterpret_cast<const uint8_t*>(payload.data()), |
679 payload.size()); | 683 payload.size()); |
680 CallBoolMethod(&method_call, callback); | 684 CallBoolMethod(&method_call, callback); |
681 } | 685 } |
682 | 686 |
683 // CryptohomeClient override. | 687 // CryptohomeClient override. |
684 void TpmAttestationDeleteKeys( | 688 void TpmAttestationDeleteKeys( |
685 attestation::AttestationKeyType key_type, | 689 attestation::AttestationKeyType key_type, |
686 const std::string& user_id, | 690 const std::string& user_id, |
687 const std::string& key_prefix, | 691 const std::string& key_prefix, |
688 const BoolDBusMethodCallback& callback) override { | 692 const BoolDBusMethodCallback& callback) override { |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 LOG(ERROR) << "Invalid response: " << response->ToString(); | 898 LOG(ERROR) << "Invalid response: " << response->ToString(); |
895 return; | 899 return; |
896 } | 900 } |
897 callback.Run(async_id); | 901 callback.Run(async_id); |
898 } | 902 } |
899 | 903 |
900 // Handles the result of GetSystemSalt(). | 904 // Handles the result of GetSystemSalt(). |
901 void OnGetSystemSalt(const GetSystemSaltCallback& callback, | 905 void OnGetSystemSalt(const GetSystemSaltCallback& callback, |
902 dbus::Response* response) { | 906 dbus::Response* response) { |
903 if (!response) { | 907 if (!response) { |
904 callback.Run(DBUS_METHOD_CALL_FAILURE, std::vector<uint8>()); | 908 callback.Run(DBUS_METHOD_CALL_FAILURE, std::vector<uint8_t>()); |
905 return; | 909 return; |
906 } | 910 } |
907 dbus::MessageReader reader(response); | 911 dbus::MessageReader reader(response); |
908 const uint8* bytes = NULL; | 912 const uint8_t* bytes = NULL; |
909 size_t length = 0; | 913 size_t length = 0; |
910 if (!reader.PopArrayOfBytes(&bytes, &length)) { | 914 if (!reader.PopArrayOfBytes(&bytes, &length)) { |
911 callback.Run(DBUS_METHOD_CALL_FAILURE, std::vector<uint8>()); | 915 callback.Run(DBUS_METHOD_CALL_FAILURE, std::vector<uint8_t>()); |
912 return; | 916 return; |
913 } | 917 } |
914 callback.Run(DBUS_METHOD_CALL_SUCCESS, | 918 callback.Run(DBUS_METHOD_CALL_SUCCESS, |
915 std::vector<uint8>(bytes, bytes + length)); | 919 std::vector<uint8_t>(bytes, bytes + length)); |
916 } | 920 } |
917 | 921 |
918 // Calls a method without result values. | 922 // Calls a method without result values. |
919 void CallVoidMethod(dbus::MethodCall* method_call, | 923 void CallVoidMethod(dbus::MethodCall* method_call, |
920 const VoidDBusMethodCallback& callback) { | 924 const VoidDBusMethodCallback& callback) { |
921 proxy_->CallMethod(method_call, kTpmDBusTimeoutMs , | 925 proxy_->CallMethod(method_call, kTpmDBusTimeoutMs , |
922 base::Bind(&CryptohomeClientImpl::OnVoidMethod, | 926 base::Bind(&CryptohomeClientImpl::OnVoidMethod, |
923 weak_ptr_factory_.GetWeakPtr(), | 927 weak_ptr_factory_.GetWeakPtr(), |
924 callback)); | 928 callback)); |
925 } | 929 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 } | 992 } |
989 | 993 |
990 // Handles responses for methods with a bool result and data. | 994 // Handles responses for methods with a bool result and data. |
991 void OnDataMethod(const DataMethodCallback& callback, | 995 void OnDataMethod(const DataMethodCallback& callback, |
992 dbus::Response* response) { | 996 dbus::Response* response) { |
993 if (!response) { | 997 if (!response) { |
994 callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string()); | 998 callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string()); |
995 return; | 999 return; |
996 } | 1000 } |
997 dbus::MessageReader reader(response); | 1001 dbus::MessageReader reader(response); |
998 const uint8* data_buffer = NULL; | 1002 const uint8_t* data_buffer = NULL; |
999 size_t data_length = 0; | 1003 size_t data_length = 0; |
1000 bool result = false; | 1004 bool result = false; |
1001 if (!reader.PopArrayOfBytes(&data_buffer, &data_length) || | 1005 if (!reader.PopArrayOfBytes(&data_buffer, &data_length) || |
1002 !reader.PopBool(&result)) { | 1006 !reader.PopBool(&result)) { |
1003 callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string()); | 1007 callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string()); |
1004 return; | 1008 return; |
1005 } | 1009 } |
1006 std::string data(reinterpret_cast<const char*>(data_buffer), data_length); | 1010 std::string data(reinterpret_cast<const char*>(data_buffer), data_length); |
1007 callback.Run(DBUS_METHOD_CALL_SUCCESS, result, data); | 1011 callback.Run(DBUS_METHOD_CALL_SUCCESS, result, data); |
1008 } | 1012 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 } | 1081 } |
1078 if (!async_call_status_handler_.is_null()) | 1082 if (!async_call_status_handler_.is_null()) |
1079 async_call_status_handler_.Run(async_id, return_status, return_code); | 1083 async_call_status_handler_.Run(async_id, return_status, return_code); |
1080 } | 1084 } |
1081 | 1085 |
1082 // Handles AsyncCallStatusWithData signal. | 1086 // Handles AsyncCallStatusWithData signal. |
1083 void OnAsyncCallStatusWithData(dbus::Signal* signal) { | 1087 void OnAsyncCallStatusWithData(dbus::Signal* signal) { |
1084 dbus::MessageReader reader(signal); | 1088 dbus::MessageReader reader(signal); |
1085 int async_id = 0; | 1089 int async_id = 0; |
1086 bool return_status = false; | 1090 bool return_status = false; |
1087 const uint8* return_data_buffer = NULL; | 1091 const uint8_t* return_data_buffer = NULL; |
1088 size_t return_data_length = 0; | 1092 size_t return_data_length = 0; |
1089 if (!reader.PopInt32(&async_id) || | 1093 if (!reader.PopInt32(&async_id) || |
1090 !reader.PopBool(&return_status) || | 1094 !reader.PopBool(&return_status) || |
1091 !reader.PopArrayOfBytes(&return_data_buffer, &return_data_length)) { | 1095 !reader.PopArrayOfBytes(&return_data_buffer, &return_data_length)) { |
1092 LOG(ERROR) << "Invalid signal: " << signal->ToString(); | 1096 LOG(ERROR) << "Invalid signal: " << signal->ToString(); |
1093 return; | 1097 return; |
1094 } | 1098 } |
1095 if (!async_call_status_data_handler_.is_null()) { | 1099 if (!async_call_status_data_handler_.is_null()) { |
1096 std::string return_data(reinterpret_cast<const char*>(return_data_buffer), | 1100 std::string return_data(reinterpret_cast<const char*>(return_data_buffer), |
1097 return_data_length); | 1101 return_data_length); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 return new CryptohomeClientImpl(); | 1137 return new CryptohomeClientImpl(); |
1134 } | 1138 } |
1135 | 1139 |
1136 // static | 1140 // static |
1137 std::string CryptohomeClient::GetStubSanitizedUsername( | 1141 std::string CryptohomeClient::GetStubSanitizedUsername( |
1138 const std::string& username) { | 1142 const std::string& username) { |
1139 return username + kUserIdStubHashSuffix; | 1143 return username + kUserIdStubHashSuffix; |
1140 } | 1144 } |
1141 | 1145 |
1142 } // namespace chromeos | 1146 } // namespace chromeos |
OLD | NEW |