From: Sungbae Yoo Date: Thu, 2 Feb 2017 08:37:57 +0000 (+0900) Subject: Enable to manage the state of external encryption and automount X-Git-Tag: submit/tizen/20170213.020148~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F98%2F112698%2F2;p=platform%2Fcore%2Fsecurity%2Fode.git Enable to manage the state of external encryption and automount Signed-off-by: Sungbae Yoo Change-Id: Ie66e2577a87e983766cf02f9358ff06913be2ab4 --- diff --git a/server/external-encryption.cpp b/server/external-encryption.cpp index 8363b6d..d476a3c 100644 --- a/server/external-encryption.cpp +++ b/server/external-encryption.cpp @@ -63,33 +63,45 @@ void killDependedApplications() void externalCallback(dbus::Variant parameters) { - INFO("SD Card State Changed"); int intparams[6]; char* strparams[7]; parameters.get("(issssssisibii)", - &intparams[0], // block type: 0 - scsi, 1 : mmc - &strparams[0], // devnode - &strparams[1], // syspath - &strparams[2], // usage - &strparams[3], // fs type - &strparams[4], // fs version - &strparams[5], // fs uuid enc - &intparams[1], // readonly: 0 - rw, 1 - ro - &strparams[6], // mount point - &intparams[2], // state: 0 - unmount, 1 - mount - &intparams[3], // primary: 0 - flase, 1 - true - &intparams[4], // flags: 1 - unmounted 2 - broken filesystem 4 - no filesystem 8 - not supported 16 - readonly - &intparams[5]); // strage id + &intparams[0], // block type: 0 - scsi, 1 : mmc + &strparams[0], // devnode + &strparams[1], // syspath + &strparams[2], // usage + &strparams[3], // fs type + &strparams[4], // fs version + &strparams[5], // fs uuid enc + &intparams[1], // readonly: 0 - rw, 1 - ro + &strparams[6], // mount point + &intparams[2], // state: 0 - unmount, 1 - mount + &intparams[3], // primary: 0 - flase, 1 - true + &intparams[4], // flags: 1 - unmounted 2 - broken filesystem 4 - no filesystem 8 - not supported 16 - readonly + &intparams[5]); // strage id + if(intparams[2] == 0) { - INFO("Unmounted!!!"); + INFO("Unmounted"); } else { - INFO("Mounted!!!"); - // TODO - // Password Popup -// std::string pw = "tizen"; -// KeyManager::data data(pw.begin(), pw.end()); -// engine.mount(keyManager.getDEK(data)); + INFO("Mounted"); + char *value = ::vconf_get_str(EXTERNAL_STATE_VCONF_KEY); + if (value != NULL) { + std::string valueStr(value); + free(value); + if (valueStr == "encrypted") { + try { + INFO("Launch 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("Failed to launch SD card password popup"); + } + } + } } } @@ -98,10 +110,10 @@ void externalAddEventReceiver() dbus::Connection &systemDBus = dbus::Connection::getSystem(); systemDBus.subscribeSignal("", - "org.tizen.system.storage.BlockManager", - "DeviceChanged", - "/Org/Tizen/System/Storage/Block/Manager", - externalCallback); + "/Org/Tizen/System/Storage/Block/Manager", + "org.tizen.system.storage.BlockManager", + "DeviceChanged", + externalCallback); } unsigned int getOptions() @@ -169,6 +181,10 @@ ExternalEncryption::~ExternalEncryption() int ExternalEncryption::mount(const std::string &password) { + if (getState() != State::Encrypted) { + return -1; + } + KeyManager::data data(password.begin(), password.end()); KeyManager keyManager(engine.getKeyMeta()); @@ -182,6 +198,10 @@ int ExternalEncryption::mount(const std::string &password) int ExternalEncryption::umount() { + if (getState() != State::Encrypted) { + return -1; + } + INFO("Close all applications using external storage..."); killDependedApplications(); INFO("Umount internal storage..."); @@ -192,6 +212,10 @@ int ExternalEncryption::umount() int ExternalEncryption::encrypt(const std::string &password, unsigned int options) { + if (getState() != State::Unencrypted) { + return -1; + } + KeyManager::data pwData(password.begin(), password.end()); KeyManager keyManager(engine.getKeyMeta()); @@ -204,11 +228,13 @@ int ExternalEncryption::encrypt(const std::string &password, unsigned int option 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"); }; std::thread asyncWork(encryptWorker); @@ -219,6 +245,10 @@ int ExternalEncryption::encrypt(const std::string &password, unsigned int option int ExternalEncryption::decrypt(const std::string &password) { + if (getState() != State::Encrypted) { + return -1; + } + KeyManager::data pwData(password.begin(), password.end()); KeyManager keyManager(engine.getKeyMeta()); @@ -236,10 +266,12 @@ int ExternalEncryption::decrypt(const std::string &password) } 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"); }; std::thread asyncWork(decryptWorker); diff --git a/server/systemd/ode.service.in b/server/systemd/ode.service.in index 152ba0e..d9320ff 100644 --- a/server/systemd/ode.service.in +++ b/server/systemd/ode.service.in @@ -1,5 +1,6 @@ [Unit] Description=@PROJECT_NAME@ management daemon +Before=deviced.service [Service] Type=simple