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 6f9eae29a94d989f49678816f13f03a0c88580cb..f370da5ff8a40234b7efad72e9e0b4ae6e3894f2 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 705b7407454fc21101fa8d9059b07cd977ec1caa..6ff4f9376ff5f7a3b0e2874743da0a62f058452d 100644 (file)
@@ -49,6 +49,8 @@ public:
 
        unsigned int getSupportedOptions();
 
+       std::string getDevicePath() const;
+
 private:
        RmiClientPtr& context;
 };
index 7c0feb7d9787b78e2fce8dbf32d42a2065031527..123c8f3dd6306186cc1f16b6f9bf49deeaf51188 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 fe68ee5aa1d30c92750cd3b9a821f7789950a58f..882a464a9edb99d49669b6f3c3871d39f72f8c24 100644 (file)
@@ -49,6 +49,8 @@ public:
 
        unsigned int getSupportedOptions();
 
+       std::string getDevicePath() const;
+
 private:
        RmiClientPtr& context;
 };
index 9b2efbceddfbf40f30ffbca0d8f5fe8ba2579a56..930cbfe5e55b66a5b6e11d2b23c2ca7f1bb9c997 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 3556babd3558a9b784d9bbcd8024209673cec3c0..bb9751d50d2eb73a07c4093033e1fabace13411e 100644 (file)
@@ -316,6 +316,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 3840114a45a448470f59ac0258e43855a8bf9815..4935d073dca71ff282cd0c22c87e23e4e3b4fa50 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 6ef916e7f25f3a03a0361aeaefc3715f5f3a16ea..c55f531328ab9ce30012c8b1fc9873fc21db6eaf 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 e2a577a52f91a5ded97d29bb57d3e33cb11df321..36431000e2328db69a4f21417a7fb4b188400108 100644 (file)
@@ -60,6 +60,8 @@ public:
        };
 
        virtual unsigned int getSupportedOptions() = 0;
+
+       virtual std::string getDevicePath() const = 0;
 };
 
 } // namespace ode
index eb9f5ea699285a77301652d1e899b80da6692d13..55d842dde826fd3044a1d88988f1345bf791b3c6 100644 (file)
@@ -58,6 +58,8 @@ public:
        };
 
        virtual unsigned int getSupportedOptions() = 0;
+
+       virtual std::string getDevicePath() const = 0;
 };
 
 } // namespace ode
index 0a8d0bbe80b55d6e53a11af4b5d755d5cb2f16ef..682de644c18972d850db6a110686671102bfbfef 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 bb4d9cc74aff64a2e73c3e1d6379dc6dfa36f5fb..6cff993a92a40781e7805c769e0f0c70469acb9e 100644 (file)
@@ -57,6 +57,8 @@ public:
 
        unsigned int getSupportedOptions();
 
+       std::string getDevicePath() const;
+
 private:
        ServerContext& server;
 
index 0dfaf71d4d6006e7f090eb2865e258a960371932..814d90f16f5c629d6ebaa72c6d0fd4964aaf3d64 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 480fd8c91d787e7d200785c627e4a4cee1a96527..f5e59efcaa723f5a189008eb3d98dade28e83f35 100644 (file)
@@ -54,6 +54,8 @@ public:
 
        unsigned int getSupportedOptions();
 
+       std::string getDevicePath() const;
+
 private:
        ServerContext& server;