Added dbus bindings for new cryptohomed attestation APIs.
The new APIs add support for associating arbitrary payloads with keys. Also fixed type mismatches for other recently added attestation APIs. BUG=chromium:219959 TEST=unit Review URL: https://chromiumcodereview.appspot.com/13818032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193718 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
chrome/browser/chromeos/policy
chromeos/dbus
@ -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_;
|
||||
|
@ -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,
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user