1 /* Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License
16 * @file client-manager-impl.cpp
17 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
19 * @brief Manager implementation.
21 #include <dpl/serialization.h>
23 #include <client-manager-impl.h>
24 #include <client-common.h>
25 #include <client-key-impl.h>
26 #include <message-buffer.h>
27 #include <protocols.h>
31 int Manager::ManagerImpl::saveKey(const Alias &alias, const Key &key, const Policy &policy) {
34 return try_catch([&] {
35 if (alias.empty() || key.empty())
36 return KEY_MANAGER_API_ERROR_INPUT_PARAM;
38 MessageBuffer send, recv;
39 Serialization::Serialize(send, static_cast<int>(LogicCommand::SAVE));
40 Serialization::Serialize(send, m_counter);
41 Serialization::Serialize(send, static_cast<int>(toDBDataType(key.getType())));
42 Serialization::Serialize(send, alias);
43 Serialization::Serialize(send, key.getKey());
44 Serialization::Serialize(send, PolicySerializable(policy));
46 int retCode = sendToServer(
47 SERVICE_SOCKET_CKM_STORAGE,
51 if (KEY_MANAGER_API_SUCCESS != retCode) {
58 Deserialization::Deserialize(recv, command);
59 Deserialization::Deserialize(recv, counter);
60 Deserialization::Deserialize(recv, opType);
61 Deserialization::Deserialize(recv, retCode);
63 if (counter != m_counter) {
64 return KEY_MANAGER_API_ERROR_UNKNOWN;
71 int Manager::ManagerImpl::removeKey(const Alias &alias) {
72 return try_catch([&] {
74 return KEY_MANAGER_API_ERROR_INPUT_PARAM;
76 MessageBuffer send, recv;
77 Serialization::Serialize(send, static_cast<int>(LogicCommand::REMOVE));
78 Serialization::Serialize(send, m_counter);
79 Serialization::Serialize(send, static_cast<int>(DBDataType::KEY_RSA_PUBLIC));
80 Serialization::Serialize(send, alias);
82 int retCode = sendToServer(
83 SERVICE_SOCKET_CKM_STORAGE,
87 if (KEY_MANAGER_API_SUCCESS != retCode) {
94 Deserialization::Deserialize(recv, command);
95 Deserialization::Deserialize(recv, counter);
96 Deserialization::Deserialize(recv, opType);
97 Deserialization::Deserialize(recv, retCode);
99 if (counter != m_counter) {
100 return KEY_MANAGER_API_ERROR_UNKNOWN;
107 int Manager::ManagerImpl::getBinaryData(
109 DBDataType sendDataType,
110 const RawData &password,
111 DBDataType &recvDataType,
114 return try_catch([&] {
116 return KEY_MANAGER_API_ERROR_INPUT_PARAM;
118 MessageBuffer send, recv;
119 Serialization::Serialize(send, static_cast<int>(LogicCommand::GET));
120 Serialization::Serialize(send, m_counter);
121 Serialization::Serialize(send, static_cast<int>(sendDataType));
122 Serialization::Serialize(send, alias);
123 Serialization::Serialize(send, password);
125 int retCode = sendToServer(
126 SERVICE_SOCKET_CKM_STORAGE,
130 if (KEY_MANAGER_API_SUCCESS != retCode) {
137 Deserialization::Deserialize(recv, command);
138 Deserialization::Deserialize(recv, counter);
139 Deserialization::Deserialize(recv, opType);
140 Deserialization::Deserialize(recv, retCode);
142 if (retCode == KEY_MANAGER_API_SUCCESS) {
144 Deserialization::Deserialize(recv, tmpDataType);
145 Deserialization::Deserialize(recv, rawData);
146 recvDataType = static_cast<DBDataType>(tmpDataType);
149 if (counter != m_counter) {
150 return KEY_MANAGER_API_ERROR_UNKNOWN;
157 int Manager::ManagerImpl::getKey(const Alias &alias, const RawData &password, Key &key) {
158 DBDataType recvDataType;
161 int retCode = getBinaryData(
163 DBDataType::KEY_RSA_PUBLIC,
168 if (retCode != KEY_MANAGER_API_SUCCESS)
171 Key keyParsed(rawData, toKeyType(recvDataType));
173 if (keyParsed.empty())
174 return KEY_MANAGER_API_ERROR_BAD_RESPONSE;
178 return KEY_MANAGER_API_SUCCESS;