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 <client-manager-impl.h>
22 #include <message-buffer.h>
23 #include <client-common.h>
24 #include <dpl/serialization.h>
25 #include <protocols.h>
26 #include <client-key-impl.h>
30 int Manager::ManagerImpl::saveKey(const Alias &alias, const Key &key, const Policy &policy) {
33 return try_catch([&] {
34 if (alias.empty() || key.empty())
35 return KEY_MANAGER_API_ERROR_INPUT_PARAM;
37 MessageBuffer send, recv;
38 Serialization::Serialize(send, static_cast<int>(StorageCommand::SAVE));
39 Serialization::Serialize(send, m_counter);
40 Serialization::Serialize(send, static_cast<int>(toDBDataType(key.getType())));
41 Serialization::Serialize(send, alias);
42 Serialization::Serialize(send, key.getImpl());
43 Serialization::Serialize(send, PolicySerializable(policy));
45 int retCode = sendToServer(
46 SERVICE_SOCKET_CKM_STORAGE,
50 if (KEY_MANAGER_API_SUCCESS != retCode) {
57 Deserialization::Deserialize(recv, command);
58 Deserialization::Deserialize(recv, counter);
59 Deserialization::Deserialize(recv, opType);
60 Deserialization::Deserialize(recv, retCode);
62 if (counter != m_counter) {
63 return KEY_MANAGER_API_ERROR_UNKNOWN;
70 int Manager::ManagerImpl::removeKey(const Alias &alias) {
71 return try_catch([&] {
73 return KEY_MANAGER_API_ERROR_INPUT_PARAM;
75 MessageBuffer send, recv;
76 Serialization::Serialize(send, static_cast<int>(StorageCommand::REMOVE));
77 Serialization::Serialize(send, m_counter);
78 Serialization::Serialize(send, static_cast<int>(DBDataType::KEY_RSA_PUBLIC));
79 Serialization::Serialize(send, alias);
81 int retCode = sendToServer(
82 SERVICE_SOCKET_CKM_STORAGE,
86 if (KEY_MANAGER_API_SUCCESS != retCode) {
93 Deserialization::Deserialize(recv, command);
94 Deserialization::Deserialize(recv, counter);
95 Deserialization::Deserialize(recv, opType);
96 Deserialization::Deserialize(recv, retCode);
98 if (counter != m_counter) {
99 return KEY_MANAGER_API_ERROR_UNKNOWN;
106 int Manager::ManagerImpl::getKey(const Alias &alias, const RawData &password, Key &key) {
107 return try_catch([&] {
109 return KEY_MANAGER_API_ERROR_INPUT_PARAM;
111 MessageBuffer send, recv;
112 Serialization::Serialize(send, static_cast<int>(StorageCommand::GET));
113 Serialization::Serialize(send, m_counter);
114 Serialization::Serialize(send, static_cast<int>(DBDataType::KEY_RSA_PUBLIC));
115 Serialization::Serialize(send, alias);
116 Serialization::Serialize(send, password);
118 int retCode = sendToServer(
119 SERVICE_SOCKET_CKM_STORAGE,
123 if (KEY_MANAGER_API_SUCCESS != retCode) {
130 Deserialization::Deserialize(recv, command);
131 Deserialization::Deserialize(recv, counter);
132 Deserialization::Deserialize(recv, opType);
133 Deserialization::Deserialize(recv, retCode);
135 if (retCode == KEY_MANAGER_API_SUCCESS)
136 Deserialization::Deserialize(recv, *(key.getImpl()));
138 if (counter != m_counter) {
139 return KEY_MANAGER_API_ERROR_UNKNOWN;