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