diff options
author | gspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-27 20:20:47 +0000 |
---|---|---|
committer | gspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-27 20:20:47 +0000 |
commit | ce3bcdc75450a607cb86f4776ffc31f4b647ca12 (patch) | |
tree | c0b1aba315115076f583ae045738239c9bb9651c /chromeos | |
parent | 2b61d94e705ff089f9327c801e435ca9b4d62638 (diff) | |
download | chromium_src-ce3bcdc75450a607cb86f4776ffc31f4b647ca12.zip chromium_src-ce3bcdc75450a607cb86f4776ffc31f4b647ca12.tar.gz chromium_src-ce3bcdc75450a607cb86f4776ffc31f4b647ca12.tar.bz2 |
Merge 183358
> This adds the remaining extension functions for networkingPrivate.
>
> BUG=chromium:172996
> TEST=ran new unit and browser tests.
>
>
> Review URL: https://chromiumcodereview.appspot.com/12286012
TBR=gspencer@chromium.org
Review URL: https://codereview.chromium.org/12358002
git-svn-id: svn://svn.chromium.org/chrome/branches/1410/src@185013 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r-- | chromeos/dbus/dbus_method_call_status.h | 5 | ||||
-rw-r--r-- | chromeos/dbus/mock_shill_manager_client.h | 25 | ||||
-rw-r--r-- | chromeos/dbus/shill_client_helper.cc | 317 | ||||
-rw-r--r-- | chromeos/dbus/shill_client_helper.h | 60 | ||||
-rw-r--r-- | chromeos/dbus/shill_client_unittest_base.cc | 14 | ||||
-rw-r--r-- | chromeos/dbus/shill_client_unittest_base.h | 9 | ||||
-rw-r--r-- | chromeos/dbus/shill_manager_client.cc | 65 | ||||
-rw-r--r-- | chromeos/dbus/shill_manager_client.h | 38 | ||||
-rw-r--r-- | chromeos/dbus/shill_manager_client_unittest.cc | 137 |
9 files changed, 499 insertions, 171 deletions
diff --git a/chromeos/dbus/dbus_method_call_status.h b/chromeos/dbus/dbus_method_call_status.h index 89cae4a..582849e 100644 --- a/chromeos/dbus/dbus_method_call_status.h +++ b/chromeos/dbus/dbus_method_call_status.h @@ -34,6 +34,11 @@ typedef base::Callback<void( DBusMethodCallStatus call_status, const std::string& result)> StringDBusMethodCallback; +// A callback to handle responses of methods returning a boolean value. +typedef base::Callback<void( + DBusMethodCallStatus call_status, + bool result)> BooleanDBusMethodCallback; + // A callback to handle responses of methods returning a ObjectPath value. typedef base::Callback<void( DBusMethodCallStatus call_status, diff --git a/chromeos/dbus/mock_shill_manager_client.h b/chromeos/dbus/mock_shill_manager_client.h index f27c066..5536870d 100644 --- a/chromeos/dbus/mock_shill_manager_client.h +++ b/chromeos/dbus/mock_shill_manager_client.h @@ -44,7 +44,32 @@ class MockShillManagerClient : public ShillManagerClient { MOCK_METHOD3(GetService, void(const base::DictionaryValue& properties, const ObjectPathCallback& callback, const ErrorCallback& error_callback)); + MOCK_METHOD7(VerifyDestination, void(const std::string& certificate, + const std::string& public_key, + const std::string& nonce, + const std::string& signed_data, + const std::string& device_serial, + const BooleanCallback& callback, + const ErrorCallback& error_callback)); + MOCK_METHOD8(VerifyAndSignCredentials, + void(const std::string& certificate, + const std::string& public_key, + const std::string& nonce, + const std::string& signed_data, + const std::string& device_serial, + const std::string& service_path, + const StringCallback& callback, + const ErrorCallback& error_callback)); + MOCK_METHOD8(VerifyAndSignData, void(const std::string& certificate, + const std::string& public_key, + const std::string& nonce, + const std::string& signed_data, + const std::string& device_serial, + const std::string& data, + const StringCallback& callback, + const ErrorCallback& error_callback)); MOCK_METHOD0(GetTestInterface, TestInterface*()); + }; } // namespace chromeos diff --git a/chromeos/dbus/shill_client_helper.cc b/chromeos/dbus/shill_client_helper.cc index e7c6dc8..b07b486 100644 --- a/chromeos/dbus/shill_client_helper.cc +++ b/chromeos/dbus/shill_client_helper.cc @@ -18,6 +18,157 @@ namespace { const char kInvalidResponseErrorName[] = ""; // No error name. const char kInvalidResponseErrorMessage[] = "Invalid response."; +void OnBooleanMethodWithErrorCallback( + const ShillClientHelper::BooleanCallback& callback, + const ShillClientHelper::ErrorCallback& error_callback, + dbus::Response* response) { + if (!response) { + error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); + return; + } + dbus::MessageReader reader(response); + bool result; + if (!reader.PopBool(&result)) { + error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); + return; + } + callback.Run(result); +} + +void OnStringMethodWithErrorCallback( + const ShillClientHelper::StringCallback& callback, + const ShillClientHelper::ErrorCallback& error_callback, + dbus::Response* response) { + if (!response) { + error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); + return; + } + dbus::MessageReader reader(response); + std::string result; + if (!reader.PopString(&result)) { + error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); + return; + } + callback.Run(result); +} + +// Handles responses for methods without results. +void OnVoidMethod(const VoidDBusMethodCallback& callback, + dbus::Response* response) { + if (!response) { + callback.Run(DBUS_METHOD_CALL_FAILURE); + return; + } + callback.Run(DBUS_METHOD_CALL_SUCCESS); +} + +// Handles responses for methods with ObjectPath results. +void OnObjectPathMethod( + const ObjectPathDBusMethodCallback& callback, + dbus::Response* response) { + if (!response) { + callback.Run(DBUS_METHOD_CALL_FAILURE, dbus::ObjectPath()); + return; + } + dbus::MessageReader reader(response); + dbus::ObjectPath result; + if (!reader.PopObjectPath(&result)) { + callback.Run(DBUS_METHOD_CALL_FAILURE, dbus::ObjectPath()); + return; + } + callback.Run(DBUS_METHOD_CALL_SUCCESS, result); +} + +// Handles responses for methods with ObjectPath results and no status. +void OnObjectPathMethodWithoutStatus( + const ObjectPathCallback& callback, + const ShillClientHelper::ErrorCallback& error_callback, + dbus::Response* response) { + if (!response) { + error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); + return; + } + dbus::MessageReader reader(response); + dbus::ObjectPath result; + if (!reader.PopObjectPath(&result)) { + error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); + return; + } + callback.Run(result); +} + +// Handles responses for methods with DictionaryValue results. +void OnDictionaryValueMethod( + const ShillClientHelper::DictionaryValueCallback& callback, + dbus::Response* response) { + if (!response) { + base::DictionaryValue result; + callback.Run(DBUS_METHOD_CALL_FAILURE, result); + return; + } + dbus::MessageReader reader(response); + scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); + base::DictionaryValue* result = NULL; + if (!value.get() || !value->GetAsDictionary(&result)) { + base::DictionaryValue result; + callback.Run(DBUS_METHOD_CALL_FAILURE, result); + return; + } + callback.Run(DBUS_METHOD_CALL_SUCCESS, *result); +} + +// Handles responses for methods without results. +void OnVoidMethodWithErrorCallback( + const base::Closure& callback, + dbus::Response* response) { + callback.Run(); +} + +// Handles responses for methods with DictionaryValue results. +// Used by CallDictionaryValueMethodWithErrorCallback(). +void OnDictionaryValueMethodWithErrorCallback( + const ShillClientHelper::DictionaryValueCallbackWithoutStatus& callback, + const ShillClientHelper::ErrorCallback& error_callback, + dbus::Response* response) { + dbus::MessageReader reader(response); + scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); + base::DictionaryValue* result = NULL; + if (!value.get() || !value->GetAsDictionary(&result)) { + error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); + return; + } + callback.Run(*result); +} + +// Handles responses for methods with ListValue results. +void OnListValueMethodWithErrorCallback( + const ShillClientHelper::ListValueCallback& callback, + const ShillClientHelper::ErrorCallback& error_callback, + dbus::Response* response) { + dbus::MessageReader reader(response); + scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); + base::ListValue* result = NULL; + if (!value.get() || !value->GetAsList(&result)) { + error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); + return; + } + callback.Run(*result); +} + +// Handles running appropriate error callbacks. +void OnError(const ShillClientHelper::ErrorCallback& error_callback, + dbus::ErrorResponse* response) { + std::string error_name; + std::string error_message; + if (response) { + // Error message may contain the error message as string. + dbus::MessageReader reader(response); + error_name = response->GetErrorName(); + reader.PopString(&error_message); + } + error_callback.Run(error_name, error_message); +} + } // namespace ShillClientHelper::ShillClientHelper(dbus::Bus* bus, @@ -76,8 +227,7 @@ void ShillClientHelper::CallVoidMethod( dbus::MethodCall* method_call, const VoidDBusMethodCallback& callback) { proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&ShillClientHelper::OnVoidMethod, - weak_ptr_factory_.GetWeakPtr(), + base::Bind(&OnVoidMethod, callback)); } @@ -85,8 +235,7 @@ void ShillClientHelper::CallObjectPathMethod( dbus::MethodCall* method_call, const ObjectPathDBusMethodCallback& callback) { proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&ShillClientHelper::OnObjectPathMethod, - weak_ptr_factory_.GetWeakPtr(), + base::Bind(&OnObjectPathMethod, callback)); } @@ -97,12 +246,10 @@ void ShillClientHelper::CallObjectPathMethodWithErrorCallback( proxy_->CallMethodWithErrorCallback( method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&ShillClientHelper::OnObjectPathMethodWithoutStatus, - weak_ptr_factory_.GetWeakPtr(), + base::Bind(&OnObjectPathMethodWithoutStatus, callback, error_callback), - base::Bind(&ShillClientHelper::OnError, - weak_ptr_factory_.GetWeakPtr(), + base::Bind(&OnError, error_callback)); } @@ -110,8 +257,7 @@ void ShillClientHelper::CallDictionaryValueMethod( dbus::MethodCall* method_call, const DictionaryValueCallback& callback) { proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&ShillClientHelper::OnDictionaryValueMethod, - weak_ptr_factory_.GetWeakPtr(), + base::Bind(&OnDictionaryValueMethod, callback)); } @@ -121,11 +267,35 @@ void ShillClientHelper::CallVoidMethodWithErrorCallback( const ErrorCallback& error_callback) { proxy_->CallMethodWithErrorCallback( method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&ShillClientHelper::OnVoidMethodWithErrorCallback, - weak_ptr_factory_.GetWeakPtr(), + base::Bind(&OnVoidMethodWithErrorCallback, callback), - base::Bind(&ShillClientHelper::OnError, - weak_ptr_factory_.GetWeakPtr(), + base::Bind(&OnError, + error_callback)); +} + +void ShillClientHelper::CallBooleanMethodWithErrorCallback( + dbus::MethodCall* method_call, + const BooleanCallback& callback, + const ErrorCallback& error_callback) { + proxy_->CallMethodWithErrorCallback( + method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, + base::Bind(&OnBooleanMethodWithErrorCallback, + callback, + error_callback), + base::Bind(&OnError, + error_callback)); +} + +void ShillClientHelper::CallStringMethodWithErrorCallback( + dbus::MethodCall* method_call, + const StringCallback& callback, + const ErrorCallback& error_callback) { + proxy_->CallMethodWithErrorCallback( + method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, + base::Bind(&OnStringMethodWithErrorCallback, + callback, + error_callback), + base::Bind(&OnError, error_callback)); } @@ -136,12 +306,10 @@ void ShillClientHelper::CallDictionaryValueMethodWithErrorCallback( proxy_->CallMethodWithErrorCallback( method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, base::Bind( - &ShillClientHelper::OnDictionaryValueMethodWithErrorCallback, - weak_ptr_factory_.GetWeakPtr(), + &OnDictionaryValueMethodWithErrorCallback, callback, error_callback), - base::Bind(&ShillClientHelper::OnError, - weak_ptr_factory_.GetWeakPtr(), + base::Bind(&OnError, error_callback)); } @@ -152,12 +320,10 @@ void ShillClientHelper::CallListValueMethodWithErrorCallback( proxy_->CallMethodWithErrorCallback( method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, base::Bind( - &ShillClientHelper::OnListValueMethodWithErrorCallback, - weak_ptr_factory_.GetWeakPtr(), + &OnListValueMethodWithErrorCallback, callback, error_callback), - base::Bind(&ShillClientHelper::OnError, - weak_ptr_factory_.GetWeakPtr(), + base::Bind(&OnError, error_callback)); } @@ -252,112 +418,5 @@ void ShillClientHelper::OnPropertyChanged(dbus::Signal* signal) { OnPropertyChanged(name, *value)); } -void ShillClientHelper::OnVoidMethod(const VoidDBusMethodCallback& callback, - dbus::Response* response) { - if (!response) { - callback.Run(DBUS_METHOD_CALL_FAILURE); - return; - } - callback.Run(DBUS_METHOD_CALL_SUCCESS); -} - -void ShillClientHelper::OnObjectPathMethod( - const ObjectPathDBusMethodCallback& callback, - dbus::Response* response) { - if (!response) { - callback.Run(DBUS_METHOD_CALL_FAILURE, dbus::ObjectPath()); - return; - } - dbus::MessageReader reader(response); - dbus::ObjectPath result; - if (!reader.PopObjectPath(&result)) { - callback.Run(DBUS_METHOD_CALL_FAILURE, dbus::ObjectPath()); - return; - } - callback.Run(DBUS_METHOD_CALL_SUCCESS, result); -} - -void ShillClientHelper::OnObjectPathMethodWithoutStatus( - const ObjectPathCallback& callback, - const ErrorCallback& error_callback, - dbus::Response* response) { - if (!response) { - error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); - return; - } - dbus::MessageReader reader(response); - dbus::ObjectPath result; - if (!reader.PopObjectPath(&result)) { - error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); - return; - } - callback.Run(result); -} - -void ShillClientHelper::OnDictionaryValueMethod( - const DictionaryValueCallback& callback, - dbus::Response* response) { - if (!response) { - base::DictionaryValue result; - callback.Run(DBUS_METHOD_CALL_FAILURE, result); - return; - } - dbus::MessageReader reader(response); - scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); - base::DictionaryValue* result = NULL; - if (!value.get() || !value->GetAsDictionary(&result)) { - base::DictionaryValue result; - callback.Run(DBUS_METHOD_CALL_FAILURE, result); - return; - } - callback.Run(DBUS_METHOD_CALL_SUCCESS, *result); -} - -void ShillClientHelper::OnVoidMethodWithErrorCallback( - const base::Closure& callback, - dbus::Response* response) { - callback.Run(); -} - -void ShillClientHelper::OnDictionaryValueMethodWithErrorCallback( - const DictionaryValueCallbackWithoutStatus& callback, - const ErrorCallback& error_callback, - dbus::Response* response) { - dbus::MessageReader reader(response); - scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); - base::DictionaryValue* result = NULL; - if (!value.get() || !value->GetAsDictionary(&result)) { - error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); - return; - } - callback.Run(*result); -} - -void ShillClientHelper::OnListValueMethodWithErrorCallback( - const ListValueCallback& callback, - const ErrorCallback& error_callback, - dbus::Response* response) { - dbus::MessageReader reader(response); - scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); - base::ListValue* result = NULL; - if (!value.get() || !value->GetAsList(&result)) { - error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); - return; - } - callback.Run(*result); -} - -void ShillClientHelper::OnError(const ErrorCallback& error_callback, - dbus::ErrorResponse* response) { - std::string error_name; - std::string error_message; - if (response) { - // Error message may contain the error message as string. - dbus::MessageReader reader(response); - error_name = response->GetErrorName(); - reader.PopString(&error_message); - } - error_callback.Run(error_name, error_message); -} } // namespace chromeos diff --git a/chromeos/dbus/shill_client_helper.h b/chromeos/dbus/shill_client_helper.h index 1036015..cb796f1 100644 --- a/chromeos/dbus/shill_client_helper.h +++ b/chromeos/dbus/shill_client_helper.h @@ -62,6 +62,13 @@ class ShillClientHelper { typedef base::Callback<void(const std::string& error_name, const std::string& error_message)> ErrorCallback; + // A callback that handles responses for methods with string results. + typedef base::Callback<void(const std::string& result)> StringCallback; + + // A callback that handles responses for methods with boolean results. + typedef base::Callback<void(bool result)> BooleanCallback; + + ShillClientHelper(dbus::Bus* bus, dbus::ObjectProxy* proxy); virtual ~ShillClientHelper(); @@ -100,6 +107,18 @@ class ShillClientHelper { const base::Closure& callback, const ErrorCallback& error_callback); + // Calls a method with a boolean result with error callback. + void CallBooleanMethodWithErrorCallback( + dbus::MethodCall* method_call, + const BooleanCallback& callback, + const ErrorCallback& error_callback); + + // Calls a method with a string result with error callback. + void CallStringMethodWithErrorCallback(dbus::MethodCall* method_call, + const StringCallback& callback, + const ErrorCallback& error_callback); + + // Calls a method with a dictionary value result with error callback. void CallDictionaryValueMethodWithErrorCallback( dbus::MethodCall* method_call, @@ -138,47 +157,6 @@ class ShillClientHelper { // Handles PropertyChanged signal. void OnPropertyChanged(dbus::Signal* signal); - // Handles responses for methods without results. - void OnVoidMethod(const VoidDBusMethodCallback& callback, - dbus::Response* response); - - // Handles responses for methods with ObjectPath results. - void OnObjectPathMethod(const ObjectPathDBusMethodCallback& callback, - dbus::Response* response); - - // Handles responses for methods with ObjectPath results. - void OnObjectPathMethodWithoutStatus( - const ObjectPathCallback& callback, - const ErrorCallback& error_callback, - dbus::Response* response); - - // Handles responses for methods with DictionaryValue results. - void OnDictionaryValueMethod(const DictionaryValueCallback& callback, - dbus::Response* response); - - // Handles responses for methods without results. - // Used by CallVoidMethodWithErrorCallback(). - void OnVoidMethodWithErrorCallback(const base::Closure& callback, - dbus::Response* response); - - // Handles responses for methods with DictionaryValue results. - // Used by CallDictionaryValueMethodWithErrorCallback(). - void OnDictionaryValueMethodWithErrorCallback( - const DictionaryValueCallbackWithoutStatus& callback, - const ErrorCallback& error_callback, - dbus::Response* response); - - // Handles responses for methods with Boolean array results. - // Used by CallBooleanArrayMethodWithErrorCallback(). - void OnListValueMethodWithErrorCallback( - const ListValueCallback& callback, - const ErrorCallback& error_callback, - dbus::Response* response); - - // Handles errors for method calls. - void OnError(const ErrorCallback& error_callback, - dbus::ErrorResponse* response); - // TODO(hashimoto): Remove this when we no longer need to make blocking calls. BlockingMethodCaller blocking_method_caller_; dbus::ObjectProxy* proxy_; diff --git a/chromeos/dbus/shill_client_unittest_base.cc b/chromeos/dbus/shill_client_unittest_base.cc index 72906e5..1fa9b7f 100644 --- a/chromeos/dbus/shill_client_unittest_base.cc +++ b/chromeos/dbus/shill_client_unittest_base.cc @@ -254,6 +254,20 @@ void ShillClientUnittestBase::ExpectObjectPathResultWithoutStatus( } // static +void ShillClientUnittestBase::ExpectBoolResultWithoutStatus( + bool expected_result, + bool result) { + EXPECT_EQ(expected_result, result); +} + +// static +void ShillClientUnittestBase::ExpectStringResultWithoutStatus( + const std::string& expected_result, + const std::string& result) { + EXPECT_EQ(expected_result, result); +} + +// static void ShillClientUnittestBase::ExpectDictionaryValueResultWithoutStatus( const base::DictionaryValue* expected_result, const base::DictionaryValue& result) { diff --git a/chromeos/dbus/shill_client_unittest_base.h b/chromeos/dbus/shill_client_unittest_base.h index f893bfd..61d4ce0 100644 --- a/chromeos/dbus/shill_client_unittest_base.h +++ b/chromeos/dbus/shill_client_unittest_base.h @@ -151,11 +151,18 @@ class ShillClientUnittestBase : public testing::Test { DBusMethodCallStatus call_status, const dbus::ObjectPath& result); - // Checks the result and expects the call status to be SUCCESS. static void ExpectObjectPathResultWithoutStatus( const dbus::ObjectPath& expected_result, const dbus::ObjectPath& result); + static void ExpectBoolResultWithoutStatus( + bool expected_result, + bool result); + + static void ExpectStringResultWithoutStatus( + const std::string& expected_result, + const std::string& result); + // Checks the result and expects the call status to be SUCCESS. static void ExpectDictionaryValueResult( const base::DictionaryValue* expected_result, diff --git a/chromeos/dbus/shill_manager_client.cc b/chromeos/dbus/shill_manager_client.cc index 4e89c69..2a9723d 100644 --- a/chromeos/dbus/shill_manager_client.cc +++ b/chromeos/dbus/shill_manager_client.cc @@ -168,6 +168,71 @@ class ShillManagerClientImpl : public ShillManagerClient { error_callback); } + virtual void VerifyDestination(const std::string& certificate, + const std::string& public_key, + const std::string& nonce, + const std::string& signed_data, + const std::string& device_serial, + const BooleanCallback& callback, + const ErrorCallback& error_callback) OVERRIDE { + dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, + shill::kVerifyDestinationFunction); + dbus::MessageWriter writer(&method_call); + writer.AppendString(certificate); + writer.AppendString(public_key); + writer.AppendString(nonce); + writer.AppendString(signed_data); + writer.AppendString(device_serial); + helper_.CallBooleanMethodWithErrorCallback(&method_call, + callback, + error_callback); + } + + virtual void VerifyAndSignCredentials( + const std::string& certificate, + const std::string& public_key, + const std::string& nonce, + const std::string& signed_data, + const std::string& device_serial, + const std::string& service_path, + const StringCallback& callback, + const ErrorCallback& error_callback) OVERRIDE { + dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, + shill::kVerifyAndSignCredentialsFunction); + dbus::MessageWriter writer(&method_call); + writer.AppendString(certificate); + writer.AppendString(public_key); + writer.AppendString(nonce); + writer.AppendString(signed_data); + writer.AppendString(device_serial); + writer.AppendObjectPath(dbus::ObjectPath(service_path)); + helper_.CallStringMethodWithErrorCallback(&method_call, + callback, + error_callback); + } + + virtual void VerifyAndSignData(const std::string& certificate, + const std::string& public_key, + const std::string& nonce, + const std::string& signed_data, + const std::string& device_serial, + const std::string& data, + const StringCallback& callback, + const ErrorCallback& error_callback) OVERRIDE { + dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, + shill::kVerifyAndSignDataFunction); + dbus::MessageWriter writer(&method_call); + writer.AppendString(certificate); + writer.AppendString(public_key); + writer.AppendString(nonce); + writer.AppendString(signed_data); + writer.AppendString(device_serial); + writer.AppendString(data); + helper_.CallStringMethodWithErrorCallback(&method_call, + callback, + error_callback); + } + virtual TestInterface* GetTestInterface() OVERRIDE { return NULL; } diff --git a/chromeos/dbus/shill_manager_client.h b/chromeos/dbus/shill_manager_client.h index f191753..473efc0 100644 --- a/chromeos/dbus/shill_manager_client.h +++ b/chromeos/dbus/shill_manager_client.h @@ -31,6 +31,8 @@ class CHROMEOS_EXPORT ShillManagerClient { typedef ShillClientHelper::PropertyChangedHandler PropertyChangedHandler; typedef ShillClientHelper::DictionaryValueCallback DictionaryValueCallback; typedef ShillClientHelper::ErrorCallback ErrorCallback; + typedef ShillClientHelper::StringCallback StringCallback; + typedef ShillClientHelper::BooleanCallback BooleanCallback; // Interface for setting up devices, services, and technologies for testing. // Accessed through GetTestInterface(), only implemented in the Stub Impl. @@ -126,6 +128,42 @@ class CHROMEOS_EXPORT ShillManagerClient { const ObjectPathCallback& callback, const ErrorCallback& error_callback) = 0; + // Verify that the given data corresponds to a trusted device, and return true + // to the callback if it is. + virtual void VerifyDestination(const std::string& certificate, + const std::string& public_key, + const std::string& nonce, + const std::string& signed_data, + const std::string& device_serial, + const BooleanCallback& callback, + const ErrorCallback& error_callback) = 0; + + // Verify that the given data corresponds to a trusted device, and if it is, + // return the encrypted credentials for connecting to the network represented + // by the given |service_path|, encrypted using the |public_key| for the + // trusted device. If the device is not trusted, return the empty string. + virtual void VerifyAndSignCredentials( + const std::string& certificate, + const std::string& public_key, + const std::string& nonce, + const std::string& signed_data, + const std::string& device_serial, + const std::string& service_path, + const StringCallback& callback, + const ErrorCallback& error_callback) = 0; + + // Verify that the given data corresponds to a trusted device, and return the + // |data| encrypted using the |public_key| for the trusted device. If the + // device is not trusted, return the empty string. + virtual void VerifyAndSignData(const std::string& certificate, + const std::string& public_key, + const std::string& nonce, + const std::string& signed_data, + const std::string& device_serial, + const std::string& data, + const StringCallback& callback, + const ErrorCallback& error_callback) = 0; + // Returns an interface for testing (stub only), or returns NULL. virtual TestInterface* GetTestInterface() = 0; diff --git a/chromeos/dbus/shill_manager_client_unittest.cc b/chromeos/dbus/shill_manager_client_unittest.cc index e98d62f..9ba2dd3 100644 --- a/chromeos/dbus/shill_manager_client_unittest.cc +++ b/chromeos/dbus/shill_manager_client_unittest.cc @@ -97,6 +97,34 @@ base::DictionaryValue* CreateExampleProperties() { return properties; } +void ExpectStringArguments(const std::vector<std::string>& arguments, + dbus::MessageReader* reader) { + for (std::vector<std::string>::const_iterator iter = arguments.begin(); + iter != arguments.end(); ++iter) { + std::string arg_string; + ASSERT_TRUE(reader->PopString(&arg_string)); + EXPECT_EQ(*iter, arg_string); + } + EXPECT_FALSE(reader->HasMoreData()); +} + +void ExpectStringArgumentsFollowedByObjectPath( + const std::vector<std::string>& arguments, + const dbus::ObjectPath& object_path, + dbus::MessageReader* reader) { + for (std::vector<std::string>::const_iterator iter = arguments.begin(); + iter != arguments.end(); ++iter) { + std::string arg_string; + ASSERT_TRUE(reader->PopString(&arg_string)); + EXPECT_EQ(*iter, arg_string); + } + dbus::ObjectPath path; + ASSERT_TRUE(reader->PopObjectPath(&path)); + EXPECT_EQ(object_path, path); + EXPECT_FALSE(reader->HasMoreData()); +} + + } // namespace class ShillManagerClientTest : public ShillClientUnittestBase { @@ -392,4 +420,113 @@ TEST_F(ShillManagerClientTest, GetService) { message_loop_.RunUntilIdle(); } +TEST_F(ShillManagerClientTest, VerifyDestination) { + // Create response. + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + dbus::MessageWriter writer(response.get()); + bool expected = true; + writer.AppendBool(expected); + // Set expectations. + std::vector<std::string> arguments; + arguments.push_back("certificate"); + arguments.push_back("public_key"); + arguments.push_back("nonce"); + arguments.push_back("signed_data"); + arguments.push_back("device_serial"); + PrepareForMethodCall(shill::kVerifyDestinationFunction, + base::Bind(&ExpectStringArguments, arguments), + response.get()); + + + // Call method. + MockErrorCallback mock_error_callback; + client_->VerifyDestination(arguments[0], + arguments[1], + arguments[2], + arguments[3], + arguments[4], + base::Bind(&ExpectBoolResultWithoutStatus, + expected), + mock_error_callback.GetCallback()); + EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); + + // Run the message loop. + message_loop_.RunUntilIdle(); +} + +TEST_F(ShillManagerClientTest, VerifyAndSignCredentials) { + // Create response. + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + dbus::MessageWriter writer(response.get()); + std::string expected = "encrypted_credentials"; + writer.AppendString(expected); + // Set expectations. + std::vector<std::string> arguments; + arguments.push_back("certificate"); + arguments.push_back("public_key"); + arguments.push_back("nonce"); + arguments.push_back("signed_data"); + arguments.push_back("device_serial"); + std::string service_path = "/"; + dbus::ObjectPath service_path_obj(service_path); + PrepareForMethodCall(shill::kVerifyAndSignCredentialsFunction, + base::Bind(&ExpectStringArgumentsFollowedByObjectPath, + arguments, + service_path_obj), + response.get()); + + + // Call method. + MockErrorCallback mock_error_callback; + client_->VerifyAndSignCredentials(arguments[0], + arguments[1], + arguments[2], + arguments[3], + arguments[4], + service_path, + base::Bind(&ExpectStringResultWithoutStatus, + expected), + mock_error_callback.GetCallback()); + EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); + + // Run the message loop. + message_loop_.RunUntilIdle(); +} + +TEST_F(ShillManagerClientTest, VerifyAndSignData) { + // Create response. + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + dbus::MessageWriter writer(response.get()); + std::string expected = "encrypted_data"; + writer.AppendString(expected); + // Set expectations. + std::vector<std::string> arguments; + arguments.push_back("certificate"); + arguments.push_back("public_key"); + arguments.push_back("nonce"); + arguments.push_back("signed_data"); + arguments.push_back("device_serial"); + arguments.push_back("data"); + PrepareForMethodCall(shill::kVerifyAndSignDataFunction, + base::Bind(&ExpectStringArguments, arguments), + response.get()); + + + // Call method. + MockErrorCallback mock_error_callback; + client_->VerifyAndSignData(arguments[0], + arguments[1], + arguments[2], + arguments[3], + arguments[4], + arguments[5], + base::Bind(&ExpectStringResultWithoutStatus, + expected), + mock_error_callback.GetCallback()); + EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); + + // Run the message loop. + message_loop_.RunUntilIdle(); +} + } // namespace chromeos |