Modify the explanation of access control APIs in the doxygen document
[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  * @param[in] alias  The name of a certificate to be stored
183  * @param[in] cert   The certificate's binary value to be stored
184  * @param[in] policy The policy about how to store a certificate securely
185  *
186  * @return @c 0 on success,
187  *         otherwise a negative error value
188  *
189  * @retval #CKMC_ERROR_NONE               Successful
190  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
191  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
192  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
193  * @retval #CKMC_ERROR_INVALID_FORMAT     The format of raw_cert is not valid
194  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
195  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
196  *
197  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
198  *
199  * @see ckmc_remove_cert()
200  * @see ckmc_get_cert()
201  * @see ckmc_get_cert_alias_list()
202  * @see #ckmc_cert_s
203  * @see #ckmc_policy_s
204  */
205 int ckmc_save_cert(const char *alias, const ckmc_cert_s cert, const ckmc_policy_s policy);
206
207 /**
208  * @brief Removes a certificate from key manager.
209  *
210  * @since_tizen 2.3
211  * @privlevel public
212  * @privilege %http://tizen.org/privilege/keymanager
213  *
214  * @remarks A client can remove only certificates stored by the client.
215  *
216  * @param[in] alias The name of a certificate to be removed
217  *
218  * @return @c 0 on success,
219  *         otherwise a negative error value
220  *
221  * @retval #CKMC_ERROR_NONE               Successful
222  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
223  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
224  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
225  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
226  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
227  *
228  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
229  *
230  * @see ckmc_save_cert()
231  * @see ckmc_get_cert()
232  * @see ckmc_get_cert_alias_list()
233  */
234 int ckmc_remove_cert(const char *alias);
235
236 /**
237  * @brief Gets a certificate from key manager.
238  *
239  * @since_tizen 2.3
240  * @privlevel public
241  * @privilege %http://tizen.org/privilege/keymanager
242  *
243  * @remarks A client can access only certificate stored by the client.
244  * @remarks You must destroy the newly created @a ppcert by calling ckmc_cert_free() if it is no longer needed.
245  *
246  * @param[in] alias    The name of a certificate to retrieve
247  * @param[in] password The password used in decrypting a certificate value \n
248  *                     If password of policy is provided in ckmc_save_cert(), the same password should be provided.
249  * @param[out] ppcert  The pointer to a newly created ckmc_cert_s handle
250  *
251  * @return @c 0 on success,
252  *         otherwise a negative error value
253  *
254  * @retval #CKMC_ERROR_NONE               Successful
255  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
256  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
257  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
258  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exists
259  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
260  *
261  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
262  *
263  * @see ckmc_save_cert()
264  * @see ckmc_remove_cert()
265  * @see ckmc_get_cert_alias_list()
266  */
267 int ckmc_get_cert(const char *alias, const char *password, ckmc_cert_s **ppcert);
268
269 /**
270  * @brief Gets all alias of certificates which the client can access.
271  *
272  * @since_tizen 2.3
273  * @privlevel public
274  * @privilege %http://tizen.org/privilege/keymanager
275  *
276  * @remarks A client can access only data stored by the client.
277  * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free() if it is no longer needed.
278  *
279  * @param[out] ppalias_list The pointer to a newly created ckmc_alias_list_s handle containing all available alias of keys \n
280  *                          If there is no available key alias, *ppalias_list will be null.
281  *
282  * @return @c 0 on success,
283  *         otherwise a negative error value
284  *
285  * @retval #CKMC_ERROR_NONE               Successful
286  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
287  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
288  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
289  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
290  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
291  *
292  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
293  *
294  * @see ckmc_save_cert()
295  * @see ckmc_remove_cert()
296  * @see ckmc_get_cert()
297  */
298 int ckmc_get_cert_alias_list(ckmc_alias_list_s** ppalias_list);
299
300
301
302
303 /**
304  * @brief Stores a data inside key manager based on the provided policy.
305  *
306  * @since_tizen 2.3
307  * @privlevel public
308  * @privilege %http://tizen.org/privilege/keymanager
309  *
310  * @param[in] alias  The name of a data to be stored
311  * @param[in] data   The binary value to be stored
312  * @param[in] policy The policy about how to store a data securely
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 in)
320  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
321  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
322  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
323  *
324  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
325  *
326  * @see ckmc_remove_data()
327  * @see ckmc_get_data()
328  * @see ckmc_get_data_alias_list()
329  * @see #ckmc_raw_buffer_s
330  * @see #ckmc_policy_s
331  */
332 int ckmc_save_data(const char *alias, ckmc_raw_buffer_s data, const ckmc_policy_s policy);
333
334 /**
335  * @brief Removes a data from key manager.
336  *
337  * @since_tizen 2.3
338  * @privlevel public
339  * @privilege %http://tizen.org/privilege/keymanager
340  *
341  * @remarks A client can remove only data stored by the client.
342  *
343  * @param[in] alias The name of a data to be removed
344  *
345  * @return @c 0 on success,
346  *         otherwise a negative error value
347  *
348  * @retval #CKMC_ERROR_NONE               Successful
349  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
350  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
351  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
352  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
353  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
354  *
355  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
356  *
357  * @see ckmc_save_data()
358  * @see ckmc_get_data()
359  * @see ckmc_get_data_alias_list()
360  */
361 int ckmc_remove_data(const char *alias);
362
363 /**
364  * @brief Gets a data from key manager.
365  *
366  * @since_tizen 2.3
367  * @privlevel public
368  * @privilege %http://tizen.org/privilege/keymanager
369  *
370  * @remarks A client can access only data stored by the client.
371  * @remarks You must destroy the newly created @a ppdata by calling ckmc_buffer_free() if it is no longer needed.
372  *
373  * @param[in]  alias     The name of a data to retrieve
374  * @param[in]  password  The password used in decrypting a data value \n
375  *                       If password of policy is provided in ckmc_save_data(), the same password should be provided.
376  * @param[out] ppdata    The pointer to a newly created ckmc_raw_buffer_s handle
377  *
378  * @return @c 0 on success,
379  *         otherwise a negative error value
380  *
381  * @retval #CKMC_ERROR_NONE               Successful
382  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
383  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
384  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
385  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
386  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
387  *
388  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
389  *
390  * @see ckmc_save_data()
391  * @see ckmc_remove_data()
392  * @see ckmc_get_data_alias_list()
393  */
394 int ckmc_get_data(const char *alias, const char *password, ckmc_raw_buffer_s **ppdata);
395
396 /**
397  * @brief Gets all alias of data which the client can access.
398  *
399  * @since_tizen 2.3
400  * @privlevel public
401  * @privilege %http://tizen.org/privilege/keymanager
402  *
403  * @remarks A client can access only data stored by the client.
404  * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free() if it is no longer needed.
405  *
406  * @param[out] ppalias_list The pointer to a newly created ckmc_alias_list_s handle containing all available alias of keys \n
407  *                          If there is no available key alias, *ppalias_list will be null.
408  *
409  * @return @c 0 on success,
410  *         otherwise a negative error value
411  *
412  * @retval #CKMC_ERROR_NONE               Successful
413  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
414  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
415  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
416  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
417  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
418  *
419  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
420  *
421  * @see ckmc_save_data()
422  * @see ckmc_remove_data()
423  * @see ckmc_get_data()
424  */
425 int ckmc_get_data_alias_list(ckmc_alias_list_s** ppalias_list);
426
427
428
429
430 /**
431  * @brief Creates RSA private/public key pair and stores them inside key manager based on each policy.
432  *
433  * @since_tizen 2.3
434  * @privlevel public
435  * @privilege %http://tizen.org/privilege/keymanager
436  *
437  * @remarks If password in policy is provided, the key is additionally encrypted with the password in policy.
438  *
439  * @param[in] size                The size of key strength to be created \n
440  *                                @c 1024, @c 2048, and @c 4096 are supported.
441  * @param[in] private_key_alias   The name of private key to be stored
442  * @param[in] public_key_alias    The name of public key to be stored
443  * @param[in] policy_private_key  The policy about how to store a private key securely
444  * @param[in] policy_public_key   The policy about how to store a public key securely
445  *
446  * @return @c 0 on success,
447  *         otherwise a negative error value
448  *
449  * @retval #CKMC_ERROR_NONE               Successful
450  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
451  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
452  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
453  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
454  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
455  *
456  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
457  *
458  * @see ckmc_create_key_pair_dsa()
459  * @see ckmc_create_key_pair_ecdsa()
460  * @see ckmc_create_signature()
461  * @see ckmc_verify_signature()
462  */
463 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);
464
465 /**
466  * @brief Creates DSA private/public key pair and stores them inside key manager based on each policy.
467  *
468  * @since_tizen 2.3
469  * @privlevel public
470  * @privilege %http://tizen.org/privilege/keymanager
471  *
472  * @remarks If password in policy is provided, the key is additionally encrypted with the password in policy.
473  *
474  * @param[in] size                The size of key strength to be created \n
475  *                                @c 1024, @c 2048, @c 3072 and @c 4096 are supported.
476  * @param[in] private_key_alias   The name of private key to be stored
477  * @param[in] public_key_alias    The name of public key to be stored
478  * @param[in] policy_private_key  The policy about how to store a private key securely
479  * @param[in] policy_public_key   The policy about how to store a public key securely
480  *
481  * @return @c 0 on success,
482  *         otherwise a negative error value
483  *
484  * @retval #CKMC_ERROR_NONE               Successful
485  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
486  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
487  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
488  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
489  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
490  *
491  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
492  *
493  * @see ckmc_create_key_pair_rsa()
494  * @see ckmc_create_key_pair_ecdsa()
495  * @see ckmc_create_signature()
496  * @see ckmc_verify_signature()
497  */
498 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);
499
500 /**
501  * @brief Creates ECDSA private/public key pair and stores them inside key manager based on each policy.
502  *
503  * @since_tizen 2.3
504  * @privlevel public
505  * @privilege %http://tizen.org/privilege/keymanager
506  *
507  * @remarks If password in policy is provided, the key is additionally encrypted with the password in policy.
508  *
509  * @param[in] type                The type of elliptic curve of ECDSA
510  * @param[in] private_key_alias   The name of private key to be stored
511  * @param[in] public_key_alias    The name of public key to be stored
512  * @param[in] policy_private_key  The policy about how to store a private key securely
513  * @param[in] policy_public_key   The policy about how to store a public key securely
514  *
515  * @return @c 0 on success,
516  *         otherwise a negative error value
517  *
518  * @retval #CKMC_ERROR_NONE               Successful
519  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
520  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
521  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
522  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
523  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
524  *
525  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
526  *
527  * @see ckmc_create_key_pair_rsa()
528  * @see ckmc_create_key_pair_dsa()
529  * @see ckmc_create_signature()
530  * @see ckmc_verify_signature()
531  * @see #ckmc_ec_type_e
532  */
533 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);
534
535 /**
536  * @brief Creates a signature on a given message using a private key and returns the signature.
537  *
538  * @since_tizen 2.3
539  * @privlevel public
540  * @privilege %http://tizen.org/privilege/keymanager
541  *
542  * @remarks If password of policy is provided during storing a key, the same password should be provided.
543  * @remarks You must destroy the newly created @a ppsignature by calling ckmc_buffer_free() if it is no longer needed.
544  *
545  * @param[in]  private_key_alias  The name of private key
546  * @param[in]  password           The password used in decrypting a private key value
547  * @param[in]  message            The message that is signed with a private key
548  * @param[in]  hash               The hash algorithm used in creating signature
549  * @param[in]  padding            The RSA padding algorithm used in creating signature \n
550  *                                It is used only when the signature algorithm is RSA.
551  * @param[out] ppsignature        The pointer to a newly created signature \n
552  *                                If an error occurs, @a *ppsignature will be null.
553  *
554  * @return @c 0 on success,
555  *         otherwise a negative error value
556  *
557  * @retval #CKMC_ERROR_NONE               Successful
558  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
559  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
560  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
561  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
562  *
563  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
564  *
565  * @see ckmc_create_key_pair_rsa()
566  * @see ckmc_create_key_pair_ecdsa()
567  * @see ckmc_verify_signature()
568  * @see ckmc_buffer_free()
569  * @see #ckmc_hash_algo_e
570  * @see #ckmc_rsa_padding_algo_e
571  */
572 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);
573
574 /**
575  * @brief Verifies a given signature on a given message using a public key and returns the signature status.
576  *
577  * @since_tizen 2.3
578  * @privlevel public
579  * @privilege %http://tizen.org/privilege/keymanager
580  *
581  * @remarks If password of policy is provided during storing a key, the same password should be provided.
582  *
583  * @param[in] public_key_alias  The name of public key
584  * @param[in] password          The password used in decrypting a public key value
585  * @param[in] message           The input on which the signature is created
586  * @param[in] signature         The signature that is verified with public key
587  * @param[in] hash              The hash algorithm used in verifying signature
588  * @param[in] padding           The RSA padding algorithm used in verifying signature \n
589  *                              It is used only when the signature algorithm is RSA.
590  *
591  * @return @c 0 on success and the signature is valid,
592  *         otherwise a negative error value
593  *
594  * @retval #CKMC_ERROR_NONE                 Successful
595  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The signature is invalid
596  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
597  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged in)
598  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
599  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
600  *
601  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
602  *
603  * @see ckmc_create_key_pair_rsa()
604  * @see ckmc_create_key_pair_ecdsa()
605  * @see ckmc_verify_signature()
606  * @see #ckmc_hash_algo_e
607  * @see #ckmc_rsa_padding_algo_e
608  */
609 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);
610
611 /**
612  * @brief Verifies a certificate chain and returns that chain.
613  *
614  * @since_tizen 2.3
615  * @privlevel public
616  * @privilege %http://tizen.org/privilege/keymanager
617  *
618  * @remarks The trusted root certificate of the chain should exist in the system's certificate storage.
619  * @remarks You must destroy the newly created @a ppcert_chain_list by calling ckmc_cert_list_all_free() if it is no longer needed.
620  *
621  * @param[in] cert               The certificate to be verified
622  * @param[in] untrustedcerts     The untrusted CA certificates to be used in verifying a certificate chain
623  * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n
624  *                               If an error occurs, @a *ppcert_chain_list will be null.
625  *
626  * @return @c 0 on success and the signature is valid,
627  *         otherwise a negative error value
628  *
629  * @retval #CKMC_ERROR_NONE                 Successful
630  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The certificate chain is not valid
631  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
632  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged in)
633  * @retval #CKMC_ERROR_INVALID_FORMAT       The format of certificate is not valid
634  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
635  *
636  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
637  *
638  * @see ckmc_get_cert_chain_with_alias())
639  * @see ckmc_cert_list_all_free()
640  */
641 int ckmc_get_cert_chain(const ckmc_cert_s *cert, const ckmc_cert_list_s *untrustedcerts, ckmc_cert_list_s **ppcert_chain_list);
642
643 /**
644  * @brief Verifies a certificate chain using an alias list of untrusted certificates and return that chain.
645  *
646  * @since_tizen 2.3
647  * @privlevel public
648  * @privilege %http://tizen.org/privilege/keymanager
649  *
650  * @remarks The trusted root certificate of the chain should exist in the system's certificate storage.
651  * @remarks You must destroy the newly created @a ppcert_chain_list by calling ckmc_cert_list_all_free() if it is no longer needed.
652  *
653  * @param[in] cert               The certificate to be verified
654  * @param[in] untrustedcerts     The alias list of untrusted CA certificates stored in key manager to be used in verifying a certificate chain
655  * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n
656  *                               If an error occurs, @a *ppcert_chain_list will be null.
657  *
658  * @return @c 0 on success and the signature is valid,
659  *         otherwise a negative error value
660  *
661  * @retval #CKMC_ERROR_NONE                 Successful
662  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The certificate chain is not valid
663  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
664  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged in)
665  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
666  * @retval #CKMC_ERROR_INVALID_FORMAT       The format of certificate is not valid
667  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
668  *
669  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
670  *
671  * @see ckmc_get_cert_chain())
672  * @see ckmc_cert_list_all_free()
673  */
674 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);
675
676 /**
677  * @brief Allows another application to access client's application data
678  *
679  * @since_tizen 2.3
680  * @privlevel public
681  * @privilege %http://tizen.org/privilege/keymanager
682  *
683  * @remarks Data identified by @a alias should exist
684  *
685  * @param[in] alias       Data alias for which access will be granted
686  * @param[in] accessor    Package id of the application that will gain access rights
687  * @param[in] granted     Rights granted for @a accessor application
688  *
689  * @return @c 0 on success, 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 in)
694  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
695  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
696  *
697  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
698  *
699  * @see ckmc_deny_access()
700  */
701 int ckmc_allow_access(const char *alias, const char *accessor, ckmc_access_right_e granted);
702
703 /**
704  * @brief Revokes another application's access to client's application data
705  *
706  * @since_tizen 2.3
707  * @privlevel public
708  * @privilege %http://tizen.org/privilege/keymanager
709  *
710  * @remarks Data identified by @a alias should exist
711  * @remarks Only access previously granted with ckmc_allow_access can be revoked.
712  *
713  * @param[in] alias       Data alias for which access will be revoked
714  * @param[in] accessor    Package id of the application that will lose access rights
715  *
716  * @return @c 0 on success, otherwise a negative error value
717  *
718  * @retval #CKMC_ERROR_NONE                 Successful
719  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid or the @a accessor doesn't
720  *                                          have access to @a alias
721  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged in)
722  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
723  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
724  *
725  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
726  *
727  * @see ckmc_allow_access()
728  */
729 int ckmc_deny_access(const char *alias, const char *accessor);
730
731
732 #ifdef __cplusplus
733 }
734 #endif
735
736 /**
737  * @}
738  */
739
740
741 #endif /* __TIZEN_CORE_CKMC_MANAGER_H */