Fix ckmc headers grammar
[platform/core/security/key-manager.git] / src / include / ckmc / ckmc-manager.h
1 /*
2  *  Copyright (c) 2000 - 2015 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  * @brief Gets a pkcs12 from key manager.
377  *
378  * @since_tizen 2.4
379  * @privlevel public
380  * @privilege %http://tizen.org/privilege/keymanager
381  *
382  * @remarks A client can access only data stored by the client.
383  * @remarks You must destroy the newly created @a pkcs12 by calling ckmc_pkcs12_free() if it is no
384  *          longer needed.
385  *
386  * @param[in]  alias        The name of a data to retrieve
387  * @param[in]  key_password  Password that was used to encrypt privateKey (may be NULL)
388  * @param[in]  cert_password Password used to encrypt certificates (may be NULL)
389  * @param[out] pkcs12       The pointer to a newly created ckmc_pkcs12_s handle
390  *
391  * @return @c 0 on success,
392  *         otherwise a negative error value
393  *
394  * @retval #CKMC_ERROR_NONE               Successful
395  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
396  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
397  *                                        in)
398  * @retval #CKMC_ERROR_DB_ERROR           Failed due to a database error
399  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
400  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
401  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
402  *                                        key_password or cert_password does not match with password
403  *                                        used to encrypt data
404  *
405  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
406  *
407  * @see ckmc_save_pkcs12()
408  * @see ckmc_remove_alias()
409  */
410 int ckmc_get_pkcs12(const char *alias, const char *key_password, const char *cert_password, ckmc_pkcs12_s **pkcs12);
411
412 /**
413  * @brief Stores a data inside key manager based on the provided policy.
414  *
415  * @since_tizen 2.3
416  * @privlevel public
417  * @privilege %http://tizen.org/privilege/keymanager
418  *
419  * @param[in] alias  The name of a data to be stored
420  * @param[in] data   The binary value to be stored
421  * @param[in] policy The policy about how to store a data securely
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_ALIAS_EXISTS    Alias already exists
431  * @retval #CKMC_ERROR_DB_ERROR           Failed due to a database error
432  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
433  *
434  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
435  *
436  * @see ckmc_remove_alias()
437  * @see ckmc_get_data()
438  * @see ckmc_get_data_alias_list()
439  * @see #ckmc_raw_buffer_s
440  * @see #ckmc_policy_s
441  */
442 int ckmc_save_data(const char *alias, ckmc_raw_buffer_s data, const ckmc_policy_s policy);
443
444 /**
445  * @deprecated Deprecated since 2.4. [Use ckmc_remove_alias() instead]
446  * @brief Removes a data from key manager.
447  *
448  * @since_tizen 2.3
449  * @privlevel public
450  * @privilege %http://tizen.org/privilege/keymanager
451  *
452  * @remarks To remove data, client must have remove permission to the specified data object.
453  * @remarks The data owner can remove by default.
454  *
455  * @param[in] alias The name of a data to be removed
456  *
457  * @return @c 0 on success,
458  *         otherwise a negative error value
459  *
460  * @retval #CKMC_ERROR_NONE               Successful
461  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
462  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
463  *                                        in)
464  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
465  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
466  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
467  *
468  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
469  *
470  * @see ckmc_save_data()
471  * @see ckmc_get_data()
472  * @see ckmc_get_data_alias_list()
473  */
474 int ckmc_remove_data(const char *alias);
475
476 /**
477  * @brief Gets a data from key manager.
478  *
479  * @since_tizen 2.3
480  * @privlevel public
481  * @privilege %http://tizen.org/privilege/keymanager
482  *
483  * @remarks A client can access only data stored by the client.
484  * @remarks You must destroy the newly created @a ppdata by calling ckmc_buffer_free() if it is no
485  *          longer needed.
486  *
487  * @param[in]  alias     The name of a data to retrieve
488  * @param[in]  password  The password used in decrypting a data value \n
489  *                       If password of policy is provided in ckmc_save_data(), the same password
490  *                       should be provided.
491  * @param[out] ppdata    The pointer to a newly created ckmc_raw_buffer_s handle
492  *
493  * @return @c 0 on success,
494  *         otherwise a negative error value
495  *
496  * @retval #CKMC_ERROR_NONE               Successful
497  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
498  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
499  *                                        in)
500  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
501  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
502  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
503  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
504  *                                        Decryption failed because password is incorrect.
505  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
506  *
507  * @see ckmc_save_data()
508  * @see ckmc_remove_alias()
509  * @see ckmc_get_data_alias_list()
510  */
511 int ckmc_get_data(const char *alias, const char *password, ckmc_raw_buffer_s **ppdata);
512
513 /**
514  * @brief Gets all alias of data which the client can access.
515  *
516  * @since_tizen 2.3
517  * @privlevel public
518  * @privilege %http://tizen.org/privilege/keymanager
519  *
520  * @remarks A client can access only data stored by the client.
521  * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free()
522  *          if it is no longer needed.
523  *
524  * @param[out] ppalias_list The pointer to a newly created ckmc_alias_list_s handle containing all
525  *                          available alias of keys \n
526  *                          If there is no available key alias, *ppalias_list will be null.
527  *
528  * @return @c 0 on success,
529  *         otherwise a negative error value
530  *
531  * @retval #CKMC_ERROR_NONE               Successful
532  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
533  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
534  *                                        in)
535  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
536  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
537  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
538  *
539  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
540  *
541  * @see ckmc_save_data()
542  * @see ckmc_remove_alias()
543  * @see ckmc_get_data()
544  */
545 int ckmc_get_data_alias_list(ckmc_alias_list_s** ppalias_list);
546
547
548
549
550 /**
551  * @brief Creates RSA private/public key pair and stores them inside key manager based on each
552  *        policy.
553  *
554  * @since_tizen 2.3
555  * @privlevel public
556  * @privilege %http://tizen.org/privilege/keymanager
557  *
558  * @remarks If password in policy is provided, the key is additionally encrypted with the password
559  *          in policy.
560  *
561  * @param[in] size                The size of key strength to be created \n
562  *                                @c 1024, @c 2048, and @c 4096 are supported.
563  * @param[in] private_key_alias   The name of private key to be stored
564  * @param[in] public_key_alias    The name of public key to be stored
565  * @param[in] policy_private_key  The policy about how to store a private key securely
566  * @param[in] policy_public_key   The policy about how to store a public key securely
567  *
568  * @return @c 0 on success,
569  *         otherwise a negative error value
570  *
571  * @retval #CKMC_ERROR_NONE               Successful
572  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
573  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
574  *                                        in)
575  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
576  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
577  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
578  *
579  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
580  *
581  * @see ckmc_create_key_pair_dsa()
582  * @see ckmc_create_key_pair_ecdsa()
583  * @see ckmc_create_signature()
584  * @see ckmc_verify_signature()
585  */
586 int ckmc_create_key_pair_rsa(const size_t size,
587                              const char *private_key_alias,
588                              const char *public_key_alias,
589                              const ckmc_policy_s policy_private_key,
590                              const ckmc_policy_s policy_public_key);
591
592 /**
593  * @brief Creates DSA private/public key pair and stores them inside key manager based on each
594  *        policy.
595  *
596  * @since_tizen 2.3
597  * @privlevel public
598  * @privilege %http://tizen.org/privilege/keymanager
599  *
600  * @remarks If password in policy is provided, the key is additionally encrypted with the password
601  *          in policy.
602  *
603  * @param[in] size                The size of key strength to be created \n
604  *                                @c 1024, @c 2048, @c 3072 and @c 4096 are supported.
605  * @param[in] private_key_alias   The name of private key to be stored
606  * @param[in] public_key_alias    The name of public key to be stored
607  * @param[in] policy_private_key  The policy about how to store a private key securely
608  * @param[in] policy_public_key   The policy about how to store a public key securely
609  *
610  * @return @c 0 on success,
611  *         otherwise a negative error value
612  *
613  * @retval #CKMC_ERROR_NONE               Successful
614  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
615  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
616  *                                        in)
617  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
618  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
619  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
620  *
621  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
622  *
623  * @see ckmc_create_key_pair_rsa()
624  * @see ckmc_create_key_pair_ecdsa()
625  * @see ckmc_create_signature()
626  * @see ckmc_verify_signature()
627  */
628 int ckmc_create_key_pair_dsa(const size_t size,
629                              const char *private_key_alias,
630                              const char *public_key_alias,
631                              const ckmc_policy_s policy_private_key,
632                              const ckmc_policy_s policy_public_key);
633
634 /**
635  * @brief Creates ECDSA private/public key pair and stores them inside key manager based on each
636  *        policy.
637  *
638  * @since_tizen 2.3
639  * @privlevel public
640  * @privilege %http://tizen.org/privilege/keymanager
641  *
642  * @remarks If password in policy is provided, the key is additionally encrypted with the password
643  *          in policy.
644  *
645  * @param[in] type                The type of elliptic curve of ECDSA
646  * @param[in] private_key_alias   The name of private key to be stored
647  * @param[in] public_key_alias    The name of public key to be stored
648  * @param[in] policy_private_key  The policy about how to store a private key securely
649  * @param[in] policy_public_key   The policy about how to store a public key securely
650  *
651  * @return @c 0 on success,
652  *         otherwise a negative error value
653  *
654  * @retval #CKMC_ERROR_NONE               Successful
655  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
656  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
657  *                                        in)
658  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
659  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
660  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
661  *
662  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
663  *
664  * @see ckmc_create_key_pair_rsa()
665  * @see ckmc_create_key_pair_dsa()
666  * @see ckmc_create_signature()
667  * @see ckmc_verify_signature()
668  * @see #ckmc_ec_type_e
669  */
670 int ckmc_create_key_pair_ecdsa(const ckmc_ec_type_e type,
671                                const char *private_key_alias,
672                                const char *public_key_alias,
673                                const ckmc_policy_s policy_private_key,
674                                const ckmc_policy_s policy_public_key);
675
676 /**
677  * @brief Creates AES key and stores it inside key manager based on the policy.
678  *
679  * @since_tizen 3.0
680  * @privlevel public
681  * @privilege %http://tizen.org/privilege/keymanager
682  *
683  * @remarks If password in policy is provided, the key is additionally encrypted with the password
684  *          in policy.
685  *
686  * @param[in] size                The size of key strength to be created. \n
687  *                                @c 128, @c 192 and @c 256 are supported.
688  * @param[in] key_alias           The name of key to be stored
689  * @param[in] key_policy          The policy about how to store the key securely
690  *
691  * @return @c 0 on success,
692  *         otherwise a negative error value
693  *
694  * @retval #CKMC_ERROR_NONE               Successful
695  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
696  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
697  *                                        in)
698  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
699  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
700  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
701  *
702  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
703  *
704  * @see ckmc_create_key_pair_rsa()
705  * @see ckmc_create_key_pair_dsa()
706  * @see ckmc_create_key_pair_ecdsa()
707  */
708 int ckmc_create_key_aes(const size_t size,
709                         const char *key_alias,
710                         const ckmc_policy_s key_policy);
711
712 /**
713  * @brief Creates a signature on a given message using a private key and returns the signature.
714  *
715  * @since_tizen 2.3
716  * @privlevel public
717  * @privilege %http://tizen.org/privilege/keymanager
718  *
719  * @remarks If password of policy is provided during storing a key, the same password should be
720  *          provided.
721  * @remarks You must destroy the newly created @a ppsignature by calling ckmc_buffer_free() if it is
722  *          no longer needed.
723  *
724  * @param[in]  private_key_alias  The name of private key
725  * @param[in]  password           The password used in decrypting a private key value
726  * @param[in]  message            The message that is signed with a private key
727  * @param[in]  hash               The hash algorithm used in creating signature
728  * @param[in]  padding            The RSA padding algorithm used in creating signature \n
729  *                                It is used only when the signature algorithm is RSA.
730  * @param[out] ppsignature        The pointer to a newly created signature \n
731  *                                If an error occurs, @a *ppsignature will be null.
732  *
733  * @return @c 0 on success,
734  *         otherwise a negative error value
735  *
736  * @retval #CKMC_ERROR_NONE               Successful
737  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
738  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged
739  *                                        in)
740  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
741  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
742  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
743  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
744  *                                        Decryption failed because password is incorrect.
745  *
746  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
747  *
748  * @see ckmc_create_key_pair_rsa()
749  * @see ckmc_create_key_pair_ecdsa()
750  * @see ckmc_verify_signature()
751  * @see ckmc_buffer_free()
752  * @see #ckmc_hash_algo_e
753  * @see #ckmc_rsa_padding_algo_e
754  */
755 int ckmc_create_signature(const char *private_key_alias,
756                           const char *password,
757                           const ckmc_raw_buffer_s message,
758                           const ckmc_hash_algo_e hash,
759                           const ckmc_rsa_padding_algo_e padding,
760                           ckmc_raw_buffer_s **ppsignature);
761
762 /**
763  * @brief Verifies a given signature on a given message using a public key and returns the signature
764  *        status.
765  *
766  * @since_tizen 2.3
767  * @privlevel public
768  * @privilege %http://tizen.org/privilege/keymanager
769  *
770  * @remarks If password of policy is provided during storing a key, the same password should be
771  *          provided.
772  *
773  * @param[in] public_key_alias  The name of public key
774  * @param[in] password          The password used in decrypting a public key value
775  * @param[in] message           The input on which the signature is created
776  * @param[in] signature         The signature that is verified with public key
777  * @param[in] hash              The hash algorithm used in verifying signature
778  * @param[in] padding           The RSA padding algorithm used in verifying signature \n
779  *                              It is used only when the signature algorithm is RSA.
780  *
781  * @return @c 0 on success and the signature is valid,
782  *         otherwise a negative error value
783  *
784  * @retval #CKMC_ERROR_NONE                 Successful
785  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The signature is invalid
786  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
787  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
788  *                                          in)
789  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
790  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
791  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
792  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
793  *                                          Decryption failed because password is incorrect.
794  *
795  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
796  *
797  * @see ckmc_create_key_pair_rsa()
798  * @see ckmc_create_key_pair_ecdsa()
799  * @see ckmc_verify_signature()
800  * @see #ckmc_hash_algo_e
801  * @see #ckmc_rsa_padding_algo_e
802  */
803 int ckmc_verify_signature(const char *public_key_alias,
804                           const char *password,
805                           const ckmc_raw_buffer_s message,
806                           const ckmc_raw_buffer_s signature,
807                           const ckmc_hash_algo_e hash,
808                           const ckmc_rsa_padding_algo_e padding);
809
810 /**
811  * @brief Verifies a certificate chain and returns that chain.
812  *
813  * @since_tizen 2.3
814  * @privlevel public
815  * @privilege %http://tizen.org/privilege/keymanager
816  *
817  * @remarks The trusted root certificate of the chain should exist in the system's certificate
818  *          storage.
819  * @remarks You must destroy the newly created @a ppcert_chain_list by calling
820  *          ckmc_cert_list_all_free() if it is no longer needed.
821  *
822  * @param[in] cert               The certificate to be verified
823  * @param[in] untrustedcerts     The untrusted CA certificates to be used in verifying a certificate
824  *                               chain
825  * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n
826  *                               If an error occurs, @a *ppcert_chain_list will be null.
827  *
828  * @return @c 0 on success and the signature is valid,
829  *         otherwise a negative error value
830  *
831  * @retval #CKMC_ERROR_NONE                 Successful
832  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The certificate chain is not valid
833  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
834  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
835  *                                          in)
836  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
837  * @retval #CKMC_ERROR_INVALID_FORMAT       The format of certificate is not valid
838  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
839  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
840  *                                          Decryption failed because password is incorrect.
841  *
842  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
843  *
844  * @see ckmc_get_cert_chain_with_alias())
845  * @see ckmc_cert_list_all_free()
846  */
847 int ckmc_get_cert_chain(const ckmc_cert_s *cert,
848                         const ckmc_cert_list_s *untrustedcerts,
849                         ckmc_cert_list_s **ppcert_chain_list);
850
851 /**
852  * @brief Verifies a certificate chain using an alias list of untrusted certificates and return that
853  *        chain.
854  *
855  * @since_tizen 2.3
856  * @privlevel public
857  * @privilege %http://tizen.org/privilege/keymanager
858  *
859  * @remarks The trusted root certificate of the chain should exist in the system's certificate
860  *          storage.
861  * @remarks You must destroy the newly created @a ppcert_chain_list by calling
862  *          ckmc_cert_list_all_free() if it is no longer needed.
863  *
864  * @param[in] cert               The certificate to be verified
865  * @param[in] untrustedcerts     The alias list of untrusted CA certificates stored in key manager
866  *                               to be used in verifying a certificate chain
867  * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n
868  *                               If an error occurs, @a *ppcert_chain_list will be null.
869  *
870  * @return @c 0 on success and the signature is valid,
871  *         otherwise a negative error value
872  *
873  * @retval #CKMC_ERROR_NONE                 Successful
874  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The certificate chain is not valid
875  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
876  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
877  *                                          in)
878  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
879  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
880  * @retval #CKMC_ERROR_INVALID_FORMAT       The format of certificate is not valid
881  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
882  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
883  *                                          Some certificates were encrypted with password and could not
884  *                                          be used.
885  *
886  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
887  *
888  * @see ckmc_get_cert_chain()
889  * @see ckmc_cert_list_all_free()
890  */
891 int ckmc_get_cert_chain_with_alias(const ckmc_cert_s *cert,
892                                    const ckmc_alias_list_s *untrustedcerts,
893                                    ckmc_cert_list_s **ppcert_chain_list);
894
895 /**
896  * @brief Verifies a certificate chain and returns that chain using user entered trusted and
897  *        untrusted CA certificates
898  *
899  * @since_tizen 2.4
900  * @privlevel public
901  * @privilege %http://tizen.org/privilege/keymanager
902  *
903  * @remarks If the trusted root certificates are provided as a user input, these certificates do not
904  *          need to exist in the system's certificate storage.
905  * @remarks You must destroy the newly created @a ppcert_chain_list by calling
906  *          ckmc_cert_list_all_free() if it is no longer needed.
907  *  *
908  * @param[in] cert                    The certificate to be verified
909  * @param[in] untrustedcerts          The untrusted CA certificates to be used in verifying a
910  *                                    certificate chain
911  * @param[in] trustedcerts            The trusted CA certificates to be used in verifying a
912  *                                    certificate chain
913  * @param[in] use_trustedsystemcerts  The flag indicating the use of the trusted root certificates
914  *                                    in the system's certificate storage.
915  * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n
916  *                               If an error occurs, @a *ppcert_chain_list will be null.
917  *
918  * @return @c 0 on success and the signature is valid,
919  *         otherwise a negative error value
920  *
921  * @retval #CKMC_ERROR_NONE                 Successful
922  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The certificate chain is not valid
923  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
924  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
925  *                                          in)
926  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
927  * @retval #CKMC_ERROR_INVALID_FORMAT       The format of certificate is not valid
928  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
929  *
930  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
931  *
932  * @see ckmc_get_cert_chain_with_trustedcert_alias()
933  * @see ckmc_cert_list_all_free()
934  */
935 int ckmc_get_cert_chain_with_trustedcert(const ckmc_cert_s *cert,
936                                          const ckmc_cert_list_s *untrustedcerts,
937                                          const ckmc_cert_list_s *trustedcerts,
938                                          const bool use_trustedsystemcerts,
939                                          ckmc_cert_list_s **ppcert_chain_list);
940
941 /**
942  * @brief Verifies a certificate chain and returns that chain using alias lists of untrusted and
943  *        trusted certificates
944  *
945  * @since_tizen 2.4
946  * @privlevel public
947  * @privilege %http://tizen.org/privilege/keymanager
948  *
949  * @remarks If the alias list of trusted root certificates is provided as a user input, these
950  *          certificates do not need to exist in the system's certificate storage.
951  * @remarks You must destroy the newly created @a ppcert_chain_list by calling
952  *          ckmc_cert_list_all_free() if it is no longer needed.
953  *
954  * @param[in] cert                    The certificate to be verified
955  * @param[in] untrustedcerts          The alias list of untrusted CA certificates stored in key
956  *                                    manager to be used in verifying a certificate chain
957  * @param[in] trustedcerts            The alias list of trusted CA certificates stored in key
958  *                                    manager to be used in verifying a certificate chain
959  * @param[in] use_trustedsystemcerts  The flag indicating the use of the trusted root certificates
960  *                                    in the system's certificate storage.
961  * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n
962  *                               If an error occurs, @a *ppcert_chain_list will be null.
963  *
964  * @return @c 0 on success and the signature is valid,
965  *         otherwise a negative error value
966  *
967  * @retval #CKMC_ERROR_NONE                 Successful
968  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The certificate chain is not valid
969  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
970  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
971  *                                          in)
972  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
973  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
974  * @retval #CKMC_ERROR_INVALID_FORMAT       The format of certificate is not valid
975  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
976  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
977  *                                          Some certificates were encrypted with password and could not
978  *                                          be used.
979  *
980  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
981  *
982  * @see ckmc_get_cert_chain_with_trustedcert() 
983  * @see ckmc_cert_list_all_free()
984  */
985 int ckmc_get_cert_chain_with_trustedcert_alias(const ckmc_cert_s *cert,
986                                                const ckmc_alias_list_s *untrustedcerts,
987                                                const ckmc_alias_list_s *trustedcerts,
988                                                const bool use_trustedsystemcerts,
989                                                ckmc_cert_list_s **ppcert_chain_list);
990
991 /**
992  * @brief Perform OCSP which checks certificate is whether revoked or not
993  *
994  * @since_tizen 2.4
995  * @privlevel public
996  * @privilege %http://tizen.org/privilege/keymanager
997  *
998  * @param[in] pcert_chain_list   Valid certificate chain to perform OCSP check
999  * @param[out] ocsp_status       The pointer to status result of OCSP check
1000  *
1001  * @return @c 0 on success, otherwise a negative error value
1002  *
1003  * @retval #CKMC_ERROR_NONE                 Successful
1004  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
1005  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
1006  *
1007  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
1008  * @pre @a pcert_chain_list is created with ckmc_get_certificate_chain() or
1009  *      ckmc_get_certificate_chain_with_alias()
1010  *
1011  * @see ckmc_get_cert_chain())
1012  * @see ckmc_cert_list_all_free()
1013  */
1014 int ckmc_ocsp_check(const ckmc_cert_list_s *pcert_chain_list, ckmc_ocsp_status_e *ocsp_status);
1015
1016 /**
1017  * @deprecated Deprecated since 2.4. [Use ckmc_set_permission() instead]
1018  * @brief Allows another application to access client's application data
1019  *
1020  * @since_tizen 2.3
1021  * @privlevel public
1022  * @privilege %http://tizen.org/privilege/keymanager
1023  *
1024  * @remarks Data identified by @a alias should exist
1025  *
1026  * @param[in] alias       Data alias for which access will be granted
1027  * @param[in] accessor    Package id of the application that will gain access rights
1028  * @param[in] granted     Rights granted for @a accessor application
1029  *
1030  * @return @c 0 on success, otherwise a negative error value
1031  *
1032  * @retval #CKMC_ERROR_NONE                 Successful
1033  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
1034  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
1035  *                                          in)
1036  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
1037  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
1038  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
1039  *
1040  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
1041  *
1042  * @see ckmc_deny_access()
1043  */
1044 int ckmc_allow_access(const char *alias, const char *accessor, ckmc_access_right_e granted);
1045
1046 /**
1047  * @brief Allows another application to access client's application data
1048  *
1049  * @since_tizen 2.4
1050  * @privlevel public
1051  * @privilege %http://tizen.org/privilege/keymanager
1052  *
1053  * @remarks Data identified by @a alias should exist
1054  *
1055  * @param[in] alias       Data alias for which access will be granted
1056  * @param[in] accessor    Package id of the application that will gain access rights
1057  * @param[in] permissions Mask of permissions granted for @a accessor application
1058  *                        (@a ckmc_permission_e)
1059  *                        (previous permission mask will be replaced with the new mask value)
1060  *
1061  * @return @c 0 on success, otherwise a negative error value
1062  *
1063  * @retval #CKMC_ERROR_NONE                 Successful
1064  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
1065  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
1066  *                                          in)
1067  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
1068  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
1069  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
1070  *
1071  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
1072  */
1073 int ckmc_set_permission(const char *alias, const char *accessor, int permissions);
1074
1075 /**
1076  * @deprecated Deprecated since 2.4. [Use ckmc_set_permission() instead]
1077  * @brief Revokes another application's access to client's application data
1078  *
1079  * @since_tizen 2.3
1080  * @privlevel public
1081  * @privilege %http://tizen.org/privilege/keymanager
1082  *
1083  * @remarks Data identified by @a alias should exist
1084  * @remarks Only access previously granted with ckmc_allow_access can be revoked.
1085  *
1086  * @param[in] alias       Data alias for which access will be revoked
1087  * @param[in] accessor    Package id of the application that will lose access rights
1088  *
1089  * @return @c 0 on success, otherwise a negative error value
1090  *
1091  * @retval #CKMC_ERROR_NONE                 Successful
1092  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid or the @a accessor doesn't
1093  *                                          have access to @a alias
1094  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
1095  *                                          in)
1096  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
1097  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
1098  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
1099  *
1100  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
1101  *
1102  * @see ckmc_allow_access()
1103  * @see ckmc_set_permission()
1104  */
1105 int ckmc_deny_access(const char *alias, const char *accessor);
1106
1107 /**
1108  * @brief Removes a an entry (no matter of type) from the key manager.
1109  *
1110  * @since_tizen 2.4
1111  * @privlevel public
1112  * @privilege %http://tizen.org/privilege/keymanager
1113  *
1114  * @remarks To remove item, client must have remove permission to the specified item.
1115  * @remarks The item owner can remove by default.
1116  *
1117  * @param[in] alias Item alias to be removed
1118  *
1119  * @return @c 0 on success,
1120  *         otherwise a negative error value
1121  *
1122  * @retval #CKMC_ERROR_NONE              Successful
1123  * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
1124  * @retval #CKMC_ERROR_DB_LOCKED         A user key is not loaded in memory (a user is not logged
1125  *                                       in)
1126  * @retval #CKMC_ERROR_DB_ERROR          Failed due to a database error
1127  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN  Alias does not exist
1128  * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
1129  *
1130  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
1131  *
1132  * @see ckmc_save_key()
1133  * @see ckmc_save_cert()
1134  * @see ckmc_save_data()
1135  * @see ckmc_save_pkcs12()
1136  * @see ckmc_create_key_pair_rsa()
1137  * @see ckmc_create_key_pair_dsa()
1138  * @see ckmc_create_key_pair_ecdsa()
1139  */
1140 int ckmc_remove_alias(const char *alias);
1141
1142 /**
1143  * @brief Encrypts data using selected key and algorithm.
1144  *
1145  * @since_tizen 3.0
1146  * @privlevel public
1147  * @privilege %http://tizen.org/privilege/keymanager
1148  *
1149  * @remarks Key identified by @a key_alias should exist.
1150  *
1151  * @param[in] params            Algorithm parameters
1152  * @param[in] key_alias         Alias of the key to be used for encryption
1153  * @param[in] password          The password used in decrypting a key value \n
1154  *                              If password of policy is provided in ckmc_save_key(), the same
1155  *                              password should be provided
1156  * @param[in] decrypted         Data to be encrypted
1157  * @param[out] ppencrypted      Encrypted data (some algorithms may return additional information
1158  *                              embedded in encrypted data. AES GCM is an example) \n
1159  *                              The caller is responsible for freeing ppencrypted with
1160  *                              ckmc_buffer_free()
1161  *
1162  * @return @c 0 on success, otherwise a negative error value
1163  *
1164  * @retval #CKMC_ERROR_NONE                 Successful
1165  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
1166  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
1167  *                                          in)
1168  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
1169  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Key with given alias does not exist
1170  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
1171  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
1172  *                                          Key decryption failed because password is incorrect
1173  *
1174  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
1175  *
1176  * @see ckmc_buffer_free()
1177  * @see ckmc_param_list_new()
1178  * @see ckmc_param_list_free()
1179  * @see ckmc_param_list_add_integer()
1180  * @see ckmc_param_list_add_buffer()
1181  * @see ckmc_generate_params()
1182  * @see #ckmc_param_list_s
1183  * @see #ckmc_param_name_e
1184  */
1185 int ckmc_encrypt_data(const ckmc_param_list_s *params,
1186                       const char *key_alias,
1187                       const char *password,
1188                       const ckmc_raw_buffer_s decrypted,
1189                       ckmc_raw_buffer_s **ppencrypted);
1190
1191 /**
1192  * @brief Decrypts data using selected key and algorithm.
1193  *
1194  * @since_tizen 3.0
1195  * @privlevel public
1196  * @privilege %http://tizen.org/privilege/keymanager
1197  *
1198  * @remarks Key identified by @a key_alias should exist.
1199  *
1200  * @param[in] params            Algorithm parameters
1201  * @param[in] key_alias         Alias of the key to be used for encryption
1202  * @param[in] password          The password used in decrypting a key value \n
1203  *                              If password of policy is provided in ckmc_save_key(), the same
1204  *                              password should be provided
1205  * @param[in] encrypted         Data to be decrypted (some algorithms may require additional
1206  *                              information embedded in encrypted data. AES GCM is an example)
1207  * @param[out] ppdecrypted      Decrypted data \n
1208  *                              The caller is responsible for freeing ppdecrypted with
1209  *                              ckmc_buffer_free()
1210  *
1211  * @return @c 0 on success, otherwise a negative error value
1212  *
1213  * @retval #CKMC_ERROR_NONE                 Successful
1214  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
1215  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged
1216  *                                          in)
1217  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
1218  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Key with given alias does not exist
1219  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
1220  * @retval #CKMC_ERROR_AUTHENTICATION_FAILED
1221  *                                          Key decryption failed because password is incorrect
1222  *
1223  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
1224  *
1225  * @see ckmc_buffer_free()
1226  * @see ckmc_param_list_new()
1227  * @see ckmc_param_list_free()
1228  * @see ckmc_param_list_add_integer()
1229  * @see ckmc_param_list_add_buffer()
1230  * @see ckmc_generate_params()
1231  * @see #ckmc_param_list_s
1232  * @see #ckmc_param_name_e
1233  */
1234 int ckmc_decrypt_data(const ckmc_param_list_s *params,
1235                       const char *key_alias,
1236                       const char *password,
1237                       const ckmc_raw_buffer_s encrypted,
1238                       ckmc_raw_buffer_s **ppdecrypted);
1239
1240 #ifdef __cplusplus
1241 }
1242 #endif
1243
1244 /**
1245  * @}
1246  */
1247
1248
1249 #endif /* __TIZEN_CORE_CKMC_MANAGER_H */