diff --git a/chrome/browser/chromeos/policy/device_local_account_browsertest.cc b/chrome/browser/chromeos/policy/device_local_account_browsertest.cc index 5fa6f6bb7ae0e..0a25469212a06 100644 --- a/chrome/browser/chromeos/policy/device_local_account_browsertest.cc +++ b/chrome/browser/chromeos/policy/device_local_account_browsertest.cc @@ -356,6 +356,15 @@ class FakeCryptohomeClient : public chromeos::CryptohomeClient { const std::string& key_name, const std::string& challenge, const AsyncMethodCallback& callback) OVERRIDE {} + virtual void TpmAttestationGetKeyPayload( + AttestationKeyType key_type, + const std::string& key_name, + const DataMethodCallback& callback) OVERRIDE {} + virtual void TpmAttestationSetKeyPayload( + AttestationKeyType key_type, + const std::string& key_name, + const std::string& payload, + const chromeos::BoolDBusMethodCallback& callback) OVERRIDE {} private: AsyncCallStatusHandler handler_; diff --git a/chromeos/dbus/cryptohome_client.cc b/chromeos/dbus/cryptohome_client.cc index 27e8af0591d41..7bcbc4a338322 100644 --- a/chromeos/dbus/cryptohome_client.cc +++ b/chromeos/dbus/cryptohome_client.cc @@ -530,10 +530,12 @@ class CryptohomeClientImpl : public CryptohomeClient { writer.AppendBool(is_user_specific); writer.AppendString(key_name); writer.AppendString(domain); - writer.AppendString(device_id); + writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(device_id.data()), + device_id.size()); bool include_signed_public_key = (options & INCLUDE_SIGNED_PUBLIC_KEY); writer.AppendBool(include_signed_public_key); - writer.AppendString(challenge); + writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(challenge.data()), + challenge.size()); proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, weak_ptr_factory_.GetWeakPtr(), @@ -553,13 +555,50 @@ class CryptohomeClientImpl : public CryptohomeClient { bool is_user_specific = (key_type == USER_KEY); writer.AppendBool(is_user_specific); writer.AppendString(key_name); - writer.AppendString(challenge); + writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(challenge.data()), + challenge.size()); proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall, weak_ptr_factory_.GetWeakPtr(), callback)); } + // CryptohomeClient override. + virtual void TpmAttestationGetKeyPayload( + AttestationKeyType key_type, + const std::string& key_name, + const DataMethodCallback& callback) OVERRIDE { + dbus::MethodCall method_call( + cryptohome::kCryptohomeInterface, + cryptohome::kCryptohomeTpmAttestationGetKeyPayload); + dbus::MessageWriter writer(&method_call); + bool is_user_specific = (key_type == USER_KEY); + writer.AppendBool(is_user_specific); + writer.AppendString(key_name); + proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, + base::Bind(&CryptohomeClientImpl::OnDataMethod, + weak_ptr_factory_.GetWeakPtr(), + callback)); + } + + // CryptohomeClient override. + virtual void TpmAttestationSetKeyPayload( + AttestationKeyType key_type, + const std::string& key_name, + const std::string& payload, + const BoolDBusMethodCallback& callback) OVERRIDE { + dbus::MethodCall method_call( + cryptohome::kCryptohomeInterface, + cryptohome::kCryptohomeTpmAttestationSetKeyPayload); + dbus::MessageWriter writer(&method_call); + bool is_user_specific = (key_type == USER_KEY); + writer.AppendBool(is_user_specific); + writer.AppendString(key_name); + writer.AppendArrayOfBytes(reinterpret_cast<const uint8*>(payload.data()), + payload.size()); + CallBoolMethod(&method_call, callback); + } + private: // Handles the result of AsyncXXX methods. void OnAsyncMethodCall(const AsyncMethodCallback& callback, @@ -654,16 +693,15 @@ class CryptohomeClientImpl : public CryptohomeClient { return; } dbus::MessageReader reader(response); + uint8* data_buffer = NULL; + size_t data_length = 0; bool result = false; - if (!reader.PopBool(&result)) { - callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string()); - return; - } - std::string data; - if (!reader.PopString(&data)) { + if (!reader.PopArrayOfBytes(&data_buffer, &data_length) || + !reader.PopBool(&result)) { callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string()); return; } + std::string data(reinterpret_cast<char*>(data_buffer), data_length); callback.Run(DBUS_METHOD_CALL_SUCCESS, result, data); } @@ -1070,6 +1108,26 @@ class CryptohomeClientStubImpl : public CryptohomeClient { ReturnAsyncMethodResult(callback, true); } + virtual void TpmAttestationGetKeyPayload( + AttestationKeyType key_type, + const std::string& key_name, + const DataMethodCallback& callback) OVERRIDE { + MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string())); + } + + virtual void TpmAttestationSetKeyPayload( + AttestationKeyType key_type, + const std::string& key_name, + const std::string& payload, + const BoolDBusMethodCallback& callback) OVERRIDE { + MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); + } + + private: // Posts tasks which return fake results to the UI thread. void ReturnAsyncMethodResult(const AsyncMethodCallback& callback, diff --git a/chromeos/dbus/cryptohome_client.h b/chromeos/dbus/cryptohome_client.h index 7cc3c233b8388..d9ddf1b66ea0e 100644 --- a/chromeos/dbus/cryptohome_client.h +++ b/chromeos/dbus/cryptohome_client.h @@ -324,6 +324,25 @@ class CHROMEOS_EXPORT CryptohomeClient { const std::string& challenge, const AsyncMethodCallback& callback) = 0; + // Gets the payload associated with the key specified by |key_type| and + // |key_name|. The |callback| will be called when the operation completes. + // If the key does not exist the callback |result| parameter will be false. + // If no payload has been set for the key the callback |result| parameter will + // be true and the |data| parameter will be empty. + virtual void TpmAttestationGetKeyPayload( + AttestationKeyType key_type, + const std::string& key_name, + const DataMethodCallback& callback) = 0; + + // Sets the |payload| associated with the key specified by |key_type| and + // |key_name|. The |callback| will be called when the operation completes. + // If the operation succeeds, the callback |result| parameter will be true. + virtual void TpmAttestationSetKeyPayload( + AttestationKeyType key_type, + const std::string& key_name, + const std::string& payload, + const BoolDBusMethodCallback& callback) = 0; + protected: // Create() should be used instead. CryptohomeClient(); diff --git a/chromeos/dbus/mock_cryptohome_client.h b/chromeos/dbus/mock_cryptohome_client.h index 5a683704be82f..2563aac43629a 100644 --- a/chromeos/dbus/mock_cryptohome_client.h +++ b/chromeos/dbus/mock_cryptohome_client.h @@ -120,6 +120,15 @@ class MockCryptohomeClient : public CryptohomeClient { const std::string& key_name, const std::string& challenge, const AsyncMethodCallback& callback)); + MOCK_METHOD3(TpmAttestationGetKeyPayload, + void(AttestationKeyType key_type, + const std::string& key_name, + const DataMethodCallback& callback)); + MOCK_METHOD4(TpmAttestationSetKeyPayload, + void(AttestationKeyType key_type, + const std::string& key_name, + const std::string& payload, + const BoolDBusMethodCallback& callback)); }; } // namespace chromeos