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-control.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(uid_t user, const std::string &password) {
40 return try_catch([&] {
41 MessageBuffer send, recv;
42 Serialization::Serialize(send, static_cast<int>(ControlCommand::UNLOCK_USER_KEY));
43 Serialization::Serialize(send, user);
44 Serialization::Serialize(send, password);
46 int retCode = sendToServer(
47 SERVICE_SOCKET_CKM_CONTROL,
51 if (CKM_API_SUCCESS != retCode) {
55 Deserialization::Deserialize(recv, retCode);
61 static int lockUserKey(uid_t user) {
62 return try_catch([&] {
63 MessageBuffer send, recv;
64 Serialization::Serialize(send, static_cast<int>(ControlCommand::LOCK_USER_KEY));
65 Serialization::Serialize(send, user);
67 int retCode = sendToServer(
68 SERVICE_SOCKET_CKM_CONTROL,
72 if (CKM_API_SUCCESS != retCode) {
76 Deserialization::Deserialize(recv, retCode);
82 static int removeUserData(uid_t user) {
83 return try_catch([&] {
84 MessageBuffer send, recv;
85 Serialization::Serialize(send, static_cast<int>(ControlCommand::REMOVE_USER_DATA));
86 Serialization::Serialize(send, user);
88 int retCode = sendToServer(
89 SERVICE_SOCKET_CKM_CONTROL,
93 if (CKM_API_SUCCESS != retCode) {
97 Deserialization::Deserialize(recv, retCode);
103 static int changeUserPassword(uid_t user, const std::string &oldPassword, const std::string &newPassword) {
104 return try_catch([&] {
105 MessageBuffer send, recv;
106 Serialization::Serialize(send, static_cast<int>(ControlCommand::CHANGE_USER_PASSWORD));
107 Serialization::Serialize(send, user);
108 Serialization::Serialize(send, oldPassword);
109 Serialization::Serialize(send, newPassword);
111 int retCode = sendToServer(
112 SERVICE_SOCKET_CKM_CONTROL,
116 if (CKM_API_SUCCESS != retCode) {
120 Deserialization::Deserialize(recv, retCode);
126 static int resetUserPassword(uid_t user, const std::string &newPassword) {
127 return try_catch([&] {
128 MessageBuffer send, recv;
129 Serialization::Serialize(send, static_cast<int>(ControlCommand::RESET_USER_PASSWORD));
130 Serialization::Serialize(send, user);
131 Serialization::Serialize(send, newPassword);
133 int retCode = sendToServer(
134 SERVICE_SOCKET_CKM_CONTROL,
138 if (CKM_API_SUCCESS != retCode) {
142 Deserialization::Deserialize(recv, retCode);
148 virtual ~ControlImpl(){}
152 : m_impl(new ControlImpl)
155 Control::~Control(){}
157 int Control::unlockUserKey(uid_t user, const std::string &password) const {
158 return m_impl->unlockUserKey(user, password);
161 int Control::lockUserKey(uid_t user) const {
162 return m_impl->lockUserKey(user);
165 int Control::removeUserData(uid_t user) const {
166 return m_impl->removeUserData(user);
169 int Control::changeUserPassword(uid_t user, const std::string &oldPassword, const std::string &newPassword) const {
170 return m_impl->changeUserPassword(user, oldPassword, newPassword);
173 int Control::resetUserPassword(uid_t user, const std::string &newPassword) const {
174 return m_impl->resetUserPassword(user, newPassword);