Add missing return value explanations in doxygen
[platform/core/security/key-manager.git] / src / include / ckmc / ckmc-manager.h
1 /*
2  *  Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License
15  *
16  *
17  * @file        ckmc-manager.h
18  * @version     1.0
19  * @brief       Provides management functions(storing, retrieving, and removing) for keys, certificates and data of a user and additional crypto functions.
20  */
21
22
23 #ifndef __TIZEN_CORE_CKMC_MANAGER_H
24 #define __TIZEN_CORE_CKMC_MANAGER_H
25
26 #include <stddef.h>
27 #include <sys/types.h>
28 #include <tizen.h>
29 #include <ckmc/ckmc-type.h>
30 #include <ckmc/ckmc-error.h>
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 /**
37  * @addtogroup CAPI_KEY_MANAGER_CLIENT_MODULE
38  * @{
39  */
40
41
42 /**
43  * @brief Stores a key inside key manager based on the provided policy.
44  *
45  * @since_tizen 2.3
46  * @privlevel public
47  * @privilege %http://tizen.org/privilege/keymanager
48  *
49  * @remarks Currently only six types of keys are supported for this API. These are RSA public/private key, DSA public/private key and ECDSA public/private key.
50  * @remarks key_type in key may be set to #CKMC_KEY_NONE as an input. key_type is determined inside key manager during storing keys.
51  * @remarks Some private key files are protected by a password. If raw_key in key read from those encrypted files is encrypted with a password, the password should be provided in the #ckmc_key_s structure.
52  * @remarks If password in policy is provided, the key is additionally encrypted with the password in policy.
53  *
54  * @param[in] alias   The name of a key to be stored
55  * @param[in] key     The key's binary value to be stored
56  * @param[in] policy  The policy about how to store a key securely
57  *
58  * @return @c 0 on success,
59  *         otherwise a negative error value
60  *
61  * @retval #CKMC_ERROR_NONE              Successful
62  * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
63  * @retval #CKMC_ERROR_DB_LOCKED         A user key is not loaded in memory (a user is not logged in)
64  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS   Alias already exists
65  * @retval #CKMC_ERROR_INVALID_FORMAT    The format of raw_key is not valid
66  * @retval #CKMC_ERROR_DB_ERROR          Failed due to other DB transaction unexpectedly
67  * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
68  *
69  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
70  *
71  * @see ckmc_remove_key()
72  * @see ckmc_get_key()
73  * @see ckmc_get_key_alias_list()
74  * @see #ckmc_key_s
75  * @see #ckmc_policy_s
76  */
77 int ckmc_save_key(const char *alias, const ckmc_key_s key, const ckmc_policy_s policy);
78
79 /**
80  * @brief Removes a key from key manager.
81  *
82  * @since_tizen 2.3
83  * @privlevel public
84  * @privilege %http://tizen.org/privilege/keymanager
85  *
86  * @remarks A client can remove only keys stored by the client.
87  *
88  * @param[in] alias The name of a key to be removed
89  *
90  * @return @c 0 on success,
91  *         otherwise a negative error value
92  *
93  * @retval #CKMC_ERROR_NONE              Successful
94  * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
95  * @retval #CKMC_ERROR_DB_LOCKED         A user key is not loaded in memory (a user is not logged in)
96  * @retval #CKMC_ERROR_DB_ERROR          Failed due to the error with unknown reason
97  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN  Alias does not exist
98  * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
99  *
100  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
101  *
102  * @see ckmc_save_key()
103  * @see ckmc_get_key()
104  * @see ckmc_get_key_alias_list()
105  */
106 int ckmc_remove_key(const char *alias);
107
108 /**
109  * @brief Gets a key from key manager.
110  *
111  * @since_tizen 2.3
112  * @privlevel public
113  * @privilege %http://tizen.org/privilege/keymanager
114  *
115  * @remarks A client can access only data stored by the client.
116  * @remarks You must destroy the newly created @a ppkey by calling ckmc_key_free() if it is no longer needed.
117  *
118  * @param[in] alias     The name of a key to retrieve
119  * @param[in] password  The password used in decrypting a key value \n
120  *                      If password of policy is provided in ckmc_save_key(), the same password should be provided.
121  * @param[out] ppkey    The pointer to a newly created ckmc_key_s handle
122  *
123  * @return @c 0 on success,
124  *         otherwise a negative error value
125  *
126  * @retval #CKMC_ERROR_NONE              Successful
127  * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
128  * @retval #CKMC_ERROR_DB_LOCKED         A user key is not loaded in memory (a user is not logged in)
129  * @retval #CKMC_ERROR_DB_ERROR          Failed due to the error with unknown reason
130  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN  Alias does not exist
131  * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
132  *
133  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
134  *
135  * @see ckmc_save_key()
136  * @see ckmc_remove_key()
137  * @see ckmc_get_key_alias_list()
138  */
139 int ckmc_get_key(const char *alias, const char *password, ckmc_key_s **ppkey);
140
141 /**
142  * @brief Gets all the alias of keys that the client can access.
143  *
144  * @since_tizen 2.3
145  * @privlevel public
146  * @privilege %http://tizen.org/privilege/keymanager
147  *
148  * @remarks A client can access only data stored by the client.
149  * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free() if it is no longer needed.
150  *
151  * @param[out] ppalias_list  The pointer to a newly created ckmc_alias_list_s handle containing all available alias of keys \n
152  *                           If there is no available key alias, *ppalias_list will be null.
153  *
154  * @return @c 0 on success,
155  *         otherwise a negative error value
156  *
157  * @retval #CKMC_ERROR_NONE              Successful
158  * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
159  * @retval #CKMC_ERROR_DB_LOCKED         A user key is not loaded in memory (a user is not logged in)
160  * @retval #CKMC_ERROR_DB_ERROR          Failed due to the error with unknown reason
161  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN  Alias does not exist
162  * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
163  *
164  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
165  *
166  * @see ckmc_save_key()
167  * @see ckmc_remove_key()
168  * @see ckmc_get_key()
169  */
170 int ckmc_get_key_alias_list(ckmc_alias_list_s** ppalias_list);
171
172
173
174
175 /**
176  * @brief Stores a certificate inside key manager based on the provided policy.
177  *
178  * @since_tizen 2.3
179  * @privlevel public
180  * @privilege %http://tizen.org/privilege/keymanager
181  *
182  * @remarks the certificate's binary value will be converted and saved as binary DER encoded certificates.
183  *
184  * @param[in] alias  The name of a certificate to be stored
185  * @param[in] cert   The certificate's binary value to be stored
186  * @param[in] policy The policy about how to store a certificate securely
187  *
188  * @return @c 0 on success,
189  *         otherwise a negative error value
190  *
191  * @retval #CKMC_ERROR_NONE               Successful
192  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
193  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
194  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
195  * @retval #CKMC_ERROR_INVALID_FORMAT     The format of raw_cert is not valid
196  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
197  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
198  *
199  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
200  *
201  * @see ckmc_remove_cert()
202  * @see ckmc_get_cert()
203  * @see ckmc_get_cert_alias_list()
204  * @see #ckmc_cert_s
205  * @see #ckmc_policy_s
206  */
207 int ckmc_save_cert(const char *alias, const ckmc_cert_s cert, const ckmc_policy_s policy);
208
209 /**
210  * @brief Removes a certificate from key manager.
211  *
212  * @since_tizen 2.3
213  * @privlevel public
214  * @privilege %http://tizen.org/privilege/keymanager
215  *
216  * @remarks A client can remove only certificates stored by the client.
217  *
218  * @param[in] alias The name of a certificate to be removed
219  *
220  * @return @c 0 on success,
221  *         otherwise a negative error value
222  *
223  * @retval #CKMC_ERROR_NONE               Successful
224  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
225  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
226  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
227  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
228  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
229  *
230  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
231  *
232  * @see ckmc_save_cert()
233  * @see ckmc_get_cert()
234  * @see ckmc_get_cert_alias_list()
235  */
236 int ckmc_remove_cert(const char *alias);
237
238 /**
239  * @brief Gets a certificate from key manager.
240  *
241  * @since_tizen 2.3
242  * @privlevel public
243  * @privilege %http://tizen.org/privilege/keymanager
244  *
245  * @remarks A client can access only certificate stored by the client.
246  * @remarks A DER encoded certificate will be returned as a return value.
247  * @remarks You must destroy the newly created @a ppcert by calling ckmc_cert_free() if it is no longer needed.
248  *
249  * @param[in] alias    The name of a certificate to retrieve
250  * @param[in] password The password used in decrypting a certificate value \n
251  *                     If password of policy is provided in ckmc_save_cert(), the same password should be provided.
252  * @param[out] ppcert  The pointer to a newly created ckmc_cert_s handle
253  *
254  * @return @c 0 on success,
255  *         otherwise a negative error value
256  *
257  * @retval #CKMC_ERROR_NONE               Successful
258  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
259  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
260  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
261  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exists
262  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
263  *
264  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
265  *
266  * @see ckmc_save_cert()
267  * @see ckmc_remove_cert()
268  * @see ckmc_get_cert_alias_list()
269  */
270 int ckmc_get_cert(const char *alias, const char *password, ckmc_cert_s **ppcert);
271
272 /**
273  * @brief Gets all alias of certificates which the client can access.
274  *
275  * @since_tizen 2.3
276  * @privlevel public
277  * @privilege %http://tizen.org/privilege/keymanager
278  *
279  * @remarks A client can access only data stored by the client.
280  * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free() if it is no longer needed.
281  *
282  * @param[out] ppalias_list The pointer to a newly created ckmc_alias_list_s handle containing all available alias of keys \n
283  *                          If there is no available key alias, *ppalias_list will be null.
284  *
285  * @return @c 0 on success,
286  *         otherwise a negative error value
287  *
288  * @retval #CKMC_ERROR_NONE               Successful
289  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
290  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
291  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
292  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
293  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
294  *
295  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
296  *
297  * @see ckmc_save_cert()
298  * @see ckmc_remove_cert()
299  * @see ckmc_get_cert()
300  */
301 int ckmc_get_cert_alias_list(ckmc_alias_list_s** ppalias_list);
302
303
304
305
306 /**
307  * @brief Stores a data inside key manager based on the provided policy.
308  *
309  * @since_tizen 2.3
310  * @privlevel public
311  * @privilege %http://tizen.org/privilege/keymanager
312  *
313  * @param[in] alias  The name of a data to be stored
314  * @param[in] data   The binary value to be stored
315  * @param[in] policy The policy about how to store a data securely
316  *
317  * @return @c 0 on success,
318  *         otherwise a negative error value
319  *
320  * @retval #CKMC_ERROR_NONE               Successful
321  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
322  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
323  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
324  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
325  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
326  *
327  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
328  *
329  * @see ckmc_remove_data()
330  * @see ckmc_get_data()
331  * @see ckmc_get_data_alias_list()
332  * @see #ckmc_raw_buffer_s
333  * @see #ckmc_policy_s
334  */
335 int ckmc_save_data(const char *alias, ckmc_raw_buffer_s data, const ckmc_policy_s policy);
336
337 /**
338  * @brief Removes a data from key manager.
339  *
340  * @since_tizen 2.3
341  * @privlevel public
342  * @privilege %http://tizen.org/privilege/keymanager
343  *
344  * @remarks A client can remove only data stored by the client.
345  *
346  * @param[in] alias The name of a data to be removed
347  *
348  * @return @c 0 on success,
349  *         otherwise a negative error value
350  *
351  * @retval #CKMC_ERROR_NONE               Successful
352  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
353  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
354  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
355  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
356  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
357  *
358  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
359  *
360  * @see ckmc_save_data()
361  * @see ckmc_get_data()
362  * @see ckmc_get_data_alias_list()
363  */
364 int ckmc_remove_data(const char *alias);
365
366 /**
367  * @brief Gets a data from key manager.
368  *
369  * @since_tizen 2.3
370  * @privlevel public
371  * @privilege %http://tizen.org/privilege/keymanager
372  *
373  * @remarks A client can access only data stored by the client.
374  * @remarks You must destroy the newly created @a ppdata by calling ckmc_buffer_free() if it is no longer needed.
375  *
376  * @param[in]  alias     The name of a data to retrieve
377  * @param[in]  password  The password used in decrypting a data value \n
378  *                       If password of policy is provided in ckmc_save_data(), the same password should be provided.
379  * @param[out] ppdata    The pointer to a newly created ckmc_raw_buffer_s handle
380  *
381  * @return @c 0 on success,
382  *         otherwise a negative error value
383  *
384  * @retval #CKMC_ERROR_NONE               Successful
385  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
386  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
387  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
388  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
389  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
390  *
391  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
392  *
393  * @see ckmc_save_data()
394  * @see ckmc_remove_data()
395  * @see ckmc_get_data_alias_list()
396  */
397 int ckmc_get_data(const char *alias, const char *password, ckmc_raw_buffer_s **ppdata);
398
399 /**
400  * @brief Gets all alias of data which the client can access.
401  *
402  * @since_tizen 2.3
403  * @privlevel public
404  * @privilege %http://tizen.org/privilege/keymanager
405  *
406  * @remarks A client can access only data stored by the client.
407  * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free() if it is no longer needed.
408  *
409  * @param[out] ppalias_list The pointer to a newly created ckmc_alias_list_s handle containing all available alias of keys \n
410  *                          If there is no available key alias, *ppalias_list will be null.
411  *
412  * @return @c 0 on success,
413  *         otherwise a negative error value
414  *
415  * @retval #CKMC_ERROR_NONE               Successful
416  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
417  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
418  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
419  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
420  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
421  *
422  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
423  *
424  * @see ckmc_save_data()
425  * @see ckmc_remove_data()
426  * @see ckmc_get_data()
427  */
428 int ckmc_get_data_alias_list(ckmc_alias_list_s** ppalias_list);
429
430
431
432
433 /**
434  * @brief Creates RSA private/public key pair and stores them inside key manager based on each policy.
435  *
436  * @since_tizen 2.3
437  * @privlevel public
438  * @privilege %http://tizen.org/privilege/keymanager
439  *
440  * @remarks If password in policy is provided, the key is additionally encrypted with the password in policy.
441  *
442  * @param[in] size                The size of key strength to be created \n
443  *                                @c 1024, @c 2048, and @c 4096 are supported.
444  * @param[in] private_key_alias   The name of private key to be stored
445  * @param[in] public_key_alias    The name of public key to be stored
446  * @param[in] policy_private_key  The policy about how to store a private key securely
447  * @param[in] policy_public_key   The policy about how to store a public key securely
448  *
449  * @return @c 0 on success,
450  *         otherwise a negative error value
451  *
452  * @retval #CKMC_ERROR_NONE               Successful
453  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
454  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
455  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
456  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
457  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
458  *
459  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
460  *
461  * @see ckmc_create_key_pair_dsa()
462  * @see ckmc_create_key_pair_ecdsa()
463  * @see ckmc_create_signature()
464  * @see ckmc_verify_signature()
465  */
466 int ckmc_create_key_pair_rsa(const size_t size, const char *private_key_alias, const char *public_key_alias, const ckmc_policy_s policy_private_key, const ckmc_policy_s policy_public_key);
467
468 /**
469  * @brief Creates DSA private/public key pair and stores them inside key manager based on each policy.
470  *
471  * @since_tizen 2.3
472  * @privlevel public
473  * @privilege %http://tizen.org/privilege/keymanager
474  *
475  * @remarks If password in policy is provided, the key is additionally encrypted with the password in policy.
476  *
477  * @param[in] size                The size of key strength to be created \n
478  *                                @c 1024, @c 2048, @c 3072 and @c 4096 are supported.
479  * @param[in] private_key_alias   The name of private key to be stored
480  * @param[in] public_key_alias    The name of public key to be stored
481  * @param[in] policy_private_key  The policy about how to store a private key securely
482  * @param[in] policy_public_key   The policy about how to store a public key securely
483  *
484  * @return @c 0 on success,
485  *         otherwise a negative error value
486  *
487  * @retval #CKMC_ERROR_NONE               Successful
488  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
489  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
490  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
491  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
492  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
493  *
494  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
495  *
496  * @see ckmc_create_key_pair_rsa()
497  * @see ckmc_create_key_pair_ecdsa()
498  * @see ckmc_create_signature()
499  * @see ckmc_verify_signature()
500  */
501 int ckmc_create_key_pair_dsa(const size_t size, const char *private_key_alias, const char *public_key_alias, const ckmc_policy_s policy_private_key, const ckmc_policy_s policy_public_key);
502
503 /**
504  * @brief Creates ECDSA private/public key pair and stores them inside key manager based on each policy.
505  *
506  * @since_tizen 2.3
507  * @privlevel public
508  * @privilege %http://tizen.org/privilege/keymanager
509  *
510  * @remarks If password in policy is provided, the key is additionally encrypted with the password in policy.
511  *
512  * @param[in] type                The type of elliptic curve of ECDSA
513  * @param[in] private_key_alias   The name of private key to be stored
514  * @param[in] public_key_alias    The name of public key to be stored
515  * @param[in] policy_private_key  The policy about how to store a private key securely
516  * @param[in] policy_public_key   The policy about how to store a public key securely
517  *
518  * @return @c 0 on success,
519  *         otherwise a negative error value
520  *
521  * @retval #CKMC_ERROR_NONE               Successful
522  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
523  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
524  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
525  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
526  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
527  *
528  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
529  *
530  * @see ckmc_create_key_pair_rsa()
531  * @see ckmc_create_key_pair_dsa()
532  * @see ckmc_create_signature()
533  * @see ckmc_verify_signature()
534  * @see #ckmc_ec_type_e
535  */
536 int ckmc_create_key_pair_ecdsa(const ckmc_ec_type_e type, const char *private_key_alias, const char *public_key_alias, const ckmc_policy_s policy_private_key, const ckmc_policy_s policy_public_key);
537
538 /**
539  * @brief Creates a signature on a given message using a private key and returns the signature.
540  *
541  * @since_tizen 2.3
542  * @privlevel public
543  * @privilege %http://tizen.org/privilege/keymanager
544  *
545  * @remarks If password of policy is provided during storing a key, the same password should be provided.
546  * @remarks You must destroy the newly created @a ppsignature by calling ckmc_buffer_free() if it is no longer needed.
547  *
548  * @param[in]  private_key_alias  The name of private key
549  * @param[in]  password           The password used in decrypting a private key value
550  * @param[in]  message            The message that is signed with a private key
551  * @param[in]  hash               The hash algorithm used in creating signature
552  * @param[in]  padding            The RSA padding algorithm used in creating signature \n
553  *                                It is used only when the signature algorithm is RSA.
554  * @param[out] ppsignature        The pointer to a newly created signature \n
555  *                                If an error occurs, @a *ppsignature will be null.
556  *
557  * @return @c 0 on success,
558  *         otherwise a negative error value
559  *
560  * @retval #CKMC_ERROR_NONE               Successful
561  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
562  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
563  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
564  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
565  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
566  *
567  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
568  *
569  * @see ckmc_create_key_pair_rsa()
570  * @see ckmc_create_key_pair_ecdsa()
571  * @see ckmc_verify_signature()
572  * @see ckmc_buffer_free()
573  * @see #ckmc_hash_algo_e
574  * @see #ckmc_rsa_padding_algo_e
575  */
576 int ckmc_create_signature(const char *private_key_alias, const char *password, const ckmc_raw_buffer_s message, const ckmc_hash_algo_e hash, const ckmc_rsa_padding_algo_e padding, ckmc_raw_buffer_s **ppsignature);
577
578 /**
579  * @brief Verifies a given signature on a given message using a public key and returns the signature status.
580  *
581  * @since_tizen 2.3
582  * @privlevel public
583  * @privilege %http://tizen.org/privilege/keymanager
584  *
585  * @remarks If password of policy is provided during storing a key, the same password should be provided.
586  *
587  * @param[in] public_key_alias  The name of public key
588  * @param[in] password          The password used in decrypting a public key value
589  * @param[in] message           The input on which the signature is created
590  * @param[in] signature         The signature that is verified with public key
591  * @param[in] hash              The hash algorithm used in verifying signature
592  * @param[in] padding           The RSA padding algorithm used in verifying signature \n
593  *                              It is used only when the signature algorithm is RSA.
594  *
595  * @return @c 0 on success and the signature is valid,
596  *         otherwise a negative error value
597  *
598  * @retval #CKMC_ERROR_NONE                 Successful
599  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The signature is invalid
600  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
601  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged in)
602  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
603  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
604  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
605  *
606  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
607  *
608  * @see ckmc_create_key_pair_rsa()
609  * @see ckmc_create_key_pair_ecdsa()
610  * @see ckmc_verify_signature()
611  * @see #ckmc_hash_algo_e
612  * @see #ckmc_rsa_padding_algo_e
613  */
614 int ckmc_verify_signature(const char *public_key_alias, const char *password, const ckmc_raw_buffer_s message, const ckmc_raw_buffer_s signature, const ckmc_hash_algo_e hash, const ckmc_rsa_padding_algo_e padding);
615
616 /**
617  * @brief Verifies a certificate chain and returns that chain.
618  *
619  * @since_tizen 2.3
620  * @privlevel public
621  * @privilege %http://tizen.org/privilege/keymanager
622  *
623  * @remarks The trusted root certificate of the chain should exist in the system's certificate storage.
624  * @remarks You must destroy the newly created @a ppcert_chain_list by calling ckmc_cert_list_all_free() if it is no longer needed.
625  *
626  * @param[in] cert               The certificate to be verified
627  * @param[in] untrustedcerts     The untrusted CA certificates to be used in verifying a certificate chain
628  * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n
629  *                               If an error occurs, @a *ppcert_chain_list will be null.
630  *
631  * @return @c 0 on success and the signature is valid,
632  *         otherwise a negative error value
633  *
634  * @retval #CKMC_ERROR_NONE                 Successful
635  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The certificate chain is not valid
636  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
637  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged in)
638  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
639  * @retval #CKMC_ERROR_INVALID_FORMAT       The format of certificate is not valid
640  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
641  *
642  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
643  *
644  * @see ckmc_get_cert_chain_with_alias())
645  * @see ckmc_cert_list_all_free()
646  */
647 int ckmc_get_cert_chain(const ckmc_cert_s *cert, const ckmc_cert_list_s *untrustedcerts, ckmc_cert_list_s **ppcert_chain_list);
648
649 /**
650  * @brief Verifies a certificate chain using an alias list of untrusted certificates and return that chain.
651  *
652  * @since_tizen 2.3
653  * @privlevel public
654  * @privilege %http://tizen.org/privilege/keymanager
655  *
656  * @remarks The trusted root certificate of the chain should exist in the system's certificate storage.
657  * @remarks You must destroy the newly created @a ppcert_chain_list by calling ckmc_cert_list_all_free() if it is no longer needed.
658  *
659  * @param[in] cert               The certificate to be verified
660  * @param[in] untrustedcerts     The alias list of untrusted CA certificates stored in key manager to be used in verifying a certificate chain
661  * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n
662  *                               If an error occurs, @a *ppcert_chain_list will be null.
663  *
664  * @return @c 0 on success and the signature is valid,
665  *         otherwise a negative error value
666  *
667  * @retval #CKMC_ERROR_NONE                 Successful
668  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The certificate chain is not valid
669  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
670  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged in)
671  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
672  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
673  * @retval #CKMC_ERROR_INVALID_FORMAT       The format of certificate is not valid
674  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
675  *
676  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
677  *
678  * @see ckmc_get_cert_chain())
679  * @see ckmc_cert_list_all_free()
680  */
681 int ckmc_get_cert_chain_with_alias(const ckmc_cert_s *cert, const ckmc_alias_list_s *untrustedcerts, ckmc_cert_list_s **ppcert_chain_list);
682
683 /**
684  * @brief Allows another application to access client's application data
685  *
686  * @since_tizen 2.3
687  * @privlevel public
688  * @privilege %http://tizen.org/privilege/keymanager
689  *
690  * @remarks Data identified by @a alias should exist
691  *
692  * @param[in] alias       Data alias for which access will be granted
693  * @param[in] accessor    Package id of the application that will gain access rights
694  * @param[in] granted     Rights granted for @a accessor application
695  *
696  * @return @c 0 on success, otherwise a negative error value
697  *
698  * @retval #CKMC_ERROR_NONE                 Successful
699  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
700  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged in)
701  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
702  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
703  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
704  *
705  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
706  *
707  * @see ckmc_deny_access()
708  */
709 int ckmc_allow_access(const char *alias, const char *accessor, ckmc_access_right_e granted);
710
711 /**
712  * @brief Revokes another application's access to client's application data
713  *
714  * @since_tizen 2.3
715  * @privlevel public
716  * @privilege %http://tizen.org/privilege/keymanager
717  *
718  * @remarks Data identified by @a alias should exist
719  * @remarks Only access previously granted with ckmc_allow_access can be revoked.
720  *
721  * @param[in] alias       Data alias for which access will be revoked
722  * @param[in] accessor    Package id of the application that will lose access rights
723  *
724  * @return @c 0 on success, otherwise a negative error value
725  *
726  * @retval #CKMC_ERROR_NONE                 Successful
727  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid or the @a accessor doesn't
728  *                                          have access to @a alias
729  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged in)
730  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
731  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
732  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
733  *
734  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
735  *
736  * @see ckmc_allow_access()
737  */
738 int ckmc_deny_access(const char *alias, const char *accessor);
739
740
741 #ifdef __cplusplus
742 }
743 #endif
744
745 /**
746  * @}
747  */
748
749
750 #endif /* __TIZEN_CORE_CKMC_MANAGER_H */