2 * Copyright (c) 2014-2020 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 final {
39 const ObserverPtr &observer,
42 const Policy &policy);
44 const ObserverPtr &observer,
46 const CertificateShPtr &cert,
47 const Policy &policy);
49 const ObserverPtr &observer,
51 const RawBuffer &data,
52 const Policy &policy);
54 const ObserverPtr &observer,
56 const PKCS12ShPtr &pkcs,
57 const Policy &keyPolicy,
58 const Policy &certPolicy);
61 const ObserverPtr &observer,
62 const Alias &privateKeyAlias,
63 const Password &password,
64 const RawBuffer &message,
65 const CryptoAlgorithm &cAlgorithm);
67 const ObserverPtr &observer,
68 const Alias &publicKeyOrCertAlias,
69 const Password &password,
70 const RawBuffer &message,
71 const RawBuffer &signature,
72 const CryptoAlgorithm &cAlgorithm);
75 const ObserverPtr &observer,
76 const CertificateShPtrVector &certificateChainVector);
79 const ObserverPtr &observer,
81 const ClientId &accessor,
82 PermissionMask permissionMask);
86 const ObserverPtr &observer,
89 const RawBuffer &rawData,
90 const Policy &policy);
93 const ObserverPtr &observer,
97 const ObserverPtr &observer,
99 DataType sendDataType,
100 const Password &password);
103 const ObserverPtr &observer,
105 const Password &keyPassword,
106 const Password &certPassword);
108 void getBinaryDataAliasVector(
109 const ObserverPtr &observer,
113 const ObserverPtr &observer,
114 const KeyType key_type,
115 const int additional_param,
116 const Alias &privateKeyAlias,
117 const Alias &publicKeyAlias,
118 const Policy &policyPrivateKey,
119 const Policy &policyPublicKey);
122 const ObserverPtr &observer,
124 const Alias &keyAlias,
125 const Policy &policyKey);
127 template <typename T>
129 const ObserverPtr &observer,
130 LogicCommand command,
131 const CertificateShPtr &certificate,
134 bool useSystemTrustedCertificates)
136 if (!certificate || certificate->empty())
137 ThrowMsg(Exc::InputParam, "Empty certificate");
139 sendToStorage(command, observer,
140 certificate->getDER(), untrusted, trusted, useSystemTrustedCertificates);
144 const ObserverPtr &observer,
145 const CryptoAlgorithm &algo,
146 const Alias &keyAlias,
147 const Password &password,
148 const RawBuffer &input,
151 static void observerCheck(const ObserverPtr &observer);
154 template <typename... Args>
155 void sendToStorage(LogicCommand command, const ObserverPtr &observer, Args &&... args)
158 auto send = SerializeMessage(command, m_counter, std::forward<Args>(args)...);
159 thread()->sendMessage(AsyncRequest(observer, SERVICE_SOCKET_CKM_STORAGE,
160 std::move(send), m_counter, static_cast<int>(command)));
163 typedef std::unique_ptr<ConnectionThread> ConnectionThreadPtr;
165 ConnectionThreadPtr &thread()
167 if (!m_thread || m_thread->finished()) {
168 m_thread.reset(new ConnectionThread());
175 ConnectionThreadPtr m_thread;
177 static inline int m_counter = 0;