}
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()));
}
}
}
//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) {
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()));
}
}
}
KeyManager::data pwData(password.begin(), password.end());
KeyManager keyManager(engine->getKeyMeta());
if (!keyManager.verifyPassword(pwData)) {
+ ERROR(SINK, "Wrong password passed.");
return -2;
}
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;
}
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) {
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) {
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;
}
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()));
}
};
int ExternalEncryptionServer::decrypt(const std::string &password)
{
if (getState() != State::Encrypted) {
+ ERROR(SINK, "Cannot decrypt, SD card's state incorrect.");
return -1;
}
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();
}
}
- 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()));
}
};
KeyManager keyManager(engine->getKeyMeta());
if (!keyManager.verifyPassword(pwData)) {
+ ERROR(SINK, "Wrong password passed.");
return -2;
}
KeyManager keyManager(engine->getKeyMeta());
if (!keyManager.verifyPassword(oldPwData)) {
+ ERROR(SINK, "Wrong password passed.");
return -2;
}
{
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);
#include <klay/file-user.h>
#include <klay/filesystem.h>
#include <klay/dbus/connection.h>
+#include <klay/error.h>
#include "misc.h"
#include "logger.h"
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 "";
}
return devPath;
}
-void stopKnownSystemdServices() {
+void stopKnownSystemdServices()
+{
std::vector<std::string> knownSystemdServices;
dbus::Connection& systemDBus = dbus::Connection::getSystem();
dbus::VariantIterator iter;
}
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",
.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",
}
}
-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();
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<std::string> args = {
KeyManager::data pwData(password.begin(), password.end());
KeyManager keyManager(engine->getKeyMeta());
if (!keyManager.verifyPassword(pwData)) {
+ ERROR(SINK, "Wrong password passed.");
return -2;
}
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;
}
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");
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;
}
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;
}
int InternalEncryptionServer::encrypt(const std::string& password, unsigned int options)
{
if (getState() != State::Unencrypted) {
+ ERROR(SINK, "Cannot encrypt, partition's state incorrect.");
return -1;
}
KeyManager keyManager(engine->getKeyMeta());
if (!keyManager.verifyPassword(pwData)) {
+ ERROR(SINK, "Wrong password passed.");
return -2;
}
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();
}
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()));
}
};
int InternalEncryptionServer::decrypt(const std::string& password)
{
if (getState() != State::Encrypted) {
+ ERROR(SINK, "Cannot decrypt, partition's state incorrect.");
return -1;
}
KeyManager keyManager(engine->getKeyMeta());
if (!keyManager.verifyPassword(pwData)) {
+ ERROR(SINK, "Wrong password passed.");
return -2;
}
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();
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()));
}
};
KeyManager keyManager(engine->getKeyMeta());
if (!keyManager.verifyPassword(pwData)) {
+ ERROR(SINK, "Wrong password passed.");
return -2;
}
KeyManager keyManager(engine->getKeyMeta());
if (!keyManager.verifyPassword(oldPwData)) {
+ ERROR(SINK, "Wrong password passed.");
return -2;
}
{
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);