Async API stubs
[platform/core/security/key-manager.git] / src / manager / client-async / client-manager-async-impl.cpp
1 /*
2  *  Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License
15  */
16 /*
17  * @file       client-manager-async-impl.cpp
18  * @author     Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
19  * @version    1.0
20  */
21
22 #include <client-manager-async-impl.h>
23 #include <ckm/ckm-error.h>
24 #include <message-buffer.h>
25 #include <client-common.h>
26 #include <stdexcept>
27
28 namespace CKM {
29
30 int ManagerAsync::Impl::m_counter = 0;
31
32 ManagerAsync::Impl::Impl()
33 {
34 }
35
36 ManagerAsync::Impl::~Impl()
37 {
38 }
39
40 void ManagerAsync::Impl::saveKey(const ManagerAsync::ObserverPtr& observer,
41                                  const Alias& alias,
42                                  const KeyShPtr& key,
43                                  const Policy& policy)
44 {
45     observerCheck(observer);
46
47     if (!key) {
48         observer->ReceivedError(CKM_API_ERROR_INPUT_PARAM);
49         return;
50     }
51     saveBinaryData(observer, alias, toDBDataType(key->getType()), key->getDER(), policy);
52 }
53
54 void ManagerAsync::Impl::saveCertificate(const ObserverPtr& observer,
55                                          const Alias& /*alias*/,
56                                          const CertificateShPtr& /*cert*/,
57                                          const Policy& /*policy*/)
58 {
59     observerCheck(observer);
60     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
61 }
62 void ManagerAsync::Impl::saveData(const ObserverPtr& observer,
63                                   const Alias& /*alias*/,
64                                   const RawBuffer& /*data*/,
65                                   const Policy& /*policy*/)
66 {
67     observerCheck(observer);
68     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
69 }
70
71 void ManagerAsync::Impl::removeKey(const ObserverPtr& observer, const Alias& /*alias*/)
72 {
73     observerCheck(observer);
74     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
75 }
76 void ManagerAsync::Impl::removeCertificate(const ObserverPtr& observer, const Alias& /*alias*/)
77 {
78     observerCheck(observer);
79     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
80 }
81 void ManagerAsync::Impl::removeData(const ObserverPtr& observer, const Alias& /*alias*/)
82 {
83     observerCheck(observer);
84     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
85 }
86
87 void ManagerAsync::Impl::getKey(const ObserverPtr& observer,
88                                 const Alias& /*alias*/,
89                                 const Password& /*password*/)
90 {
91     observerCheck(observer);
92     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
93 }
94 void ManagerAsync::Impl::getCertificate(const ObserverPtr& observer,
95                                         const Alias& /*alias*/,
96                                         const Password& /*password*/)
97 {
98     observerCheck(observer);
99     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
100 }
101 void ManagerAsync::Impl::getData(const ObserverPtr& observer,
102                                  const Alias& /*alias*/,
103                                  const Password& /*password*/)
104 {
105     observerCheck(observer);
106     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
107 }
108
109 void ManagerAsync::Impl::getKeyAliasVector(const ObserverPtr& observer)
110 {
111     observerCheck(observer);
112     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
113 }
114 void ManagerAsync::Impl::getCertificateAliasVector(const ObserverPtr& observer)
115 {
116     observerCheck(observer);
117     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
118 }
119 void ManagerAsync::Impl::getDataAliasVector(const ObserverPtr& observer)
120 {
121     observerCheck(observer);
122     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
123 }
124
125 void ManagerAsync::Impl::createKeyPairRSA(const ObserverPtr& observer,
126                                           int /*size*/,
127                                           const Alias& /*privateKeyAlias*/,
128                                           const Alias& /*publicKeyAlias*/,
129                                           const Policy& /*policyPrivateKey*/,
130                                           const Policy& /*policyPublicKey*/)
131 {
132     observerCheck(observer);
133     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
134 }
135 void ManagerAsync::Impl::createKeyPairDSA(const ObserverPtr& observer,
136                                           int /*size*/,
137                                           const Alias& /*privateKeyAlias*/,
138                                           const Alias& /*publicKeyAlias*/,
139                                           const Policy& /*policyPrivateKey*/,
140                                           const Policy& /*policyPublicKey*/)
141 {
142     observerCheck(observer);
143     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
144 }
145 void ManagerAsync::Impl::createKeyPairECDSA(const ObserverPtr& observer,
146                                             const ElipticCurve /*type*/,
147                                             const Alias& /*privateKeyAlias*/,
148                                             const Alias& /*publicKeyAlias*/,
149                                             const Policy& /*policyPrivateKey*/,
150                                             const Policy& /*policyPublicKey*/)
151 {
152     observerCheck(observer);
153     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
154 }
155
156 void ManagerAsync::Impl::getCertificateChain(const ObserverPtr& observer,
157                                              const CertificateShPtr& /*certificate*/,
158                                              const CertificateShPtrVector& /*untrustedCertificates*/)
159 {
160     observerCheck(observer);
161     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
162 }
163
164 void ManagerAsync::Impl::getCertificateChain(const ObserverPtr& observer,
165                                              const CertificateShPtr& /*certificate*/,
166                                              const AliasVector& /*untrustedCertificates*/)
167 {
168     observerCheck(observer);
169     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
170 }
171
172 void ManagerAsync::Impl::createSignature(const ObserverPtr& observer,
173                                          const Alias& /*privateKeyAlias*/,
174                                          const Password& /*password*/,
175                                          const RawBuffer& /*message*/,
176                                          const HashAlgorithm /*hash*/,
177                                          const RSAPaddingAlgorithm /*padding*/)
178 {
179     observerCheck(observer);
180     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
181 }
182
183 void ManagerAsync::Impl::verifySignature(const ObserverPtr& observer,
184                                          const Alias& /*publicKeyOrCertAlias*/,
185                                          const Password& /*password*/,
186                                          const RawBuffer& /*message*/,
187                                          const RawBuffer& /*signature*/,
188                                          const HashAlgorithm /*hash*/,
189                                          const RSAPaddingAlgorithm /*padding*/)
190 {
191     observerCheck(observer);
192     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
193 }
194
195 void ManagerAsync::Impl::ocspCheck(const ObserverPtr& observer,
196                                    const CertificateShPtrVector& /*certificateChainVector*/)
197 {
198     observerCheck(observer);
199     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
200 }
201
202 void ManagerAsync::Impl::allowAccess(const ObserverPtr& observer,
203                                      const std::string& /*alias*/,
204                                      const std::string& /*accessor*/,
205                                      AccessRight /*granted*/)
206 {
207     observerCheck(observer);
208     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
209 }
210
211 void ManagerAsync::Impl::denyAccess(const ObserverPtr& observer,
212                                     const std::string& /*alias*/,
213                                     const std::string& /*accessor*/)
214 {
215     observerCheck(observer);
216     observer->ReceivedError(CKM_API_ERROR_UNKNOWN);
217 }
218
219 void ManagerAsync::Impl::saveBinaryData(const ManagerAsync::ObserverPtr& observer,
220                                         const Alias& alias,
221                                         DBDataType dataType,
222                                         const RawBuffer& rawData,
223                                         const Policy& policy)
224 {
225     if (alias.empty() || rawData.empty()) {
226         observer->ReceivedError(CKM_API_ERROR_INPUT_PARAM);
227         return;
228     }
229
230     try_catch_async([&] {
231         m_counter++;
232
233         MessageBuffer send;
234         Serialization::Serialize(send, static_cast<int>(LogicCommand::SAVE));
235         Serialization::Serialize(send, m_counter);
236         Serialization::Serialize(send, static_cast<int>(dataType));
237         Serialization::Serialize(send, alias);
238         Serialization::Serialize(send, rawData);
239         Serialization::Serialize(send, PolicySerializable(policy));
240
241         thread()->sendMessage(AsyncRequest(observer,
242                                            SERVICE_SOCKET_CKM_STORAGE,
243                                            send.Pop(),
244                                            m_counter));
245
246     }, [&observer](int error){ observer->ReceivedError(error); } );
247 }
248
249 void ManagerAsync::Impl::observerCheck(const ManagerAsync::ObserverPtr& observer)
250 {
251     if(!observer)
252         throw std::invalid_argument("Empty observer");
253 }
254
255 } // namespace CKM