fca4408aad5a3129fd8cb05ed563aa930cc4de68
[platform/core/security/key-manager.git] / src / include / ckm / ckm-manager-async.h
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        ckm-manager-async.h
18  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
19  * @version     1.0
20  * @brief       Async key manager API.
21  */
22 #pragma once
23
24 #include <memory>
25
26 #include <ckm/ckm-certificate.h>
27 #include <ckm/ckm-error.h>
28 #include <ckm/ckm-key.h>
29 #include <ckm/ckm-type.h>
30 #include <ckm/ckm-pkcs12.h>
31
32 // Central Key Manager namespace
33 namespace CKM {
34
35 // Asynchronous interface to Central Key Manager. This implementation uses
36 // internal thread for connection. Key Manager is not thread safe.
37 class KEY_MANAGER_API ManagerAsync
38 {
39 public:
40     class Impl;
41
42     ManagerAsync();
43
44     ManagerAsync(const ManagerAsync&) = delete;
45     ManagerAsync& operator=(const ManagerAsync&) = delete;
46
47     // Observer will observer custom operation.
48     struct Observer {
49         virtual void ReceivedError(int error) = 0;
50
51         virtual void ReceivedSaveKey() {}
52         virtual void ReceivedSaveCertificate() {}
53         virtual void ReceivedSaveData() {}
54         virtual void ReceivedSavePKCS12() {}
55
56         virtual void ReceivedRemovedAlias() {}
57
58         virtual void ReceivedKey(Key &&) {}
59         virtual void ReceivedCertificate(Certificate &&) {}
60         virtual void ReceivedData(RawBuffer &&) {}
61         virtual void ReceivedPKCS12(PKCS12ShPtr &&) {}
62
63         virtual void ReceivedKeyAliasVector(AliasVector &&) {}
64         virtual void ReceivedCertificateAliasVector(AliasVector &&) {}
65         virtual void ReceivedDataAliasVector(AliasVector &&) {}
66
67         virtual void ReceivedCreateKeyAES() {}
68         virtual void ReceivedCreateKeyPair() {}
69
70         virtual void ReceivedGetCertificateChain(CertificateShPtrVector &&) {}
71
72         virtual void ReceivedCreateSignature(RawBuffer &&) {}
73         virtual void ReceivedVerifySignature() {}
74
75         virtual void ReceivedOCSPCheck(int) {}
76
77         virtual void ReceivedSetPermission() {}
78
79         virtual ~Observer() {}
80     };
81
82     typedef std::shared_ptr<Observer> ObserverPtr;
83
84     virtual ~ManagerAsync();
85
86     void saveKey(
87             const ObserverPtr& observer,
88             const Alias& alias,
89             const KeyShPtr& key,
90             const Policy& policy);
91     void saveCertificate(
92             const ObserverPtr& observer,
93             const Alias& alias,
94             const CertificateShPtr& cert,
95             const Policy& policy);
96     void saveData(
97             const ObserverPtr& observer,
98             const Alias& alias,
99             const RawBuffer& data,
100             const Policy& policy);
101     void savePKCS12(
102             const ObserverPtr& observer,
103             const Alias &alias,
104             const PKCS12ShPtr &pkcs,
105             const Policy &keyPolicy,
106             const Policy &certPolicy);
107
108     void removeAlias(const ObserverPtr& observer, const Alias& alias);
109
110     void getKey(const ObserverPtr& observer, const Alias& alias, const Password& password);
111     void getCertificate(const ObserverPtr& observer, const Alias& alias, const Password& password);
112     void getData(const ObserverPtr& observer, const Alias& alias, const Password& password);
113
114     void getPKCS12(
115         const ObserverPtr& observer,
116         const Alias &alias,
117         const Password& passwordKey = Password(),
118         const Password& passwordCert = Password());
119
120     // send request for list of all keys/certificates/data that application/user may use
121     void getKeyAliasVector(const ObserverPtr& observer);
122     void getCertificateAliasVector(const ObserverPtr& observer);
123     void getDataAliasVector(const ObserverPtr& observer);
124
125     void createKeyPairRSA(
126             const ObserverPtr& observer,
127             int size,
128             const Alias& privateKeyAlias,
129             const Alias& publicKeyAlias,
130             const Policy& policyPrivateKey = Policy(),
131             const Policy& policyPublicKey = Policy());
132     void createKeyPairDSA(
133             const ObserverPtr& observer,
134             int size,
135             const Alias& privateKeyAlias,
136             const Alias& publicKeyAlias,
137             const Policy& policyPrivateKey = Policy(),
138             const Policy& policyPublicKey = Policy());
139     void createKeyPairECDSA(
140             const ObserverPtr& observer,
141             const ElipticCurve type,
142             const Alias& privateKeyAlias,
143             const Alias& publicKeyAlias,
144             const Policy& policyPrivateKey = Policy(),
145             const Policy& policyPublicKey = Policy());
146     void createKeyAES(
147             const ObserverPtr& observer,
148             int sizeBits,
149             const Alias &keyAlias,
150             const Policy &policyKey = Policy());
151
152     void getCertificateChain(
153             const ObserverPtr& observer,
154             const CertificateShPtr& certificate,
155             const CertificateShPtrVector& untrustedCertificates,
156             const CertificateShPtrVector& trustedCertificates,
157             bool useSystemTrustedCertificates);
158     void getCertificateChain(
159             const ObserverPtr& observer,
160             const CertificateShPtr& certificate,
161             const AliasVector& untrustedCertificates,
162             const AliasVector& trustedCertificates,
163             bool useSystemTrustedCertificates);
164
165     void createSignature(
166             const ObserverPtr& observer,
167             const Alias& privateKeyAlias,
168             const Password& password,           // password for private_key
169             const RawBuffer& message,
170             const HashAlgorithm hash,
171             const RSAPaddingAlgorithm padding);
172     void verifySignature(
173             const ObserverPtr& observer,
174             const Alias& publicKeyOrCertAlias,
175             const Password& password,           // password for public_key (optional)
176             const RawBuffer& message,
177             const RawBuffer& signature,
178             const HashAlgorithm hash,
179             const RSAPaddingAlgorithm padding);
180
181     // This function will check all certificates in chain except Root CA.
182     // This function will delegate task to service. You may use this even
183     // if application does not have permission to use network.
184     void ocspCheck(
185             const ObserverPtr& observer,
186             const CertificateShPtrVector& certificateChainVector);
187
188     void setPermission(
189             const ObserverPtr& observer,
190             const Alias& alias,
191             const Label& accessor,
192             PermissionMask permissionMask);
193
194 private:
195     std::unique_ptr<Impl> m_impl;
196 };
197
198 } // namespace CKM
199