Fix to set state of encryption process accepted/tizen/4.0/unified/20180914.132325 submit/tizen_4.0/20180913.090020
authorseolheui, kim <s414.kim@samsung.com>
Thu, 13 Sep 2018 08:09:15 +0000 (17:09 +0900)
committerJaemin Ryu <jm77.ryu@samsung.com>
Thu, 13 Sep 2018 08:26:32 +0000 (17:26 +0900)
Change-Id: Iebb2101fe7a41ba54b745c9b417d2297b5831e99
Signed-off-by: seolheui, kim <s414.kim@samsung.com>
server/engine/encryption/dmcrypt-engine.cpp
server/engine/encryption/dmcrypt-engine.h
server/internal-encryption.cpp

index 60c217a..4fbba93 100644 (file)
@@ -267,7 +267,7 @@ void copyInPlace(const std::string &source, const std::string &destination,
 } // namepsace
 
 DMCryptEngine::DMCryptEngine(const std::string &src, const std::string &dest, const ProgressBar &prgsBar) :
-       source(src), destination(dest), progress(prgsBar)
+       source(src), destination(dest), progress(prgsBar), start(false)
 {
 }
 
@@ -326,6 +326,7 @@ void DMCryptEngine::encrypt(const BinaryData &key, unsigned int options)
        // create crypto type device mapping layer to mount the plain partition
        // should be encrypted here.
        auto cryptoBlkDev = createCryptoBlkDev(source, DM_DEFAULT_LABEL_NAME, sanitizeKey(key), DM_DEFAULT_CRYPTO_NAME);
+       start = true;
 
        std::function<bool(blkcnt_t)> isTarget;
        if (!(options & OPTION_INCLUDE_UNUSED_REGION)) {
@@ -355,6 +356,7 @@ void DMCryptEngine::decrypt(const BinaryData &key, unsigned int options)
        // create crypto type device mapping layer to mount the plain partition
        // should be encrypted here.
        auto cryptoBlkDev = createCryptoBlkDev(source, DM_DEFAULT_LABEL_NAME, sanitizeKey(key), DM_DEFAULT_CRYPTO_NAME);
+       start = true;
 
        // Force filesystem check via fcsf might be able to avoid fail situation during decryption.
        Ext4Tool ext4CryptoBlkDev(cryptoBlkDev);
index 1761598..a93260b 100644 (file)
@@ -44,6 +44,11 @@ public:
                return destination;
        }
 
+       bool isStarted()
+       {
+               return start;
+       }
+
        void mount(const BinaryData &key, unsigned int options);
        void umount();
        bool isMounted();
@@ -56,6 +61,7 @@ public:
 private:
        std::string source, destination;
        ProgressBar progress;
+       bool start;
 };
 
 } // namespace ode
index d29d876..d913667 100644 (file)
@@ -520,7 +520,17 @@ int InternalEncryptionServer::encrypt(const std::string& password, unsigned int
 
                        INFO(SINK, "Encryption started.");
                        ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "error_partially_encrypted");
-                       engine->encrypt(masterKey, options);
+                       try {
+                               engine->encrypt(masterKey, options);
+                       } catch (runtime::Exception &e) {
+                               ERROR(SINK, e.what());
+                               if (!engine->isStarted()) {
+                                       ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "unencrypted");
+                                       file.remove();
+                               }
+                               ::sync();
+                               ::reboot(RB_AUTOBOOT);
+                       }
                        setOptions(options & getSupportedOptions());
 
                        INFO(SINK, "Encryption completed.");
@@ -574,7 +584,17 @@ int InternalEncryptionServer::decrypt(const std::string& password)
 
                        INFO(SINK, "Decryption started.");
                        ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "error_partially_decrypted");
-                       engine->decrypt(masterKey, getOptions());
+                       try {
+                               engine->decrypt(masterKey, getOptions());
+                       } catch (runtime::Exception &e) {
+                               ERROR(SINK, e.what());
+                               if (!engine->isStarted()) {
+                                       ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "encrypted");
+                                       file.remove();
+                               }
+                               ::sync();
+                               ::reboot(RB_AUTOBOOT);
+                       }
 
                        INFO(SINK, "Decryption complete.");
                        ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "unencrypted");