From f4011350a3603110ab72817fccd628573ea2eb25 Mon Sep 17 00:00:00 2001 From: Lukasz Pawelczyk Date: Wed, 20 Sep 2017 14:05:02 +0200 Subject: [PATCH] Log messages: unify and add missing For Internal and External encryption. Change-Id: I20bd74f06d90b07a2111ffa1a4bff5eff443b81d --- server/external-encryption.cpp | 66 +++++++++++++++++++++-------------- server/internal-encryption.cpp | 78 ++++++++++++++++++++++++------------------ server/misc.cpp | 2 +- 3 files changed, 87 insertions(+), 59 deletions(-) diff --git a/server/external-encryption.cpp b/server/external-encryption.cpp index 1481b1c..2b69c13 100644 --- a/server/external-encryption.cpp +++ b/server/external-encryption.cpp @@ -74,23 +74,23 @@ void externalCallback(dbus::Variant parameters) } if(intparams[2] == 0) { - INFO(SINK, "Unmounted"); + INFO(SINK, "SD card not mounted, ignoring."); } else { - INFO(SINK, "Mounted"); + INFO(SINK, "SD card mounted."); char *value = ::vconf_get_str(EXTERNAL_STATE_VCONF_KEY); if (value != NULL) { std::string valueStr(value); free(value); if (valueStr == "encrypted" && isBootCompleted) { try { - INFO(SINK, "Launch SD card password popup"); + INFO(SINK, "Launching SD card password popup."); AppBundle bundle; bundle.add("viewtype", "SD_CARD_PASSWORD"); Launchpad launchpad(::tzplatform_getuid(TZ_SYS_DEFAULT_USER)); launchpad.launch("org.tizen.ode", bundle); } catch (runtime::Exception &e) { - ERROR(SINK, "Failed to launch SD card password popup"); + ERROR(SINK, "Failed to launch SD card password popup: " + std::string(e.what())); } } } @@ -103,7 +103,7 @@ void bootCompletionCallback(dbus::Variant parameters) //For a delay until homescreen is totally loaded sleep(8); - INFO(SINK, "Boot completed"); + INFO(SINK, "Boot completed."); char *value = ::vconf_get_str(EXTERNAL_STATE_VCONF_KEY); if (value != NULL) { @@ -111,13 +111,13 @@ void bootCompletionCallback(dbus::Variant parameters) free(value); if (valueStr == "encrypted") { try { - INFO(SINK, "Launch SD card password popup"); + INFO(SINK, "Launching SD card password popup."); AppBundle bundle; bundle.add("viewtype", "SD_CARD_PASSWORD"); Launchpad launchpad(::tzplatform_getuid(TZ_SYS_DEFAULT_USER)); launchpad.launch("org.tizen.ode", bundle); } catch (runtime::Exception &e) { - ERROR(SINK, "Failed to launch SD card password popup"); + ERROR(SINK, "Failed to launch SD card password popup: " + std::string(e.what())); } } } @@ -224,6 +224,7 @@ int ExternalEncryptionServer::setMountPassword(const std::string& password) KeyManager::data pwData(password.begin(), password.end()); KeyManager keyManager(engine->getKeyMeta()); if (!keyManager.verifyPassword(pwData)) { + ERROR(SINK, "Wrong password passed."); return -2; } @@ -235,7 +236,7 @@ int ExternalEncryptionServer::setMountPassword(const std::string& password) int ExternalEncryptionServer::mount() { if (mountKey.empty()) { - ERROR(SINK, "You need to call set_mount_password() first"); + ERROR(SINK, "You need to call set_mount_password() first."); return -1; } @@ -243,15 +244,16 @@ int ExternalEncryptionServer::mount() mountKey.clear(); if (getState() != State::Encrypted) { + ERROR(SINK, "Cannot mount, SD card's state incorrect."); return -1; } if (engine->isMounted()) { - INFO(SINK, "Already mounted"); + INFO(SINK, "SD card already mounted."); return 0; } - INFO(SINK, "Mount external storage..."); + INFO(SINK, "Mounting external storage."); try { engine->mount(key, getOptions()); } catch (runtime::Exception &e) { @@ -267,17 +269,19 @@ int ExternalEncryptionServer::mount() int ExternalEncryptionServer::umount() { if (getState() != State::Encrypted) { + ERROR(SINK, "Cannot umount, SD card's state incorrect."); return -1; } if (!engine->isMounted()) { - INFO(SINK, "Already umounted"); + INFO(SINK, "SD card already umounted."); return 0; } - INFO(SINK, "Close all applications using external storage..."); + INFO(SINK, "Closing all applications using external storage."); killDependentApplications(EXTERNAL_PATH); - INFO(SINK, "Umount external storage..."); + + INFO(SINK, "Umounting external storage."); try { engine->umount(); } catch (runtime::Exception &e) { @@ -291,6 +295,7 @@ int ExternalEncryptionServer::umount() int ExternalEncryptionServer::encrypt(const std::string &password, unsigned int options) { if (getState() != State::Unencrypted) { + INFO(SINK, "Cannot encrypt, SD card's state incorrect."); return -1; } @@ -298,25 +303,29 @@ int ExternalEncryptionServer::encrypt(const std::string &password, unsigned int KeyManager keyManager(engine->getKeyMeta()); if (!keyManager.verifyPassword(pwData)) { + ERROR(SINK, "Wrong password passed."); return -2; } KeyManager::data MasterKey = keyManager.getMasterKey(pwData); auto encryptWorker = [MasterKey, options, this]() { try { - INFO(SINK, "Close all applications using external storage..."); + INFO(SINK, "Closing all applications using external storage."); killDependentApplications(EXTERNAL_PATH); - INFO(SINK, "Encryption started..."); + + INFO(SINK, "Encryption started."); engine->encrypt(MasterKey, options); setOptions(options & getSupportedOptions()); - INFO(SINK, "Encryption completed"); + + INFO(SINK, "Encryption completed."); ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "encrypted"); server.notify("ExternalEncryptionServer::mount"); - INFO(SINK, "Sync disk..."); + + INFO(SINK, "Syncing disk."); sync(); } catch (runtime::Exception &e) { ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "error_partially_encrypted"); - ERROR(SINK, "Encryption failed - " + std::string(e.what())); + ERROR(SINK, "Encryption failed: " + std::string(e.what())); } }; @@ -329,6 +338,7 @@ int ExternalEncryptionServer::encrypt(const std::string &password, unsigned int int ExternalEncryptionServer::decrypt(const std::string &password) { if (getState() != State::Encrypted) { + ERROR(SINK, "Cannot decrypt, SD card's state incorrect."); return -1; } @@ -336,15 +346,17 @@ int ExternalEncryptionServer::decrypt(const std::string &password) KeyManager keyManager(engine->getKeyMeta()); if (!keyManager.verifyPassword(pwData)) { + ERROR(SINK, "Wrong password passed."); return -2; } KeyManager::data MasterKey = keyManager.getMasterKey(pwData); auto decryptWorker = [MasterKey, this]() { try { - INFO(SINK, "Close all applications using external storage..."); + INFO(SINK, "Closing all applications using external storage."); killDependentApplications(EXTERNAL_PATH); - INFO(SINK, "Umount external storage..."); + + INFO(SINK, "Umounting external storage."); while (1) { try { engine->umount(); @@ -354,15 +366,17 @@ int ExternalEncryptionServer::decrypt(const std::string &password) } } - INFO(SINK, "Decryption started..."); + INFO(SINK, "Decryption started."); ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "error_partially_encrypted"); engine->decrypt(MasterKey, getOptions()); - INFO(SINK, "Decryption completed"); + + INFO(SINK, "Decryption completed."); ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "unencrypted"); - INFO(SINK, "Sync disk..."); + + INFO(SINK, "Syncing disk."); sync(); } catch (runtime::Exception &e) { - ERROR(SINK, "Decryption failed - " + std::string(e.what())); + ERROR(SINK, "Decryption failed: " + std::string(e.what())); } }; @@ -413,6 +427,7 @@ int ExternalEncryptionServer::cleanPassword(const std::string& password) KeyManager keyManager(engine->getKeyMeta()); if (!keyManager.verifyPassword(pwData)) { + ERROR(SINK, "Wrong password passed."); return -2; } @@ -428,6 +443,7 @@ int ExternalEncryptionServer::changePassword(const std::string &oldPassword, KeyManager keyManager(engine->getKeyMeta()); if (!keyManager.verifyPassword(oldPwData)) { + ERROR(SINK, "Wrong password passed."); return -2; } @@ -452,7 +468,7 @@ int ExternalEncryptionServer::getState() { char *value = ::vconf_get_str(EXTERNAL_STATE_VCONF_KEY); if (value == NULL) { - throw runtime::Exception("Failed to get vconf value"); + throw runtime::Exception("Failed to get vconf value."); } std::string valueStr(value); diff --git a/server/internal-encryption.cpp b/server/internal-encryption.cpp index c5e762e..0c07c0e 100644 --- a/server/internal-encryption.cpp +++ b/server/internal-encryption.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include "misc.h" #include "logger.h" @@ -85,7 +86,7 @@ std::string findDevPath() char *dev = ::realpath(source.c_str(), NULL); if (dev == NULL) { - ERROR(SINK, "failed to get device path"); + ERROR(SINK, "Failed to get device path."); return ""; } @@ -95,7 +96,8 @@ std::string findDevPath() return devPath; } -void stopKnownSystemdServices() { +void stopKnownSystemdServices() +{ std::vector knownSystemdServices; dbus::Connection& systemDBus = dbus::Connection::getSystem(); dbus::VariantIterator iter; @@ -130,7 +132,7 @@ void stopKnownSystemdServices() { } for (const std::string& service : knownSystemdServices) { - INFO(SINK, "Stop service - " + service); + INFO(SINK, "Stopping service: " + service); systemDBus.methodcall("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", @@ -157,13 +159,13 @@ void stopDependedSystemdServices() .get("(o)", &service); servicesToStop.insert(service); } catch (runtime::Exception &e) { - INFO(SINK, "Close process - " + std::to_string(pid)); + INFO(SINK, "Killing process: " + std::to_string(pid)); ::kill(pid, SIGKILL); } } for (const std::string& service : servicesToStop) { - INFO(SINK, "Close service - " + service); + INFO(SINK, "Stopping service: " + service); systemDBus.methodcall("org.freedesktop.systemd1", service, "org.freedesktop.systemd1.Unit", @@ -172,7 +174,8 @@ void stopDependedSystemdServices() } } -void showProgressUI(const std::string type) { +void showProgressUI(const std::string type) +{ ::tzplatform_set_user(::tzplatform_getuid(TZ_SYS_DEFAULT_USER)); std::string defaultUserHome(::tzplatform_getenv(TZ_USER_HOME)); ::tzplatform_reset_user(); @@ -189,7 +192,7 @@ void showProgressUI(const std::string type) { defaultElmConfigDir.copyTo(shareDirectory.getPath()); } } catch (runtime::Exception &e) { - ERROR(SINK, "Failed to set up elm configuration"); + ERROR(SINK, "Failed to set up elm configuration: " + std::string(e.what())); } std::vector args = { @@ -266,6 +269,7 @@ int InternalEncryptionServer::setMountPassword(const std::string& password) KeyManager::data pwData(password.begin(), password.end()); KeyManager keyManager(engine->getKeyMeta()); if (!keyManager.verifyPassword(pwData)) { + ERROR(SINK, "Wrong password passed."); return -2; } @@ -277,7 +281,7 @@ int InternalEncryptionServer::setMountPassword(const std::string& password) int InternalEncryptionServer::mount() { if (mountKey.empty()) { - ERROR(SINK, "You need to call set_mount_password() first"); + ERROR(SINK, "You need to call set_mount_password() first."); return -1; } @@ -285,16 +289,17 @@ int InternalEncryptionServer::mount() mountKey.clear(); if (getState() != State::Encrypted) { + INFO(SINK, "Cannot mount, SD partition's state incorrect."); return -1; } if (engine->isMounted()) { - INFO(SINK, "Already mounted"); + INFO(SINK, "Partition already mounted."); return 0; } + INFO(SINK, "Mounting internal storage."); try { - INFO(SINK, "Mount internal storage..."); engine->mount(key, getOptions()); server.notify("InternalEncryptionServer::mount"); @@ -302,7 +307,7 @@ int InternalEncryptionServer::mount() runtime::File("/tmp/.lazy_mount").create(O_WRONLY); runtime::File("/tmp/.unlock_mnt").create(O_WRONLY); } catch (runtime::Exception &e) { - ERROR(SINK, "Mount failed - " + std::string(e.what())); + ERROR(SINK, "Mount failed: " + std::string(e.what())); return -1; } @@ -312,21 +317,22 @@ int InternalEncryptionServer::mount() int InternalEncryptionServer::umount() { if (getState() != State::Encrypted) { + ERROR(SINK, "Cannot umount, partition's state incorrect."); return -1; } if (!engine->isMounted()) { - INFO(SINK, "Already umounted"); + INFO(SINK, "Partition already umounted."); return 0; } + INFO(SINK, "Closing all processes using internal storage."); try { - INFO(SINK, "Close all processes using internal storage..."); stopDependedSystemdServices(); - INFO(SINK, "Umount internal storage..."); + INFO(SINK, "Umounting internal storage."); engine->umount(); } catch (runtime::Exception &e) { - ERROR(SINK, "Umount failed - " + std::string(e.what())); + ERROR(SINK, "Umount failed: " + std::string(e.what())); return -1; } @@ -336,6 +342,7 @@ int InternalEncryptionServer::umount() int InternalEncryptionServer::encrypt(const std::string& password, unsigned int options) { if (getState() != State::Unencrypted) { + ERROR(SINK, "Cannot encrypt, partition's state incorrect."); return -1; } @@ -343,6 +350,7 @@ int InternalEncryptionServer::encrypt(const std::string& password, unsigned int KeyManager keyManager(engine->getKeyMeta()); if (!keyManager.verifyPassword(pwData)) { + ERROR(SINK, "Wrong password passed."); return -2; } @@ -353,17 +361,17 @@ int InternalEncryptionServer::encrypt(const std::string& password, unsigned int std::string mntPath = findMntPath(source); if (!mntPath.empty()) { - INFO(SINK, "Close all known systemd services that might be using internal storage..."); + INFO(SINK, "Closing all known systemd services that might be using internal storage."); stopKnownSystemdServices(); - INFO(SINK, "Close all processes using internal storage..."); + INFO(SINK, "Closing all processes using internal storage."); stopDependedSystemdServices(); } while (!mntPath.empty()) { - INFO(SINK, "Umount internal storage..."); + INFO(SINK, "Umounting internal storage."); while (::umount(mntPath.c_str()) == -1) { if (errno != EBUSY) { - throw runtime::Exception("Umount error - " + std::to_string(errno)); + throw runtime::Exception("Umount error: " + runtime::GetSystemErrorMessage()); } stopDependedSystemdServices(); } @@ -372,20 +380,20 @@ int InternalEncryptionServer::encrypt(const std::string& password, unsigned int showProgressUI("Encrypting"); - INFO(SINK, "Encryption started..."); + INFO(SINK, "Encryption started."); + ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "error_partially_encrypted"); engine->encrypt(MasterKey, options); setOptions(options & getSupportedOptions()); - INFO(SINK, "Encryption completed"); + INFO(SINK, "Encryption completed."); ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "encrypted"); server.notify("InternalEncryptionServer::mount"); - INFO(SINK, "Syncing disk and rebooting..."); + INFO(SINK, "Syncing disk and rebooting."); ::sync(); ::reboot(RB_AUTOBOOT); } catch (runtime::Exception &e) { - ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "error_partially_encrypted"); - ERROR(SINK, "Encryption failed - " + std::string(e.what())); + ERROR(SINK, "Encryption failed: " + std::string(e.what())); } }; @@ -398,6 +406,7 @@ int InternalEncryptionServer::encrypt(const std::string& password, unsigned int int InternalEncryptionServer::decrypt(const std::string& password) { if (getState() != State::Encrypted) { + ERROR(SINK, "Cannot decrypt, partition's state incorrect."); return -1; } @@ -405,6 +414,7 @@ int InternalEncryptionServer::decrypt(const std::string& password) KeyManager keyManager(engine->getKeyMeta()); if (!keyManager.verifyPassword(pwData)) { + ERROR(SINK, "Wrong password passed."); return -2; } @@ -412,12 +422,12 @@ int InternalEncryptionServer::decrypt(const std::string& password) auto decryptWorker = [MasterKey, this]() { try { if (engine->isMounted()) { - INFO(SINK, "Close all known systemd services that might be using internal storage..."); + INFO(SINK, "Closing all known systemd services that might be using internal storage."); stopKnownSystemdServices(); - INFO(SINK, "Close all processes using internal storage..."); + INFO(SINK, "Closing all processes using internal storage."); stopDependedSystemdServices(); - INFO(SINK, "Umount internal storage..."); + INFO(SINK, "Umounting internal storage."); while (1) { try { engine->umount(); @@ -430,18 +440,18 @@ int InternalEncryptionServer::decrypt(const std::string& password) showProgressUI("Decrypting"); - INFO(SINK, "Decryption started..."); + INFO(SINK, "Decryption started."); + ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "error_partially_encrypted"); engine->decrypt(MasterKey, getOptions()); - INFO(SINK, "Decryption completed"); + INFO(SINK, "Decryption complete."); ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "unencrypted"); - INFO(SINK, "Syncing disk and rebooting..."); + INFO(SINK, "Syncing disk and rebooting."); ::sync(); ::reboot(RB_AUTOBOOT); } catch (runtime::Exception &e) { - ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "error_partially_encrypted"); - ERROR(SINK, "Decryption failed - " + std::string(e.what())); + ERROR(SINK, "Decryption failed: " + std::string(e.what())); } }; @@ -491,6 +501,7 @@ int InternalEncryptionServer::cleanPassword(const std::string& password) KeyManager keyManager(engine->getKeyMeta()); if (!keyManager.verifyPassword(pwData)) { + ERROR(SINK, "Wrong password passed."); return -2; } @@ -506,6 +517,7 @@ int InternalEncryptionServer::changePassword(const std::string& oldPassword, KeyManager keyManager(engine->getKeyMeta()); if (!keyManager.verifyPassword(oldPwData)) { + ERROR(SINK, "Wrong password passed."); return -2; } @@ -530,7 +542,7 @@ int InternalEncryptionServer::getState() { char *value = ::vconf_get_str(VCONFKEY_ODE_CRYPTO_STATE); if (value == NULL) { - throw runtime::Exception("Failed to get vconf value"); + throw runtime::Exception("Failed to get vconf value."); } std::string valueStr(value); diff --git a/server/misc.cpp b/server/misc.cpp index c7ba4b3..80a6458 100644 --- a/server/misc.cpp +++ b/server/misc.cpp @@ -45,7 +45,7 @@ std::string findMntPath(const std::string &devPath) void killDependentApplications(const std::string &mntPath) { for (pid_t pid : runtime::FileUser::getList(mntPath, true)) { - INFO(SINK, "Close process - " + std::to_string(pid)); + INFO(SINK, "Killing process: " + std::to_string(pid)); ::kill(pid, SIGKILL); } } -- 2.7.4