2 * Copyright (c) 2000 - 2015 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 CryptoAlgorithm& cAlgorithm);
70 const ObserverPtr& observer,
71 const Alias& publicKeyOrCertAlias,
72 const Password& password,
73 const RawBuffer& message,
74 const RawBuffer& signature,
75 const CryptoAlgorithm& cAlgorithm);
78 const ObserverPtr& observer,
79 const CertificateShPtrVector& certificateChainVector);
82 const ObserverPtr& observer,
84 const Label& accessor,
85 PermissionMask permissionMask);
89 const ManagerAsync::ObserverPtr& observer,
92 const RawBuffer& rawData,
93 const Policy& policy);
96 const ManagerAsync::ObserverPtr& observer,
100 const ManagerAsync::ObserverPtr& observer,
102 DataType sendDataType,
103 const Password &password);
106 const ManagerAsync::ObserverPtr& observer,
108 const Password &keyPassword,
109 const Password &certPassword);
111 void getBinaryDataAliasVector(
112 const ManagerAsync::ObserverPtr& observer,
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);
125 const ManagerAsync::ObserverPtr& observer,
127 const Alias &keyAlias,
128 const Policy &policyKey);
130 template <typename T>
132 const ManagerAsync::ObserverPtr& observer,
133 LogicCommand command,
134 const CertificateShPtr &certificate,
137 bool useSystemTrustedCertificates)
139 observerCheck(observer);
141 observer->ReceivedError(CKM_API_ERROR_INPUT_PARAM);
144 try_catch_async([&] {
145 sendToStorage(observer,
146 static_cast<int>(command),
148 certificate->getDER(),
151 useSystemTrustedCertificates);
152 }, [&observer](int error){ observer->ReceivedError(error); } );
156 const ObserverPtr& observer,
157 const CryptoAlgorithm& algo,
158 const Alias& keyAlias,
159 const Password& password,
160 const RawBuffer& input,
165 template <typename... Args>
166 void sendToStorage(const ManagerAsync::ObserverPtr& observer, const Args&... args)
168 m_counter++; // yes, it changes m_counter argument passed in args
170 auto send = MessageBuffer::Serialize(args...);
171 thread()->sendMessage(AsyncRequest(observer,
172 SERVICE_SOCKET_CKM_STORAGE,
177 void observerCheck(const ManagerAsync::ObserverPtr& observer);
179 typedef std::unique_ptr<ConnectionThread> ConnectionThreadPtr;
181 ConnectionThreadPtr& thread() {
182 if (!m_thread || m_thread->finished()) {
183 m_thread.reset(new ConnectionThread());
189 ConnectionThreadPtr m_thread;
191 static int m_counter;