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