#include <unistd.h>
#include <sys/mount.h>
+#include <vconf.h>
#include <tzplatform_config.h>
+
#include <klay/file-user.h>
#include <klay/filesystem.h>
#include <klay/audit/logger.h>
#define EXTERNAL_STORAGE_PATH "/opt/media/SDCardA1"
#define DEFAULT_USER "owner"
+#define EXTERNAL_STORAGE_VCONF_KEY VCONFKEY_SDE_CRYPTO_STATE
namespace ode {
int ExternalEncryption::getState()
{
- //TODO
+ char *value = ::vconf_get_str(EXTERNAL_STORAGE_VCONF_KEY);
+ if (value == NULL) {
+ throw runtime::Exception("Failed to get vconf value");
+ }
+
+ std::string valueStr(value);
+ free(value);
+
+ if (valueStr == "encrypted") {
+ return State::Encrypted;
+ } else if (valueStr == "unencrypted") {
+ return State::Unencrypted;
+ } else {
+ return State::Corrupted;
+ }
+
return 0;
}
#include <sys/mount.h>
#include <sys/reboot.h>
+#include <vconf.h>
#include <klay/process.h>
#include <klay/file-user.h>
#include <klay/filesystem.h>
#include "rmi/internal-encryption.h"
#define INTERNAL_STORAGE_PATH "/opt/usr"
+#define INTERNAL_STORAGE_VCONF_KEY VCONFKEY_ODE_CRYPTO_STATE
namespace ode {
int InternalEncryption::mount(const std::string& password)
{
+ if (getState() != State::Encrypted) {
+ return -1;
+ }
+
KeyManager::data pwData(password.begin(), password.end());
KeyManager keyManager(engine.getKeyMeta());
int InternalEncryption::umount()
{
+ if (getState() != State::Encrypted) {
+ return -1;
+ }
+
INFO("Close all processes using internal storage...");
stopDependedSystemdServices();
INFO("Umount internal storage...");
int InternalEncryption::encrypt(const std::string& password)
{
+ if (getState() != State::Unencrypted) {
+ return -1;
+ }
+
KeyManager::data pwData(password.begin(), password.end());
KeyManager keyManager;
}
INFO("Encryption started...");
+ ::vconf_set_str(INTERNAL_STORAGE_VCONF_KEY, "error_partially_encrypted");
engine.encrypt(MasterKey);
INFO("Sync disk...");
sync();
INFO("Encryption completed");
+
+ ::vconf_set_str(INTERNAL_STORAGE_VCONF_KEY, "encrypted");
::reboot(RB_AUTOBOOT);
};
int InternalEncryption::decrypt(const std::string& password)
{
+ if (getState() != State::Encrypted) {
+ return -1;
+ }
+
KeyManager::data pwData(password.begin(), password.end());
KeyManager keyManager(engine.getKeyMeta());
} catch (runtime::Exception& e) {}
INFO("Decryption started...");
+ ::vconf_set_str(INTERNAL_STORAGE_VCONF_KEY, "error_partially_encrypted");
engine.decrypt(MasterKey);
INFO("Sync disk...");
sync();
INFO("Decryption completed");
+
+ ::vconf_set_str(INTERNAL_STORAGE_VCONF_KEY, "unencrypted");
::reboot(RB_AUTOBOOT);
};
int InternalEncryption::getState()
{
- //TODO
+ char *value = ::vconf_get_str(INTERNAL_STORAGE_VCONF_KEY);
+ if (value == NULL) {
+ throw runtime::Exception("Failed to get vconf value");
+ }
+
+ std::string valueStr(value);
+ free(value);
+
+ if (valueStr == "encrypted") {
+ return State::Encrypted;
+ } else if (valueStr == "unencrypted") {
+ return State::Unencrypted;
+ } else {
+ return State::Corrupted;
+ }
+
return 0;
}