Merge tizen_4.0 into tizen 26/199226/2 submit/tizen/20190311.143210 submit/tizen/20190312.095229 submit/tizen/20190315.105214 submit/tizen_5.0/20190311.143405 submit/tizen_5.0/20190312.095251 submit/tizen_5.0/20190314.052825 submit/tizen_5.0/20190315.105239
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 7 Feb 2019 10:16:12 +0000 (11:16 +0100)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 7 Feb 2019 10:35:32 +0000 (11:35 +0100)
Change-Id: Ibc4f1105aad26c5df9a640775e81bfc761403c5a

1  2 
fota/fota.cpp
server/engine/encryption/dmcrypt-engine.cpp
server/external-encryption.cpp
server/internal-encryption.cpp
server/upgrade-support.cpp

diff --cc fota/fota.cpp
@@@ -67,10 -144,16 +143,16 @@@ int main(int argc, char* argv[]
                        return EXIT_FAILURE;
                }
  
+               MmcDevice dev(0);
+               std::string devpath = dev.findNode("user");
                if (MOUNT == argv[1]) {
-                       auto masterKey = UpgradeSupport::loadMasterKey(DEV_PATH);
+                       auto masterKey = UpgradeSupport::loadMasterKey(devpath);
+                       std::string path = INTERNAL_PATH;
+                       if (argc == 3)
+                               path = argv[2];
  
-                       DMCryptEngine dmcrypt(DEV_PATH, INTERNAL_PATH, ProgressBar([](unsigned){}));
 -                      DMCryptEngine dmcrypt(devpath, path, ProgressBar([](int){}));
++                      DMCryptEngine dmcrypt(devpath, path, ProgressBar([](unsigned){}));
  
                        // mount options are ignored by mount()
                        dmcrypt.mount(masterKey, 0);
@@@ -115,7 -111,8 +115,7 @@@ const std::string createCryptoBlkDev(co
  
        // Create Device (mount_name)
        initDMIoctl(dmBuf, DM_MAX_BUFFER_SIZE, mountName, 0);
-       if (ioctl(fd, DM_DEV_CREATE, dmBuf)) {
+       if (ioctl(fd, DM_DEV_CREATE, dmBuf) && errno != EBUSY) {
 -              close(fd);
                throw runtime::Exception("Cannot create dm-crypt device");
        }
  
@@@ -344,9 -326,23 +344,10 @@@ void DMCryptEngine::encrypt(const Binar
        // create crypto type device mapping layer to mount the plain partition
        // should be encrypted here.
        auto cryptoBlkDev = createCryptoBlkDev(source, DM_DEFAULT_LABEL_NAME, sanitizeKey(key), DM_DEFAULT_CRYPTO_NAME);
+       start = true;
  
 -      std::function<bool(blkcnt_t)> isTarget;
 -      if (!(options & OPTION_INCLUDE_UNUSED_REGION)) {
 -              INFO(SINK, "FastEncryption: Disabled");
 -              isTarget = std::bind(&Ext4Tool::isUsedBlock, &ext4Source, _1);
 -      } else {
 -              INFO(SINK, "FastEncryption: Enabled");
 -              isTarget = [](unsigned int n) {
 -                      return true;
 -              };
 -      }
 -
        // We always do In-place encryption
 -      copyInPlace(source, cryptoBlkDev, isTarget,
 -                      std::bind((void(ProgressBar::*)(int, int, int))&ProgressBar::update,
 -                                      &progress, _1, _2, 1));
 +      copyInPlace(source, cryptoBlkDev, options, progress);
  
        // remove crypto type device mapper
        destroyCryptoBlkDev(DM_DEFAULT_LABEL_NAME);
Simple merge
@@@ -52,7 -58,16 +58,17 @@@ namespace ode 
  namespace {
  
  const char *PRIVILEGE_PLATFORM        = "http://tizen.org/privilege/internal/default/platform";
 +const mode_t MODE_0640 = S_IRUSR | S_IWUSR | S_IRGRP;
+ const std::string ODE_OBJECT_PATH = "/Org/Tizen/OnDeviceEncryption";
+ const std::string ODE_INTERFACE_EVENT = "org.tizen.OnDeviceEncryption.Event";
+ const std::string ODE_SIGNAL_NAME = "unmount";
+ const std::string manifest =
+       "<node>"
+       "       <interface name='" + ODE_INTERFACE_EVENT + "'>"
+       "       <signal name='" + ODE_SIGNAL_NAME + "'>"
+       "       </signal>"
+       "       </interface>"
+       "</node>";
  
  // watches systemd jobs
  class JobWatch {
@@@ -315,9 -450,17 +451,17 @@@ InternalEncryptionServer::InternalEncry
  
        std::string source = findDevPath();
  
+       if (getState() == State::Encrypted) {
+               //"error_partially_encrypted"
+               if (!FileFooter::exist(source) && !UpgradeSupport::checkUpgradeFlag()) {
+                       // Trigger key migration process
+                       UpgradeSupport::createUpgradeFlag();
+               }
+       }
        engine.reset(new INTERNAL_ENGINE(
                source, INTERNAL_PATH,
 -              ProgressBar([](int v) {
 +              ProgressBar([](unsigned v) {
                        ::vconf_set_str(VCONFKEY_ODE_ENCRYPT_PROGRESS,
                                                        std::to_string(v).c_str());
                })
@@@ -409,11 -604,8 +605,8 @@@ int InternalEncryptionServer::encrypt(c
                        ::sleep(1);
  
                        runtime::File file("/opt/etc/.odeprogress");
 -                      file.create(0640);
 +                      file.create(MODE_0640);
  
-                       INFO(SINK, "Closing all known systemd services that might be using internal storage.");
-                       stopKnownSystemdUnits();
                        std::string source = engine->getSource();
                        auto mntPaths = findMountPointsByDevice(source);
  
@@@ -468,23 -682,15 +683,15 @@@ int InternalEncryptionServer::decrypt(c
                        ::sleep(1);
  
                        runtime::File file("/opt/etc/.odeprogress");
 -                      file.create(0640);
 +                      file.create(MODE_0640);
  
                        if (engine->isMounted()) {
-                               INFO(SINK, "Closing all known systemd services that might be using internal storage.");
-                               stopKnownSystemdUnits();
                                INFO(SINK, "Closing all processes using internal storage.");
-                               stopDependedSystemdUnits();
+                               stopSystemdUnits();
  
                                INFO(SINK, "Umounting internal storage.");
-                               while (1) {
-                                       try {
-                                               engine->umount();
-                                               break;
-                                       } catch (runtime::Exception& e) {
-                                               stopDependedSystemdUnits();
-                                       }
-                               }
+                               unmountInternalStorage("/dev/mapper/userdata");
+                               engine->umount();
                        }
  
                        INFO(SINK, "Decryption started.");
@@@ -517,11 -733,8 +734,8 @@@ int InternalEncryptionServer::recovery(
        if (state == State::Unencrypted)
                return error::NoSuchDevice;
  
-       if (state == State::Corrupted)
-               Ext4Tool::mkfs(engine->getSource());
        runtime::File file("/opt/.factoryreset");
 -      file.create(0640);
 +      file.create(MODE_0640);
  
        ::sync();
        try {
@@@ -184,7 -186,7 +186,7 @@@ void writeToken(runtime::File &file, co
  {
        size_t tokenSize(token.size());
  
-       file.create(S_IRUSR | S_IWUSR);
 -      file.create(0640);
++      file.create(S_IRUSR | S_IWUSR | S_IRGRP);
  
        file.write(&tokenSize, sizeof(tokenSize));
        file.write(token.data(), token.size());