Remove 'forceCleanup' code during decryption after tizen 4.0 27/220127/4 submit/tizen_4.0/20191223.082114
authors414.kim <s414.kim@samsung.com>
Fri, 13 Dec 2019 08:48:52 +0000 (17:48 +0900)
committers414.kim <s414.kim@samsung.com>
Thu, 19 Dec 2019 07:29:55 +0000 (16:29 +0900)
This commit is to prevent unknown bugs in decryption. After starting decryption,
the ode is in a deadlock with the progress bar is zero for unknown reasons.

Change-Id: Ifbec9da6894eef35b09039bbe0da022ac25f8dc1
Signed-off-by: s414.kim <s414.kim@samsung.com>
fota/CMakeLists.txt
server/engine/encryption/dmcrypt-engine.cpp
server/ext4-tool.cpp

index e7d41a0..c966bd9 100755 (executable)
@@ -16,7 +16,7 @@
 
 SET(PROJECT_NAME "ode-fota")
 
-PKG_CHECK_MODULES(FOTA_DEPS REQUIRED klay-static blkid)
+PKG_CHECK_MODULES(FOTA_DEPS REQUIRED vconf klay-static blkid)
 
 SET(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/fota.cpp
                        ${ODE_SERVER}/upgrade-support.cpp
index 88d7c0d..45ea9c9 100644 (file)
@@ -21,6 +21,7 @@
 #include <fcntl.h>
 #include <errno.h>
 
+#include <vconf.h>
 #include <klay/error.h>
 #include <klay/exception.h>
 #include <klay/filesystem.h>
@@ -363,14 +364,28 @@ void DMCryptEngine::decrypt(const BinaryData &key, unsigned int options)
 
        start = true;
 
-       for (int retry = 0; retry < 32; retry++) {
-               try {
-                       ext4CryptoBlkDev.forceCleanUp();
-               } catch (runtime::Exception &e) {
-                       continue;
+       // Since the vconf value for crypto status is different before and after tizen 5.0,
+       // check the version of tizen platform using the vconf value.
+       char *value = ::vconf_get_str(VCONFKEY_ODE_CRYPTO_STATE);
+       if (value == NULL)
+               throw runtime::Exception("Failed to get a vconf value.");
+
+       bool needCleanUp = strcmp(value, "encrypted") == 0 ? true : false;
+       ::free(value);
+
+       // The forceCleanUp is unnecessary after tizen 5.0.
+       // But leave this for tizen 4.0.
+       if (needCleanUp) {
+               for (int retry = 0; retry < 32; retry++) {
+                       try {
+                               ext4CryptoBlkDev.forceCleanUp();
+                       } catch (runtime::Exception &e) {
+                               continue;
+                       }
+                       break;
                }
-               break;
        }
+
        INFO(SINK, "Crypto Engine : checked target device");
 
        std::function<bool(blkcnt_t)> isTarget;
index 2fc1ffe..80e8dba 100644 (file)
@@ -116,6 +116,8 @@ void Ext4Tool::readInfo()
        // read totalBlockCount
        device.lseek(ODE_SUPERBLOCK_OFFSET +  4, SEEK_SET);
        device.read(&totalBlockCount, 4);
+       if (totalBlockCount == 0)
+               throw runtime::Exception("Invalid totalBlockCount");
 
        // read firstDataBlock
        device.lseek(ODE_SUPERBLOCK_OFFSET + 20, SEEK_SET);