From: Sungbae Yoo Date: Thu, 2 Feb 2017 09:08:24 +0000 (+0900) Subject: Add exception handling in threads for encryption/decryption X-Git-Tag: accepted/tizen/common/20170213.174442~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=022c3dd8a26467ac891c2093ae2fbcac2b8da90a;p=platform%2Fcore%2Fsecurity%2Fode.git Add exception handling in threads for encryption/decryption Signed-off-by: Sungbae Yoo Change-Id: Ieb65804da717e4812f9854d73718a9daebb2b10c --- diff --git a/server/external-encryption.cpp b/server/external-encryption.cpp index d476a3c..42d3b04 100644 --- a/server/external-encryption.cpp +++ b/server/external-encryption.cpp @@ -204,7 +204,7 @@ int ExternalEncryption::umount() INFO("Close all applications using external storage..."); killDependedApplications(); - INFO("Umount internal storage..."); + INFO("Umount external storage..."); engine.umount(); return 0; @@ -225,16 +225,20 @@ int ExternalEncryption::encrypt(const std::string &password, unsigned int option KeyManager::data MasterKey = keyManager.getMasterKey(pwData); auto encryptWorker = [&MasterKey, options, this]() { - INFO("Close all applications using external storage..."); - killDependedApplications(); - INFO("Encryption started..."); - ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "error_partially_encrypted"); - engine.encrypt(MasterKey, options); - setOptions(options & getSupportedOptions()); - INFO("Sync disk..."); - sync(); - INFO("Encryption completed"); - ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "encrypted"); + try { + INFO("Close all applications using external storage..."); + killDependedApplications(); + INFO("Encryption started..."); + ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "error_partially_encrypted"); + engine.encrypt(MasterKey, options); + setOptions(options & getSupportedOptions()); + INFO("Sync disk..."); + sync(); + INFO("Encryption completed"); + ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "encrypted"); + } catch (runtime::Exception &e) { + ERROR("Encryption failed - " + std::string(e.what())); + } }; std::thread asyncWork(encryptWorker); @@ -258,20 +262,29 @@ int ExternalEncryption::decrypt(const std::string &password) KeyManager::data MasterKey = keyManager.getMasterKey(pwData); auto decryptWorker = [MasterKey, this]() { - INFO("Close all applications using external storage..."); - killDependedApplications(); - INFO("Umount internal storage..."); try { - engine.umount(); - } catch (runtime::Exception &e) {} - - INFO("Decryption started..."); - ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "error_partially_encrypted"); - engine.decrypt(MasterKey, getOptions()); - INFO("Sync disk..."); - sync(); - INFO("Decryption completed"); - ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "unencrypted"); + INFO("Close all applications using external storage..."); + killDependedApplications(); + INFO("Umount external storage..."); + while (1) { + try { + engine.umount(); + break; + } catch (runtime::Exception &e) { + killDependedApplications(); + } + } + + INFO("Decryption started..."); + ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "error_partially_encrypted"); + engine.decrypt(MasterKey, getOptions()); + INFO("Sync disk..."); + sync(); + INFO("Decryption completed"); + ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "unencrypted"); + } catch (runtime::Exception &e) { + ERROR("Decryption failed - " + std::string(e.what())); + } }; std::thread asyncWork(decryptWorker); @@ -339,8 +352,6 @@ int ExternalEncryption::verifyPassword(const std::string& password) return 0; } - - int ExternalEncryption::getState() { char *value = ::vconf_get_str(EXTERNAL_STATE_VCONF_KEY); diff --git a/server/internal-encryption.cpp b/server/internal-encryption.cpp index a8f3ad6..01b3ea5 100644 --- a/server/internal-encryption.cpp +++ b/server/internal-encryption.cpp @@ -179,26 +179,31 @@ int InternalEncryption::encrypt(const std::string& password, unsigned int option KeyManager::data MasterKey = keyManager.getMasterKey(pwData); auto encryptWorker = [&MasterKey, options, this]() { - showProgressUI("Encrypting"); - - INFO("Close all processes using internal storage..."); - stopDependedSystemdServices(); - INFO("Umount internal storage..."); - while (::umount(INTERNAL_STORAGE_PATH) == -1) { - if (errno != EBUSY) { - break; + try { + showProgressUI("Encrypting"); + + INFO("Close all processes using internal storage..."); + stopDependedSystemdServices(); + INFO("Umount internal storage..."); + while (::umount(INTERNAL_STORAGE_PATH) == -1) { + if (errno != EBUSY) { + throw runtime::Exception("Umount error - " + std::to_string(errno)); + } + stopDependedSystemdServices(); } - } - INFO("Encryption started..."); - ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "error_partially_encrypted"); - engine.encrypt(MasterKey, options); - setOptions(options & getSupportedOptions()); - INFO("Sync disk..."); - sync(); - INFO("Encryption completed"); + INFO("Encryption started..."); + ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "error_partially_encrypted"); + engine.encrypt(MasterKey, options); + setOptions(options & getSupportedOptions()); + INFO("Sync disk..."); + sync(); + INFO("Encryption completed"); - ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "encrypted"); + ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "encrypted"); + } catch (runtime::Exception &e) { + ERROR("Encryption failed - " + std::string(e.what())); + } ::reboot(RB_AUTOBOOT); }; @@ -223,23 +228,32 @@ int InternalEncryption::decrypt(const std::string& password) KeyManager::data MasterKey = keyManager.getMasterKey(pwData); auto decryptWorker = [MasterKey, this]() { - showProgressUI("Decrypting"); - - INFO("Close all processes using internal storage..."); - stopDependedSystemdServices(); - INFO("Umount internal storage..."); try { - engine.umount(); - } catch (runtime::Exception& e) {} + showProgressUI("Decrypting"); + + INFO("Close all processes using internal storage..."); + stopDependedSystemdServices(); + INFO("Umount internal storage..."); + while (1) { + try { + engine.umount(); + break; + } catch (runtime::Exception& e) { + stopDependedSystemdServices(); + } + } - INFO("Decryption started..."); - ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "error_partially_encrypted"); - engine.decrypt(MasterKey, getOptions()); - INFO("Sync disk..."); - sync(); - INFO("Decryption completed"); + INFO("Decryption started..."); + ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "error_partially_encrypted"); + engine.decrypt(MasterKey, getOptions()); + INFO("Sync disk..."); + sync(); + INFO("Decryption completed"); - ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "unencrypted"); + ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "unencrypted"); + } catch (runtime::Exception &e) { + ERROR("Decryption failed - " + std::string(e.what())); + } ::reboot(RB_AUTOBOOT); }; @@ -308,8 +322,6 @@ int InternalEncryption::verifyPassword(const std::string& password) return 0; } - - int InternalEncryption::getState() { char *value = ::vconf_get_str(INTERNAL_STATE_VCONF_KEY);