318447035edfc7f9a1dd55156472a7389a94e426
[platform/framework/native/appfw.git] / src / security / inc / FSecCert_CertServiceProxy.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FSecCert_CertServiceProxy.h
20  * @brief       This is the header file for the _CertServiceProxy class.
21  *
22  * This file contains the declarations of _CertServiceProxy.
23  */
24
25 #ifndef _FSEC_CERT_INTERNAL_CERT_SERVICE_PROXY_H_
26 #define _FSEC_CERT_INTERNAL_CERT_SERVICE_PROXY_H_
27
28 #include <FBaseResult.h>
29 #include <FBaseObject.h>
30 #include <FBaseString.h>
31 #include "FSecCert_CertTypes.h"
32
33 namespace Tizen { namespace Io
34 {
35 class _IpcClient;
36 } }
37
38 namespace Tizen { namespace Base { namespace Runtime
39 {
40 class Mutex;
41 } } }
42
43 namespace Tizen { namespace Security { namespace Cert
44 {
45
46 /**
47  * @class       _CertServiceProxy
48  * @brief       This class is provide IPC API for Certificate Management.
49  * @since 2.1
50  *
51  * The %_CertServiceProxy class is used for to provide Certificate Management's IPC API.
52  *
53  * For more information on the class features, see <a href="../com.osp.cppappprogramming.help/html/dev_guide/security/certificate_namespace.htm">Certificates</a>.
54  *
55  */
56 class _OSP_EXPORT_ _CertServiceProxy
57 {
58
59 public:
60         /**
61          * Creates and intialize the instance of _CertServiceProxy class.
62          *
63          * @since 2.1
64          * @return                      An error code.
65          * @exception           E_SUCCESS                                       The method is successful.
66          * @exception           E_OUT_OF_MEMORY                         The memory is insufficient.
67          * @exception           E_SYSTEM                                        A system error has occurred.
68          *                                                                                              - IPC operation failed.
69          */
70         static _CertServiceProxy* GetInstance(void);
71
72         /**
73          *      This function returns name of root Certificate store.
74          *
75          * @since 2.1
76          * @return                      An error code.
77          * @exception           E_SUCCESS                                       The method is successful.
78          * @exception           E_OUT_OF_MEMORY                         The memory is insufficient.
79          * @exception           E_SYSTEM                                        A system error has occurred.
80          *                                                                                              - IPC operation failed.
81          */
82         result GetName(void);
83
84         /**
85          *      This function closes root Certificate Handle.
86          *
87          * @since 2.1
88          * @return                      An error code.
89          * @param[in]           certificateStoreCtx                                     Certificate store context, can be get using OpenCertificateStoreByType function.
90          * @exception           E_SUCCESS                                       The method is successful.
91          * @exception           E_OUT_OF_MEMORY                         The memory is insufficient.
92          * @exception           E_SYSTEM                                        A system error has occurred.
93          *                                                                                              - IPC operation failed.
94          */
95         result CloseCertificateStore(int certificateStoreCtx);
96
97         /**
98          *      This function provides handle of the required Certificate type.
99          *
100          * @since 2.1
101          * @return                      An error code.
102          * @param[in]           type                        _CaCertType Type info.
103          * @param[out]          count                                           Number of certificates in store.
104          * @param[out]          certificateStoreCtx                  Certificate store context, can be get using OpenCertificateStoreByType function.
105          * @exception           E_SUCCESS                                       The method is successful.
106          * @exception           E_OUT_OF_MEMORY             The memory is insufficient.
107          * @exception           E_INVALID_ARG                           The specified input parameter is invalid.
108          * @exception           E_SYSTEM                                        A system error has occurred.
109          *                                                                                              - IPC operation failed.
110          */
111         result OpenCertificateStoreByType(int type, int& count, int& certificateStoreCtx);
112
113         /**
114          *      This function counts Root CA.
115          *
116          * @since 2.1
117          * @return                      An error code.
118          * @param[in]           certificateStoreCtx                                     Certificate store context, can be get using OpenCertificateStoreByType function.
119          * @param[out]          count                                           Count of certificates in store.
120          * @exception           E_SUCCESS                                       The method is successful.
121          * @exception           E_INVALID_ARG                           The specified input parameter is invalid.
122          * @exception           E_OUT_OF_MEMORY                         The memory is insufficient.
123          * @exception           E_SYSTEM                                        A system error has occurred.
124          *                                                                                              - IPC operation failed.
125          */
126         result GetCertificateCount(int certificateStoreCtx, int& count);
127
128         /**
129          *      This function returns the next root CA pBuffer.
130          *
131          * @since 2.1
132          * @return                      An error code.
133          * @param[in]           certificateStoreCtx                                     Certificate store context, can be get using OpenCertificateStoreByType function.
134          * @param[out]          pBuffer                                         Output buffer.
135          * @param[out]          bufferLen                                       Buffer length.
136          * @exception           E_SUCCESS                                       The method is successful.
137          * @exception           E_INVALID_ARG                           The specified input parameter is invalid.
138          * @exception           E_OUT_OF_MEMORY                         The memory is insufficient.
139          * @exception           E_SYSTEM                                        A system error has occurred.
140          *                                                                                              - IPC operation failed.
141          */
142         result GetNextCertificate(int certificateStoreCtx, byte* pBuffer, int& bufferLen);
143
144         /**
145          *      This function updates Root CA certificate.
146          *
147          * @since 2.1
148          * @return                      An error code.
149          * @param[in]           type                                            CA Cert Type.
150          * @param[in]           pOldCert                                        Old Certificate Buffer.
151          * @param[in]           oldCertLen                                      Old Certificate length.
152          * @param[in]           pNewCert                                        New Certificate Buffer.
153          * @param[in]           newCertLen                                      New Certificate length.
154          * @exception           E_SUCCESS                                       The method is successful.
155          * @exception           E_OUT_OF_MEMORY                         The memory is insufficient.
156          * @exception           E_INVALID_ARG                           The specified input parameter is invalid.
157          * @exception           E_SYSTEM                                        A system error has occurred.
158          *                                                                                              - IPC operation failed.
159          */
160         result UpdateCaCertificate(int type, byte* pOldCert, int oldCertLen, byte* pNewCert, int newCertLen);
161
162         /**
163          *      This function deletes the root certificate
164          *
165          * @since 2.1
166          * @return                      An error code.
167          * @param[in]           type                                            CA Cert Type.
168          * @param[in]           pBuffer                                         Input Buffer.
169          * @param[in]           bufLen                                          Buffer length.
170          * @exception           E_SUCCESS                                       The method is successful.
171          * @exception           E_OUT_OF_MEMORY                         The memory is insufficient.
172          * @exception           E_INVALID_ARG                           The specified input parameter is invalid.
173          * @exception           E_SYSTEM                                        A system error has occurred.
174          *                                                                                              - IPC operation failed.
175          *                                                                                              - File operation failed.
176          *                                                                                              - DB operation failed.
177          */
178         result RemoveCaCertificate(int type, byte* pBuffer, int bufLen);
179
180         /**
181          *       This function uninstalls User Root Certificate given by a certificate ID.
182          *
183          * @since 2.1
184          * @return                      An error code.
185          * @param[in]           certId                                          Certificate Id.
186          * @exception           E_SUCCESS                                       The method is successful.
187          * @exception           E_INVALID_ARG                           The specified input parameter is invalid.
188          * @exception           E_OUT_OF_MEMORY                         The memory is insufficient.
189          * @exception           E_SYSTEM                                        A system error has occurred.
190          *                                                                                              - IPC operation failed.
191          *                                                                                              - File operation failed.
192          *                                                                                              - DB operation failed.
193          */
194         result RemoveUserCaCertificateByCertId(int certId);
195
196         /**
197          * This function installs the root certificate from pBuffer into Db table identified by type and format of the certificate.
198          *
199          * @since 2.1
200          * @return                      An error code.
201          * @param[in]           type                                            Type of the certificate to install in Db table.
202          * @param[in]           format                                          Format of input certificate pBuffer (X.509)
203          * @param[in]           pCert                                           Input certificate pBuffer.
204          * @param[in]           certLen                                         Input certificate pBuffer length.
205          * @exception           E_SUCCESS                                       The method is successful.
206          * @exception           E_OUT_OF_MEMORY                         The memory is insufficient.
207          * @exception           E_INVALID_ARG                           The specified input parameter is invalid.
208          * @exception           E_SYSTEM                                        A system error has occurred.
209          *                                                                                              - IPC operation failed.
210          *                                                                                              - File operation failed.
211          *                                                                                              - DB operation failed.
212          */
213         result InsertCaCertificate(int type, int format, byte* pCert, long certLen);
214
215         /**
216          * This function installs the user root certificate from buffer into Db table identified by format of the certificate.
217          *
218          * @since 2.1
219          * @return                      An error code.
220          * @param[in]           format                                          Format of input certificate buffer (X.509).
221          * @param[in]           pCert                                           Input certificate buffer.
222          * @param[in]           certLen                                         Length of input certificate buffer.
223          * @exception           E_SUCCESS                                       The method is successful.
224          * @exception           E_INVALID_ARG                           The specified input parameter is invalid.
225          * @exception           E_OUT_OF_MEMORY                         The memory is insufficient.
226          * @exception           E_SYSTEM                                        A system error has occurred.
227          *                                                                                              - IPC operation failed.
228          *                                                                                              - File operation failed.
229          *                                                                                              - DB operation failed.
230          */
231         result InsertUserCaCertificate(int format, char* pCert, int certLen);
232
233         /**
234          *       This function installs User Root Certificate given by a certificate file path.
235          *
236          * @since 2.1
237          * @return                      An error code.
238          * @param[in]           pFilePath                                       Certificate file path where the certificate file is located.
239          * @exception           E_SUCCESS                                       The method is successful.
240          * @exception           E_INVALID_ARG                           The specified input parameter is invalid.
241          * @exception           E_OUT_OF_MEMORY                         The memory is insufficient.
242          * @exception           E_SYSTEM                                        A system error has occurred.
243          *                                                                                              - IPC operation failed.
244          *                                                                                              - File operation failed.
245          *                                                                                              - DB operation failed.
246          */
247         result InsertUserCaCertificate(byte* pFilePath);
248
249         /**
250          * This function inserts user certificate chain into DB and store certificate and private key(encrypted) in file system.
251          * The certificate chain should contain chain of certificate, be in order "DeviceCertificate||CA(n)Certificate||.....". Excluding/including Root CA.
252          * If CA is not present in chain then it should be previously installed. Format of Certificate chain/key should be DER encoded.
253          * Only one private key must be supplied in private key parameter.
254          *
255          * @since 2.1
256          * @return                      An error code.
257          * @param[in]           pCertchainBuffer                        User certificate chain buffer.
258          * @param[in]           certChainLen                            Certificate chain buffer lenth.
259          * @param[in]           pUserPrivateKey                         User private Key buffer.
260          * @param[in]           userPrivateKeyLen                       User private key length.
261          * @exception           E_SUCCESS                                       The method is successful.
262          * @exception           E_INVALID_ARG                           The specified input parameter is invalid.
263          * @exception           E_OUT_OF_MEMORY                         The memory is insufficient.
264          * @exception           E_SYSTEM                                        A system error has occurred.
265          *                                                                                              - IPC operation failed.
266          *                                                                                              - File operation failed.
267          *                                                                                              - DB operation failed.
268          */
269         result InsertUserCertChainPrivateKey(char* pCertchainBuffer, int certChainLen, char* pUserPrivateKey, int userPrivateKeyLen);
270
271         /**
272          * This function inserts user certificate chain including private key into DB and store certificate and private key(encrypted) in file system.
273          * The certificate chain should contain chain of certificate, be in order "user key || DeviceCertificate||CA(n)Certificate||.....". Excluding/including Root CA.
274          * If CA is not present in chain then it should be previously installed. Format of Certificate chain/key buffer should be DER encoded.
275          * Only one private key must be supplied in private key parameter.
276          *
277          * @since 2.1
278          * @return                      An error code.
279          * @param[in]           pCertchainPrivateKeyBuffer              User private key and certificate chain buffer.
280          * @param[in]           certChainPrivateKeyLength               Private key  and certificate chain buffer length.
281          * @exception           E_SUCCESS                                               The method is successful.
282          * @exception           E_INVALID_ARG                                   The specified input parameter is invalid.
283          * @exception           E_OUT_OF_MEMORY                                 The memory is insufficient.
284          * @exception           E_SYSTEM                                                A system error has occurred.
285          *                                                                                                      - IPC operation failed.
286          *                                                                                                      - File operation failed.
287          *                                                                                                      - DB operation failed.
288          */
289         result InsertCertificateChainWithPrivateKey(char* pCertchainPrivateKeyBuffer, int certChainPrivateKeyLength);
290
291         /**
292          *      This function installs PKCS#12 contents into certificate DB and store certificate and private key(encrypted) in file system.
293          *      Identified by filename and password provided by user.
294          *
295          * @since 2.1
296          * @return                      An error code.
297          * @param[in]           pPkcs12FilePath                                 Filename of PKCS#12 content.
298          * @param[in]           pPkcs12ImportPassword                   Password of the PKCS#12 content.
299          * @exception           E_SUCCESS                                               The method is successful.
300          * @exception           E_INVALID_ARG                                   The specified input parameter is invalid.
301          * @exception           E_OUT_OF_MEMORY                                 The memory is insufficient.
302          * @exception           E_SYSTEM                                                A system error has occurred.
303          *                                                                                                      - IPC operation failed.
304          *                                                                                                      - File operation failed.
305          *                                                                                                      - DB operation failed.
306          *                                                                                                      - OpenSSL operation failed.
307          */
308         result InsertPkcs12Content(char* pPkcs12FilePath, char* pPkcs12ImportPassword);
309
310         /**
311          *      This function deletes user certificate chain on the basis of Certificate ID.
312          *
313          * @since 2.1
314          * @return                      An error code.
315          * @param[in]           certId                                                  ID of certificate as in DB.
316          * @exception           E_SUCCESS                                               The method is successful.
317          * @exception           E_INVALID_ARG                                   The specified input parameter is invalid.
318          * @exception           E_OUT_OF_MEMORY                                 The memory is insufficient.
319          * @exception           E_SYSTEM                                                A system error has occurred.
320          *                                                                                                      - IPC operation failed.
321          *                                                                                                      - File operation failed.
322          *                                                                                                      - DB operation failed.
323          */
324         result RemoveUserCertChainByCertId(int certId);
325
326         /**
327          * This function retrieves the user certificate chain on the basis of Subject name of any Intermediate CA and
328          * subject name of user Certificate. Subject name of Device certificate is optional parameter.
329          * Subject name of any intermediate Certificate is compulsory parameter.
330          * This function will retrieve the certificate chain on the basis of Subject name of any intermediate CA taken as
331          * issuer name in function parameters. It can also extract Certificate chain on the basis of Subject name of device
332          * certificate including chain containing the Intermediate Certificate Subject name.
333          * If there are multiple cert chain from the same issuer, it will get all the cert chain and check with subject name
334          * to decide which chain is need to be returned. For input parameter it takes subject name of any intermediate CA as
335          * issuer name, and subject name of user certificate as optional parameter. Format of Subject and Issuer name will
336          * be DER encoded.
337          *
338          * @since 2.1
339          * @return                      An error code.
340          * @param[in]           pIssuerName                                                     Pointer to Issuer name.
341          * @param[in]           issuerNameLength                                        Length of Issuer name.
342          * @param[in]           pSubjectName                                            pointer to Subject name.
343          * @param[in]           subjectNameLength                                       Length of Subject name.
344          * @param[out]          pUserCertListInfoTypesRef                       Pointer to certificate list.
345          * @exception           E_SUCCESS                                                       The method is successful.
346          * @exception           E_INVALID_ARG                                           The specified input parameter is invalid.
347          * @exception           E_OUT_OF_MEMORY                                         The memory is insufficient.
348          * @exception           E_SYSTEM                                                        A system error has occurred.
349          *                                                                                                              - IPC operation failed.
350          *                                                                                                              - File operation failed.
351          *                                                                                                              - DB operation failed.
352          */
353         result GetUserCertChainByIssuerAndSubjectNameN(char* pIssuerName, int issuerNameLength, char* pSubjectName, int subjectNameLength, _CertificateListInfo*& pUserCertListInfoTypesRef);
354
355         /**
356          *        This function gets the user certificate list information by requested certificate ID. It give info of certificate only.
357           *
358          * @since 2.1
359          * @return                      User certificate information containing certificate buffer, private key buffer etc.
360          * @param[in]           certId                                                          Certificate ID as in DB.
361          * @param[in]           encodingType                                            Required encoding type of output buffer (PEM, Base64 or DER).
362          * @exception           E_SUCCESS                                                       The method is successful.
363          * @exception           E_INVALID_ARG                                           The specified input parameter is invalid.
364          * @exception           E_OUT_OF_MEMORY                                         The memory is insufficient.
365          * @exception           E_SYSTEM                                                        A system error has occurred.
366          *                                                                                                              - IPC operation error.
367          *                                                                                                              - File operation error.
368          *                                                                                                              - DB operation error.
369          */
370         _CertInfo* GetUserCertificateByCertIdN(int certId, int encodingType);
371
372         /**
373          *        This function retrieves user certificate information by requested certificate ID.
374          *
375          * @since 2.1
376          * @return                      An error code.
377          * @param[in]           certId                                                  Certificate id of requested user certificates as in DB.
378          * @param[out]          pCertFieldInfos                                 Pointer to ponter of Certificate infos structure.
379          * @exception           E_SUCCESS                                               The method is successful.
380          * @exception           E_OUT_OF_MEMORY                                 The memory is insufficient.
381          * @exception           E_INVALID_ARG                                   The specified input parameter is invalid.
382          * @exception           E_SYSTEM                                                A system error has occurred.
383          *                                                                                                      - IPC operation failed.
384          *                                                                                                      - File operation failed.
385          *                                                                                                      - DB operation failed.
386          */
387         result GetUserCertFieldInfoByCertId(int certId, _CertFieldInfos* pCertFieldInfos);
388
389 private:
390         // This default constructor is intentionally declared as private to
391         // implement the Singleton semantic.
392         _CertServiceProxy(void);
393
394         // This destructor is intentionally declared as private to
395         // implement the Singleton semantic.
396         ~_CertServiceProxy(void);
397
398         _CertServiceProxy(const _CertServiceProxy& rhs);
399
400         _CertServiceProxy& operator =(const _CertServiceProxy& rhs);
401
402         //This construct function initialises the _CertServiceProxt instance
403         static void Construct(void);
404
405 private:
406         static Tizen::Io::_IpcClient* __pIpcClient; //singleton
407         static _CertServiceProxy* __pCertServiceProxy; //singleton
408 }; // _CertServiceProxy
409
410
411 } } } //Tizen::Security::Cert
412
413 #endif // _FSEC_CERT_INTERNAL_CERT_SERVICE_PROXY_H_