CAPI cleanup: control "owner" removal, set_permission replaces allow_access.
[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 a database error
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 To remove key, client must have remove permission to the specified key.
87  * @remarks The key owner can remove by default.
88  *
89  * @param[in] alias The name of a key to be removed
90  *
91  * @return @c 0 on success,
92  *         otherwise a negative error value
93  *
94  * @retval #CKMC_ERROR_NONE              Successful
95  * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
96  * @retval #CKMC_ERROR_DB_LOCKED         A user key is not loaded in memory (a user is not logged in)
97  * @retval #CKMC_ERROR_DB_ERROR          Failed due to a database error
98  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN  Alias does not exist
99  * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
100  *
101  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
102  *
103  * @see ckmc_save_key()
104  * @see ckmc_get_key()
105  * @see ckmc_get_key_alias_list()
106  */
107 int ckmc_remove_key(const char *alias);
108
109 /**
110  * @brief Gets a key from key manager.
111  *
112  * @since_tizen 2.3
113  * @privlevel public
114  * @privilege %http://tizen.org/privilege/keymanager
115  *
116  * @remarks A client can access only data stored by the client.
117  * @remarks You must destroy the newly created @a ppkey by calling ckmc_key_free() if it is no longer needed.
118  *
119  * @param[in] alias     The name of a key to retrieve
120  * @param[in] password  The password used in decrypting a key value \n
121  *                      If password of policy is provided in ckmc_save_key(), the same password should be provided.
122  * @param[out] ppkey    The pointer to a newly created ckmc_key_s handle
123  *
124  * @return @c 0 on success,
125  *         otherwise a negative error value
126  *
127  * @retval #CKMC_ERROR_NONE              Successful
128  * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
129  * @retval #CKMC_ERROR_DB_LOCKED         A user key is not loaded in memory (a user is not logged in)
130  * @retval #CKMC_ERROR_DB_ERROR          Failed due to a database error
131  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN  Alias does not exist
132  * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
133  *
134  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
135  *
136  * @see ckmc_save_key()
137  * @see ckmc_remove_key()
138  * @see ckmc_get_key_alias_list()
139  */
140 int ckmc_get_key(const char *alias, const char *password, ckmc_key_s **ppkey);
141
142 /**
143  * @brief Gets all the alias of keys that the client can access.
144  *
145  * @since_tizen 2.3
146  * @privlevel public
147  * @privilege %http://tizen.org/privilege/keymanager
148  *
149  * @remarks A client can access only data stored by the client.
150  * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free() if it is no longer needed.
151  *
152  * @param[out] ppalias_list  The pointer to a newly created ckmc_alias_list_s handle containing all available alias of keys \n
153  *                           If there is no available key alias, *ppalias_list will be null.
154  *
155  * @return @c 0 on success,
156  *         otherwise a negative error value
157  *
158  * @retval #CKMC_ERROR_NONE              Successful
159  * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
160  * @retval #CKMC_ERROR_DB_LOCKED         A user key is not loaded in memory (a user is not logged in)
161  * @retval #CKMC_ERROR_DB_ERROR          Failed due to a database error
162  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN  Alias does not exist
163  * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
164  *
165  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
166  *
167  * @see ckmc_save_key()
168  * @see ckmc_remove_key()
169  * @see ckmc_get_key()
170  */
171 int ckmc_get_key_alias_list(ckmc_alias_list_s** ppalias_list);
172
173
174
175
176 /**
177  * @brief Stores a certificate inside key manager based on the provided policy.
178  *
179  * @since_tizen 2.3
180  * @privlevel public
181  * @privilege %http://tizen.org/privilege/keymanager
182  *
183  * @remarks the certificate's binary value will be converted and saved as binary DER encoded certificates.
184  *
185  * @param[in] alias  The name of a certificate to be stored
186  * @param[in] cert   The certificate's binary value to be stored
187  * @param[in] policy The policy about how to store a certificate securely
188  *
189  * @return @c 0 on success,
190  *         otherwise a negative error value
191  *
192  * @retval #CKMC_ERROR_NONE               Successful
193  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
194  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
195  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
196  * @retval #CKMC_ERROR_INVALID_FORMAT     The format of raw_cert is not valid
197  * @retval #CKMC_ERROR_DB_ERROR           Failed due to a database error
198  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
199  *
200  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
201  *
202  * @see ckmc_remove_cert()
203  * @see ckmc_get_cert()
204  * @see ckmc_get_cert_alias_list()
205  * @see #ckmc_cert_s
206  * @see #ckmc_policy_s
207  */
208 int ckmc_save_cert(const char *alias, const ckmc_cert_s cert, const ckmc_policy_s policy);
209
210 /**
211  * @brief Removes a certificate from key manager.
212  *
213  * @since_tizen 2.3
214  * @privlevel public
215  * @privilege %http://tizen.org/privilege/keymanager
216  *
217  * @remarks To remove certificate, client must have remove permission to the specified certificate.
218  * @remarks The key owner can remove by default.
219  *
220  * @param[in] alias The name of a certificate to be removed
221  *
222  * @return @c 0 on success,
223  *         otherwise a negative error value
224  *
225  * @retval #CKMC_ERROR_NONE               Successful
226  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
227  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
228  * @retval #CKMC_ERROR_DB_ERROR           Failed due to a database error
229  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
230  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
231  *
232  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
233  *
234  * @see ckmc_save_cert()
235  * @see ckmc_get_cert()
236  * @see ckmc_get_cert_alias_list()
237  */
238 int ckmc_remove_cert(const char *alias);
239
240 /**
241  * @brief Gets a certificate from key manager.
242  *
243  * @since_tizen 2.3
244  * @privlevel public
245  * @privilege %http://tizen.org/privilege/keymanager
246  *
247  * @remarks A client can access only certificate stored by the client.
248  * @remarks A DER encoded certificate will be returned as a return value.
249  * @remarks You must destroy the newly created @a ppcert by calling ckmc_cert_free() if it is no longer needed.
250  *
251  * @param[in] alias    The name of a certificate to retrieve
252  * @param[in] password The password used in decrypting a certificate value \n
253  *                     If password of policy is provided in ckmc_save_cert(), the same password should be provided.
254  * @param[out] ppcert  The pointer to a newly created ckmc_cert_s handle
255  *
256  * @return @c 0 on success,
257  *         otherwise a negative error value
258  *
259  * @retval #CKMC_ERROR_NONE               Successful
260  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
261  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
262  * @retval #CKMC_ERROR_DB_ERROR           Failed due to a database error
263  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exists
264  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
265  *
266  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
267  *
268  * @see ckmc_save_cert()
269  * @see ckmc_remove_cert()
270  * @see ckmc_get_cert_alias_list()
271  */
272 int ckmc_get_cert(const char *alias, const char *password, ckmc_cert_s **ppcert);
273
274 /**
275  * @brief Gets all alias of certificates which the client can access.
276  *
277  * @since_tizen 2.3
278  * @privlevel public
279  * @privilege %http://tizen.org/privilege/keymanager
280  *
281  * @remarks A client can access only data stored by the client.
282  * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free() if it is no longer needed.
283  *
284  * @param[out] ppalias_list The pointer to a newly created ckmc_alias_list_s handle containing all available alias of keys \n
285  *                          If there is no available key alias, *ppalias_list will be null.
286  *
287  * @return @c 0 on success,
288  *         otherwise a negative error value
289  *
290  * @retval #CKMC_ERROR_NONE               Successful
291  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
292  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
293  * @retval #CKMC_ERROR_DB_ERROR           Failed due to a database error
294  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
295  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
296  *
297  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
298  *
299  * @see ckmc_save_cert()
300  * @see ckmc_remove_cert()
301  * @see ckmc_get_cert()
302  */
303 int ckmc_get_cert_alias_list(ckmc_alias_list_s** ppalias_list);
304
305
306
307
308 /**
309  * @brief Stores PKCS12's contents inside key manager based on the provided policies.
310  * All items from the PKCS12 will use the same alias.
311  *
312  * @since_tizen 2.3
313  * @privlevel public
314  * @privilege %http://tizen.org/privilege/keymanager
315  *
316  * @param[in] alias         The name of a data to be stored
317  * @param[in] pkcs          Pointer to the pkcs12 structure to be saved
318  * @param[in] key_policy    The policy about how to store pkcs's private key
319  * @param[in] cert_policy   The policy about how to store pkcs's certificate
320  *
321  * @return @c 0 on success,
322  *         otherwise a negative error value
323  *
324  * @retval #CKMC_ERROR_NONE               Successful
325  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
326  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
327  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
328  * @retval #CKMC_ERROR_DB_ERROR           Failed due to a database error
329  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
330  *
331  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
332  *
333  * @see ckmc_remove_pkcs12()
334  * @see ckmc_get_pkcs12()
335  * @see ckmc_get_data_alias_list()
336  * @see ckmc_load_from_pkcs12_file2()
337  * @see #ckmc_pkcs12_s
338  * @see #ckmc_policy_s
339  */
340 int ckmc_save_pkcs12(const char *alias, const ckmc_pkcs12_s *pkcs, const ckmc_policy_s key_policy, const ckmc_policy_s cert_policy);
341
342 /**
343  * @brief Removes all PKCS12 contents from key manager.
344  *
345  * @since_tizen 2.3
346  * @privlevel public
347  * @privilege %http://tizen.org/privilege/keymanager
348  *
349  * @remarks To remove PKCS12, client must have remove permission to the specified PKCS12 object.
350  * @remarks The key owner can remove by default.
351  *
352  * @param[in] alias The name of PKCS12 to be removed
353  *
354  * @return @c 0 on success,
355  *         otherwise a negative error value
356  *
357  * @retval #CKMC_ERROR_NONE               Successful
358  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
359  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
360  * @retval #CKMC_ERROR_DB_ERROR           Failed due to a database error
361  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
362  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
363  *
364  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
365  *
366  * @see ckmc_save_pkcs12()
367  * @see ckmc_get_pkcs12()
368  */
369 int ckmc_remove_pkcs12(const char *alias);
370
371 /**
372  * @brief Gets a pkcs12 from key manager.
373  *
374  * @since_tizen 2.3
375  * @privlevel public
376  * @privilege %http://tizen.org/privilege/keymanager
377  *
378  * @remarks A client can access only data stored by the client.
379  * @remarks You must destroy the newly created @a pkcs12 by calling ckmc_pkcs12_free() if it is no longer needed.
380  *
381  * @param[in]  alias     The name of a data to retrieve
382  * @param[out] pkcs12    The pointer to a newly created ckmc_pkcs12_s handle
383  *
384  * @return @c 0 on success,
385  *         otherwise a negative error value
386  *
387  * @retval #CKMC_ERROR_NONE               Successful
388  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
389  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
390  * @retval #CKMC_ERROR_DB_ERROR           Failed due to a database error
391  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
392  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
393  *
394  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
395  *
396  * @see ckmc_save_pkcs12()
397  * @see ckmc_remove_pkcs12()
398  */
399 int ckmc_get_pkcs12(const char *alias, ckmc_pkcs12_s **pkcs12);
400
401
402
403
404 /**
405  * @brief Stores a data inside key manager based on the provided policy.
406  *
407  * @since_tizen 2.3
408  * @privlevel public
409  * @privilege %http://tizen.org/privilege/keymanager
410  *
411  * @param[in] alias  The name of a data to be stored
412  * @param[in] data   The binary value to be stored
413  * @param[in] policy The policy about how to store a data securely
414  *
415  * @return @c 0 on success,
416  *         otherwise a negative error value
417  *
418  * @retval #CKMC_ERROR_NONE               Successful
419  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
420  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
421  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
422  * @retval #CKMC_ERROR_DB_ERROR           Failed due to a database error
423  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
424  *
425  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
426  *
427  * @see ckmc_remove_data()
428  * @see ckmc_get_data()
429  * @see ckmc_get_data_alias_list()
430  * @see #ckmc_raw_buffer_s
431  * @see #ckmc_policy_s
432  */
433 int ckmc_save_data(const char *alias, ckmc_raw_buffer_s data, const ckmc_policy_s policy);
434
435 /**
436  * @brief Removes a data from key manager.
437  *
438  * @since_tizen 2.3
439  * @privlevel public
440  * @privilege %http://tizen.org/privilege/keymanager
441  *
442  * @remarks To remove data, client must have remove permission to the specified data object.
443  * @remarks The data owner can remove by default.
444  *
445  * @param[in] alias The name of a data to be removed
446  *
447  * @return @c 0 on success,
448  *         otherwise a negative error value
449  *
450  * @retval #CKMC_ERROR_NONE               Successful
451  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
452  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
453  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
454  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
455  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
456  *
457  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
458  *
459  * @see ckmc_save_data()
460  * @see ckmc_get_data()
461  * @see ckmc_get_data_alias_list()
462  */
463 int ckmc_remove_data(const char *alias);
464
465 /**
466  * @brief Gets a data from key manager.
467  *
468  * @since_tizen 2.3
469  * @privlevel public
470  * @privilege %http://tizen.org/privilege/keymanager
471  *
472  * @remarks A client can access only data stored by the client.
473  * @remarks You must destroy the newly created @a ppdata by calling ckmc_buffer_free() if it is no longer needed.
474  *
475  * @param[in]  alias     The name of a data to retrieve
476  * @param[in]  password  The password used in decrypting a data value \n
477  *                       If password of policy is provided in ckmc_save_data(), the same password should be provided.
478  * @param[out] ppdata    The pointer to a newly created ckmc_raw_buffer_s handle
479  *
480  * @return @c 0 on success,
481  *         otherwise a negative error value
482  *
483  * @retval #CKMC_ERROR_NONE               Successful
484  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
485  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
486  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
487  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
488  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
489  *
490  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
491  *
492  * @see ckmc_save_data()
493  * @see ckmc_remove_data()
494  * @see ckmc_get_data_alias_list()
495  */
496 int ckmc_get_data(const char *alias, const char *password, ckmc_raw_buffer_s **ppdata);
497
498 /**
499  * @brief Gets all alias of data which the client can access.
500  *
501  * @since_tizen 2.3
502  * @privlevel public
503  * @privilege %http://tizen.org/privilege/keymanager
504  *
505  * @remarks A client can access only data stored by the client.
506  * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free() if it is no longer needed.
507  *
508  * @param[out] ppalias_list The pointer to a newly created ckmc_alias_list_s handle containing all available alias of keys \n
509  *                          If there is no available key alias, *ppalias_list will be null.
510  *
511  * @return @c 0 on success,
512  *         otherwise a negative error value
513  *
514  * @retval #CKMC_ERROR_NONE               Successful
515  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
516  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
517  * @retval #CKMC_ERROR_DB_ERROR           Failed due to the error with unknown reason
518  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
519  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
520  *
521  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
522  *
523  * @see ckmc_save_data()
524  * @see ckmc_remove_data()
525  * @see ckmc_get_data()
526  */
527 int ckmc_get_data_alias_list(ckmc_alias_list_s** ppalias_list);
528
529
530
531
532 /**
533  * @brief Creates RSA private/public key pair and stores them inside key manager based on each policy.
534  *
535  * @since_tizen 2.3
536  * @privlevel public
537  * @privilege %http://tizen.org/privilege/keymanager
538  *
539  * @remarks If password in policy is provided, the key is additionally encrypted with the password in policy.
540  *
541  * @param[in] size                The size of key strength to be created \n
542  *                                @c 1024, @c 2048, and @c 4096 are supported.
543  * @param[in] private_key_alias   The name of private key to be stored
544  * @param[in] public_key_alias    The name of public key to be stored
545  * @param[in] policy_private_key  The policy about how to store a private key securely
546  * @param[in] policy_public_key   The policy about how to store a public key securely
547  *
548  * @return @c 0 on success,
549  *         otherwise a negative error value
550  *
551  * @retval #CKMC_ERROR_NONE               Successful
552  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
553  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
554  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
555  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
556  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
557  *
558  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
559  *
560  * @see ckmc_create_key_pair_dsa()
561  * @see ckmc_create_key_pair_ecdsa()
562  * @see ckmc_create_signature()
563  * @see ckmc_verify_signature()
564  */
565 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);
566
567 /**
568  * @brief Creates DSA private/public key pair and stores them inside key manager based on each policy.
569  *
570  * @since_tizen 2.3
571  * @privlevel public
572  * @privilege %http://tizen.org/privilege/keymanager
573  *
574  * @remarks If password in policy is provided, the key is additionally encrypted with the password in policy.
575  *
576  * @param[in] size                The size of key strength to be created \n
577  *                                @c 1024, @c 2048, @c 3072 and @c 4096 are supported.
578  * @param[in] private_key_alias   The name of private key to be stored
579  * @param[in] public_key_alias    The name of public key to be stored
580  * @param[in] policy_private_key  The policy about how to store a private key securely
581  * @param[in] policy_public_key   The policy about how to store a public key securely
582  *
583  * @return @c 0 on success,
584  *         otherwise a negative error value
585  *
586  * @retval #CKMC_ERROR_NONE               Successful
587  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
588  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
589  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
590  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
591  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
592  *
593  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
594  *
595  * @see ckmc_create_key_pair_rsa()
596  * @see ckmc_create_key_pair_ecdsa()
597  * @see ckmc_create_signature()
598  * @see ckmc_verify_signature()
599  */
600 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);
601
602 /**
603  * @brief Creates ECDSA private/public key pair and stores them inside key manager based on each policy.
604  *
605  * @since_tizen 2.3
606  * @privlevel public
607  * @privilege %http://tizen.org/privilege/keymanager
608  *
609  * @remarks If password in policy is provided, the key is additionally encrypted with the password in policy.
610  *
611  * @param[in] type                The type of elliptic curve of ECDSA
612  * @param[in] private_key_alias   The name of private key to be stored
613  * @param[in] public_key_alias    The name of public key to be stored
614  * @param[in] policy_private_key  The policy about how to store a private key securely
615  * @param[in] policy_public_key   The policy about how to store a public key securely
616  *
617  * @return @c 0 on success,
618  *         otherwise a negative error value
619  *
620  * @retval #CKMC_ERROR_NONE               Successful
621  * @retval #CKMC_ERROR_INVALID_PARAMETER  Input parameter is invalid
622  * @retval #CKMC_ERROR_DB_LOCKED          A user key is not loaded in memory (a user is not logged in)
623  * @retval #CKMC_ERROR_DB_ALIAS_EXISTS    Alias already exists
624  * @retval #CKMC_ERROR_DB_ERROR           Failed due to other DB transaction unexpectedly
625  * @retval #CKMC_ERROR_PERMISSION_DENIED  Failed to access key manager
626  *
627  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
628  *
629  * @see ckmc_create_key_pair_rsa()
630  * @see ckmc_create_key_pair_dsa()
631  * @see ckmc_create_signature()
632  * @see ckmc_verify_signature()
633  * @see #ckmc_ec_type_e
634  */
635 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);
636
637 /**
638  * @brief Creates a signature on a given message using a private key and returns the signature.
639  *
640  * @since_tizen 2.3
641  * @privlevel public
642  * @privilege %http://tizen.org/privilege/keymanager
643  *
644  * @remarks If password of policy is provided during storing a key, the same password should be provided.
645  * @remarks You must destroy the newly created @a ppsignature by calling ckmc_buffer_free() if it is no longer needed.
646  *
647  * @param[in]  private_key_alias  The name of private key
648  * @param[in]  password           The password used in decrypting a private key value
649  * @param[in]  message            The message that is signed with a private key
650  * @param[in]  hash               The hash algorithm used in creating signature
651  * @param[in]  padding            The RSA padding algorithm used in creating signature \n
652  *                                It is used only when the signature algorithm is RSA.
653  * @param[out] ppsignature        The pointer to a newly created signature \n
654  *                                If an error occurs, @a *ppsignature will be null.
655  *
656  * @return @c 0 on success,
657  *         otherwise a negative error value
658  *
659  * @retval #CKMC_ERROR_NONE               Successful
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_ERROR           Failed due to the error with unknown reason
663  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN   Alias does not exist
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_create_key_pair_rsa()
669  * @see ckmc_create_key_pair_ecdsa()
670  * @see ckmc_verify_signature()
671  * @see ckmc_buffer_free()
672  * @see #ckmc_hash_algo_e
673  * @see #ckmc_rsa_padding_algo_e
674  */
675 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);
676
677 /**
678  * @brief Verifies a given signature on a given message using a public key and returns the signature status.
679  *
680  * @since_tizen 2.3
681  * @privlevel public
682  * @privilege %http://tizen.org/privilege/keymanager
683  *
684  * @remarks If password of policy is provided during storing a key, the same password should be provided.
685  *
686  * @param[in] public_key_alias  The name of public key
687  * @param[in] password          The password used in decrypting a public key value
688  * @param[in] message           The input on which the signature is created
689  * @param[in] signature         The signature that is verified with public key
690  * @param[in] hash              The hash algorithm used in verifying signature
691  * @param[in] padding           The RSA padding algorithm used in verifying signature \n
692  *                              It is used only when the signature algorithm is RSA.
693  *
694  * @return @c 0 on success and the signature is valid,
695  *         otherwise a negative error value
696  *
697  * @retval #CKMC_ERROR_NONE                 Successful
698  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The signature is invalid
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_create_key_pair_rsa()
708  * @see ckmc_create_key_pair_ecdsa()
709  * @see ckmc_verify_signature()
710  * @see #ckmc_hash_algo_e
711  * @see #ckmc_rsa_padding_algo_e
712  */
713 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);
714
715 /**
716  * @brief Verifies a certificate chain and returns that chain.
717  *
718  * @since_tizen 2.3
719  * @privlevel public
720  * @privilege %http://tizen.org/privilege/keymanager
721  *
722  * @remarks The trusted root certificate of the chain should exist in the system's certificate storage.
723  * @remarks You must destroy the newly created @a ppcert_chain_list by calling ckmc_cert_list_all_free() if it is no longer needed.
724  *
725  * @param[in] cert               The certificate to be verified
726  * @param[in] untrustedcerts     The untrusted CA certificates to be used in verifying a certificate chain
727  * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n
728  *                               If an error occurs, @a *ppcert_chain_list will be null.
729  *
730  * @return @c 0 on success and the signature is valid,
731  *         otherwise a negative error value
732  *
733  * @retval #CKMC_ERROR_NONE                 Successful
734  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The certificate chain is not valid
735  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
736  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged in)
737  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
738  * @retval #CKMC_ERROR_INVALID_FORMAT       The format of certificate is not valid
739  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
740  *
741  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
742  *
743  * @see ckmc_get_cert_chain_with_alias())
744  * @see ckmc_cert_list_all_free()
745  */
746 int ckmc_get_cert_chain(const ckmc_cert_s *cert, const ckmc_cert_list_s *untrustedcerts, ckmc_cert_list_s **ppcert_chain_list);
747
748 /**
749  * @brief Verifies a certificate chain using an alias list of untrusted certificates and return that chain.
750  *
751  * @since_tizen 2.3
752  * @privlevel public
753  * @privilege %http://tizen.org/privilege/keymanager
754  *
755  * @remarks The trusted root certificate of the chain should exist in the system's certificate storage.
756  * @remarks You must destroy the newly created @a ppcert_chain_list by calling ckmc_cert_list_all_free() if it is no longer needed.
757  *
758  * @param[in] cert               The certificate to be verified
759  * @param[in] untrustedcerts     The alias list of untrusted CA certificates stored in key manager to be used in verifying a certificate chain
760  * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n
761  *                               If an error occurs, @a *ppcert_chain_list will be null.
762  *
763  * @return @c 0 on success and the signature is valid,
764  *         otherwise a negative error value
765  *
766  * @retval #CKMC_ERROR_NONE                 Successful
767  * @retval #CKMC_ERROR_VERIFICATION_FAILED  The certificate chain is not valid
768  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
769  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged in)
770  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
771  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
772  * @retval #CKMC_ERROR_INVALID_FORMAT       The format of certificate is not valid
773  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
774  *
775  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
776  *
777  * @see ckmc_get_cert_chain())
778  * @see ckmc_cert_list_all_free()
779  */
780 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);
781
782 /**
783  * @deprecated, see ckmc_set_permission()
784  * @brief Allows another application to access client's application data
785  *
786  * @since_tizen 2.3
787  * @privlevel public
788  * @privilege %http://tizen.org/privilege/keymanager
789  *
790  * @remarks Data identified by @a alias should exist
791  *
792  * @param[in] alias       Data alias for which access will be granted
793  * @param[in] accessor    Package id of the application that will gain access rights
794  * @param[in] granted     Rights granted for @a accessor application
795  *
796  * @return @c 0 on success, otherwise a negative error value
797  *
798  * @retval #CKMC_ERROR_NONE                 Successful
799  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
800  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged in)
801  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
802  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
803  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
804  *
805  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
806  *
807  * @see ckmc_deny_access()
808  */
809 int ckmc_allow_access(const char *alias, const char *accessor, ckmc_access_right_e granted);
810
811 /**
812  * @brief Allows another application to access client's application data
813  *
814  * @since_tizen 3.0
815  * @privlevel public
816  * @privilege %http://tizen.org/privilege/keymanager
817  *
818  * @remarks Data identified by @a alias should exist
819  *
820  * @param[in] alias       Data alias for which access will be granted
821  * @param[in] accessor    Package id of the application that will gain access rights
822  * @param[in] permissions Mask of permissions granted for @a accessor application (@a ckmc_permission_e)
823  *                        (previous permission mask will be replaced with the new mask value)
824  *
825  * @return @c 0 on success, otherwise a negative error value
826  *
827  * @retval #CKMC_ERROR_NONE                 Successful
828  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
829  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged in)
830  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
831  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
832  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
833  *
834  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
835  */
836 int ckmc_set_permission(const char *alias, const char *accessor, int permissions);
837
838 /**
839  * @deprecated, see ckmc_set_permission()
840  * @brief Revokes another application's access to client's application data
841  *
842  * @since_tizen 2.3
843  * @privlevel public
844  * @privilege %http://tizen.org/privilege/keymanager
845  *
846  * @remarks Data identified by @a alias should exist
847  * @remarks Only access previously granted with ckmc_allow_access can be revoked.
848  *
849  * @param[in] alias       Data alias for which access will be revoked
850  * @param[in] accessor    Package id of the application that will lose access rights
851  *
852  * @return @c 0 on success, otherwise a negative error value
853  *
854  * @retval #CKMC_ERROR_NONE                 Successful
855  * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid or the @a accessor doesn't
856  *                                          have access to @a alias
857  * @retval #CKMC_ERROR_DB_LOCKED            A user key is not loaded in memory (a user is not logged in)
858  * @retval #CKMC_ERROR_DB_ERROR             Failed due to the error with unknown reason
859  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN     Alias does not exist
860  * @retval #CKMC_ERROR_PERMISSION_DENIED    Failed to access key manager
861  *
862  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
863  *
864  * @see ckmc_allow_access()
865  * @see ckmc_set_permission()
866  */
867 int ckmc_deny_access(const char *alias, const char *accessor);
868
869 /**
870  * @brief Removes a an entry (no matter of type) from the key manager.
871  *
872  * @since_tizen 3.0
873  * @privlevel public
874  * @privilege %http://tizen.org/privilege/keymanager
875  *
876  * @remarks To remove item, client must have remove permission to the specified item.
877  * @remarks The item owner can remove by default.
878  *
879  * @param[in] alias Item alias to be removed
880  *
881  * @return @c 0 on success,
882  *         otherwise a negative error value
883  *
884  * @retval #CKMC_ERROR_NONE              Successful
885  * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
886  * @retval #CKMC_ERROR_DB_LOCKED         A user key is not loaded in memory (a user is not logged in)
887  * @retval #CKMC_ERROR_DB_ERROR          Failed due to a database error
888  * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN  Alias does not exist
889  * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
890  *
891  * @pre User is already logged in and the user key is already loaded into memory in plain text form.
892  *
893  * @see ckmc_save_key()
894  * @see ckmc_save_cert
895  * @see ckmc_save_data
896  * @see ckmc_save_pkcs12
897  * @see ckmc_create_key_pair_rsa
898  * @see ckmc_create_key_pair_dsa
899  * @see ckmc_create_key_pair_ecdsa
900  */
901 int ckmc_remove_alias(const char *alias);
902
903 #ifdef __cplusplus
904 }
905 #endif
906
907 /**
908  * @}
909  */
910
911
912 #endif /* __TIZEN_CORE_CKMC_MANAGER_H */