Separate corrupted error and fix external recovery API 16/181216/4
authorseolheui kim <s414.kim@samsung.com>
Mon, 11 Jun 2018 05:27:47 +0000 (14:27 +0900)
committerseolheui kim <s414.kim@samsung.com>
Mon, 11 Jun 2018 09:58:26 +0000 (18:58 +0900)
- separate corrupted error into "error_partially_encrypted" and "error_partially_decrypted"
- fix to expose the external recovery API and add it to cli tool

Change-Id: I601a83a6a72e22be5c44d13ff830896300c5e578
Signed-off-by: seolheui kim <s414.kim@samsung.com>
lib/ode/common.h
rmi/external-encryption.h
rmi/internal-encryption.h
server/external-encryption.cpp
server/internal-encryption.cpp
tools/cli/ode-admin-cli.cpp

index 275356f..f2fc30b 100644 (file)
@@ -70,7 +70,8 @@ typedef enum {
 typedef enum {
     ODE_STATE_UNENCRYPTED   = 0x00, /**< Device is not encrypted */
     ODE_STATE_ENCRYPTED     = 0x01, /**< Device is encrypted  */
-    ODE_STATE_CORRUPTED     = 0x02  /**< Device is corrupted because of encryption error  */
+    ODE_STATE_CORRUPTED_ENCRYPTION     = 0x02,  /**< Device is corrupted because of encryption error  */
+    ODE_STATE_CORRUPTED_DECRYPTION     = 0x03,  /**< Device is corrupted becouse of decryption error  */
 } ode_state_e;
 
 /**
index 3643100..540d947 100644 (file)
@@ -49,7 +49,9 @@ public:
        enum State {
                Unencrypted = 0x00,
                Encrypted   = 0x01,
-               Corrupted   = 0x02,
+               CorruptedEncryption   = 0x02,
+               CorruptedDecryption   = 0x03,
+               Invalid = 0x04,
        };
 
        virtual int getState() = 0;
index 55d842d..659482e 100644 (file)
@@ -48,7 +48,9 @@ public:
        enum State {
                Unencrypted = 0x00,
                Encrypted   = 0x01,
-               Corrupted   = 0x02,
+               CorruptedEncryption   = 0x02,
+               CorruptedDecryption   = 0x03,
+               Invalid = 0x04,
        };
 
        virtual int getState() = 0;
index 682de64..dfed067 100644 (file)
@@ -192,6 +192,7 @@ ExternalEncryptionServer::ExternalEncryptionServer(ServerContext &srv,
        server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::umount)());
        server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::encrypt)(std::string, unsigned int));
        server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::decrypt)(std::string));
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::recovery)());
        server.expose(this, "", (int)(ExternalEncryptionServer::isPasswordInitialized)());
        server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::initPassword)(std::string));
        server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::cleanPassword)(std::string));
@@ -349,7 +350,7 @@ int ExternalEncryptionServer::decrypt(const std::string &password)
                        }
 
                        INFO(SINK, "Decryption started.");
-                       ::vconf_set_str(VCONFKEY_SDE_CRYPTO_STATE, "error_partially_encrypted");
+                       ::vconf_set_str(VCONFKEY_SDE_CRYPTO_STATE, "error_partially_decrypted");
                        engine->decrypt(masterKey, getOptions());
 
                        INFO(SINK, "Decryption completed.");
@@ -421,13 +422,16 @@ int ExternalEncryptionServer::getState()
        std::string valueStr(value);
        free(value);
 
-       if (valueStr == "encrypted") {
+       if (valueStr == "encrypted")
                return State::Encrypted;
-       } else if (valueStr == "unencrypted") {
+       else if (valueStr == "unencrypted")
                return State::Unencrypted;
-       } else {
-               return State::Corrupted;
-       }
+       else if (valueStr == "error_partially_encrypted")
+               return State::CorruptedEncryption;
+       else if (valueStr == "error_partially_decrypted")
+               return State::CorruptedDecryption;
+
+       return State::Invalid;
 }
 
 unsigned int ExternalEncryptionServer::getSupportedOptions()
index 53cd3f0..1900f62 100644 (file)
@@ -43,6 +43,7 @@
 #include "progress-bar.h"
 #include "rmi/common.h"
 
+#include "ext4-tool.h"
 #include "internal-encryption.h"
 #include "internal-encryption-common.h"
 
@@ -482,7 +483,7 @@ int InternalEncryptionServer::decrypt(const std::string& password)
                        }
 
                        INFO(SINK, "Decryption started.");
-                       ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "error_partially_encrypted");
+                       ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "error_partially_decrypted");
                        engine->decrypt(masterKey, getOptions());
 
                        INFO(SINK, "Decryption complete.");
@@ -509,20 +510,8 @@ int InternalEncryptionServer::recovery()
        if (state == State::Unencrypted)
                return error::NoSuchDevice;
 
-       if (state == State::Corrupted) {
-               const char *mkfsPath = "/sbin/mkfs.ext4";
-               std::vector<std::string> formatArg = {
-                       mkfsPath, "-F", engine->getSource()};
-               runtime::Process proc(mkfsPath, formatArg);
-
-               int ret = proc.execute();
-               if (ret < 0)
-                       throw runtime::Exception("Failed to execute mkfs.ext4");
-
-               ret = proc.waitForFinished();
-               if (ret < 0 || !WIFEXITED(ret) || WEXITSTATUS(ret) != 0)
-                       throw runtime::Exception("Failed to wait for finish of format");
-       }
+       if (state == State::CorruptedEncryption || state == State::CorruptedDecryption)
+               Ext4Tool::mkfs(engine->getSource());
 
        std::fstream fs;
        fs.open("/opt/.factoryreset", std::ios::out);
@@ -578,13 +567,16 @@ int InternalEncryptionServer::getState()
        std::string valueStr(value);
        free(value);
 
-       if (valueStr == "encrypted") {
+       if (valueStr == "encrypted")
                return State::Encrypted;
-       } else if (valueStr == "unencrypted") {
+       else if (valueStr == "unencrypted")
                return State::Unencrypted;
-       } else {
-               return State::Corrupted;
-       }
+       else if (valueStr == "error_partially_encrypted")
+               return State::CorruptedEncryption;
+       else if (valueStr == "error_partially_decrypted")
+               return State::CorruptedDecryption;
+
+       return State::Invalid;
 }
 
 unsigned int InternalEncryptionServer::getSupportedOptions()
index 3838ccb..5bdf1d1 100644 (file)
@@ -65,7 +65,7 @@ static inline int usage(const std::string name)
                          << "  -s, --state=internal|external      get state" << std::endl
                          << "  -w, --waitmnt=internal|external    wait for mount"<< std::endl
                          << "  -c, --clean=DIRECTORY              secure-clean" << std::endl
-                         << "  -r, --recovery                     recovery" << std::endl
+                         << "  -r, --recovery=internal|external   recovery" << std::endl
                          << "  -h, --help                         show this" << std::endl
                          << std::endl;
 
@@ -549,9 +549,14 @@ static inline int get_state(const std::string name)
        case ODE_STATE_UNENCRYPTED:
                std::cout << "Unencrypted";
                break;
-       case ODE_STATE_CORRUPTED:
-               std::cout << "Corrupted";
+       case ODE_STATE_CORRUPTED_ENCRYPTION:
+               std::cout << "Corrupted Encryption";
                break;
+       case ODE_STATE_CORRUPTED_DECRYPTION:
+               std::cout << "Corrupted Decryption";
+               break;
+       default:
+               std::cout << "Invalid";
        }
        std::cout << std::endl;
 
@@ -606,11 +611,15 @@ static inline int clean(const std::string name)
        return ret;
 }
 
-static inline int recovery()
+static inline int recovery(const std::string &name)
 {
-       int ret = 0;
+       int ret = -1;
+
+       if (name == "internal")
+               ret = ode_internal_encryption_recovery();
+       else if (name == "external")
+               ret = ode_external_encryption_recovery();
 
-       ret = ode_internal_encryption_recovery();
        if (ret != 0)
                std::cerr << "Error : " << ret << std::endl;
 
@@ -633,7 +642,7 @@ int main(int argc, char* argv[])
                {"state", required_argument, 0, 's'},
                {"waitmnt", required_argument, 0, 'w'},
                {"clean", required_argument, 0, 'c'},
-               {"recovery", no_argument, 0, 'r'},
+               {"recovery", required_argument, 0, 'r'},
                {0, 0, 0, 0}
        };
 
@@ -652,7 +661,7 @@ int main(int argc, char* argv[])
        std::string mapping, device, op;
        bool sync = true;
 
-       while ((opt = getopt_long(argc, argv, "m:u:e:d:l:L:p:k:s:w:c:rh", options, &index)) != -1) {
+       while ((opt = getopt_long(argc, argv, "m:u:e:d:l:L:p:k:s:w:c:r:h", options, &index)) != -1) {
                switch (opt) {
                case 'm':
                        ret = mount(optarg);
@@ -713,7 +722,7 @@ int main(int argc, char* argv[])
                        ret = clean(optarg);
                        break;
                case 'r':
-                       ret = recovery();
+                       ret = recovery(optarg);
                        break;
                case 'D':
                        device = optarg;