*_set_mount_password() must be called before every *_mount() 60/150160/8
authorLukasz Pawelczyk <l.pawelczyk@samsung.com>
Thu, 14 Sep 2017 12:02:42 +0000 (14:02 +0200)
committerLukasz Pawelczyk <l.pawelczyk@samsung.com>
Mon, 16 Oct 2017 11:22:55 +0000 (11:22 +0000)
Change-Id: Ie55ee30a386a1784bff301dc5602b48978095e24

lib/ode/external-encryption.h
lib/ode/internal-encryption.h
server/external-encryption.cpp
server/internal-encryption.cpp

index d40fb5f..a64f561 100644 (file)
@@ -63,7 +63,8 @@ ODE_API int ode_external_encryption_set_mount_password(const char* password);
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
  * @pre         A password must be set by
- *              ode_external_encryption_set_mount_password().
+ *              ode_external_encryption_set_mount_password() before every
+ *              mount attempt.
  * @see         ode_external_encryption_set_mount_password()
  * @see         ode_external_encryption_umount()
  */
index 885b6b6..1ecfc5b 100644 (file)
@@ -62,7 +62,8 @@ ODE_API int ode_internal_encryption_set_mount_password(const char* password);
  * @retval      #ODE_ERROR_PERMISSION_DENIED The application does not have
  *              the privilege to call this API
  * @pre         A password must be set by
- *              ode_internal_encryption_set_mount_password().
+ *              ode_internal_encryption_set_mount_password() before every
+ *              mount attempt.
  * @see         ode_internal_encryption_set_mount_password()
  * @see         ode_internal_encryption_umount()
  */
index 62a9fc2..1481b1c 100644 (file)
@@ -234,6 +234,14 @@ int ExternalEncryptionServer::setMountPassword(const std::string& password)
 
 int ExternalEncryptionServer::mount()
 {
+       if (mountKey.empty()) {
+               ERROR(SINK, "You need to call set_mount_password() first");
+               return -1;
+       }
+
+       KeyManager::data key = mountKey;
+       mountKey.clear();
+
        if (getState() != State::Encrypted) {
                return -1;
        }
@@ -245,10 +253,8 @@ int ExternalEncryptionServer::mount()
 
        INFO(SINK, "Mount external storage...");
        try {
-               engine->mount(mountKey, getOptions());
-               mountKey.clear();
+               engine->mount(key, getOptions());
        } catch (runtime::Exception &e) {
-               mountKey.clear();
                ERROR(SINK, "Failed to mount: " + std::string(e.what()));
                return -3;
        }
index f03b006..c5e762e 100644 (file)
@@ -276,6 +276,14 @@ int InternalEncryptionServer::setMountPassword(const std::string& password)
 
 int InternalEncryptionServer::mount()
 {
+       if (mountKey.empty()) {
+               ERROR(SINK, "You need to call set_mount_password() first");
+               return -1;
+       }
+
+       KeyManager::data key = mountKey;
+       mountKey.clear();
+
        if (getState() != State::Encrypted) {
                return -1;
        }
@@ -287,8 +295,7 @@ int InternalEncryptionServer::mount()
 
        try {
                INFO(SINK, "Mount internal storage...");
-               engine->mount(mountKey, getOptions());
-               mountKey.clear();
+               engine->mount(key, getOptions());
 
                server.notify("InternalEncryptionServer::mount");