Add device path getters 44/160144/16
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 14 Nov 2017 13:23:55 +0000 (14:23 +0100)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 28 Nov 2017 15:34:57 +0000 (16:34 +0100)
Device path getters allow switching from old internal/external key API to new
generic key API (keys.h).

If external and (possibly) internal encryption APIs are modified to accept
device path as an argument instead of using hardcoded value these getters will
become unnecessary.

Change-Id: I78d288798a6cd267a7c6ee8d279d0d33a6813aab

14 files changed:
lib/external-encryption.cpp
lib/external-encryption.h
lib/internal-encryption.cpp
lib/internal-encryption.h
lib/ode/external-encryption.cpp
lib/ode/external-encryption.h
lib/ode/internal-encryption.cpp
lib/ode/internal-encryption.h
rmi/external-encryption.h
rmi/internal-encryption.h
server/external-encryption.cpp
server/external-encryption.h
server/internal-encryption.cpp
server/internal-encryption.h

index 6f9eae2..f370da5 100644 (file)
@@ -149,4 +149,13 @@ unsigned int ExternalEncryptionClient::getSupportedOptions()
        }
 }
 
+std::string ExternalEncryptionClient::getDevicePath() const
+{
+       try {
+               return context->methodCall<std::string>("ExternalEncryptionServer::getDevicePath");
+       } catch (runtime::Exception& e) {
+               return "";
+       }
+}
+
 } // namespace ode
index 705b740..6ff4f93 100644 (file)
@@ -49,6 +49,8 @@ public:
 
        unsigned int getSupportedOptions();
 
+       std::string getDevicePath() const;
+
 private:
        RmiClientPtr& context;
 };
index 7c0feb7..123c8f3 100644 (file)
@@ -149,4 +149,13 @@ unsigned int InternalEncryptionClient::getSupportedOptions()
        }
 }
 
+std::string InternalEncryptionClient::getDevicePath() const
+{
+       try {
+               return context->methodCall<std::string>("InternalEncryptionServer::getDevicePath");
+       } catch (runtime::Exception& e) {
+               return "";
+       }
+}
+
 } // namespace ode
index fe68ee5..882a464 100644 (file)
@@ -49,6 +49,8 @@ public:
 
        unsigned int getSupportedOptions();
 
+       std::string getDevicePath() const;
+
 private:
        RmiClientPtr& context;
 };
index 9b2efbc..930cbfe 100644 (file)
@@ -22,6 +22,8 @@
 #include "error-translation.h"
 #include "rmi/common.h"
 
+#include <string.h>
+
 using namespace ode;
 
 int ode_external_encryption_set_mount_password(const char* password)
@@ -207,3 +209,25 @@ int ode_external_encryption_unset_mount_event_cb()
 
        return ODE_ERROR_NONE;
 }
+
+/*
+ * TODO
+ * This API is required to move from old external key API to new generic one
+ * (see keys.h). The old API could be then removed. Next step could be to pass
+ * the device as argument to all functions as LUKS API does. If that happens
+ * this function will become unnecessary.
+ */
+int ode_external_encryption_get_device_path(char** device)
+{
+       RET_ON_FAILURE(device, ODE_ERROR_INVALID_PARAMETER);
+
+       ClientContext client;
+       RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+       ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
+       std::string path = external.getDevicePath();
+       if (path.empty())
+               return ODE_ERROR_UNKNOWN;
+
+       *device = strdup(path.c_str());
+       return ODE_ERROR_NONE;
+}
index 3556bab..bb9751d 100644 (file)
@@ -317,6 +317,21 @@ ODE_API int ode_external_encryption_set_mount_event_cb(ode_mount_event_cb callba
 ODE_API int ode_external_encryption_unset_mount_event_cb();
 
 /**
+ * @brief       Get the device path of external storage
+ * @details     Services can use this API to retrieve the path to external
+ *              storage device node.
+ * @since_tizen 4.0
+ * @param[out]  device The path to external storage device node. Caller is
+ *                     responsible for freeing it with free()
+ * @return      #ODE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #ODE_ERROR_NONE Successful
+ * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
+ */
+ODE_API int ode_external_encryption_get_device_path(char** device);
+
+/**
  * @}
  */
 
index 3840114..4935d07 100644 (file)
@@ -22,6 +22,8 @@
 #include "error-translation.h"
 #include "rmi/common.h"
 
+#include <string.h>
+
 using namespace ode;
 
 int ode_internal_encryption_set_mount_password(const char* password)
@@ -207,3 +209,25 @@ int ode_internal_encryption_unset_mount_event_cb()
 
        return ODE_ERROR_NONE;
 }
+
+/*
+ * TODO
+ * This API is required to move from old internal key API to new generic one
+ * (see keys.h). The old API could be then removed. Next step could be to pass
+ * the device as argument to all functions as LUKS API does. If that happens
+ * this function will become unnecessary.
+ */
+int ode_internal_encryption_get_device_path(char** device)
+{
+       RET_ON_FAILURE(device, ODE_ERROR_INVALID_PARAMETER);
+
+       ClientContext client;
+       RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+       InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
+       std::string path = internal.getDevicePath();
+       if (path.empty())
+               return ODE_ERROR_UNKNOWN;
+
+       *device = strdup(path.c_str());
+       return ODE_ERROR_NONE;
+}
index 6ef916e..c55f531 100644 (file)
@@ -316,6 +316,21 @@ ODE_API int ode_internal_encryption_set_mount_event_cb(ode_mount_event_cb callba
  */
 ODE_API int ode_internal_encryption_unset_mount_event_cb();
 
+/**
+ * @brief       Get the device path of internal storage
+ * @details     Services can use this API to retrieve the path to internal
+ *              storage device node.
+ * @since_tizen 4.0
+ * @param[out]  device The path to internal storage device node. Caller is
+ *                     responsible for freeing it with free()
+ * @return      #ODE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #ODE_ERROR_NONE Successful
+ * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #ODE_ERROR_CONNECTION_REFUSED Connection to server failed
+ * @retval      #ODE_ERROR_UNKNOWN Unknown error
+ */
+ODE_API int ode_internal_encryption_get_device_path(char** device);
+
 /*
  * @}
  */
index e2a577a..3643100 100644 (file)
@@ -60,6 +60,8 @@ public:
        };
 
        virtual unsigned int getSupportedOptions() = 0;
+
+       virtual std::string getDevicePath() const = 0;
 };
 
 } // namespace ode
index eb9f5ea..55d842d 100644 (file)
@@ -58,6 +58,8 @@ public:
        };
 
        virtual unsigned int getSupportedOptions() = 0;
+
+       virtual std::string getDevicePath() const = 0;
 };
 
 } // namespace ode
index 0a8d0bb..682de64 100644 (file)
@@ -199,6 +199,7 @@ ExternalEncryptionServer::ExternalEncryptionServer(ServerContext &srv,
        server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::verifyPassword)(std::string));
        server.expose(this, "", (int)(ExternalEncryptionServer::getState)());
        server.expose(this, "", (unsigned int)(ExternalEncryptionServer::getSupportedOptions)());
+       server.expose(this, "", (std::string)(ExternalEncryptionServer::getDevicePath)());
 
        server.createNotification("ExternalEncryptionServer::mount");
 
@@ -434,4 +435,9 @@ unsigned int ExternalEncryptionServer::getSupportedOptions()
        return engine->getSupportedOptions();
 }
 
+std::string ExternalEncryptionServer::getDevicePath() const
+{
+       return engine->getSource();
+}
+
 } // namespace ode
index bb4d9cc..6cff993 100644 (file)
@@ -57,6 +57,8 @@ public:
 
        unsigned int getSupportedOptions();
 
+       std::string getDevicePath() const;
+
 private:
        ServerContext& server;
 
index 0dfaf71..814d90f 100644 (file)
@@ -249,6 +249,7 @@ InternalEncryptionServer::InternalEncryptionServer(ServerContext& srv,
        server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::verifyPassword)(std::string));
        server.expose(this, "", (int)(InternalEncryptionServer::getState)());
        server.expose(this, "", (unsigned int)(InternalEncryptionServer::getSupportedOptions)());
+       server.expose(this, "", (std::string)(InternalEncryptionServer::getDevicePath)());
 
        server.createNotification("InternalEncryptionServer::mount");
 
@@ -513,4 +514,9 @@ unsigned int InternalEncryptionServer::getSupportedOptions()
        return engine->getSupportedOptions();
 }
 
+std::string InternalEncryptionServer::getDevicePath() const
+{
+       return engine->getSource();
+}
+
 } // namespace ode
index 480fd8c..f5e59ef 100644 (file)
@@ -54,6 +54,8 @@ public:
 
        unsigned int getSupportedOptions();
 
+       std::string getDevicePath() const;
+
 private:
        ServerContext& server;