ode/internal-encryption.cpp
ode/external-encryption.cpp
ode/luks.cpp
+ ode/error-translation.cpp
)
SET(CAPI_INCLUDE_FILES ode/common.h
* limitations under the License
*/
#include "external-encryption.h"
+#include "rmi/common.h"
namespace ode {
try {
return context->methodCall<int>("ExternalEncryptionServer::setMountPassword", password);
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
try {
return context->methodCall<int>("ExternalEncryptionServer::mount");
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
try {
return context->methodCall<int>("ExternalEncryptionServer::umount");
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
try {
return context->methodCall<int>("ExternalEncryptionServer::encrypt", password, options);
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
try {
return context->methodCall<int>("ExternalEncryptionServer::decrypt", password);
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
try {
return context->methodCall<int>("ExternalEncryptionServer::recovery");
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
try {
return context->methodCall<int>("ExternalEncryptionServer::isPasswordInitialized");
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
return context->methodCall<int>("ExternalEncryptionServer::initPassword",
password);
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
return context->methodCall<int>("ExternalEncryptionServer::cleanPassword",
password);
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
return context->methodCall<int>("ExternalEncryptionServer::changePassword",
oldPassword, newPassword);
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
return context->methodCall<int>("ExternalEncryptionServer::verifyPassword",
password);
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
try {
return context->methodCall<int>("ExternalEncryptionServer::getState");
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
try {
return context->methodCall<unsigned int>("ExternalEncryptionServer::getSupportedOptions");
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
* limitations under the License
*/
#include "internal-encryption.h"
+#include "rmi/common.h"
namespace ode {
try {
return context->methodCall<int>("InternalEncryptionServer::setMountPassword", password);
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
try {
return context->methodCall<int>("InternalEncryptionServer::mount");
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
try {
return context->methodCall<int>("InternalEncryptionServer::umount");
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
try {
return context->methodCall<int>("InternalEncryptionServer::encrypt", password, options);
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
try {
return context->methodCall<int>("InternalEncryptionServer::decrypt", password);
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
try {
return context->methodCall<int>("InternalEncryptionServer::recovery");
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
try {
return context->methodCall<int>("InternalEncryptionServer::isPasswordInitialized");
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
return context->methodCall<int>("InternalEncryptionServer::initPassword",
password);
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
return context->methodCall<int>("InternalEncryptionServer::cleanPassword",
password);
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
return context->methodCall<int>("InternalEncryptionServer::changePassword",
oldPassword, newPassword);
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
return context->methodCall<int>("InternalEncryptionServer::verifyPassword",
password);
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
try {
return context->methodCall<int>("InternalEncryptionServer::getState");
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
try {
return context->methodCall<unsigned int>("InternalEncryptionServer::getSupportedOptions");
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
* limitations under the License
*/
#include "luks.h"
+#include "rmi/common.h"
namespace ode {
device,
password);
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
password,
mapping);
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
try {
return context->methodCall<int>("LuksServer::close", sync, mapping);
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
ODE_ERROR_NONE = TIZEN_ERROR_NONE, /**< The operation was successful */
ODE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
ODE_ERROR_CONNECTION_REFUSED = TIZEN_ERROR_CONNECTION_REFUSED, /**< Connection refused */
- ODE_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< Time out */
ODE_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Access privilege is not sufficient */
- ODE_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Operation is not supported */
ODE_ERROR_NO_SUCH_FILE = TIZEN_ERROR_NO_SUCH_FILE, /**< No such file or directory */
- ODE_ERROR_FILE_EXISTS = TIZEN_ERROR_FILE_EXISTS, /**< File exists */
ODE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
- ODE_ERROR_NOT_PERMITTED = TIZEN_ERROR_NOT_PERMITTED, /**< Operation is not permitted */
- ODE_ERROR_KEY_REJECTED = TIZEN_ERROR_KEY_REJECTED, /**< Passwor is rejected */
+ ODE_ERROR_NO_SUCH_DEVICE = TIZEN_ERROR_NO_SUCH_DEVICE, /**< No such device */
+ ODE_ERROR_KEY_REJECTED = TIZEN_ERROR_KEY_REJECTED, /**< Password is rejected */
ODE_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA, /**< No Data */
ODE_ERROR_RESOURCE_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Device or resource busy */
ODE_ERROR_UNKNOWN = TIZEN_ERROR_UNKNOWN /**< Unknown error */
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+#include "error-translation.h"
+#include "common.h"
+#include "rmi/common.h"
+
+#include <map>
+
+using namespace ode;
+
+namespace {
+
+std::map<int, int> ODE_ERROR_TO_API_ERROR = {
+ { error::None, ODE_ERROR_NONE },
+ { error::InvalidParameter, ODE_ERROR_INVALID_PARAMETER },
+ { error::ConnectionRefused, ODE_ERROR_CONNECTION_REFUSED },
+ { error::PermissionDenied, ODE_ERROR_PERMISSION_DENIED },
+ { error::NoSuchFile, ODE_ERROR_NO_SUCH_FILE },
+ { error::OutOfMemory, ODE_ERROR_OUT_OF_MEMORY },
+ { error::NoSuchDevice, ODE_ERROR_NO_SUCH_DEVICE },
+ { error::WrongPassword, ODE_ERROR_KEY_REJECTED },
+ { error::NoData, ODE_ERROR_NO_DATA },
+ { error::DeviceBusy, ODE_ERROR_RESOURCE_BUSY },
+ { error::Unknown, ODE_ERROR_UNKNOWN }
+};
+} // anonymous namespace
+
+int toApiError(int error)
+{
+ int ret = ODE_ERROR_UNKNOWN;
+ auto it = ODE_ERROR_TO_API_ERROR.find(error);
+ if (it != ODE_ERROR_TO_API_ERROR.end())
+ ret = it->second;
+ return ret;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+#ifndef __CAPI_ODE_ERROR_TRANSLATION_H__
+#define __CAPI_ODE_ERROR_TRANSLATION_H__
+
+int toApiError(int error);
+
+#endif // __CAPI_ODE_ERROR_TRANSLATION_H__
#include "client.h"
#include "lib/external-encryption.h"
+#include "error-translation.h"
+#include "rmi/common.h"
using namespace ode;
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
- return external.setMountPassword(password);
+ return toApiError(external.setMountPassword(password));
}
int ode_external_encryption_mount()
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
- return external.mount();
+ return toApiError(external.mount());
}
int ode_external_encryption_umount()
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
- return external.umount();
+ return toApiError(external.umount());
}
int ode_external_encryption_encrypt(const char* password, unsigned int options)
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
- return external.encrypt(password, options);
+ return toApiError(external.encrypt(password, options));
}
int ode_external_encryption_decrypt(const char* password)
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
- return external.decrypt(password);
+ return toApiError(external.decrypt(password));
}
int ode_external_encryption_recovery()
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
- return external.recovery();
+ return toApiError(external.recovery());
}
int ode_external_encryption_is_password_initialized(bool* result)
ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
int ret = external.isPasswordInitialized();
- RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
+ if (ret == error::None)
+ *result = true;
+ else if (ret == error::NoSuchFile)
+ *result = false;
+ else
+ return toApiError(ret);
- *result = ret;
return ODE_ERROR_NONE;
}
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
- return external.initPassword(password);
+ return toApiError(external.initPassword(password));
}
int ode_external_encryption_clean_password(const char* password)
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
- return external.cleanPassword(password);
+ return toApiError(external.cleanPassword(password));
}
int ode_external_encryption_change_password(const char* old_password,
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
- return external.changePassword(old_password, new_password);
+ return toApiError(external.changePassword(old_password, new_password));
}
int ode_external_encryption_verify_password(const char* password, bool* result)
ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
int ret = external.verifyPassword(password);
- RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
+ if (ret == error::None)
+ *result = true;
+ else if (ret == error::WrongPassword)
+ *result = false;
+ else
+ return toApiError(ret);
- *result = ret;
return ODE_ERROR_NONE;
}
ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
int ret = external.getState();
- RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
+ if (ret < 0)
+ return toApiError(ret);
*state = ret;
return ODE_ERROR_NONE;
RET_ON_FAILURE(mountEventCallbackContext->connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
int ret = mountEventCallbackContext->subscribeSignal("ExternalEncryption::mount", callback, user_data);
- RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
-
- return ODE_ERROR_NONE;
+ return toApiError(ret);
}
int ode_external_encryption_unset_mount_event_cb()
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_KEY_REJECTED Password doen't match
+ * @retval #ODE_ERROR_KEY_REJECTED Password doesn't match
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @pre The password must match with what is set by
* ode_external_encryption_init_password().
* @see ode_external_encryption_init_password()
* @since_tizen 4.0
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
- * @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
+ * @retval #ODE_ERROR_NO_SUCH_DEVICE External storage is not encrypted
* @retval #ODE_ERROR_NO_DATA Password isn't set
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @pre A password must be set by
* ode_external_encryption_set_mount_password() before every
* mount attempt.
* @since_tizen 4.0
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
- * @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval #ODE_ERROR_NO_SUCH_DEVICE External storage is not encrypted
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @see ode_external_encryption_mount()
*/
ODE_API int ode_external_encryption_umount();
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_KEY_REJECTED Password doen't match
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval #ODE_ERROR_KEY_REJECTED Password doesn't match
+ * @retval #ODE_ERROR_NO_SUCH_DEVICE External storage is not decrypted
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
- * @retval #ODE_ERROR_NOT_SUPPORTED Given options are not supported
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @see ode_external_encryption_mount()
* @see ode_external_encryption_decrypt()
* @see ode_external_encryption_get_supported_options()
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_KEY_REJECTED Password doen't match
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval #ODE_ERROR_KEY_REJECTED Password doesn't match
+ * @retval #ODE_ERROR_NO_SUCH_DEVICE External storage is not encrypted
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @pre The password must match with what is set by
* ode_external_encryption_init_password().
* @see ode_external_encryption_encrypt()
* @since_tizen 4.0
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
- * @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval #ODE_ERROR_NO_SUCH_DEVICE External storage is decrypted
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @see ode_external_encryption_encrypt()
*/
ODE_API int ode_external_encryption_recovery();
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
- * @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
- * the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @see ode_external_encryption_init_password()
* @see ode_external_encryption_clean_password()
*/
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @see ode_external_encryption_change_password()
* @see ode_external_encryption_clean_password()
* @see ode_external_encryption_encrypt()
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_KEY_REJECTED old_password doen't match
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval #ODE_ERROR_KEY_REJECTED Password doesn't match
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @pre The password must match with what is set by
* ode_external_encryption_init_password().
* @see ode_external_encryption_init_password()
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_KEY_REJECTED old_password doen't match
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval #ODE_ERROR_KEY_REJECTED Old password doesn't match
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @pre The password must match with what is set by
* ode_external_encryption_init_password().
* @see ode_external_encryption_encrypt()
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @pre The password must match with what is set by
* ode_external_encryption_init_password().
* @see ode_external_encryption_encrypt()
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
- * the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @see ode_external_encryption_encrypt()
* @see ode_external_encryption_decrypt()
*/
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
- * the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @see ode_external_encryption_encrypt()
*/
ODE_API int ode_external_encryption_get_supported_options(unsigned int* options);
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @post If the callback is not needed,
* ode_external_encryption_unset_mount_event_cb() must be called.
* @see ode_external_encryption_mount()
* @since_tizen 4.0
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * the privilege to call this API
* @see ode_external_encryption_mount()
* @see ode_external_encryption_set_mount_event_cb()
*/
#include "client.h"
#include "lib/internal-encryption.h"
+#include "error-translation.h"
+#include "rmi/common.h"
using namespace ode;
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
- return internal.setMountPassword(password);
+ return toApiError(internal.setMountPassword(password));
}
int ode_internal_encryption_mount()
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
- return internal.mount();
+ return toApiError(internal.mount());
}
int ode_internal_encryption_umount()
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
- return internal.umount();
+ return toApiError(internal.umount());
}
int ode_internal_encryption_encrypt(const char* password, unsigned int options)
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
- return internal.encrypt(password, options);
+ return toApiError(internal.encrypt(password, options));
}
int ode_internal_encryption_decrypt(const char* password)
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
- return internal.decrypt(password);
+ return toApiError(internal.decrypt(password));
}
int ode_internal_encryption_recovery()
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
- return internal.recovery();
+ return toApiError(internal.recovery());
}
int ode_internal_encryption_is_password_initialized(bool* result)
{
- RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
+ RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
- ClientContext client;
- RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+ ClientContext client;
+ RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
int ret = internal.isPasswordInitialized();
- RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
+ if (ret == error::None)
+ *result = true;
+ else if (ret == error::NoSuchFile)
+ *result = false;
+ else
+ return toApiError(ret);
- *result = ret;
- return ODE_ERROR_NONE;
+ return ODE_ERROR_NONE;
}
int ode_internal_encryption_init_password(const char* password)
{
- RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
+ RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
- ClientContext client;
- RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+ ClientContext client;
+ RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
- return internal.initPassword(password);
+ return toApiError(internal.initPassword(password));
}
int ode_internal_encryption_clean_password(const char* password)
{
- RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
+ RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
- ClientContext client;
- RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+ ClientContext client;
+ RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
- return internal.cleanPassword(password);
+ return toApiError(internal.cleanPassword(password));
}
int ode_internal_encryption_change_password(const char* old_password,
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
- return internal.changePassword(old_password, new_password);
+ return toApiError(internal.changePassword(old_password, new_password));
}
int ode_internal_encryption_verify_password(const char* password, bool* result)
{
- RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
- RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
+ RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
+ RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
- ClientContext client;
- RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
+ ClientContext client;
+ RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
int ret = internal.verifyPassword(password);
- RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
+ if (ret == error::None)
+ *result = true;
+ else if (ret == error::WrongPassword)
+ *result = false;
+ else
+ return toApiError(ret);
- *result = ret;
- return ODE_ERROR_NONE;
+ return ODE_ERROR_NONE;
}
int ode_internal_encryption_get_state(int* state)
InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
int ret = internal.getState();
- RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
+ if (ret < 0)
+ return toApiError(ret);
*state = ret;
return ODE_ERROR_NONE;
mountEventCallbackContext.reset(new ClientContext);
RET_ON_FAILURE(mountEventCallbackContext->connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
- int ret = mountEventCallbackContext->subscribeSignal("InternalEncryptionServer::mount", callback, user_data);
- RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
-
- return ODE_ERROR_NONE;
+ int ret = mountEventCallbackContext->subscribeSignal("InternalEncryptionServer::mount", callback, user_data);
+ return toApiError(ret);
}
int ode_internal_encryption_unset_mount_event_cb()
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_KEY_REJECTED Password doen't match
+ * @retval #ODE_ERROR_KEY_REJECTED Password doesn't match
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @pre The password set before must match with what is set by
* ode_internal_encryption_init_password().
* @see ode_internal_encryption_init_password()
* @since_tizen 4.0
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
- * @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
+ * @retval #ODE_ERROR_NO_SUCH_DEVICE Internal storage is not encrypted
* @retval #ODE_ERROR_NO_DATA Password isn't set
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @pre A password must be set by
* ode_internal_encryption_set_mount_password() before every
* mount attempt.
* @since_tizen 4.0
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
- * @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval #ODE_ERROR_NO_SUCH_DEVICE Internal storage is not encrypted
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @see ode_internal_encryption_mount()
*/
ODE_API int ode_internal_encryption_umount();
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_KEY_REJECTED Password doen't match
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval #ODE_ERROR_KEY_REJECTED Password doesn't match
+ * @retval #ODE_ERROR_NO_SUCH_DEVICE Internal storage is not decrypted
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
- * @retval #ODE_ERROR_NOT_SUPPORTED Given options are not supported
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @pre The password must match with what is set by
* ode_internal_encryption_init_password().
* @see ode_internal_encryption_mount()
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_KEY_REJECTED Password doen't match
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval #ODE_ERROR_KEY_REJECTED Password doesn't match
+ * @retval #ODE_ERROR_NO_SUCH_DEVICE Internal storage is not encrypted
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @pre The password must match with what is set by
* ode_internal_encryption_init_password().
* @see ode_internal_encryption_encrypt()
* @since_tizen 4.0
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
- * @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval #ODE_ERROR_NO_SUCH_DEVICE Internal storage is decrypted
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @see ode_internal_encryption_encrypt()
*/
ODE_API int ode_internal_encryption_recovery();
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
- * @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
- * the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @see ode_internal_encryption_init_password()
* @see ode_internal_encryption_clean_password()
*/
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @see ode_internal_encryption_change_password()
* @see ode_internal_encryption_clean_password()
* @see ode_internal_encryption_encrypt()
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_KEY_REJECTED old_password doen't match
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval #ODE_ERROR_KEY_REJECTED Password doesn't match
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @pre The password must match with what is set by
* ode_internal_encryption_init_password().
* @see ode_internal_encryption_init_password()
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_KEY_REJECTED old_password doen't match
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
+ * @retval #ODE_ERROR_KEY_REJECTED Old password doesn't match
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @pre Old password must match with what is set by
* ode_internal_encryption_init_password().
* @see ode_internal_encryption_init_password()
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @pre The password must match with what is set by
* ode_internal_encryption_init_password().
* @see ode_internal_encryption_init_password()
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
- * the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @see ode_internal_encryption_encrypt()
* @see ode_internal_encryption_decrypt()
*/
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
- * the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @see ode_internal_encryption_encrypt()
*/
ODE_API int ode_internal_encryption_get_supported_options(unsigned int* options);
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @post If the callback is not needed,
* ode_internal_encryption_unset_mount_event_cb() must be called.
* @see ode_internal_encryption_mount()
* @since_tizen 4.0
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
- * @retval #ODE_ERROR_TIMED_OUT Time out
- * the privilege to call this API
* @see ode_internal_encryption_set_mount_event_cb()
*/
ODE_API int ode_internal_encryption_unset_mount_event_cb();
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
*
* @see ode_key_init()
* @see ode_key_clean()
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
+ * the privilege to call this API
* @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
*
* @see ode_key_change_password()
* @see ode_key_clean()
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ODE_ERROR_KEY_REJECTED Password doesn't match
+ * @retval #ODE_ERROR_NO_SUCH_FILE No key exists for given @a device
+ * @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
+ * the privilege to call this API
* @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
*
* @pre The @a password must match the current password used for
* @a device key encryption
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ODE_ERROR_KEY_REJECTED Current password doesn't match
+ * @retval #ODE_ERROR_NO_SUCH_FILE No key exists for given @a device
+ * @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
+ * the privilege to call this API
* @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
*
* @pre The @a cur_password must match the current password used for
* @a device key encryption
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ODE_ERROR_NO_SUCH_FILE No key exists for given @a device
+ * @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
+ * the privilege to call this API
* @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
*
* @see ode_key_init()
* @see ode_key_change_password()
#include "client.h"
#include "lib/luks.h"
#include "rmi/common.h"
+#include "error-translation.h"
using namespace ode;
namespace {
std::unique_ptr<ClientContext> luksEventCallbackContext;
-// TODO Extend it and make it common for whole API
-std::map<OdeError, int> ODE_ERROR_TO_API_ERROR = {
- { OdeError::None, ODE_ERROR_NONE },
- { OdeError::InvalidParameter, ODE_ERROR_INVALID_PARAMETER },
- { OdeError::WrongPassword, ODE_ERROR_KEY_REJECTED },
- { OdeError::OutOfMemory, ODE_ERROR_OUT_OF_MEMORY },
- { OdeError::NoSuchFile, ODE_ERROR_NO_SUCH_FILE },
- { OdeError::DeviceBusy, ODE_ERROR_RESOURCE_BUSY },
- { OdeError::Unknown, ODE_ERROR_UNKNOWN }
-};
-
-int toApiError(int error)
-{
- int ret = ODE_ERROR_UNKNOWN;
- auto it = ODE_ERROR_TO_API_ERROR.find(static_cast<OdeError>(error));
- if (it != ODE_ERROR_TO_API_ERROR.end())
- ret = it->second;
- return ret;
-}
-
int luks_format_internal(bool sync, const char* device, const char* password)
{
RET_ON_FAILURE(device, ODE_ERROR_INVALID_PARAMETER);
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
LuksClient luks = client.createInterface<LuksClient>();
- return luks.format(sync, device, password);
+ return toApiError(luks.format(sync, device, password));
}
int luks_open_internal(bool sync,
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
LuksClient luks = client.createInterface<LuksClient>();
- return luks.open(sync, device, password, mapping);
+ return toApiError(luks.open(sync, device, password, mapping));
}
int luks_close_internal(bool sync, const char* mapping)
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
LuksClient luks = client.createInterface<LuksClient>();
- return luks.close(sync, mapping);
+ return toApiError(luks.close(sync, mapping));
}
} // anonymous namespace
};
ret = luksEventCallbackContext->subscribeSignal(Luks::NOTIFICATION, cb);
- RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
-
- return ODE_ERROR_NONE;
+ return toApiError(ret);
}
void ode_luks_unset_event_cb()
int ode_luks_format_sync(const char* device, const char* password)
{
- int err = luks_format_internal(true, device, password);
- return toApiError(err);
+ return luks_format_internal(true, device, password);
}
int ode_luks_open_sync(const char* device, const char* password, const char* mapping)
{
- int err = luks_open_internal(true, device, password, mapping);
- return toApiError(err);
+ return luks_open_internal(true, device, password, mapping);
}
int ode_luks_close_sync(const char* mapping)
{
- int err = luks_close_internal(true, mapping);
- return toApiError(err);
+ return luks_close_internal(true, mapping);
}
* function as a result of this function call:
* #ODE_ERROR_NONE Successful
* #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * #ODE_ERROR_KEY_REJECTED Wrong password
+ * #ODE_ERROR_KEY_REJECTED Password doesn't match
* #ODE_ERROR_OUT_OF_MEMORY Out of memory
* #ODE_ERROR_NO_SUCH_FILE Wrong device or mapping
* #ODE_ERROR_RESOURCE_BUSY Device is busy
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
- * @retval #ODE_ERROR_KEY_REJECTED Wrong password
+ * @retval #ODE_ERROR_KEY_REJECTED Password doesn't match
* @retval #ODE_ERROR_OUT_OF_MEMORY Out of memory
* @retval #ODE_ERROR_NO_SUCH_FILE Wrong device or mapping
* @retval #ODE_ERROR_RESOURCE_BUSY Device is busy
#include "client.h"
#include "lib/secure-erase.h"
+#include "error-translation.h"
using namespace ode;
RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
SecureEraseClient secure = client.createInterface<SecureEraseClient>();
- return secure.clean(name);
+ return toApiError(secure.clean(name));
}
* @return #ODE_ERROR_NONE on success, otherwise a negative value
* @retval #ODE_ERROR_NONE Successful
* @retval #ODE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ODE_ERROR_TIMED_OUT Time out
* @retval #ODE_ERROR_NO_SUCH_FILE No such file or directory
- * @retval #ODE_ERROR_NOT_PERMITTED Operation not permitted
* @retval #ODE_ERROR_PERMISSION_DENIED The application does not have
* the privilege to call this API
+ * @retval #ODE_ERROR_CONNECTION_REFUSED Connection to the server failed
+ * @retval #ODE_ERROR_UNKNOWN Unknown error
* @pre The device to the given name must be exists.
*/
ODE_API int ode_secure_clean(const char* name);
* limitations under the License
*/
#include "secure-erase.h"
+#include "rmi/common.h"
namespace ode {
try {
return context->methodCall<int>("SecureEraseServer::clean", name);
} catch (runtime::Exception& e) {
- return -1;
+ return error::Unknown;
}
}
namespace ode {
-enum class OdeError {
- None = 0,
- InvalidParameter,
- WrongPassword,
- OutOfMemory,
- NoSuchFile,
- DeviceBusy,
- Unknown
+// TODO make it an enum when klay starts to support enum serialization in rmi
+namespace error {
+
+const int None = 0;
+const int InvalidParameter = -1;
+const int ConnectionRefused = -2;
+const int PermissionDenied = -3;
+const int NoSuchFile = -4;
+const int OutOfMemory = -5;
+const int NoSuchDevice = -6;
+const int WrongPassword = -7;
+const int NoData = -8;
+const int DeviceBusy = -9;
+const int Unknown = -10;
+
};
} // namespace ode
#include "launchpad.h"
#include "app-bundle.h"
#include "progress-bar.h"
+#include "rmi/common.h"
#include "external-encryption.h"
KeyManager keyManager(engine->getKeyMeta());
if (!keyManager.verifyPassword(pwData)) {
ERROR(SINK, "Wrong password passed.");
- return -2;
+ return error::WrongPassword;
}
mountKey = keyManager.getMasterKey(pwData);
- return 0;
+ return error::None;
}
int ExternalEncryptionServer::mount()
{
if (mountKey.empty()) {
ERROR(SINK, "You need to call set_mount_password() first.");
- return -1;
+ return error::NoData;
}
KeyManager::data key = mountKey;
if (getState() != State::Encrypted) {
ERROR(SINK, "Cannot mount, SD card's state incorrect.");
- return -1;
+ return error::NoSuchDevice;
}
if (engine->isMounted()) {
INFO(SINK, "SD card already mounted.");
- return 0;
+ return error::None;
}
INFO(SINK, "Mounting external storage.");
engine->mount(key, getOptions());
} catch (runtime::Exception &e) {
ERROR(SINK, "Failed to mount: " + std::string(e.what()));
- return -3;
+ return error::Unknown;
}
server.notify("ExternalEncryptionServer::mount");
- return 0;
+ return error::None;
}
int ExternalEncryptionServer::umount()
{
if (getState() != State::Encrypted) {
ERROR(SINK, "Cannot umount, SD card's state incorrect.");
- return -1;
+ return error::NoSuchDevice;
}
if (!engine->isMounted()) {
INFO(SINK, "SD card already umounted.");
- return 0;
+ return error::None;
}
INFO(SINK, "Closing all applications using external storage.");
engine->umount();
} catch (runtime::Exception &e) {
ERROR(SINK, "Failed to umount: " + std::string(e.what()));
- return -3;
+ return error::Unknown;
}
- return 0;
+ return error::None;
}
int ExternalEncryptionServer::encrypt(const std::string &password, unsigned int options)
{
if (getState() != State::Unencrypted) {
INFO(SINK, "Cannot encrypt, SD card's state incorrect.");
- return -1;
+ return error::NoSuchDevice;
}
KeyManager::data pwData(password.begin(), password.end());
if (!keyManager.verifyPassword(pwData)) {
ERROR(SINK, "Wrong password passed.");
- return -2;
+ return error::WrongPassword;
}
KeyManager::data MasterKey = keyManager.getMasterKey(pwData);
std::thread asyncWork(encryptWorker);
asyncWork.detach();
- return 0;
+ return error::None;
}
int ExternalEncryptionServer::decrypt(const std::string &password)
{
if (getState() != State::Encrypted) {
ERROR(SINK, "Cannot decrypt, SD card's state incorrect.");
- return -1;
+ return error::NoSuchDevice;
}
KeyManager::data pwData(password.begin(), password.end());
if (!keyManager.verifyPassword(pwData)) {
ERROR(SINK, "Wrong password passed.");
- return -2;
+ return error::WrongPassword;
}
KeyManager::data MasterKey = keyManager.getMasterKey(pwData);
std::thread asyncWork(decryptWorker);
asyncWork.detach();
- return 0;
+ return error::None;
}
int ExternalEncryptionServer::recovery()
{
if (getState() == State::Unencrypted) {
- return -1;
+ return error::NoSuchDevice;
}
for (runtime::DirectoryIterator iter(engine->getSource()), end;
engine->clearKeyMeta();
::vconf_set_str(VCONFKEY_SDE_CRYPTO_STATE, "unencrypted");
- return 0;
+ return error::None;
}
int ExternalEncryptionServer::isPasswordInitialized()
{
if (engine->isKeyMetaSet()) {
- return 1;
+ return error::None;
}
- return 0;
+ return error::NoSuchFile;
}
int ExternalEncryptionServer::initPassword(const std::string& password)
keyManager.initPassword(pwData);
engine->setKeyMeta(keyManager.serialize());
- return 0;
+ return error::None;
}
int ExternalEncryptionServer::cleanPassword(const std::string& password)
if (!keyManager.verifyPassword(pwData)) {
ERROR(SINK, "Wrong password passed.");
- return -2;
+ return error::WrongPassword;
}
engine->clearKeyMeta();
- return 0;
+ return error::None;
}
int ExternalEncryptionServer::changePassword(const std::string &oldPassword,
if (!keyManager.verifyPassword(oldPwData)) {
ERROR(SINK, "Wrong password passed.");
- return -2;
+ return error::WrongPassword;
}
keyManager.changePassword(oldPwData, newPwData);
engine->setKeyMeta(keyManager.serialize());
- return 0;
+ return error::None;
}
int ExternalEncryptionServer::verifyPassword(const std::string& password)
KeyManager keyManager(engine->getKeyMeta());
if (keyManager.verifyPassword(pwData)) {
- return 1;
+ return error::None;
}
- return 0;
+ return error::WrongPassword;
}
int ExternalEncryptionServer::getState()
} else {
return State::Corrupted;
}
-
- return 0;
}
unsigned int ExternalEncryptionServer::getSupportedOptions()
#include "misc.h"
#include "logger.h"
#include "progress-bar.h"
+#include "rmi/common.h"
#include "internal-encryption.h"
KeyManager keyManager(engine->getKeyMeta());
if (!keyManager.verifyPassword(pwData)) {
ERROR(SINK, "Wrong password passed.");
- return -2;
+ return error::WrongPassword;
}
mountKey = keyManager.getMasterKey(pwData);
- return 0;
+ return error::None;
}
int InternalEncryptionServer::mount()
{
if (mountKey.empty()) {
ERROR(SINK, "You need to call set_mount_password() first.");
- return -1;
+ return error::NoData;
}
KeyManager::data key = mountKey;
if (getState() != State::Encrypted) {
INFO(SINK, "Cannot mount, SD partition's state incorrect.");
- return -1;
+ return error::NoSuchDevice;
}
- if (engine->isMounted()) {
+ if (engine->isMounted()) {
INFO(SINK, "Partition already mounted.");
- return 0;
+ return error::None;
}
INFO(SINK, "Mounting internal storage.");
runtime::File("/tmp/.unlock_mnt").create(O_WRONLY);
} catch (runtime::Exception &e) {
ERROR(SINK, "Mount failed: " + std::string(e.what()));
- return -1;
+ return error::Unknown;
}
- return 0;
+ return error::None;
}
int InternalEncryptionServer::umount()
{
if (getState() != State::Encrypted) {
ERROR(SINK, "Cannot umount, partition's state incorrect.");
- return -1;
+ return error::NoSuchDevice;
}
if (!engine->isMounted()) {
INFO(SINK, "Partition already umounted.");
- return 0;
+ return error::None;
}
INFO(SINK, "Closing all processes using internal storage.");
engine->umount();
} catch (runtime::Exception &e) {
ERROR(SINK, "Umount failed: " + std::string(e.what()));
- return -1;
+ return error::Unknown;
}
- return 0;
+ return error::None;
}
int InternalEncryptionServer::encrypt(const std::string& password, unsigned int options)
{
if (getState() != State::Unencrypted) {
ERROR(SINK, "Cannot encrypt, partition's state incorrect.");
- return -1;
+ return error::NoSuchDevice;
}
KeyManager::data pwData(password.begin(), password.end());
if (!keyManager.verifyPassword(pwData)) {
ERROR(SINK, "Wrong password passed.");
- return -2;
+ return error::WrongPassword;
}
KeyManager::data MasterKey = keyManager.getMasterKey(pwData);
std::thread asyncWork(encryptWorker);
asyncWork.detach();
- return 0;
+ return error::None;
}
int InternalEncryptionServer::decrypt(const std::string& password)
{
if (getState() != State::Encrypted) {
ERROR(SINK, "Cannot decrypt, partition's state incorrect.");
- return -1;
+ return error::NoSuchDevice;
}
KeyManager::data pwData(password.begin(), password.end());
if (!keyManager.verifyPassword(pwData)) {
ERROR(SINK, "Wrong password passed.");
- return -2;
+ return error::WrongPassword;
}
KeyManager::data MasterKey = keyManager.getMasterKey(pwData);
std::thread asyncWork(decryptWorker);
asyncWork.detach();
- return 0;
+ return error::None;
}
int InternalEncryptionServer::recovery()
{
- if (getState() != State::Unencrypted) {
- return -1;
+ if (getState() == State::Unencrypted) {
+ return error::NoSuchDevice;
}
//TODO
runtime::Process proc(PROG_FACTORY_RESET, wipeCommand);
if (proc.execute() == -1) {
ERROR(SINK, "Failed to launch factory-reset");
- return -2;
+ return error::WrongPassword;
}
- return 0;
+ return error::None;
}
int InternalEncryptionServer::isPasswordInitialized()
{
if (engine->isKeyMetaSet()) {
- return 1;
+ return error::None;
}
- return 0;
+ return error::NoSuchFile;
}
int InternalEncryptionServer::initPassword(const std::string& password)
keyManager.initPassword(pwData);
engine->setKeyMeta(keyManager.serialize());
- return 0;
+ return error::None;
}
int InternalEncryptionServer::cleanPassword(const std::string& password)
if (!keyManager.verifyPassword(pwData)) {
ERROR(SINK, "Wrong password passed.");
- return -2;
+ return error::WrongPassword;
}
engine->clearKeyMeta();
- return 0;
+ return error::None;
}
int InternalEncryptionServer::changePassword(const std::string& oldPassword,
if (!keyManager.verifyPassword(oldPwData)) {
ERROR(SINK, "Wrong password passed.");
- return -2;
+ return error::WrongPassword;
}
keyManager.changePassword(oldPwData, newPwData);
engine->setKeyMeta(keyManager.serialize());
- return 0;
+ return error::None;
}
int InternalEncryptionServer::verifyPassword(const std::string& password)
KeyManager keyManager(engine->getKeyMeta());
if (keyManager.verifyPassword(pwData)) {
- return 1;
+ return error::None;
}
- return 0;
+ return error::WrongPassword;
}
int InternalEncryptionServer::getState()
} else {
return State::Corrupted;
}
-
- return 0;
}
unsigned int InternalEncryptionServer::getSupportedOptions()
const size_t DEFAULT_KEY_SIZE = 64;
std::map<Luks::Operation, std::string> OPERATION_NAME = {
- { Luks::Format, "Formatting" },
- { Luks::Open, "Opening" },
- { Luks::Close, "Closing" },
+ { Luks::Format, "Formatting" },
+ { Luks::Open, "Opening" },
+ { Luks::Close, "Closing" },
};
-std::map<CryptsetupEngine::ReturnCode, OdeError> CRYPTSETUP_ERROR_2_ODE_ERROR = {
- { CryptsetupEngine::ReturnCode::SUCCESS, OdeError::None },
- { CryptsetupEngine::ReturnCode::WRONG_PARAMS, OdeError::InvalidParameter },
- { CryptsetupEngine::ReturnCode::NO_PERMISSION, OdeError::WrongPassword },
- { CryptsetupEngine::ReturnCode::OUT_OF_MEMORY, OdeError::OutOfMemory },
- { CryptsetupEngine::ReturnCode::WRONG_DEVICE, OdeError::NoSuchFile },
- { CryptsetupEngine::ReturnCode::DEVICE_BUSY, OdeError::DeviceBusy }
+std::map<CryptsetupEngine::ReturnCode, int> CRYPTSETUP_ERROR_2_ODE_ERROR = {
+ { CryptsetupEngine::ReturnCode::SUCCESS, error::None },
+ { CryptsetupEngine::ReturnCode::WRONG_PARAMS, error::InvalidParameter },
+ { CryptsetupEngine::ReturnCode::NO_PERMISSION, error::WrongPassword },
+ { CryptsetupEngine::ReturnCode::OUT_OF_MEMORY, error::OutOfMemory },
+ { CryptsetupEngine::ReturnCode::WRONG_DEVICE, error::NoSuchFile },
+ { CryptsetupEngine::ReturnCode::DEVICE_BUSY, error::DeviceBusy }
};
} // anonymous namespace
int LuksServer::execute(bool sync, Luks::Operation op, const F& job)
{
auto worker = [=]() {
- OdeError ret = OdeError::Unknown;
+ int ret = error::Unknown;
try {
std::lock_guard<std::mutex> guardLock(opGuard);
ret = job();
} catch (const std::exception& e) {
ERROR(SINK, OPERATION_NAME.at(op) + " thread failed: " +
std::string(e.what()));
- ret = OdeError::Unknown;
+ ret = error::Unknown;
} catch (...) {
ERROR(SINK, OPERATION_NAME.at(op) +
" thread failed: unknown exception.");
- ret = OdeError::Unknown;
+ ret = error::Unknown;
}
if (sync) {
- return static_cast<int>(ret);
+ return ret;
} else {
- server.notify(NOTIFICATION, static_cast<int>(op), static_cast<int>(ret));
- return 0;
+ server.notify(NOTIFICATION, static_cast<int>(op), ret);
+ return error::None;
}
};
} else {
std::thread work(worker);
work.detach();
- return 0;
+ return error::None;
}
}
engine.format(CryptsetupEngine::DeviceType::LUKS,
keyManager.getMasterKey(pwData));
- return OdeError::None;
+ return error::None;
});
}
if (!keyManager.verifyPassword(pwData)) {
ERROR(SINK, "Wrong password passed.");
- return OdeError::WrongPassword;
+ return error::WrongPassword;
}
KeyManager::data masterKey = keyManager.getMasterKey(pwData);
engine.open(CryptsetupEngine::DeviceType::LUKS, mapping, masterKey);
- return OdeError::None;
+ return error::None;
});
}
{
return execute(sync, Luks::Close, [=](){
CryptsetupEngine::close(mapping);
- return OdeError::None;
+ return error::None;
});
}
#include "misc.h"
#include "secure-erase.h"
+#include "rmi/common.h"
namespace ode {
std::thread asyncWork(cleanWorker);
asyncWork.detach();
- return 0;
+ return error::None;
}
} // namespace ode