2 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
17 * @file client-manager-async-impl.h
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
24 #include <ckm/ckm-manager-async.h>
26 #include <connection-thread.h>
27 #include <protocols.h>
28 #include <noncopyable.h>
32 class ManagerAsync::Impl
42 const ObserverPtr& observer,
45 const Policy& policy);
47 const ObserverPtr& observer,
49 const CertificateShPtr& cert,
50 const Policy& policy);
52 const ObserverPtr& observer,
54 const RawBuffer& data,
55 const Policy& policy);
57 const ObserverPtr& observer,
59 const PKCS12ShPtr &pkcs,
60 const Policy &keyPolicy,
61 const Policy &certPolicy);
64 const ObserverPtr& observer,
65 const Alias& privateKeyAlias,
66 const Password& password,
67 const RawBuffer& message,
68 const HashAlgorithm hash,
69 const RSAPaddingAlgorithm padding);
71 const ObserverPtr& observer,
72 const Alias& publicKeyOrCertAlias,
73 const Password& password,
74 const RawBuffer& message,
75 const RawBuffer& signature,
76 const HashAlgorithm hash,
77 const RSAPaddingAlgorithm padding);
80 const ObserverPtr& observer,
81 const CertificateShPtrVector& certificateChainVector);
84 const ObserverPtr& observer,
86 const Label& accessor,
87 Permission newPermission);
91 const ManagerAsync::ObserverPtr& observer,
94 const RawBuffer& rawData,
95 const Policy& policy);
98 const ManagerAsync::ObserverPtr& observer,
102 const ManagerAsync::ObserverPtr& observer,
104 DBDataType sendDataType,
105 const Password &password);
108 const ManagerAsync::ObserverPtr& observer,
111 void getBinaryDataAliasVector(
112 const ManagerAsync::ObserverPtr& observer,
113 DBDataType dataType);
116 const ManagerAsync::ObserverPtr& observer,
117 const KeyType key_type,
118 const int additional_param,
119 const Alias &privateKeyAlias,
120 const Alias &publicKeyAlias,
121 const Policy &policyPrivateKey,
122 const Policy &policyPublicKey);
124 template <typename T>
126 const ManagerAsync::ObserverPtr& observer,
127 LogicCommand command,
128 const CertificateShPtr &certificate,
131 observerCheck(observer);
132 if (!certificate || sendData.empty()) {
133 observer->ReceivedError(CKM_API_ERROR_INPUT_PARAM);
136 try_catch_async([&] {
137 sendToStorage(observer,
138 static_cast<int>(command),
140 certificate->getDER(),
142 }, [&observer](int error){ observer->ReceivedError(error); } );
147 template <typename... Args>
148 void sendToStorage(const ManagerAsync::ObserverPtr& observer, const Args&... args)
150 m_counter++; // yes, it changes m_counter argument passed in args
152 auto send = MessageBuffer::Serialize(args...);
153 thread()->sendMessage(AsyncRequest(observer,
154 SERVICE_SOCKET_CKM_STORAGE,
159 void observerCheck(const ManagerAsync::ObserverPtr& observer);
161 typedef std::unique_ptr<ConnectionThread> ConnectionThreadPtr;
163 ConnectionThreadPtr& thread() {
164 if (!m_thread || m_thread->finished()) {
165 m_thread.reset(new ConnectionThread());
171 ConnectionThreadPtr m_thread;
173 static int m_counter;