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 PermissionMask permissionMask);
91 const ManagerAsync::ObserverPtr& observer,
94 const RawBuffer& rawData,
95 const Policy& policy);
98 const ManagerAsync::ObserverPtr& observer,
102 const ManagerAsync::ObserverPtr& observer,
104 DataType sendDataType,
105 const Password &password);
108 const ManagerAsync::ObserverPtr& observer,
110 const Password &keyPassword,
111 const Password &certPassword);
113 void getBinaryDataAliasVector(
114 const ManagerAsync::ObserverPtr& observer,
118 const ManagerAsync::ObserverPtr& observer,
119 const KeyType key_type,
120 const int additional_param,
121 const Alias &privateKeyAlias,
122 const Alias &publicKeyAlias,
123 const Policy &policyPrivateKey,
124 const Policy &policyPublicKey);
126 template <typename T>
128 const ManagerAsync::ObserverPtr& observer,
129 LogicCommand command,
130 const CertificateShPtr &certificate,
133 bool useSystemTrustedCertificates)
135 observerCheck(observer);
137 observer->ReceivedError(CKM_API_ERROR_INPUT_PARAM);
140 try_catch_async([&] {
141 sendToStorage(observer,
142 static_cast<int>(command),
144 certificate->getDER(),
147 useSystemTrustedCertificates);
148 }, [&observer](int error){ observer->ReceivedError(error); } );
153 template <typename... Args>
154 void sendToStorage(const ManagerAsync::ObserverPtr& observer, const Args&... args)
156 m_counter++; // yes, it changes m_counter argument passed in args
158 auto send = MessageBuffer::Serialize(args...);
159 thread()->sendMessage(AsyncRequest(observer,
160 SERVICE_SOCKET_CKM_STORAGE,
165 void observerCheck(const ManagerAsync::ObserverPtr& observer);
167 typedef std::unique_ptr<ConnectionThread> ConnectionThreadPtr;
169 ConnectionThreadPtr& thread() {
170 if (!m_thread || m_thread->finished()) {
171 m_thread.reset(new ConnectionThread());
177 ConnectionThreadPtr m_thread;
179 static int m_counter;