Encryption/decryption API
[platform/core/security/key-manager.git] / src / include / ckmc / ckmc-manager.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        ckmc-manager.h
18  * @version     1.0
19  * @brief       Provides management functions(storing, retrieving, and removing) for keys,
20  *              certificates and data of a user and additional crypto functions.
21  */
22
23
24 #ifndef __TIZEN_CORE_CKMC_MANAGER_H
25 #define __TIZEN_CORE_CKMC_MANAGER_H
26
27 #include <stddef.h>
28 #include <sys/types.h>
29 #include <tizen.h>
30 #include <ckmc/ckmc-type.h>
31 #include <ckmc/ckmc-error.h>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /**
38  * @addtogroup CAPI_KEY_MANAGER_CLIENT_MODULE
39  * @{
40  */
41
42
43 /**
44  * @brief Stores a key inside key manager based on the provided policy.
45  *
46  * @since_tizen 2.3
47  * @privlevel public
48  * @privilege %http://tizen.org/privilege/keymanager
49  *
50  * @remarks Currently API supports seven types of keys. These are RSA public/private key,
51  *          DSA public/private key, ECDSA public/private key and AES symmetric key.
52  * @remarks key_type in key may be set to #CKMC_KEY_NONE as an input. key_type is determined inside
53  *          key manager during storing keys.
54  * @remarks Some private key files are protected by a password. If raw_key in key read from those
55  *          encrypted files is encrypted with a password, the password should be provided in the
56  *          #ckmc_key_s structure.
57  * @remarks If password in policy is provided, the key is additionally encrypted with the password
58  *          in policy.
59  *
60  * @param[in] alias   The name of a key to be stored
61  * @param[in] key     The key's binary value to be stored
62  * @param[in] policy  The policy about how to store a key securely
63  *
64  * @return @c 0 on success,
65  *         otherwise a negative error value
66  *
67  * @retval #CKMC_ERROR_NONE              Successful
68  * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
69  * @retval #CKMC_ERROR_DB_LOCKED         A user key is not loaded in memory (a user is not logged
70  *                                       in)
71  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS   Alias already exists
72  * @retval #CKMC_ERROR_INVALID_FORMAT    The format of raw_key is not valid
73  * @retval #CKMC_ERROR_DB_ERROR          Failed due to a database error
74  * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
75  *
76  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
77  *
78  * @see ckmc_remove_alias()
79  * @see ckmc_get_key()
80  * @see ckmc_get_key_alias_list()
81  * @see #ckmc_key_s
82  * @see #ckmc_policy_s
83  */
84 int ckmc_save_key(const char *alias, const ckmc_key_s key, const ckmc_policy_s policy);
85
86 /**
87  * @deprecated Deprecated since 2.4. [Use ckmc_remove_alias() instead]
88  * @brief Removes a key from key manager.
89  *
90  * @since_tizen 2.3
91  * @privlevel public
92  * @privilege %http://tizen.org/privilege/keymanager
93  *
94  * @remarks To remove key, client must have remove permission to the specified key.
95  * @remarks The key owner can remove by default.
96  *
97  * @param[in] alias The name of a key to be removed
98  *
99  * @return @c 0 on success,
100  *         otherwise a negative error value
101  *
102  * @retval #CKMC_ERROR_NONE              Successful
103  * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
104  * @retval #CKMC_ERROR_DB_LOCKED         A user key is not loaded in memory (a user is not logged
105  *                                       in)
106  * @retval #CKMC_ERROR_DB_ERROR          Failed due to a database error
107  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN  Alias does not exist
108  * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
109  *
110  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
111  *
112  * @see ckmc_save_key()
113  * @see ckmc_get_key()
114  * @see ckmc_get_key_alias_list()
115  */
116 int ckmc_remove_key(const char *alias);
117
118 /**
119  * @brief Gets a key from key manager.
120  *
121  * @since_tizen 2.3
122  * @privlevel public
123  * @privilege %http://tizen.org/privilege/keymanager
124  *
125  * @remarks A client can access only data stored by the client.
126  * @remarks You must destroy the newly created @a ppkey by calling ckmc_key_free() if it is no
127  *          longer needed.
128  *
129  * @param[in] alias     The name of a key to retrieve
130  * @param[in] password  The password used in decrypting a key value \n
131  *                      If password of policy is provided in ckmc_save_key(), the same password
132  *                      should be provided.
133  * @param[out] ppkey    The pointer to a newly created ckmc_key_s handle
134  *
135  * @return @c 0 on success,
136  *         otherwise a negative error value
137  *
138  * @retval #CKMC_ERROR_NONE              Successful
139  * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
140  * @retval #CKMC_ERROR_DB_LOCKED         A user key is not loaded in memory (a user is not logged
141  *                                       in)
142  * @retval #CKMC_ERROR_DB_ERROR          Failed due to a database error
143  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN  Alias does not exist
144  * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
145  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
146  *                                       Decryption failed because password is incorrect.
147  *
148  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
149  *
150  * @see ckmc_save_key()
151  * @see ckmc_remove_alias()
152  * @see ckmc_get_key_alias_list()
153  */
154 int ckmc_get_key(const char *alias, const char *password, ckmc_key_s **ppkey);
155
156 /**
157  * @brief Gets all the alias of keys that the client can access.
158  *
159  * @since_tizen 2.3
160  * @privlevel public
161  * @privilege %http://tizen.org/privilege/keymanager
162  *
163  * @remarks A client can access only data stored by the client.
164  * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free()
165  *          if it is no longer needed.
166  *
167  * @param[out] ppalias_list  The pointer to a newly created ckmc_alias_list_s handle containing all
168  *                           available alias of keys \n
169  *                           If there is no available key alias, *ppalias_list will be null.
170  *
171  * @return @c 0 on success,
172  *         otherwise a negative error value
173  *
174  * @retval #CKMC_ERROR_NONE              Successful
175  * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
176  * @retval #CKMC_ERROR_DB_LOCKED         A user key is not loaded in memory (a user is not logged
177  *                                       in)
178  * @retval #CKMC_ERROR_DB_ERROR          Failed due to a database error
179  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN  Alias does not exist
180  * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
181  *
182  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
183  *
184  * @see ckmc_save_key()
185  * @see ckmc_remove_alias()
186  * @see ckmc_get_key()
187  */
188 int ckmc_get_key_alias_list(ckmc_alias_list_s** ppalias_list);
189
190
191
192
193 /**
194  * @brief Stores a certificate inside key manager based on the provided policy.
195  *
196  * @since_tizen 2.3
197  * @privlevel public
198  * @privilege %http://tizen.org/privilege/keymanager
199  *
200  * @remarks the certificate's binary value will be converted and saved as binary DER encoded
201  *          certificates.
202  *
203  * @param[in] alias  The name of a certificate to be stored
204  * @param[in] cert   The certificate's binary value to be stored
205  * @param[in] policy The policy about how to store a certificate securely
206  *
207  * @return @c 0 on success,
208  *         otherwise a negative error value
209  *
210  * @retval #CKMC_ERROR_NONE               Successful
211  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
212  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
213  *                                        in)
214  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
215  * @retval #CKMC_ERROR_INVALID_FORMAT     The format of raw_cert is not valid
216  * @retval #CKMC_ERROR_DB_ERROR           Failed due to a database error
217  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
218  *
219  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
220  *
221  * @see ckmc_remove_alias()
222  * @see ckmc_get_cert()
223  * @see ckmc_get_cert_alias_list()
224  * @see #ckmc_cert_s
225  * @see #ckmc_policy_s
226  */
227 int ckmc_save_cert(const char *alias, const ckmc_cert_s cert, const ckmc_policy_s policy);
228
229 /**
230  * @deprecated Deprecated since 2.4. [Use ckmc_remove_alias() instead]
231  * @brief Removes a certificate from key manager.
232  *
233  * @since_tizen 2.3
234  * @privlevel public
235  * @privilege %http://tizen.org/privilege/keymanager
236  *
237  * @remarks To remove certificate, client must have remove permission to the specified certificate.
238  * @remarks The key owner can remove by default.
239  *
240  * @param[in] alias The name of a certificate to be removed
241  *
242  * @return @c 0 on success,
243  *         otherwise a negative error value
244  *
245  * @retval #CKMC_ERROR_NONE               Successful
246  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
247  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
248  *                                        in)
249  * @retval #CKMC_ERROR_DB_ERROR           Failed due to a database error
250  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
251  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
252  *
253  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
254  *
255  * @see ckmc_save_cert()
256  * @see ckmc_get_cert()
257  * @see ckmc_get_cert_alias_list()
258  */
259 int ckmc_remove_cert(const char *alias);
260
261 /**
262  * @brief Gets a certificate from key manager.
263  *
264  * @since_tizen 2.3
265  * @privlevel public
266  * @privilege %http://tizen.org/privilege/keymanager
267  *
268  * @remarks A client can access only certificate stored by the client.
269  * @remarks A DER encoded certificate will be returned as a return value.
270  * @remarks You must destroy the newly created @a ppcert by calling ckmc_cert_free() if it is no
271  *          longer needed.
272  *
273  * @param[in] alias    The name of a certificate to retrieve
274  * @param[in] password The password used in decrypting a certificate value \n
275  *                     If password of policy is provided in ckmc_save_cert(), the same password
276  *                     should be provided.
277  * @param[out] ppcert  The pointer to a newly created ckmc_cert_s handle
278  *
279  * @return @c 0 on success,
280  *         otherwise a negative error value
281  *
282  * @retval #CKMC_ERROR_NONE               Successful
283  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
284  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
285  *                                        in)
286  * @retval #CKMC_ERROR_DB_ERROR           Failed due to a database error
287  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exists
288  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
289  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
290  *                                        Decryption failed because password is incorrect.
291  *
292  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
293  *
294  * @see ckmc_save_cert()
295  * @see ckmc_remove_alias()
296  * @see ckmc_get_cert_alias_list()
297  */
298 int ckmc_get_cert(const char *alias, const char *password, ckmc_cert_s **ppcert);
299
300 /**
301  * @brief Gets all alias of certificates which the client can access.
302  *
303  * @since_tizen 2.3
304  * @privlevel public
305  * @privilege %http://tizen.org/privilege/keymanager
306  *
307  * @remarks A client can access only data stored by the client.
308  * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free()
309  *          if it is no longer needed.
310  *
311  * @param[out] ppalias_list The pointer to a newly created ckmc_alias_list_s handle containing all
312  *                          available alias of keys \n
313  *                          If there is no available key alias, *ppalias_list will be null.
314  *
315  * @return @c 0 on success,
316  *         otherwise a negative error value
317  *
318  * @retval #CKMC_ERROR_NONE               Successful
319  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
320  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
321  *                                        in)
322  * @retval #CKMC_ERROR_DB_ERROR           Failed due to a database error
323  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
324  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
325  *
326  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
327  *
328  * @see ckmc_save_cert()
329  * @see ckmc_remove_alias()
330  * @see ckmc_get_cert()
331  */
332 int ckmc_get_cert_alias_list(ckmc_alias_list_s** ppalias_list);
333
334
335
336
337 /**
338  * @brief Stores PKCS12's contents inside key manager based on the provided policies.
339  * All items from the PKCS12 will use the same alias.
340  *
341  * @since_tizen 2.4
342  * @privlevel public
343  * @privilege %http://tizen.org/privilege/keymanager
344  *
345  * @param[in] alias         The name of a data to be stored
346  * @param[in] pkcs          Pointer to the pkcs12 structure to be saved
347  * @param[in] key_policy    The policy about how to store pkcs's private key
348  * @param[in] cert_policy   The policy about how to store pkcs's certificate
349  *
350  * @return @c 0 on success,
351  *         otherwise a negative error value
352  *
353  * @retval #CKMC_ERROR_NONE               Successful
354  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
355  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
356  *                                        in)
357  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
358  * @retval #CKMC_ERROR_DB_ERROR           Failed due to a database error
359  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
360  *
361  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
362  *
363  * @see ckmc_remove_alias()
364  * @see ckmc_get_pkcs12()
365  * @see ckmc_get_data_alias_list()
366  * @see ckmc_pkcs12_load()
367  * @see #ckmc_pkcs12_s
368  * @see #ckmc_policy_s
369  */
370 int ckmc_save_pkcs12(const char *alias,
371                      const ckmc_pkcs12_s *pkcs,
372                      const ckmc_policy_s key_policy,
373                      const ckmc_policy_s cert_policy);
374
375 /**
376  * @deprecated Deprecated since 2.4. [Use ckmc_remove_alias() instead]
377  * @brief Removes all PKCS12 contents from key manager.
378  *
379  * @since_tizen 2.4
380  * @privlevel public
381  * @privilege %http://tizen.org/privilege/keymanager
382  *
383  * @remarks To remove PKCS12, client must have remove permission to the specified PKCS12 object.
384  * @remarks The key owner can remove by default.
385  *
386  * @param[in] alias The name of PKCS12 to be removed
387  *
388  * @return @c 0 on success,
389  *         otherwise a negative error value
390  *
391  * @retval #CKMC_ERROR_NONE               Successful
392  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
393  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
394  *                                        in)
395  * @retval #CKMC_ERROR_DB_ERROR           Failed due to a database error
396  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
397  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
398  *
399  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
400  *
401  * @see ckmc_remove_alias()
402  * @see ckmc_save_pkcs12()
403  * @see ckmc_get_pkcs12()
404  */
405 int ckmc_remove_pkcs12(const char *alias);
406
407 /**
408  * @brief Gets a pkcs12 from key manager.
409  *
410  * @since_tizen 2.4
411  * @privlevel public
412  * @privilege %http://tizen.org/privilege/keymanager
413  *
414  * @remarks A client can access only data stored by the client.
415  * @remarks You must destroy the newly created @a pkcs12 by calling ckmc_pkcs12_free() if it is no
416  *          longer needed.
417  *
418  * @param[in]  alias        The name of a data to retrieve
419  * @param[in]  key_password  Password that was used to encrypt privateKey (may be NULL)
420  * @param[in]  cert_password Password used to encrypt certificates (may be NULL)
421  * @param[out] pkcs12       The pointer to a newly created ckmc_pkcs12_s handle
422  *
423  * @return @c 0 on success,
424  *         otherwise a negative error value
425  *
426  * @retval #CKMC_ERROR_NONE               Successful
427  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
428  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
429  *                                        in)
430  * @retval #CKMC_ERROR_DB_ERROR           Failed due to a database error
431  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
432  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
433  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
434  *                                        Decryption failed because password is incorrect.
435  *
436  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
437  *
438  * @see ckmc_save_pkcs12()
439  * @see ckmc_remove_alias()
440  */
441 int ckmc_get_pkcs12(const char *alias, const char *key_password, const char *cert_password, ckmc_pkcs12_s **pkcs12);
442
443 /**
444  * @brief Stores a data inside key manager based on the provided policy.
445  *
446  * @since_tizen 2.3
447  * @privlevel public
448  * @privilege %http://tizen.org/privilege/keymanager
449  *
450  * @param[in] alias  The name of a data to be stored
451  * @param[in] data   The binary value to be stored
452  * @param[in] policy The policy about how to store a data securely
453  *
454  * @return @c 0 on success,
455  *         otherwise a negative error value
456  *
457  * @retval #CKMC_ERROR_NONE               Successful
458  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
459  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
460  *                                        in)
461  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
462  * @retval #CKMC_ERROR_DB_ERROR           Failed due to a database error
463  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
464  *
465  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
466  *
467  * @see ckmc_remove_alias()
468  * @see ckmc_get_data()
469  * @see ckmc_get_data_alias_list()
470  * @see #ckmc_raw_buffer_s
471  * @see #ckmc_policy_s
472  */
473 int ckmc_save_data(const char *alias, ckmc_raw_buffer_s data, const ckmc_policy_s policy);
474
475 /**
476  * @deprecated Deprecated since 2.4. [Use ckmc_remove_alias() instead]
477  * @brief Removes a data from key manager.
478  *
479  * @since_tizen 2.3
480  * @privlevel public
481  * @privilege %http://tizen.org/privilege/keymanager
482  *
483  * @remarks To remove data, client must have remove permission to the specified data object.
484  * @remarks The data owner can remove by default.
485  *
486  * @param[in] alias The name of a data to be removed
487  *
488  * @return @c 0 on success,
489  *         otherwise a negative error value
490  *
491  * @retval #CKMC_ERROR_NONE               Successful
492  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
493  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
494  *                                        in)
495  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
496  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
497  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
498  *
499  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
500  *
501  * @see ckmc_save_data()
502  * @see ckmc_get_data()
503  * @see ckmc_get_data_alias_list()
504  */
505 int ckmc_remove_data(const char *alias);
506
507 /**
508  * @brief Gets a data from key manager.
509  *
510  * @since_tizen 2.3
511  * @privlevel public
512  * @privilege %http://tizen.org/privilege/keymanager
513  *
514  * @remarks A client can access only data stored by the client.
515  * @remarks You must destroy the newly created @a ppdata by calling ckmc_buffer_free() if it is no
516  *          longer needed.
517  *
518  * @param[in]  alias     The name of a data to retrieve
519  * @param[in]  password  The password used in decrypting a data value \n
520  *                       If password of policy is provided in ckmc_save_data(), the same password
521  *                       should be provided.
522  * @param[out] ppdata    The pointer to a newly created ckmc_raw_buffer_s handle
523  *
524  * @return @c 0 on success,
525  *         otherwise a negative error value
526  *
527  * @retval #CKMC_ERROR_NONE               Successful
528  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
529  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
530  *                                        in)
531  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
532  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
533  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
534  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
535  *                                        Decryption failed because password is incorrect.
536  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
537  *
538  * @see ckmc_save_data()
539  * @see ckmc_remove_alias()
540  * @see ckmc_get_data_alias_list()
541  */
542 int ckmc_get_data(const char *alias, const char *password, ckmc_raw_buffer_s **ppdata);
543
544 /**
545  * @brief Gets all alias of data which the client can access.
546  *
547  * @since_tizen 2.3
548  * @privlevel public
549  * @privilege %http://tizen.org/privilege/keymanager
550  *
551  * @remarks A client can access only data stored by the client.
552  * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free()
553  *          if it is no longer needed.
554  *
555  * @param[out] ppalias_list The pointer to a newly created ckmc_alias_list_s handle containing all
556  *                          available alias of keys \n
557  *                          If there is no available key alias, *ppalias_list will be null.
558  *
559  * @return @c 0 on success,
560  *         otherwise a negative error value
561  *
562  * @retval #CKMC_ERROR_NONE               Successful
563  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
564  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
565  *                                        in)
566  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
567  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
568  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
569  *
570  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
571  *
572  * @see ckmc_save_data()
573  * @see ckmc_remove_alias()
574  * @see ckmc_get_data()
575  */
576 int ckmc_get_data_alias_list(ckmc_alias_list_s** ppalias_list);
577
578
579
580
581 /**
582  * @brief Creates RSA private/public key pair and stores them inside key manager based on each
583  *        policy.
584  *
585  * @since_tizen 2.3
586  * @privlevel public
587  * @privilege %http://tizen.org/privilege/keymanager
588  *
589  * @remarks If password in policy is provided, the key is additionally encrypted with the password
590  *          in policy.
591  *
592  * @param[in] size                The size of key strength to be created \n
593  *                                @c 1024, @c 2048, and @c 4096 are supported.
594  * @param[in] private_key_alias   The name of private key to be stored
595  * @param[in] public_key_alias    The name of public key to be stored
596  * @param[in] policy_private_key  The policy about how to store a private key securely
597  * @param[in] policy_public_key   The policy about how to store a public key securely
598  *
599  * @return @c 0 on success,
600  *         otherwise a negative error value
601  *
602  * @retval #CKMC_ERROR_NONE               Successful
603  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
604  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
605  *                                        in)
606  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
607  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
608  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
609  *
610  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
611  *
612  * @see ckmc_create_key_pair_dsa()
613  * @see ckmc_create_key_pair_ecdsa()
614  * @see ckmc_create_signature()
615  * @see ckmc_verify_signature()
616  */
617 int ckmc_create_key_pair_rsa(const size_t size,
618                              const char *private_key_alias,
619                              const char *public_key_alias,
620                              const ckmc_policy_s policy_private_key,
621                              const ckmc_policy_s policy_public_key);
622
623 /**
624  * @brief Creates DSA private/public key pair and stores them inside key manager based on each
625  *        policy.
626  *
627  * @since_tizen 2.3
628  * @privlevel public
629  * @privilege %http://tizen.org/privilege/keymanager
630  *
631  * @remarks If password in policy is provided, the key is additionally encrypted with the password
632  *          in policy.
633  *
634  * @param[in] size                The size of key strength to be created \n
635  *                                @c 1024, @c 2048, @c 3072 and @c 4096 are supported.
636  * @param[in] private_key_alias   The name of private key to be stored
637  * @param[in] public_key_alias    The name of public key to be stored
638  * @param[in] policy_private_key  The policy about how to store a private key securely
639  * @param[in] policy_public_key   The policy about how to store a public key securely
640  *
641  * @return @c 0 on success,
642  *         otherwise a negative error value
643  *
644  * @retval #CKMC_ERROR_NONE               Successful
645  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
646  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
647  *                                        in)
648  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
649  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
650  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
651  *
652  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
653  *
654  * @see ckmc_create_key_pair_rsa()
655  * @see ckmc_create_key_pair_ecdsa()
656  * @see ckmc_create_signature()
657  * @see ckmc_verify_signature()
658  */
659 int ckmc_create_key_pair_dsa(const size_t size,
660                              const char *private_key_alias,
661                              const char *public_key_alias,
662                              const ckmc_policy_s policy_private_key,
663                              const ckmc_policy_s policy_public_key);
664
665 /**
666  * @brief Creates ECDSA private/public key pair and stores them inside key manager based on each
667  *        policy.
668  *
669  * @since_tizen 2.3
670  * @privlevel public
671  * @privilege %http://tizen.org/privilege/keymanager
672  *
673  * @remarks If password in policy is provided, the key is additionally encrypted with the password
674  *          in policy.
675  *
676  * @param[in] type                The type of elliptic curve of ECDSA
677  * @param[in] private_key_alias   The name of private key to be stored
678  * @param[in] public_key_alias    The name of public key to be stored
679  * @param[in] policy_private_key  The policy about how to store a private key securely
680  * @param[in] policy_public_key   The policy about how to store a public key securely
681  *
682  * @return @c 0 on success,
683  *         otherwise a negative error value
684  *
685  * @retval #CKMC_ERROR_NONE               Successful
686  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
687  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
688  *                                        in)
689  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
690  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
691  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
692  *
693  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
694  *
695  * @see ckmc_create_key_pair_rsa()
696  * @see ckmc_create_key_pair_dsa()
697  * @see ckmc_create_signature()
698  * @see ckmc_verify_signature()
699  * @see #ckmc_ec_type_e
700  */
701 int ckmc_create_key_pair_ecdsa(const ckmc_ec_type_e type,
702                                const char *private_key_alias,
703                                const char *public_key_alias,
704                                const ckmc_policy_s policy_private_key,
705                                const ckmc_policy_s policy_public_key);
706
707 /**
708  * @brief Creates a signature on a given message using a private key and returns the signature.
709  *
710  * @since_tizen 2.3
711  * @privlevel public
712  * @privilege %http://tizen.org/privilege/keymanager
713  *
714  * @remarks If password of policy is provided during storing a key, the same password should be
715  *          provided.
716  * @remarks You must destroy the newly created @a ppsignature by calling ckmc_buffer_free() if it is
717  *          no longer needed.
718  *
719  * @param[in]  private_key_alias  The name of private key
720  * @param[in]  password           The password used in decrypting a private key value
721  * @param[in]  message            The message that is signed with a private key
722  * @param[in]  hash               The hash algorithm used in creating signature
723  * @param[in]  padding            The RSA padding algorithm used in creating signature \n
724  *                                It is used only when the signature algorithm is RSA.
725  * @param[out] ppsignature        The pointer to a newly created signature \n
726  *                                If an error occurs, @a *ppsignature will be null.
727  *
728  * @return @c 0 on success,
729  *         otherwise a negative error value
730  *
731  * @retval #CKMC_ERROR_NONE               Successful
732  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
733  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
734  *                                        in)
735  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
736  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
737  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
738  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
739  *                                        Decryption failed because password is incorrect.
740  *
741  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
742  *
743  * @see ckmc_create_key_pair_rsa()
744  * @see ckmc_create_key_pair_ecdsa()
745  * @see ckmc_verify_signature()
746  * @see ckmc_buffer_free()
747  * @see #ckmc_hash_algo_e
748  * @see #ckmc_rsa_padding_algo_e
749  */
750 int ckmc_create_signature(const char *private_key_alias,
751                           const char *password,
752                           const ckmc_raw_buffer_s message,
753                           const ckmc_hash_algo_e hash,
754                           const ckmc_rsa_padding_algo_e padding,
755                           ckmc_raw_buffer_s **ppsignature);
756
757 /**
758  * @brief Verifies a given signature on a given message using a public key and returns the signature
759  *        status.
760  *
761  * @since_tizen 2.3
762  * @privlevel public
763  * @privilege %http://tizen.org/privilege/keymanager
764  *
765  * @remarks If password of policy is provided during storing a key, the same password should be
766  *          provided.
767  *
768  * @param[in] public_key_alias  The name of public key
769  * @param[in] password          The password used in decrypting a public key value
770  * @param[in] message           The input on which the signature is created
771  * @param[in] signature         The signature that is verified with public key
772  * @param[in] hash              The hash algorithm used in verifying signature
773  * @param[in] padding           The RSA padding algorithm used in verifying signature \n
774  *                              It is used only when the signature algorithm is RSA.
775  *
776  * @return @c 0 on success and the signature is valid,
777  *         otherwise a negative error value
778  *
779  * @retval #CKMC_ERROR_NONE                 Successful
780  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The signature is invalid
781  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
782  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
783  *                                          in)
784  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
785  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
786  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
787  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
788  *                                          Decryption failed because password is incorrect.
789  *
790  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
791  *
792  * @see ckmc_create_key_pair_rsa()
793  * @see ckmc_create_key_pair_ecdsa()
794  * @see ckmc_verify_signature()
795  * @see #ckmc_hash_algo_e
796  * @see #ckmc_rsa_padding_algo_e
797  */
798 int ckmc_verify_signature(const char *public_key_alias,
799                           const char *password,
800                           const ckmc_raw_buffer_s message,
801                           const ckmc_raw_buffer_s signature,
802                           const ckmc_hash_algo_e hash,
803                           const ckmc_rsa_padding_algo_e padding);
804
805 /**
806  * @brief Verifies a certificate chain and returns that chain.
807  *
808  * @since_tizen 2.3
809  * @privlevel public
810  * @privilege %http://tizen.org/privilege/keymanager
811  *
812  * @remarks The trusted root certificate of the chain should exist in the system's certificate
813  *          storage.
814  * @remarks You must destroy the newly created @a ppcert_chain_list by calling
815  *          ckmc_cert_list_all_free() if it is no longer needed.
816  *
817  * @param[in] cert               The certificate to be verified
818  * @param[in] untrustedcerts     The untrusted CA certificates to be used in verifying a certificate
819  *                               chain
820  * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n
821  *                               If an error occurs, @a *ppcert_chain_list will be null.
822  *
823  * @return @c 0 on success and the signature is valid,
824  *         otherwise a negative error value
825  *
826  * @retval #CKMC_ERROR_NONE                 Successful
827  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The certificate chain is not valid
828  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
829  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
830  *                                          in)
831  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
832  * @retval #CKMC_ERROR_INVALID_FORMAT       The format of certificate is not valid
833  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
834  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
835  *                                          Decryption failed because password is incorrect.
836  *
837  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
838  *
839  * @see ckmc_get_cert_chain_with_alias())
840  * @see ckmc_cert_list_all_free()
841  */
842 int ckmc_get_cert_chain(const ckmc_cert_s *cert,
843                         const ckmc_cert_list_s *untrustedcerts,
844                         ckmc_cert_list_s **ppcert_chain_list);
845
846 /**
847  * @brief Verifies a certificate chain using an alias list of untrusted certificates and return that
848  *        chain.
849  *
850  * @since_tizen 2.3
851  * @privlevel public
852  * @privilege %http://tizen.org/privilege/keymanager
853  *
854  * @remarks The trusted root certificate of the chain should exist in the system's certificate
855  *          storage.
856  * @remarks You must destroy the newly created @a ppcert_chain_list by calling
857  *          ckmc_cert_list_all_free() if it is no longer needed.
858  *
859  * @param[in] cert               The certificate to be verified
860  * @param[in] untrustedcerts     The alias list of untrusted CA certificates stored in key manager
861  *                               to be used in verifying a certificate chain
862  * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n
863  *                               If an error occurs, @a *ppcert_chain_list will be null.
864  *
865  * @return @c 0 on success and the signature is valid,
866  *         otherwise a negative error value
867  *
868  * @retval #CKMC_ERROR_NONE                 Successful
869  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The certificate chain is not valid
870  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
871  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
872  *                                          in)
873  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
874  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
875  * @retval #CKMC_ERROR_INVALID_FORMAT       The format of certificate is not valid
876  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
877  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
878  *                                          Some certificates were encrypted with password and could not
879  *                                          be used.
880  *
881  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
882  *
883  * @see ckmc_get_cert_chain()
884  * @see ckmc_cert_list_all_free()
885  */
886 int ckmc_get_cert_chain_with_alias(const ckmc_cert_s *cert,
887                                    const ckmc_alias_list_s *untrustedcerts,
888                                    ckmc_cert_list_s **ppcert_chain_list);
889
890 /**
891  * @brief Verifies a certificate chain and returns that chain using user entered trusted and
892  *        untrusted CA certificates
893  *
894  * @since_tizen 2.4
895  * @privlevel public
896  * @privilege %http://tizen.org/privilege/keymanager
897  *
898  * @remarks If the trusted root certificates are provided as a user input, these certificates do not
899  *          need to exist in the system's certificate storage.
900  * @remarks You must destroy the newly created @a ppcert_chain_list by calling
901  *          ckmc_cert_list_all_free() if it is no longer needed.
902  *  *
903  * @param[in] cert                    The certificate to be verified
904  * @param[in] untrustedcerts          The untrusted CA certificates to be used in verifying a
905  *                                    certificate chain
906  * @param[in] trustedcerts            The trusted CA certificates to be used in verifying a
907  *                                    certificate chain
908  * @param[in] use_trustedsystemcerts  The flag indicating the use of the trusted root certificates
909  *                                    in the system's certificate storage.
910  * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n
911  *                               If an error occurs, @a *ppcert_chain_list will be null.
912  *
913  * @return @c 0 on success and the signature is valid,
914  *         otherwise a negative error value
915  *
916  * @retval #CKMC_ERROR_NONE                 Successful
917  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The certificate chain is not valid
918  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
919  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
920  *                                          in)
921  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
922  * @retval #CKMC_ERROR_INVALID_FORMAT       The format of certificate is not valid
923  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
924  *
925  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
926  *
927  * @see ckmc_get_cert_chain_with_trustedcert_alias()
928  * @see ckmc_cert_list_all_free()
929  */
930 int ckmc_get_cert_chain_with_trustedcert(const ckmc_cert_s *cert,
931                                          const ckmc_cert_list_s *untrustedcerts,
932                                          const ckmc_cert_list_s *trustedcerts,
933                                          const bool use_trustedsystemcerts,
934                                          ckmc_cert_list_s **ppcert_chain_list);
935
936 /**
937  * @brief Verifies a certificate chain and returns that chain using alias lists of untrusted and
938  *        trusted certificates
939  *
940  * @since_tizen 2.4
941  * @privlevel public
942  * @privilege %http://tizen.org/privilege/keymanager
943  *
944  * @remarks If the alias list of trusted root certificates is provided as a user input, these
945  *          certificates do not need to exist in the system's certificate storage.
946  * @remarks You must destroy the newly created @a ppcert_chain_list by calling
947  *          ckmc_cert_list_all_free() if it is no longer needed.
948  *
949  * @param[in] cert                    The certificate to be verified
950  * @param[in] untrustedcerts          The alias list of untrusted CA certificates stored in key
951  *                                    manager to be used in verifying a certificate chain
952  * @param[in] trustedcerts            The alias list of trusted CA certificates stored in key
953  *                                    manager to be used in verifying a certificate chain
954  * @param[in] use_trustedsystemcerts  The flag indicating the use of the trusted root certificates
955  *                                    in the system's certificate storage.
956  * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n
957  *                               If an error occurs, @a *ppcert_chain_list will be null.
958  *
959  * @return @c 0 on success and the signature is valid,
960  *         otherwise a negative error value
961  *
962  * @retval #CKMC_ERROR_NONE                 Successful
963  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The certificate chain is not valid
964  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
965  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
966  *                                          in)
967  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
968  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
969  * @retval #CKMC_ERROR_INVALID_FORMAT       The format of certificate is not valid
970  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
971  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
972  *                                          Some certificates were encrypted with password and could not
973  *                                          be used.
974  *
975  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
976  *
977  * @see ckmc_get_cert_chain_with_trustedcert() 
978  * @see ckmc_cert_list_all_free()
979  */
980 int ckmc_get_cert_chain_with_trustedcert_alias(const ckmc_cert_s *cert,
981                                                const ckmc_alias_list_s *untrustedcerts,
982                                                const ckmc_alias_list_s *trustedcerts,
983                                                const bool use_trustedsystemcerts,
984                                                ckmc_cert_list_s **ppcert_chain_list);
985
986 /**
987  * @brief Perform OCSP which checks certificate is whether revoked or not
988  *
989  * @since_tizen 2.4
990  * @privlevel public
991  * @privilege %http://tizen.org/privilege/keymanager
992  *
993  * @param[in] pcert_chain_list   Valid certificate chain to perform OCSP check
994  * @param[out] ocsp_status       The pointer to status result of OCSP check
995  *
996  * @return @c 0 on success, otherwise a negative error value
997  *
998  * @retval #CKMC_ERROR_NONE                 Successful
999  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
1000  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
1001  *
1002  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
1003  * @pre @a pcert_chain_list is created with ckmc_get_certificate_chain() or
1004  *      ckmc_get_certificate_chain_with_alias()
1005  *
1006  * @see ckmc_get_cert_chain())
1007  * @see ckmc_cert_list_all_free()
1008  */
1009 int ckmc_ocsp_check(const ckmc_cert_list_s *pcert_chain_list, ckmc_ocsp_status_e *ocsp_status);
1010
1011 /**
1012  * @deprecated Deprecated since 2.4. [Use ckmc_set_permission() instead]
1013  * @brief Allows another application to access client's application data
1014  *
1015  * @since_tizen 2.3
1016  * @privlevel public
1017  * @privilege %http://tizen.org/privilege/keymanager
1018  *
1019  * @remarks Data identified by @a alias should exist
1020  *
1021  * @param[in] alias       Data alias for which access will be granted
1022  * @param[in] accessor    Package id of the application that will gain access rights
1023  * @param[in] granted     Rights granted for @a accessor application
1024  *
1025  * @return @c 0 on success, otherwise a negative error value
1026  *
1027  * @retval #CKMC_ERROR_NONE                 Successful
1028  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
1029  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
1030  *                                          in)
1031  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
1032  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
1033  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
1034  *
1035  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
1036  *
1037  * @see ckmc_deny_access()
1038  */
1039 int ckmc_allow_access(const char *alias, const char *accessor, ckmc_access_right_e granted);
1040
1041 /**
1042  * @brief Allows another application to access client's application data
1043  *
1044  * @since_tizen 2.4
1045  * @privlevel public
1046  * @privilege %http://tizen.org/privilege/keymanager
1047  *
1048  * @remarks Data identified by @a alias should exist
1049  *
1050  * @param[in] alias       Data alias for which access will be granted
1051  * @param[in] accessor    Package id of the application that will gain access rights
1052  * @param[in] permissions Mask of permissions granted for @a accessor application
1053  *                        (@a ckmc_permission_e)
1054  *                        (previous permission mask will be replaced with the new mask value)
1055  *
1056  * @return @c 0 on success, otherwise a negative error value
1057  *
1058  * @retval #CKMC_ERROR_NONE                 Successful
1059  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
1060  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
1061  *                                          in)
1062  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
1063  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
1064  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
1065  *
1066  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
1067  */
1068 int ckmc_set_permission(const char *alias, const char *accessor, int permissions);
1069
1070 /**
1071  * @deprecated Deprecated since 2.4. [Use ckmc_set_permission() instead]
1072  * @brief Revokes another application's access to client's application data
1073  *
1074  * @since_tizen 2.3
1075  * @privlevel public
1076  * @privilege %http://tizen.org/privilege/keymanager
1077  *
1078  * @remarks Data identified by @a alias should exist
1079  * @remarks Only access previously granted with ckmc_allow_access can be revoked.
1080  *
1081  * @param[in] alias       Data alias for which access will be revoked
1082  * @param[in] accessor    Package id of the application that will lose access rights
1083  *
1084  * @return @c 0 on success, otherwise a negative error value
1085  *
1086  * @retval #CKMC_ERROR_NONE                 Successful
1087  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid or the @a accessor doesn't
1088  *                                          have access to @a alias
1089  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
1090  *                                          in)
1091  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
1092  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
1093  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
1094  *
1095  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
1096  *
1097  * @see ckmc_allow_access()
1098  * @see ckmc_set_permission()
1099  */
1100 int ckmc_deny_access(const char *alias, const char *accessor);
1101
1102 /**
1103  * @brief Removes a an entry (no matter of type) from the key manager.
1104  *
1105  * @since_tizen 2.4
1106  * @privlevel public
1107  * @privilege %http://tizen.org/privilege/keymanager
1108  *
1109  * @remarks To remove item, client must have remove permission to the specified item.
1110  * @remarks The item owner can remove by default.
1111  *
1112  * @param[in] alias Item alias to be removed
1113  *
1114  * @return @c 0 on success,
1115  *         otherwise a negative error value
1116  *
1117  * @retval #CKMC_ERROR_NONE              Successful
1118  * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
1119  * @retval #CKMC_ERROR_DB_LOCKED         A user key is not loaded in memory (a user is not logged
1120  *                                       in)
1121  * @retval #CKMC_ERROR_DB_ERROR          Failed due to a database error
1122  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN  Alias does not exist
1123  * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
1124  *
1125  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
1126  *
1127  * @see ckmc_save_key()
1128  * @see ckmc_save_cert
1129  * @see ckmc_save_data
1130  * @see ckmc_save_pkcs12
1131  * @see ckmc_create_key_pair_rsa
1132  * @see ckmc_create_key_pair_dsa
1133  * @see ckmc_create_key_pair_ecdsa
1134  */
1135 int ckmc_remove_alias(const char *alias);
1136
1137 /**
1138  * @brief Encrypts data using selected key and algorithm
1139  *
1140  * @since_tizen 3.0
1141  * @privlevel public
1142  * @privilege %http://tizen.org/privilege/keymanager
1143  *
1144  * @remarks Key identified by @a key_alias should exist
1145  *
1146  * @param[in] params            Algorithm parameters
1147  * @param[in] key_alias         Alias of the key to be used for encryption
1148  * @param[in] password          The password used in decrypting a key value. If password of policy
1149  *                              is provided in ckmc_save_key(), the same password should be provided
1150  * @param[in] decrypted         Data to be encrypted
1151  * @param[out] ppencrypted      Encrypted data (some algorithms may return additional information
1152  *                              embedded in encrypted data. AES GCM is an example). The caller is
1153  *                              responsible for freeing ppencrypted with ckmc_buffer_free().
1154  *
1155  * @return @c 0 on success, otherwise a negative error value
1156  *
1157  * @retval #CKMC_ERROR_NONE                 Successful
1158  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
1159  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
1160  *                                          in)
1161  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
1162  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Key with given alias does not exist
1163  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
1164  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
1165  *                                          Key decryption failed because password is incorrect.
1166  *
1167  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
1168  */
1169 int ckmc_encrypt_data(const ckmc_param_list_s *params,
1170                       const char *key_alias,
1171                       const char *password,
1172                       const ckmc_raw_buffer_s decrypted,
1173                       ckmc_raw_buffer_s **ppencrypted);
1174
1175 /**
1176  * @brief Decrypts data using selected key and algorithm
1177  *
1178  * @since_tizen 3.0
1179  * @privlevel public
1180  * @privilege %http://tizen.org/privilege/keymanager
1181  *
1182  * @remarks Key identified by @a key_alias should exist
1183  *
1184  * @param[in] params            Algorithm parameters
1185  * @param[in] key_alias         Alias of the key to be used for encryption
1186  * @param[in] password          The password used in decrypting a key value. If password of policy
1187  *                              is provided in ckmc_save_key(), the same password should be provided
1188  * @param[in] encrypted         Data to be decrypted (some algorithms may require additional
1189  *                              information embedded in encrypted data. AES GCM is an example).
1190  * @param[out] ppdecrypted      Decrypted data. The caller is responsible for freeing ppdecrypted
1191  *                              with ckmc_buffer_free().
1192  *
1193  * @return @c 0 on success, otherwise a negative error value
1194  *
1195  * @retval #CKMC_ERROR_NONE                 Successful
1196  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
1197  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
1198  *                                          in)
1199  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
1200  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Key with given alias does not exist
1201  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
1202  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
1203  *                                          Key decryption failed because password is incorrect.
1204  *
1205  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
1206  */
1207 int ckmc_decrypt_data(const ckmc_param_list_s *params,
1208                       const char *key_alias,
1209                       const char *password,
1210                       const ckmc_raw_buffer_s encrypted,
1211                       ckmc_raw_buffer_s **ppdecrypted);
1212
1213 #ifdef __cplusplus
1214 }
1215 #endif
1216
1217 /**
1218  * @}
1219  */
1220
1221
1222 #endif /* __TIZEN_CORE_CKMC_MANAGER_H */