#include <sys/reboot.h>
#include <vconf.h>
+#include <tzplatform_config.h>
#include <klay/process.h>
#include <klay/file-user.h>
#include <klay/filesystem.h>
#include "vconf.h"
#include "progress-bar.h"
-#include "engine/dmcrypt-engine.h"
+#include "engine/encryption/dmcrypt-engine.h"
#include "key-manager/key-manager.h"
#include "rmi/internal-encryption.h"
#define PRIVILEGE_PLATFORM "http://tizen.org/privilege/internal/default/platform"
+const std::string PROG_FACTORY_RESET = "/usr/bin/dbus-send";
+const std::vector<std::string> wipeCommand = {
+ PROG_FACTORY_RESET,
+ "--system",
+ "--type=signal",
+ "--print-reply",
+ "--dest=com.samsung.factoryreset",
+ "/com/samsung/factoryreset",
+ "com.samsung.factoryreset.start.setting"
+};
+
namespace ode {
namespace {
}
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();
+
+ ::tzplatform_set_user(::getuid());
+ std::string currentUserHome(::tzplatform_getenv(TZ_USER_HOME));
+ ::tzplatform_reset_user();
+
+ INFO("Home directory : " + currentUserHome);
+
+ runtime::File shareDirectory(currentUserHome + "/share");
+ if (!shareDirectory.exists()) {
+ shareDirectory.makeDirectory();
+ }
+
+ runtime::File elmConfigDir(currentUserHome + "/share/.elementary");
+ if (!elmConfigDir.exists()) {
+ runtime::File defaultElmConfigDir(defaultUserHome + "/share/.elementary");
+ defaultElmConfigDir.copyTo(shareDirectory.getPath());
+ }
+
std::vector<std::string> args = {
"ode", "progress", type, "Internal"
};
}
INFO("Encryption started...");
- ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "error_partially_encrypted");
engine->encrypt(MasterKey, options);
setOptions(options & getSupportedOptions());
INFO("Sync disk...");
INFO("Encryption completed");
::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "encrypted");
+ ::reboot(RB_AUTOBOOT);
} catch (runtime::Exception &e) {
+ ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "error_partially_encrypted");
ERROR("Encryption failed - " + std::string(e.what()));
}
- ::reboot(RB_AUTOBOOT);
};
std::thread asyncWork(encryptWorker);
}
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");
+ ::reboot(RB_AUTOBOOT);
} catch (runtime::Exception &e) {
+ ::vconf_set_str(INTERNAL_STATE_VCONF_KEY, "error_partially_encrypted");
ERROR("Decryption failed - " + std::string(e.what()));
}
- ::reboot(RB_AUTOBOOT);
};
std::thread asyncWork(decryptWorker);
return 0;
}
+int InternalEncryption::recovery()
+{
+ if (getState() != State::Unencrypted) {
+ return -1;
+ }
+
+ //TODO
+ runtime::Process proc(PROG_FACTORY_RESET, wipeCommand);
+ if (proc.execute() == -1) {
+ ERROR("Failed to launch factory-reset");
+ return -2;
+ }
+
+ return 0;
+}
+
int InternalEncryption::isPasswordInitialized()
{
if (engine->isKeyMetaSet()) {