Add APIs to managing password 23/112023/4
authorSungbae Yoo <sungbae.yoo@samsung.com>
Wed, 25 Jan 2017 10:36:31 +0000 (19:36 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Thu, 2 Feb 2017 08:45:04 +0000 (17:45 +0900)
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Change-Id: Ibae77560fe68434cad0b929205d264cf4ae8c3c6

19 files changed:
lib/external-encryption.cpp
lib/internal-encryption.cpp
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/engine/dmcrypt-engine.cpp
server/engine/dmcrypt-engine.h
server/engine/ecryptfs-engine.cpp
server/engine/ecryptfs-engine.h
server/engine/ext4-engine.cpp
server/engine/ext4-engine.h
server/external-encryption.cpp
server/file-footer.cpp
server/file-footer.h
server/internal-encryption.cpp
tools/cli/ode-admin-cli.cpp

index 780f54e934a8d26be78bc0bb8e9db7982e7a1627..5fd1be85642583568cba116fae87ae7a411c4afb 100644 (file)
@@ -62,10 +62,29 @@ int ExternalEncryption::decrypt(const std::string& password)
        }
 }
 
-int ExternalEncryption::verifyPassword(const std::string& password)
+int ExternalEncryption::isPasswordCreated()
 {
        try {
-               return context->methodCall<int>("ExternalEncryption::verifyPassword",
+               return context->methodCall<int>("ExternalEncryption::isPasswordCreated");
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int ExternalEncryption::createPassword(const std::string& password)
+{
+       try {
+               return context->methodCall<int>("ExternalEncryption::createPassword",
+                                                                               password);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int ExternalEncryption::deletePassword(const std::string& password)
+{
+       try {
+               return context->methodCall<int>("ExternalEncryption::deletePassword",
                                                                                password);
        } catch (runtime::Exception& e) {
                return -1;
@@ -83,6 +102,16 @@ int ExternalEncryption::changePassword(const std::string& oldPassword,
        }
 }
 
+int ExternalEncryption::verifyPassword(const std::string& password)
+{
+       try {
+               return context->methodCall<int>("ExternalEncryption::verifyPassword",
+                                                                               password);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
 int ExternalEncryption::getState()
 {
        try {
index 48ad20cf4d86cb65c159668c6b22d086992ab6b2..b6ac308bfb247aaafb09bb568c2766af3a2d5e72 100644 (file)
@@ -62,10 +62,29 @@ int InternalEncryption::decrypt(const std::string& password)
        }
 }
 
-int InternalEncryption::verifyPassword(const std::string& password)
+int InternalEncryption::isPasswordCreated()
 {
        try {
-               return context->methodCall<int>("InternalEncryption::verifyPassword",
+               return context->methodCall<int>("InternalEncryption::isPasswordCreated");
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int InternalEncryption::createPassword(const std::string& password)
+{
+       try {
+               return context->methodCall<int>("InternalEncryption::createPassword",
+                                                                               password);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int InternalEncryption::deletePassword(const std::string& password)
+{
+       try {
+               return context->methodCall<int>("InternalEncryption::deletePassword",
                                                                                password);
        } catch (runtime::Exception& e) {
                return -1;
@@ -83,6 +102,16 @@ int InternalEncryption::changePassword(const std::string& oldPassword,
        }
 }
 
+int InternalEncryption::verifyPassword(const std::string& password)
+{
+       try {
+               return context->methodCall<int>("InternalEncryption::verifyPassword",
+                                                                               password);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
 int InternalEncryption::getState()
 {
        try {
index 5c0070ec4ee0dca0ac6523a1b760cf9447979ba3..25f8dea383386342dac1406678af3915bf3fa77a 100644 (file)
@@ -64,15 +64,14 @@ int ode_external_encryption_decrypt(const char* password)
        return external.decrypt(password);
 }
 
-int ode_external_encryption_verify_password(const char *password, int *result)
+int ode_external_encryption_is_password_created(bool *result)
 {
-       RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
        RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
 
        ODEContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryption external = client.createInterface<ExternalEncryption>();
-       int ret = external.verifyPassword(password);
+       int ret = external.isPasswordCreated();
 
        RET_ON_FAILURE(ret < 0, ODE_ERROR_INVALID_PARAMETER);
 
@@ -80,6 +79,28 @@ int ode_external_encryption_verify_password(const char *password, int *result)
        return ODE_ERROR_NONE;
 }
 
+int ode_external_encryption_create_password(const char *password)
+{
+       RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
+
+       ODEContext client;
+       RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+       ExternalEncryption external = client.createInterface<ExternalEncryption>();
+
+       return external.createPassword(password);
+}
+
+int ode_external_encryption_delete_password(const char *password)
+{
+       RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
+
+       ODEContext client;
+       RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+       ExternalEncryption external = client.createInterface<ExternalEncryption>();
+
+       return external.deletePassword(password);
+}
+
 int ode_external_encryption_change_password(const char* old_password,
                                                                                        const char* new_password)
 {
@@ -93,6 +114,22 @@ int ode_external_encryption_change_password(const char* old_password,
        return external.changePassword(old_password, new_password);
 }
 
+int ode_external_encryption_verify_password(const char *password, int *result)
+{
+       RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
+
+       ODEContext client;
+       RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+       ExternalEncryption external = client.createInterface<ExternalEncryption>();
+       int ret = external.verifyPassword(password);
+
+       RET_ON_FAILURE(ret < 0, ODE_ERROR_INVALID_PARAMETER);
+
+       *result = ret;
+       return ODE_ERROR_NONE;
+}
+
 int ode_external_encryption_get_state(int* state)
 {
        RET_ON_FAILURE(state, ODE_ERROR_INVALID_PARAMETER);
index e1bd2a6b84d87944b81873f33ebee5e637ae0ea4..b5275e012597d64b9322604b9a2f4b71dc19ce51 100644 (file)
@@ -44,7 +44,8 @@ extern "C" {
  * @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 matched with what used for encryption.
+ * @pre         The password must match with what is set by
+ *              ode_external_encryption_create_password().
  * @see         ode_external_encryption_encrypt()
  * @see         ode_external_encryption_umount()
  */
@@ -100,11 +101,72 @@ ODE_API int ode_external_encryption_encrypt(const char* password, unsigned int o
  * @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 matched with what used for encryption.
+ * @pre         The password must match with what is set by
+ *              ode_external_encryption_create_password().
  * @see         ode_external_encryption_encrypt()
  */
 ODE_API int ode_external_encryption_decrypt(const char* password);
 
+/**
+ * @brief       Checks whether the external encryption password was created
+ * @details     Administrator can use this API to check if the password that
+                will be used for external storage encryption/decryption
+                exists.
+ * @since_tizen 3.0
+ * @param[out]  result Whether encryption password was created
+ * @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_NOT_PERMITTED Operation not permitted
+ * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @see         ode_external_encryption_created_password()
+ * @see         ode_external_encryption_delete_password()
+ */
+ODE_API int ode_external_encryption_is_password_created(bool* result);
+
+/**
+ * @brief       Initialize external encryption password to given password
+ * @details     Administrator can use this API to set new password that will be
+                used for external storage encryption/decryption.
+ * @since_tizen 3.0
+ * @param[in]   password The password to set
+ * @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_NOT_PERMITTED Operation not permitted
+ * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @see         ode_external_encryption_change_password()
+ * @see         ode_external_encryption_delete_password()
+ * @see         ode_external_encryption_encrypt()
+ * @see         ode_external_encryption_decrypt()
+ * @see         ode_external_encryption_mount()
+ */
+ODE_API int ode_external_encryption_create_password(const char* password);
+
+/**
+ * @brief       Remove external encryption password
+ * @details     Administrator can use this API to delete password that was set
+                by ode_external_encryption_create_password().
+ * @since_tizen 3.0
+ * @param[in]   password The password to delete
+ * @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_KEY_REJECTED old_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_create_password().
+ * @see         ode_external_encryption_create_password()
+ */
+ODE_API int ode_external_encryption_delete_password(const char* password);
+
 /**
  * @brief       Change the password for external storage.
  * @details     Administrator can use this API to change password for external
@@ -120,12 +182,31 @@ ODE_API int ode_external_encryption_decrypt(const char* password);
  * @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 matched with what used for encryption.
+ * @pre         The password must match with what is set by
+ *              ode_external_encryption_create_password().
  * @see         ode_external_encryption_encrypt()
  */
 ODE_API int ode_external_encryption_change_password(const char* old_password,
                                                                                                        const char* new_password);
 
+/**
+ * @brief       Verify if given password is external encryption password.
+ * @details     Administrator can use this API to find if a password is used
+                by external encryption
+ * @since_tizen 3.0
+ * @param[out]  password The password to be verified
+ * @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_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_create_password().
+ * @see         ode_external_encryption_encrypt()
+ */
+ODE_API int ode_external_encryption_verify_password(const char *password);
+
 /**
  * @brief       Get current encryption state of external storage.
  * @details     Administrator can use this API to get current encryption state
@@ -168,22 +249,6 @@ typedef enum {
  */
 ODE_API int ode_external_encryption_get_supported_options(unsigned int* options);
 
-/**
- * @brief       Verify if given password is external encryption password.
- * @details     Administrator can use this API to find if a password is used
-                by external encryption
- * @since_tizen 3.0
- * @param[out]  password The password to be verified
- * @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_PERMISSION_DENIED The application does not have
- *              the privilege to call this API
- * @see         ode_external_encryption_encrypt()
- */
-ODE_API int ode_external_encryption_verify_password(const char *password);
-
 /**
  * @}
  */
index 7f227cdfe7591b584514898f37e0eb473e9d5849..9f62e048398b8791194ad92e213297627c2485c2 100644 (file)
@@ -64,15 +64,14 @@ int ode_internal_encryption_decrypt(const char* password)
        return internal.decrypt(password);
 }
 
-int ode_internal_encryption_verify_password(const char *password, int *result)
+int ode_internal_encryption_is_password_created(int *result)
 {
-    RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
 
     ODEContext client;
     RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryption internal = client.createInterface<InternalEncryption>();
-       int ret = internal.verifyPassword(password);
+       int ret = internal.isPasswordCreated();
 
        RET_ON_FAILURE(ret < 0, ODE_ERROR_INVALID_PARAMETER);
 
@@ -80,6 +79,28 @@ int ode_internal_encryption_verify_password(const char *password, int *result)
     return ODE_ERROR_NONE;
 }
 
+int ode_internal_encryption_create_password(const char *password)
+{
+    RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
+
+    ODEContext client;
+    RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+       InternalEncryption internal = client.createInterface<InternalEncryption>();
+
+       return internal.createPassword(password);
+}
+
+int ode_internal_encryption_delete_password(const char *password)
+{
+    RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
+
+    ODEContext client;
+    RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+       InternalEncryption internal = client.createInterface<InternalEncryption>();
+
+       return internal.deletePassword(password);
+}
+
 int ode_internal_encryption_change_password(const char* old_password,
                                                                                        const char* new_password)
 {
@@ -93,6 +114,22 @@ int ode_internal_encryption_change_password(const char* old_password,
        return internal.changePassword(old_password, new_password);
 }
 
+int ode_internal_encryption_verify_password(const char *password, int *result)
+{
+    RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
+
+    ODEContext client;
+    RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+       InternalEncryption internal = client.createInterface<InternalEncryption>();
+       int ret = internal.verifyPassword(password);
+
+       RET_ON_FAILURE(ret < 0, ODE_ERROR_INVALID_PARAMETER);
+
+       *result = ret;
+    return ODE_ERROR_NONE;
+}
+
 int ode_internal_encryption_get_state(int* state)
 {
        RET_ON_FAILURE(state, ODE_ERROR_INVALID_PARAMETER);
index f905034b583b68923548f0485b57d7bfca754e72..f29b31aba4ebbfc50c2180ac64fb8c8174cf7f59 100644 (file)
@@ -43,7 +43,8 @@ extern "C" {
  * @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 matched with what used for encryption.
+ * @pre         The password must match with what is set by
+ *              ode_internal_encryption_create_password().
  * @see         ode_internal_encryption_encrypt()
  * @see         ode_internal_encryption_umount()
  */
@@ -80,6 +81,8 @@ ODE_API int ode_internal_encryption_umount();
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  * @retval      #ODE_ERROR_NOT_SUPPORTED Given options are not supported
  *              the privilege to call this API
+ * @pre         The password must match with what is set by
+ *              ode_internal_encryption_create_password().
  * @see         ode_internal_encryption_mount()
  * @see         ode_internal_encryption_decrypt()
  * @see         ode_internal_encryption_get_supported_options()
@@ -99,11 +102,72 @@ ODE_API int ode_internal_encryption_encrypt(const char* password, unsigned int o
  * @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 matched with what used for encryption.
+ * @pre         The password must match with what is set by
+ *              ode_internal_encryption_create_password().
  * @see         ode_internal_encryption_encrypt()
  */
 ODE_API int ode_internal_encryption_decrypt(const char* password);
 
+/**
+ * @brief       Checks whether the internal encryption password was created
+ * @details     Administrator can use this API to check if the password that
+                will be used for internal storage encryption/decryption
+                exists.
+ * @since_tizen 3.0
+ * @param[out]  result Whether encryption password was created
+ * @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_NOT_PERMITTED Operation not permitted
+ * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @see         ode_internal_encryption_created_password()
+ * @see         ode_internal_encryption_delete_password()
+ */
+ODE_API int ode_internal_encryption_is_password_created(bool* result);
+
+/**
+ * @brief       Initialize internal encryption password to given password
+ * @details     Administrator can use this API to set new password that will be
+                used for internal storage encryption/decryption.
+ * @since_tizen 3.0
+ * @param[in]   password The password to set
+ * @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_NOT_PERMITTED Operation not permitted
+ * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @see         ode_internal_encryption_change_password()
+ * @see         ode_internal_encryption_delete_password()
+ * @see         ode_internal_encryption_encrypt()
+ * @see         ode_internal_encryption_decrypt()
+ * @see         ode_internal_encryption_mount()
+ */
+ODE_API int ode_internal_encryption_create_password(const char* password);
+
+/**
+ * @brief       Remove internal encryption password
+ * @details     Administrator can use this API to delete password that was set
+                by ode_internal_encryption_create_password().
+ * @since_tizen 3.0
+ * @param[in]   password The password to delete
+ * @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_KEY_REJECTED old_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_internal_encryption_create_password().
+ * @see         ode_internal_encryption_create_password()
+ */
+ODE_API int ode_internal_encryption_delete_password(const char* password);
+
 /**
  * @brief       Change the password for internal storage.
  * @details     Administrator can use this API to change password for internal
@@ -119,12 +183,32 @@ ODE_API int ode_internal_encryption_decrypt(const char* password);
  * @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 matched with what used for encryption.
- * @see         ode_internal_encryption_encrypt()
+ * @pre         Old password must match with what is set by
+ *              ode_internal_encryption_create_password().
+ * @see         ode_internal_encryption_create_password()
  */
 ODE_API int ode_internal_encryption_change_password(const char* old_password,
                                                                                                        const char* new_password);
 
+/**
+ * @brief       Verify if given password is internal encryption password.
+ * @details     Administrator can use this API to find if a password is used
+                by internal encryption
+ * @since_tizen 3.0
+ * @param[out]  password The password to be verified
+ * @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_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         The password must match with what is set by
+ *              ode_internal_encryption_create_password().
+ * @see         ode_internal_encryption_create_password()
+ * @see         ode_internal_encryption_change_password()
+ */
+ODE_API int ode_internal_encryption_verify_password(const char *password);
+
 /**
  * @brief       Get current encryption state of internal storage.
  * @details     Administrator can use this API to get current encryption state
@@ -166,22 +250,6 @@ typedef enum {
  */
 ODE_API int ode_internal_encryption_get_supported_options(unsigned int* options);
 
-/**
- * @brief       Verify if given password is internal encryption password.
- * @details     Administrator can use this API to find if a password is used
-                by internal encryption
- * @since_tizen 3.0
- * @param[out]  password The password to be verified
- * @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_PERMISSION_DENIED The application does not have
- *              the privilege to call this API
- * @see         ode_internal_encryption_encrypt()
- */
-ODE_API int ode_internal_encryption_verify_password(const char *password);
-
 /*
  * @}
  */
index c2cc199c0426a0cad4ae73e05f94ab2d7841a94a..f47584237e3cd392f5d39269b8989fd235c7d560 100644 (file)
@@ -39,8 +39,11 @@ public:
        int encrypt(const std::string& password, unsigned int options);
        int decrypt(const std::string& password);
 
-       int verifyPassword(const std::string& password);
+       int isPasswordCreated();
+       int createPassword(const std::string& password);
+       int deletePassword(const std::string& password);
        int changePassword(const std::string& oldPW, const std::string& newPW);
+       int verifyPassword(const std::string& password);
 
        enum State {
                Unencrypted = 0x00,
index a915a16751eff2961c3009efab8d5c643f77f4a3..28cb193bac60e3b4baeb223490e4f06de7bfcb8a 100644 (file)
@@ -36,8 +36,11 @@ public:
        int encrypt(const std::string& password, unsigned int options);
        int decrypt(const std::string& password);
 
-       int verifyPassword(const std::string& password);
+       int isPasswordCreated();
+       int createPassword(const std::string& password);
+       int deletePassword(const std::string& password);
        int changePassword(const std::string& oldPW, const std::string& newPW);
+       int verifyPassword(const std::string& password);
 
        enum State {
                Unencrypted = 0x00,
index 02fefe9e94cc1578e54d503453846336cb94ece6..52862106aed25d149812b672114e60ceca01c003 100644 (file)
@@ -344,6 +344,11 @@ void DMCryptEngine::decrypt(const DMCryptEngine::data &key, unsigned int options
        destroyCryptoBlkDev(DM_LABEL);
 }
 
+bool DMCryptEngine::isKeyMetaCreated()
+{
+       return FileFooter::exist(source);
+}
+
 const DMCryptEngine::data DMCryptEngine::getKeyMeta()
 {
        return FileFooter::read(source);
@@ -354,6 +359,11 @@ void DMCryptEngine::setKeyMeta(const data &meta)
        FileFooter::write(source, meta);
 }
 
+void DMCryptEngine::clearKeyMeta()
+{
+       FileFooter::clear(source);
+}
+
 unsigned int DMCryptEngine::getSupportedOptions()
 {
     return OPTION_INCLUDE_UNUSED_REGION;
index 3a0876c8c2403886d02da8e37084bbb77a549d50..da57559af1c5ea1a9a45175df05c6f6c963199bd 100644 (file)
@@ -68,8 +68,10 @@ public:
        void encrypt(const data &key, unsigned int options);
        void decrypt(const data &key, unsigned int options);
 
+       bool isKeyMetaCreated();
        const data getKeyMeta();
        void setKeyMeta(const data &data);
+       void clearKeyMeta();
 
        unsigned int getSupportedOptions();
 
index 8dbb499e45ec2e39ea086a2da1021c9a69fd9132..a3666cfa9108f0fe5f95df388a12fb32b3f27a27 100644 (file)
@@ -403,6 +403,11 @@ void EcryptfsEngine::decrypt(const data &key, unsigned int options)
        progress.done();
 }
 
+bool EcryptfsEngine::isKeyMetaCreated()
+{
+    return FileFooter::exist(source);
+}
+
 const EcryptfsEngine::data EcryptfsEngine::getKeyMeta()
 {
     return FileFooter::read(source);
@@ -413,6 +418,11 @@ void EcryptfsEngine::setKeyMeta(const data &meta)
        FileFooter::write(source, meta);
 }
 
+void EcryptfsEngine::clearKeyMeta()
+{
+       FileFooter::clear(source);
+}
+
 unsigned int EcryptfsEngine::getSupportedOptions()
 {
        return SUPPORTED_OPTIONS;
index 027154aa5afc42906a67aca5f1cc3a0273f80c24..9a61f1857621b2cd365666fb271ac6ebd8916b5b 100644 (file)
@@ -61,8 +61,10 @@ public:
        void encrypt(const data& key, unsigned int);
        void decrypt(const data& key, unsigned int);
 
+       bool isKeyMetaCreated();
        const data getKeyMeta();
        void setKeyMeta(const data &data);
+       void clearKeyMeta();
 
        unsigned int getSupportedOptions();
 
index 4f96fce500c9190e010903753a9d910fee5364eb..c4c0ce6552eb244ef6119f6ca677c41b23285eed 100644 (file)
@@ -494,6 +494,11 @@ void Ext4Engine::decrypt(const Ext4Engine::data& key, unsigned int options)
                ::remove(secondMountPoint.c_str());
 }
 
+bool Ext4Engine::isKeyMetaCreated()
+{
+       return FileFooter::exist(source);
+}
+
 const Ext4Engine::data Ext4Engine::getKeyMeta()
 {
        return FileFooter::read(source);
@@ -504,6 +509,11 @@ void Ext4Engine::setKeyMeta(const data &data)
        FileFooter::write(source, data);
 }
 
+void Ext4Engine::clearKeyMeta()
+{
+       FileFooter::clear(source);
+}
+
 unsigned int Ext4Engine::getSupportedOptions()
 {
        return 0;
index ffafde89198b8b202f657b841e61d3200c8d0927..00ceb1f6e145b177a45cede41e5fc88100db688f 100644 (file)
@@ -53,8 +53,10 @@ public:
        void encrypt(const data &key, unsigned int options);
        void decrypt(const data &key, unsigned int options);
 
+       bool isKeyMetaCreated();
        const data getKeyMeta();
        void setKeyMeta(const data &data);
+       void clearKeyMeta();
 
        unsigned int getSupportedOptions();
 
index 7ed8206f2423def11359dc4019a90dcbfbc35a87..73749133ad3cfaabda5f6db37323b6ad753518b1 100644 (file)
@@ -88,8 +88,8 @@ void externalCallback(dbus::Variant parameters)
                // TODO
                // Password Popup
 //             std::string pw = "tizen";
-//             KeyManager::data pwData(pw.begin(), pw.end());
-//             engine.mount(keyManager.getDEK(pwData));
+//             KeyManager::data data(pw.begin(), pw.end());
+//             engine.mount(keyManager.getDEK(data));
        }
 }
 
@@ -152,7 +152,11 @@ ExternalEncryption::ExternalEncryption(ODEControlContext &ctx) :
        context.registerNonparametricMethod(this, "", (int)(ExternalEncryption::umount));
        context.registerParametricMethod(this, "", (int)(ExternalEncryption::encrypt)(std::string, unsigned int));
        context.registerParametricMethod(this, "", (int)(ExternalEncryption::decrypt)(std::string));
+       context.registerNonparametricMethod(this, "", (int)(ExternalEncryption::isPasswordCreated));
+       context.registerParametricMethod(this, "", (int)(ExternalEncryption::createPassword)(std::string));
+       context.registerParametricMethod(this, "", (int)(ExternalEncryption::deletePassword)(std::string));
        context.registerParametricMethod(this, "", (int)(ExternalEncryption::changePassword)(std::string, std::string));
+       context.registerParametricMethod(this, "", (int)(ExternalEncryption::verifyPassword)(std::string));
        context.registerNonparametricMethod(this, "", (int)(ExternalEncryption::getState));
        context.registerNonparametricMethod(this, "", (unsigned int)(ExternalEncryption::getSupportedOptions));
 
@@ -165,14 +169,14 @@ ExternalEncryption::~ExternalEncryption()
 
 int ExternalEncryption::mount(const std::string &password)
 {
-       KeyManager::data pwData(password.begin(), password.end());
+       KeyManager::data data(password.begin(), password.end());
        KeyManager keyManager(engine.getKeyMeta());
 
-       if (!keyManager.verifyPassword(pwData)) {
+       if (!keyManager.verifyPassword(data)) {
                return -2;
        }
 
-       engine.mount(keyManager.getMasterKey(pwData), getOptions());
+       engine.mount(keyManager.getMasterKey(data), getOptions());
        return 0;
 }
 
@@ -189,10 +193,11 @@ int ExternalEncryption::umount()
 int ExternalEncryption::encrypt(const std::string &password, unsigned int options)
 {
        KeyManager::data pwData(password.begin(), password.end());
-       KeyManager keyManager;
+       KeyManager keyManager(engine.getKeyMeta());
 
-       keyManager.initPassword(pwData);
-       engine.setKeyMeta(keyManager.serialize());
+       if (!keyManager.verifyPassword(pwData)) {
+               return -2;
+       }
 
        KeyManager::data MasterKey = keyManager.getMasterKey(pwData);
        auto encryptWorker = [&MasterKey, options, this]() {
@@ -243,15 +248,40 @@ int ExternalEncryption::decrypt(const std::string &password)
        return 0;
 }
 
-int ExternalEncryption::verifyPassword(const std::string& password)
+int ExternalEncryption::isPasswordCreated()
+{
+       if (engine.isKeyMetaCreated()) {
+               return 1;
+       }
+       return 0;
+}
+
+
+int ExternalEncryption::createPassword(const std::string& password)
 {
-    KeyManager::data data(password.begin(), password.end());
-    KeyManager keyManager(engine.getKeyMeta());
+       KeyManager::data pwData(password.begin(), password.end());
+       KeyManager keyManager;
 
-    if (!keyManager.verifyPassword(data)) {
-        return 1;
-    }
-    return 0;
+       if (engine.isKeyMetaCreated()) {
+               return -2;
+       }
+
+       keyManager.initPassword(pwData);
+       engine.setKeyMeta(keyManager.serialize());
+       return 0;
+}
+
+int ExternalEncryption::deletePassword(const std::string& password)
+{
+       KeyManager::data pwData(password.begin(), password.end());
+       KeyManager keyManager(engine.getKeyMeta());
+
+       if (!keyManager.verifyPassword(pwData)) {
+               return -2;
+       }
+
+       engine.clearKeyMeta();
+       return 0;
 }
 
 int ExternalEncryption::changePassword(const std::string &oldPassword,
@@ -271,6 +301,19 @@ int ExternalEncryption::changePassword(const std::string &oldPassword,
        return 0;
 }
 
+int ExternalEncryption::verifyPassword(const std::string& password)
+{
+       KeyManager::data pwData(password.begin(), password.end());
+       KeyManager keyManager(engine.getKeyMeta());
+
+       if (!keyManager.verifyPassword(pwData)) {
+               return 1;
+       }
+       return 0;
+}
+
+
+
 int ExternalEncryption::getState()
 {
        char *value = ::vconf_get_str(EXTERNAL_STATE_VCONF_KEY);
index 3fd8e1c3162287e9144184b1aa399f63854db6fe..9ea0f6b425b63d06863e5b7395aac798132cbe7e 100644 (file)
@@ -45,6 +45,17 @@ const std::string getFileName(const std::string &key)
 
 } // namsepace
 
+bool FileFooter::exist(const std::string &key)
+{
+       std::string fileName(getFileName(key));
+
+       INFO("Footer file : " + fileName);
+
+       runtime::File file(fileName);
+
+       return file.exists();
+}
+
 const FileFooter::data FileFooter::read(const std::string &key)
 {
        std::string fileName(getFileName(key));
@@ -72,4 +83,15 @@ void FileFooter::write(const std::string &key, const data &value)
        file.write(value.data(), value.size());
 }
 
+void FileFooter::clear(const std::string &key)
+{
+       std::string fileName(getFileName(key));
+
+       INFO("Footer file : " + fileName);
+
+       runtime::File file(fileName);
+
+       file.remove();
+}
+
 } // namespace ode
index 22fa6d07667f964e32095225303bc3b710d049ea..8400162b5465b1b12cf65fb28066fee41c4717b0 100644 (file)
@@ -28,8 +28,10 @@ public:
 
        typedef std::vector<unsigned char> data;
 
+       static bool exist(const std::string &key);
        static const data read(const std::string &key);
        static void write(const std::string &key, const data &value);
+       static void clear(const std::string &key);
 };
 
 } // namespace ode
index 47c6ae1d8e186e15f99e1791d9a4139f5d0d6fd2..8c279b050ceeef93f7092382ba00957f3ebde0a0 100644 (file)
@@ -116,13 +116,17 @@ void setOptions(unsigned int options)
 InternalEncryption::InternalEncryption(ODEControlContext& ctx) :
        context(ctx)
 {
-       context.registerNonparametricMethod(this, "", (int)(InternalEncryption::getState));
-       context.registerNonparametricMethod(this, "", (unsigned int)(InternalEncryption::getSupportedOptions));
        context.registerParametricMethod(this, "", (int)(InternalEncryption::mount)(std::string));
        context.registerNonparametricMethod(this, "", (int)(InternalEncryption::umount));
        context.registerParametricMethod(this, "", (int)(InternalEncryption::encrypt)(std::string, unsigned int));
        context.registerParametricMethod(this, "", (int)(InternalEncryption::decrypt)(std::string));
+       context.registerNonparametricMethod(this, "", (int)(InternalEncryption::isPasswordCreated));
+       context.registerParametricMethod(this, "", (int)(InternalEncryption::createPassword)(std::string));
+       context.registerParametricMethod(this, "", (int)(InternalEncryption::deletePassword)(std::string));
        context.registerParametricMethod(this, "", (int)(InternalEncryption::changePassword)(std::string, std::string));
+       context.registerParametricMethod(this, "", (int)(InternalEncryption::verifyPassword)(std::string));
+       context.registerNonparametricMethod(this, "", (int)(InternalEncryption::getState));
+       context.registerNonparametricMethod(this, "", (unsigned int)(InternalEncryption::getSupportedOptions));
 }
 
 InternalEncryption::~InternalEncryption()
@@ -167,10 +171,11 @@ int InternalEncryption::encrypt(const std::string& password, unsigned int option
        }
 
        KeyManager::data pwData(password.begin(), password.end());
-       KeyManager keyManager;
+       KeyManager keyManager(engine.getKeyMeta());
 
-       keyManager.initPassword(pwData);
-       engine.setKeyMeta(keyManager.serialize());
+       if (!keyManager.verifyPassword(pwData)) {
+               return -2;
+       }
 
        KeyManager::data MasterKey = keyManager.getMasterKey(pwData);
        auto encryptWorker = [&MasterKey, options, this]() {
@@ -244,14 +249,38 @@ int InternalEncryption::decrypt(const std::string& password)
        return 0;
 }
 
-int InternalEncryption::verifyPassword(const std::string& password)
+int InternalEncryption::isPasswordCreated()
 {
-       KeyManager::data data(password.begin(), password.end());
+       if (engine.isKeyMetaCreated()) {
+               return 1;
+       }
+       return 0;
+}
+
+int InternalEncryption::createPassword(const std::string& password)
+{
+       KeyManager::data pwData(password.begin(), password.end());
+       KeyManager keyManager;
+
+       if (engine.isKeyMetaCreated()) {
+               return -2;
+       }
+
+       keyManager.initPassword(pwData);
+       engine.setKeyMeta(keyManager.serialize());
+       return 0;
+}
+
+int InternalEncryption::deletePassword(const std::string& password)
+{
+       KeyManager::data pwData(password.begin(), password.end());
        KeyManager keyManager(engine.getKeyMeta());
 
-       if (keyManager.verifyPassword(data)) {
-               return 1;
+       if (!keyManager.verifyPassword(pwData)) {
+               return -2;
        }
+
+       engine.clearKeyMeta();
        return 0;
 }
 
@@ -272,6 +301,19 @@ int InternalEncryption::changePassword(const std::string& oldPassword,
        return 0;
 }
 
+int InternalEncryption::verifyPassword(const std::string& password)
+{
+       KeyManager::data pwData(password.begin(), password.end());
+       KeyManager keyManager(engine.getKeyMeta());
+
+       if (keyManager.verifyPassword(pwData)) {
+               return 1;
+       }
+       return 0;
+}
+
+
+
 int InternalEncryption::getState()
 {
        char *value = ::vconf_get_str(INTERNAL_STATE_VCONF_KEY);
index 9ae66af72c3af389d869ca980e4a5879831b775e..0625f4d5c4f2e8b0faafc6f2d9035ef6061b4b58 100644 (file)
@@ -125,42 +125,44 @@ static inline int encrypt_storage(const std::string name)
        int ret;
 
        if (name == "internal") {
-               unsigned int options;
-               ret = ode_internal_encryption_get_supported_options(&options);
-               if (ret == 0) {
-                       char answer;
-                       if (options & ODE_OPTION_INTERNAL_INCLUDE_UNUSED_REGION) {
-                               std::cout << "Encrypt All (include unused region)? (y/n) ";
-                               std::cin >> answer;
-                               if (answer != 'Y' && answer != 'y') {
-                                       options &= ~ODE_OPTION_INTERNAL_INCLUDE_UNUSED_REGION;
-                               }
+               std::string password = getPassword();
+               ode_internal_encryption_create_password(password.c_str());
+
+               unsigned int options = 0;
+               ode_internal_encryption_get_supported_options(&options);
+
+               char answer;
+               if (options & ODE_OPTION_INTERNAL_INCLUDE_UNUSED_REGION) {
+                       std::cout << "Encrypt All (include unused region)? (y/n) ";
+                       std::cin >> answer;
+                       if (answer != 'Y' && answer != 'y') {
+                               options &= ~ODE_OPTION_INTERNAL_INCLUDE_UNUSED_REGION;
                        }
-                       std::string password = getPassword();
-                       ret = ode_internal_encryption_encrypt(password.c_str(), options);
                }
+               ret = ode_internal_encryption_encrypt(password.c_str(), options);
        } else if (name == "external") {
+               std::string password = getPassword();
+               ode_external_encryption_create_password(password.c_str());
+
                unsigned int options;
-               ret = ode_external_encryption_get_supported_options(&options);
-               if (ret == 0) {
-                       char answer;
-                       if (options & ODE_OPTION_EXTERNAL_ONLY_NEW_FILE) {
-                               std::cout << "Encrypt new files only? (y/n) ";
-                               std::cin >> answer;
-                               if (answer != 'Y' && answer != 'y') {
-                                       options &= ~ODE_OPTION_EXTERNAL_ONLY_NEW_FILE;
-                               }
+               ode_external_encryption_get_supported_options(&options);
+
+               char answer;
+               if (options & ODE_OPTION_EXTERNAL_ONLY_NEW_FILE) {
+                       std::cout << "Encrypt new files only? (y/n) ";
+                       std::cin >> answer;
+                       if (answer != 'Y' && answer != 'y') {
+                               options &= ~ODE_OPTION_EXTERNAL_ONLY_NEW_FILE;
                        }
-                       if (options & ODE_OPTION_EXTERNAL_EXCEPT_FOR_MEDIA_FILE) {
-                               std::cout << "Encrypt non-media files only? (y/n) ";
-                               std::cin >> answer;
-                               if (answer != 'Y' && answer != 'y') {
-                                       options &= ~ODE_OPTION_EXTERNAL_EXCEPT_FOR_MEDIA_FILE;
-                               }
+               }
+               if (options & ODE_OPTION_EXTERNAL_EXCEPT_FOR_MEDIA_FILE) {
+                       std::cout << "Encrypt non-media files only? (y/n) ";
+                       std::cin >> answer;
+                       if (answer != 'Y' && answer != 'y') {
+                               options &= ~ODE_OPTION_EXTERNAL_EXCEPT_FOR_MEDIA_FILE;
                        }
-                       std::string password = getPassword();
-                       ret = ode_external_encryption_encrypt(password.c_str(), options);
                }
+               ret = ode_external_encryption_encrypt(password.c_str(), options);
        } else {
                printSelectableStorage();
                return -1;
@@ -180,9 +182,11 @@ static inline int decrypt_storage(const std::string name)
        if (name == "internal") {
                std::string password = getPassword();
                ret = ode_internal_encryption_decrypt(password.c_str());
+               ode_internal_encryption_delete_password(password.c_str());
        } else if (name == "external") {
                std::string password = getPassword();
                ret = ode_external_encryption_decrypt(password.c_str());
+               ode_external_encryption_delete_password(password.c_str());
        } else {
                printSelectableStorage();
                return -1;