2 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Bumjin Im <bj.im@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
18 * @file client-common.cpp
19 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
21 * @brief This file is implementation of client-common functions.
23 #include <client-common.h>
24 #include <message-buffer.h>
25 #include <protocols.h>
27 #include <ckm/key-manager.h>
31 class Control::ControlImpl {
34 ControlImpl(const ControlImpl &) = delete;
35 ControlImpl(ControlImpl &&) = delete;
36 ControlImpl& operator=(const ControlImpl &) = delete;
37 ControlImpl& operator=(ControlImpl &&) = delete;
39 static int unlockUserKey(const std::string &user, const RawData &password) {
40 return try_catch([&] {
42 return KEY_MANAGER_API_ERROR_INPUT_PARAM;
44 MessageBuffer send, recv;
45 Serialization::Serialize(send, static_cast<int>(ControlCommand::UNLOCK_USER_KEY));
46 Serialization::Serialize(send, user);
47 Serialization::Serialize(send, password);
49 int retCode = sendToServer(
50 SERVICE_SOCKET_CKM_CONTROL,
54 if (KEY_MANAGER_API_SUCCESS != retCode) {
58 Deserialization::Deserialize(recv, retCode);
64 static int lockUserKey(const std::string &user) {
65 return try_catch([&] {
67 return KEY_MANAGER_API_ERROR_INPUT_PARAM;
69 MessageBuffer send, recv;
70 Serialization::Serialize(send, static_cast<int>(ControlCommand::LOCK_USER_KEY));
71 Serialization::Serialize(send, user);
73 int retCode = sendToServer(
74 SERVICE_SOCKET_CKM_CONTROL,
78 if (KEY_MANAGER_API_SUCCESS != retCode) {
82 Deserialization::Deserialize(recv, retCode);
88 static int removeUserData(const std::string &user) {
89 return try_catch([&] {
91 return KEY_MANAGER_API_ERROR_INPUT_PARAM;
93 MessageBuffer send, recv;
94 Serialization::Serialize(send, static_cast<int>(ControlCommand::REMOVE_USER_DATA));
95 Serialization::Serialize(send, user);
97 int retCode = sendToServer(
98 SERVICE_SOCKET_CKM_CONTROL,
102 if (KEY_MANAGER_API_SUCCESS != retCode) {
106 Deserialization::Deserialize(recv, retCode);
112 static int changeUserPassword(const std::string &user, const RawData &oldPassword, const RawData &newPassword) {
113 return try_catch([&] {
115 return KEY_MANAGER_API_ERROR_INPUT_PARAM;
117 MessageBuffer send, recv;
118 Serialization::Serialize(send, static_cast<int>(ControlCommand::CHANGE_USER_PASSWORD));
119 Serialization::Serialize(send, user);
120 Serialization::Serialize(send, oldPassword);
121 Serialization::Serialize(send, newPassword);
123 int retCode = sendToServer(
124 SERVICE_SOCKET_CKM_CONTROL,
128 if (KEY_MANAGER_API_SUCCESS != retCode) {
132 Deserialization::Deserialize(recv, retCode);
138 static int resetUserPassword(const std::string &user, const RawData &newPassword) {
139 return try_catch([&] {
141 return KEY_MANAGER_API_ERROR_INPUT_PARAM;
143 MessageBuffer send, recv;
144 Serialization::Serialize(send, static_cast<int>(ControlCommand::RESET_USER_PASSWORD));
145 Serialization::Serialize(send, user);
146 Serialization::Serialize(send, newPassword);
148 int retCode = sendToServer(
149 SERVICE_SOCKET_CKM_CONTROL,
153 if (KEY_MANAGER_API_SUCCESS != retCode) {
157 Deserialization::Deserialize(recv, retCode);
163 virtual ~ControlImpl(){}
167 : m_impl(new ControlImpl)
170 Control::~Control(){}
172 int Control::unlockUserKey(const std::string &user, const RawData &password) const {
173 return m_impl->unlockUserKey(user, password);
176 int Control::lockUserKey(const std::string &user) const {
177 return m_impl->lockUserKey(user);
180 int Control::removeUserData(const std::string &user) const {
181 return m_impl->removeUserData(user);
184 int Control::changeUserPassword(const std::string &user, const RawData &oldPassword, const RawData &newPassword) const {
185 return m_impl->changeUserPassword(user, oldPassword, newPassword);
188 int Control::resetUserPassword(const std::string &user, const RawData &newPassword) const {
189 return m_impl->resetUserPassword(user, newPassword);