Add recovery APIs to use when there is something wrong with encryption 42/114442/2
authorSungbae Yoo <sungbae.yoo@samsung.com>
Mon, 13 Feb 2017 09:52:13 +0000 (18:52 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Mon, 13 Feb 2017 10:51:17 +0000 (19:51 +0900)
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Change-Id: I6fccb22edc22e12165d7c80e43a86812ef0db804

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/external-encryption.cpp
server/internal-encryption.cpp
tools/apps/ode/src/reset-sdcard.c

index d17b444..fd0308c 100644 (file)
@@ -62,6 +62,15 @@ int ExternalEncryption::decrypt(const std::string& password)
        }
 }
 
+int ExternalEncryption::recovery()
+{
+       try {
+               return context->methodCall<int>("ExternalEncryption::recovery");
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
 int ExternalEncryption::isPasswordInitialized()
 {
        try {
index d1ac2e0..c1bf9e3 100644 (file)
@@ -62,6 +62,15 @@ int InternalEncryption::decrypt(const std::string& password)
        }
 }
 
+int InternalEncryption::recovery()
+{
+       try {
+               return context->methodCall<int>("InternalEncryption::recovery");
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
 int InternalEncryption::isPasswordInitialized()
 {
        try {
index 64ba04f..e578c65 100644 (file)
@@ -64,6 +64,15 @@ int ode_external_encryption_decrypt(const char* password)
        return external.decrypt(password);
 }
 
+int ode_external_encryption_recovery()
+{
+       ODEContext client;
+       RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+       ExternalEncryption external = client.createInterface<ExternalEncryption>();
+
+       return external.recovery();
+}
+
 int ode_external_encryption_is_password_initialized(bool* result)
 {
        RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
index e4c6d1b..5ab67c3 100644 (file)
@@ -40,7 +40,6 @@ 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_NO_SUCH_FILE No such file or directory
  * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
@@ -59,7 +58,6 @@ ODE_API int ode_external_encryption_mount(const char* password);
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_NO_SUCH_FILE No such file or directory
  * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
@@ -108,6 +106,24 @@ ODE_API int ode_external_encryption_encrypt(const char* password, unsigned int o
 ODE_API int ode_external_encryption_decrypt(const char* password);
 
 /**
+ * @brief       Recovery external encryption when there is something wrong.
+ * @details     Administrator can use this API to recovery encrypted external
+ *              storage when the password is missing or the encryption is
+ *              corrupted. Note that this API will be erase all the contents
+ *              in 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_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_encrypt()
+ */
+ODE_API int ode_external_encryption_recovery();
+
+/**
  * @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
index 16947f8..9c8aee8 100644 (file)
@@ -64,6 +64,15 @@ int ode_internal_encryption_decrypt(const char* password)
        return internal.decrypt(password);
 }
 
+int ode_internal_encryption_recovery()
+{
+       ODEContext client;
+       RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+       InternalEncryption internal = client.createInterface<InternalEncryption>();
+
+       return internal.recovery();
+}
+
 int ode_internal_encryption_is_password_initialized(bool* result)
 {
     RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
index 76d6220..45b7bbd 100644 (file)
@@ -39,7 +39,6 @@ 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_NO_SUCH_FILE No such file or directory
  * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
@@ -58,7 +57,6 @@ ODE_API int ode_internal_encryption_mount(const char* password);
  * @retval      #ODE_ERROR_NONE Successful
  * @retval      #ODE_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval      #ODE_ERROR_TIMED_OUT Time out
- * @retval      #ODE_ERROR_NO_SUCH_FILE No such file or directory
  * @retval      #ODE_ERROR_NOT_PERMITTED Operation not permitted
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
@@ -109,6 +107,24 @@ ODE_API int ode_internal_encryption_encrypt(const char* password, unsigned int o
 ODE_API int ode_internal_encryption_decrypt(const char* password);
 
 /**
+ * @brief       Recovery internal encryption when there is something wrong.
+ * @details     Administrator can use this API to recovery encrypted internal
+ *              storage when the password is missing or the encryption is
+ *              corrupted. Note that this API will be erase all the contents
+ *              in 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_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_encrypt()
+ */
+ODE_API int ode_intternal_encryption_recovery();
+
+/**
  * @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
@@ -238,7 +254,7 @@ typedef enum {
 /**
  * @brief       Get supported options for encryption of internal storage.
  * @details     Administrator can use this API to get which options are
-                supported for encryption of external storage.
+                supported for encryption of internal storage.
  * @since_tizen 3.0
  * @param[out]  option The logical OR of supported options in internal storage
  * @return      #ODE_ERROR_NONE on success, otherwise a negative value
index da1c9c5..b935018 100644 (file)
@@ -39,6 +39,8 @@ public:
        int encrypt(const std::string& password, unsigned int options);
        int decrypt(const std::string& password);
 
+       int recovery();
+
        int isPasswordInitialized();
        int initPassword(const std::string& password);
        int cleanPassword(const std::string& password);
index d6c3d85..8b04e82 100644 (file)
@@ -36,6 +36,8 @@ public:
        int encrypt(const std::string& password, unsigned int options);
        int decrypt(const std::string& password);
 
+       int recovery();
+
        int isPasswordInitialized();
        int initPassword(const std::string& password);
        int cleanPassword(const std::string& password);
index 173323a..932b83e 100644 (file)
@@ -300,6 +300,23 @@ int ExternalEncryption::decrypt(const std::string &password)
        return 0;
 }
 
+int ExternalEncryption::recovery()
+{
+       if (getState() == State::Unencrypted) {
+               return -1;
+       }
+
+       for (runtime::DirectoryIterator iter(engine->getSource()), end;
+                       iter != end; ++iter) {
+               iter->remove(true);
+       }
+
+       engine->clearKeyMeta();
+       ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "unencrypted");
+
+       return 0;
+}
+
 int ExternalEncryption::isPasswordInitialized()
 {
        if (engine->isKeyMetaSet()) {
index f294f20..d015184 100644 (file)
 
 #define PRIVILEGE_PLATFORM "http://tizen.org/privilege/internal/default/platform"
 
+const std::string PROG_FACTORY_RESET = "/usr/bin/dbus-send";
+const std::vector<std::string> wipeCommand = {
+    PROG_FACTORY_RESET,
+    "--system",
+    "--type=signal",
+    "--print-reply",
+    "--dest=com.samsung.factoryreset",
+    "/com/samsung/factoryreset",
+    "com.samsung.factoryreset.start.setting"
+};
+
 namespace ode {
 
 namespace {
@@ -274,6 +285,22 @@ int InternalEncryption::decrypt(const std::string& password)
        return 0;
 }
 
+int InternalEncryption::recovery()
+{
+       if (getState() != State::Unencrypted) {
+               return -1;
+       }
+
+       //TODO
+       runtime::Process proc(PROG_FACTORY_RESET, wipeCommand);
+       if (proc.execute() == -1) {
+               ERROR("Failed to launch factory-reset");
+               return -2;
+       }
+
+       return 0;
+}
+
 int InternalEncryption::isPasswordInitialized()
 {
        if (engine->isKeyMetaSet()) {
index 5b22336..3338fa7 100644 (file)
@@ -46,7 +46,8 @@ static void popup_confirm_cb(void *data, Evas_Object *obj, void *event_info)
        evas_object_del(popup_data->popup);
        popup_data->popup = NULL;
 
-       /* [TBD] erase external storage data */
+       ode_external_encryption_recovery();
+
        return;
 }