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 d17b444c00a35a9a6f8daf7f81ebcfac0a91e4c7..fd0308c4c26040ed387d8692f3a7bd4ea3b17ab9 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 d1ac2e0ff723bb7b48ba81bc6f6bcb7d9c399fdb..c1bf9e35a0f9f4193045ffce11395f6d45b3db65 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 64ba04f3f6e5bf673c052ed03250e498c903ed70..e578c65227651bcdcc5559dba8ecfcf4c64f8569 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 e4c6d1bd6d3bd6aace0f6573a406cf69c5330217..5ab67c3316a43f67841db3193a485f6803ad6dcd 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
@@ -107,6 +105,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
index 16947f84cd2f2dc6aa500d7f4766a804f52baf24..9c8aee88e77682258fb2a3f0067980e1b22f1962 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 76d6220c90ba96d4bf061a6eb209d794fc32b5df..45b7bbd5f81849706031eb6b22e0f7b450ae0f63 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
@@ -108,6 +106,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
@@ -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 da1c9c5a44e35aab70f558821534d8208d778c22..b935018e6a6d32c3072b5ec45a2f7ddc36165f56 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 d6c3d85363b40574e4b1718287ac3a1b630ca774..8b04e8212df069ca5ac57fed90780dd3e47d6b08 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 173323ae191c9c0a7fd8b720a46e6e0857537c48..932b83edc1da2ba336e1ab4d091d97dacfe73559 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 f294f20b402e29d8d5d0d9f79388bf523d9f4cb1..d01518497711ffc67e050e93065a7c25fb70f15e 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 5b2233643ca771a016a335d97f47b6159925e7f1..3338fa70b2778a84ddb8659e9a8c5bf64a76bfd7 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;
 }