Modify to split mount API into 2 APIs - set mount password, just mount 37/121637/1
authorSungbae Yoo <sungbae.yoo@samsung.com>
Tue, 28 Mar 2017 09:35:25 +0000 (18:35 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Tue, 28 Mar 2017 09:39:13 +0000 (18:39 +0900)
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Change-Id: I7af3071bad3fd673115fe5db25bf3887b387b13f

14 files changed:
lib/external-encryption.cpp
lib/internal-encryption.cpp
lib/ode/common.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/internal-encryption.cpp
tools/apps/lockscreen/src/ui.c
tools/apps/ode/src/password/password.c
tools/cli/ode-admin-cli.cpp

index fd0308c4c26040ed387d8692f3a7bd4ea3b17ab9..5fcb4afbd5954b9e258a4445ac57a0d6d3a873e5 100644 (file)
@@ -26,10 +26,19 @@ ExternalEncryption::~ExternalEncryption()
 {
 }
 
-int ExternalEncryption::mount(const std::string& password)
+int ExternalEncryption::setMountPassword(const std::string& password)
 {
        try {
-               return context->methodCall<int>("ExternalEncryption::mount", password);
+               return context->methodCall<int>("ExternalEncryption::setMountPassword", password);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int ExternalEncryption::mount()
+{
+       try {
+               return context->methodCall<int>("ExternalEncryption::mount");
        } catch (runtime::Exception& e) {
                return -1;
        }
index c1bf9e35a0f9f4193045ffce11395f6d45b3db65..7b5aed127def39dd40acb62253765c8a27655b8c 100644 (file)
@@ -26,10 +26,19 @@ InternalEncryption::~InternalEncryption()
 {
 }
 
-int InternalEncryption::mount(const std::string& password)
+int InternalEncryption::setMountPassword(const std::string& password)
 {
        try {
-               return context->methodCall<int>("InternalEncryption::mount", password);
+               return context->methodCall<int>("InternalEncryption::setMountPassword", password);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int InternalEncryption::mount()
+{
+       try {
+               return context->methodCall<int>("InternalEncryption::mount");
        } catch (runtime::Exception& e) {
                return -1;
        }
index d0f89ccae90a82fa8e0129c761235420ac7475d2..3d07bcc4606f8a9270ced9939e7158a684e673b9 100644 (file)
@@ -60,7 +60,8 @@ typedef enum {
        ODE_ERROR_FILE_EXISTS          = TIZEN_ERROR_FILE_EXISTS,          /**< File exists */
        ODE_ERROR_OUT_OF_MEMORY        = TIZEN_ERROR_OUT_OF_MEMORY,        /**< Out of memory */
        ODE_ERROR_NOT_PERMITTED        = TIZEN_ERROR_NOT_PERMITTED,        /**< Operation is not permitted */
-       ODE_ERROR_KEY_REJECTED         = TIZEN_ERROR_KEY_REJECTED          /**< Passwor is rejected */
+       ODE_ERROR_KEY_REJECTED         = TIZEN_ERROR_KEY_REJECTED,         /**< Passwor is rejected */
+       ODE_ERROR_NO_DATA              = TIZEN_ERROR_NO_DATA               /**< No Data */
 } ode_error_type_e;
 
 /*
index 35fe505d24f250c27f702978ce1bd7820c1f8433..eae3ecbad92653e1a0623c6bb0bd557115597077 100644 (file)
@@ -22,7 +22,7 @@
 
 using namespace ode;
 
-int ode_external_encryption_mount(const char* password)
+int ode_external_encryption_set_mount_password(const char* password)
 {
        RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
 
@@ -30,7 +30,16 @@ int ode_external_encryption_mount(const char* password)
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryption external = client.createInterface<ExternalEncryption>();
 
-       return external.mount(password);
+       return external.setMountPassword(password);
+}
+
+int ode_external_encryption_mount()
+{
+       ODEContext client;
+       RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+       ExternalEncryption external = client.createInterface<ExternalEncryption>();
+
+       return external.mount();
 }
 
 int ode_external_encryption_umount()
index b156f74bef451f2d80d545fca82746d546c42989..624832d71eef9b345719370f0d49ec2680488b1c 100644 (file)
@@ -30,9 +30,9 @@ extern "C" {
 #endif
 
 /**
- * @brief       Mount external storage with encryption by given password.
- * @details     Administrator can use this API to mount encrypted external
- *              storage.
+ * @brief       Set a password to be used by mount of encrypted external storage
+ * @details     Administrator can use this API to set a password for external
+ *              mount external storage with encryption.
  * @since_tizen 3.0
  * @param[in]   password The password to mount external storage
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
@@ -40,15 +40,34 @@ extern "C" {
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval      #ODE_ERROR_TIMED_OUT Time out
  * @retval      #ODE_ERROR_KEY_REJECTED Password doen't match
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
  * @pre         The password must match with what is set by
  *              ode_external_encryption_init_password().
- * @see         ode_external_encryption_encrypt()
+ * @see         ode_external_encryption_init_password()
+ * @see         ode_external_encryption_mount()
+ */
+ODE_API int ode_external_encryption_set_mount_password(const char* password);
+
+/**
+ * @brief       Mount external storage with encryption
+ * @details     Administrator can use this API to mount encrypted external
+ *              storage.
+ * @since_tizen 3.0
+ * @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_TIMED_OUT Time out
+ * @retval      #ODE_ERROR_NO_DATA Password isn't set
+ * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         A password must be set by
+ *              ode_external_encryption_set_mount_password().
+ * @see         ode_external_encryption_set_mount_password()
  * @see         ode_external_encryption_umount()
  */
-ODE_API int ode_external_encryption_mount(const char* password);
+ODE_API int ode_external_encryption_mount();
 
 /**
  * @brief       Umount external storage
index 527174df9374f0f87fe76be0b8a5a58afeec351d..095a75a9bcd3081a583d134781cdbf92e9e1bb39 100644 (file)
@@ -22,7 +22,7 @@
 
 using namespace ode;
 
-int ode_internal_encryption_mount(const char* password)
+int ode_internal_encryption_set_mount_password(const char* password)
 {
        RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
 
@@ -30,7 +30,16 @@ int ode_internal_encryption_mount(const char* password)
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryption internal = client.createInterface<InternalEncryption>();
 
-       return internal.mount(password);
+       return internal.setMountPassword(password);
+}
+
+int ode_internal_encryption_mount()
+{
+       ODEContext client;
+       RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+       InternalEncryption internal = client.createInterface<InternalEncryption>();
+
+       return internal.mount();
 }
 
 int ode_internal_encryption_umount()
index 94eb681b8c37e1835d5c609bd1992737209950f9..17ad2539e5ec80e9e193f493e0deac424d869d13 100644 (file)
@@ -29,9 +29,9 @@ extern "C" {
 #endif
 
 /**
- * @brief       Mount internal storage with encryption by given password.
- * @details     Administrator can use this API to mount encrypted internal
- *              storage.
+ * @brief       Set a password to be used by mount of encrypted internal storage
+ * @details     Administrator can use this API to set a password for internal
+ *              mount internal storage with encryption.
  * @since_tizen 3.0
  * @param[in]   password The password to mount internal storage
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
@@ -39,15 +39,34 @@ extern "C" {
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval      #ODE_ERROR_TIMED_OUT Time out
  * @retval      #ODE_ERROR_KEY_REJECTED Password doen't match
- * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
- * @pre         The password must match with what is set by
+ * @pre         The password set before must match with what is set by
  *              ode_internal_encryption_init_password().
- * @see         ode_internal_encryption_encrypt()
+ * @see         ode_internal_encryption_init_password()
+ * @see         ode_internal_encryption_mount()
+ */
+ODE_API int ode_internal_encryption_set_mount_password(const char* password);
+
+/**
+ * @brief       Mount internal storage with encryption
+ * @details     Administrator can use this API to mount encrypted internal
+ *              storage.
+ * @since_tizen 3.0
+ * @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_TIMED_OUT Time out
+ * @retval      #ODE_ERROR_NO_DATA Password isn't set
+ * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         A password must be set by
+ *              ode_internal_encryption_set_mount_password().
+ * @see         ode_internal_encryption_set_mount_password()
  * @see         ode_internal_encryption_umount()
  */
-ODE_API int ode_internal_encryption_mount(const char* password);
+ODE_API int ode_internal_encryption_mount();
 
 /**
  * @brief       Umount internal storage
index b935018e6a6d32c3072b5ec45a2f7ddc36165f56..5223413e6fd87771e82d68eeb54e641ce1871322 100644 (file)
@@ -31,9 +31,9 @@ public:
        ExternalEncryption(ODEControlContext& ctxt);
        ~ExternalEncryption();
 
-       unsigned int getSupportedOptions();
+       int setMountPassword(const std::string& password);
 
-       int mount(const std::string& password);
+       int mount();
        int umount();
 
        int encrypt(const std::string& password, unsigned int options);
@@ -60,6 +60,8 @@ public:
                ExceptForMediaFile = 1 << 1,
        };
 
+       unsigned int getSupportedOptions();
+
 private:
        ODEControlContext& context;
 };
index 8b04e8212df069ca5ac57fed90780dd3e47d6b08..2c8ed9e92fa9d30fdd89b21198d60f8651f9d0b9 100644 (file)
@@ -30,7 +30,9 @@ public:
        InternalEncryption(ODEControlContext& ctxt);
        ~InternalEncryption();
 
-       int mount(const std::string& password);
+       int setMountPassword(const std::string& password);
+
+       int mount();
        int umount();
 
        int encrypt(const std::string& password, unsigned int options);
index 003390402cec9599eec44e9b27acab909bf02710..6185a21ab70bd16ae966d8c22b3287c2ba249fb4 100644 (file)
@@ -51,6 +51,7 @@ namespace ode {
 namespace {
 
 std::unique_ptr<EXTERNAL_ENGINE> engine;
+KeyManager::data mountKey;
 
 void killDependedApplications()
 {
@@ -159,7 +160,8 @@ void setOptions(unsigned int options)
 ExternalEncryption::ExternalEncryption(ODEControlContext &ctx) :
        context(ctx)
 {
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryption::mount)(std::string));
+       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryption::setMountPassword)(std::string));
+       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryption::mount)());
        context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryption::umount)());
        context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryption::encrypt)(std::string, unsigned int));
        context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryption::decrypt)(std::string));
@@ -188,17 +190,24 @@ ExternalEncryption::~ExternalEncryption()
 {
 }
 
-int ExternalEncryption::mount(const std::string &password)
+
+int ExternalEncryption::setMountPassword(const std::string& password)
 {
-       if (getState() != State::Encrypted) {
-               return -1;
+       KeyManager::data pwData(password.begin(), password.end());
+       KeyManager keyManager(engine->getKeyMeta());
+       if (!keyManager.verifyPassword(pwData)) {
+               return -2;
        }
 
-       KeyManager::data data(password.begin(), password.end());
-       KeyManager keyManager(engine->getKeyMeta());
+       ode::mountKey = keyManager.getMasterKey(pwData);
 
-       if (!keyManager.verifyPassword(data)) {
-               return -2;
+       return 0;
+}
+
+int ExternalEncryption::mount()
+{
+       if (getState() != State::Encrypted) {
+               return -1;
        }
 
        if (engine->isMounted()) {
@@ -206,7 +215,9 @@ int ExternalEncryption::mount(const std::string &password)
                return 0;
        }
 
-       engine->mount(keyManager.getMasterKey(data), getOptions());
+       engine->mount(mountKey, getOptions());
+       mountKey.clear();
+
        context.notify("ExternalEncryption::mount");
 
        return 0;
index 63c0f2460f8150e41a167e7642ea64b53104caf5..e9e40e99ec0fe4f115a23b3eb642239abf476bef 100644 (file)
@@ -59,6 +59,7 @@ namespace ode {
 namespace {
 
 std::unique_ptr<INTERNAL_ENGINE> engine;
+KeyManager::data mountKey;
 
 void stopSystemdUserSessions() {
        std::vector<std::string> userSessionServices;
@@ -194,7 +195,8 @@ void setOptions(unsigned int options)
 InternalEncryption::InternalEncryption(ODEControlContext& ctx) :
        context(ctx)
 {
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryption::mount)(std::string));
+       context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryption::setMountPassword)(std::string));
+       context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryption::mount)());
        context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryption::umount)());
        context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryption::encrypt)(std::string, unsigned int));
        context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryption::decrypt)(std::string));
@@ -221,25 +223,33 @@ InternalEncryption::~InternalEncryption()
 {
 }
 
-int InternalEncryption::mount(const std::string& password)
+int InternalEncryption::setMountPassword(const std::string& password)
 {
-       if (getState() != State::Encrypted) {
-               return -1;
-       }
-
        KeyManager::data pwData(password.begin(), password.end());
        KeyManager keyManager(engine->getKeyMeta());
-
        if (!keyManager.verifyPassword(pwData)) {
                return -2;
        }
 
+       ode::mountKey = keyManager.getMasterKey(pwData);
+
+       return 0;
+}
+
+int InternalEncryption::mount()
+{
+       if (getState() != State::Encrypted) {
+               return -1;
+       }
+
     if (engine->isMounted()) {
                INFO("Already mounted");
                return 0;
        }
 
-       engine->mount(keyManager.getMasterKey(pwData), getOptions());
+       engine->mount(mountKey, getOptions());
+       mountKey.clear();
+
        context.notify("InternalEncryption::mount");
 
        return 0;
index e110b9c8f5639563b3eb991c7927b1effaa9201b..dacd897608572e636f20c1e145afe0b1511504fc 100644 (file)
@@ -31,7 +31,8 @@ static int verify_password(Evas_Object *layout)
        ode_internal_encryption_verify_password(key, &result);
        if (result) {
                dlog_print(DLOG_ERROR, LOG_TAG, "Correct password.");
-               ode_internal_encryption_mount(key);
+               ode_internal_encryption_set_mount_password(key);
+               ode_internal_encryption_mount();
                exit(0);
        } else {
                dlog_print(DLOG_ERROR, LOG_TAG, "Incorrect password.");
index 578f388ae0bb820bade43304585fdd65efa0d253..bfe06e1c86c8ee1bd6c1206dc8a50704d4863219 100755 (executable)
@@ -109,7 +109,12 @@ void password_result_callback(popup_data_s *data, const char *result)
                }
                break;
        case INSERT_SD_CARD:
-               ret = ode_external_encryption_mount(data->entry_data);
+               ret = ode_external_encryption_set_mount_password(data->entry_data);
+               if (ret != ODE_ERROR_NONE) {
+                       dlog_print(DLOG_ERROR, LOG_TAG, "failed to set mount password for external storage");
+                       return;
+               }
+               ret = ode_external_encryption_mount();
                if (ret != ODE_ERROR_NONE) {
                        dlog_print(DLOG_ERROR, LOG_TAG, "failed to mount external storage");
                        return;
index 0b412a877f9e86573aee606feda88032237eab11..a128f1504dfabc3730949dcdfaa205a33298e12e 100644 (file)
@@ -85,10 +85,20 @@ static inline int mount(const std::string name)
 
        if (name == "internal") {
                std::string password = getPassword();
-               ret = ode_internal_encryption_mount(password.c_str());
+               ret = ode_internal_encryption_set_mount_password(password.c_str());
+               if (ret == 0) {
+                       ret = ode_internal_encryption_mount();
+               } else {
+                       std::cerr << "Password setting failed" << std::endl;
+               }
        } else if (name == "external") {
                std::string password = getPassword();
-               ret = ode_external_encryption_mount(password.c_str());
+               ret = ode_external_encryption_set_mount_password(password.c_str());
+               if (ret == 0) {
+                       ret = ode_external_encryption_mount();
+               } else {
+                       std::cerr << "Password setting failed" << std::endl;
+               }
        } else {
                printSelectableStorage();
                return -1;