2 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
17 * @file ckmc-manager.h
19 * @brief Provides management functions(storing, retrieving, and removing) for keys,
20 * certificates and data of a user and additional crypto functions.
24 #ifndef __TIZEN_CORE_CKMC_MANAGER_H
25 #define __TIZEN_CORE_CKMC_MANAGER_H
28 #include <sys/types.h>
30 #include <ckmc/ckmc-type.h>
31 #include <ckmc/ckmc-error.h>
38 * @addtogroup CAPI_KEY_MANAGER_CLIENT_MODULE
44 * @brief Stores a key inside key manager based on the provided policy.
48 * @privilege %http://tizen.org/privilege/keymanager
50 * @remarks Currently only six types of keys are supported for this API. These are RSA
51 * public/private key, DSA public/private key and ECDSA public/private key.
52 * @remarks key_type in key may be set to #CKMC_KEY_NONE as an input. key_type is determined inside
53 * key manager during storing keys.
54 * @remarks Some private key files are protected by a password. If raw_key in key read from those
55 * encrypted files is encrypted with a password, the password should be provided in the
56 * #ckmc_key_s structure.
57 * @remarks If password in policy is provided, the key is additionally encrypted with the password
60 * @param[in] alias The name of a key to be stored
61 * @param[in] key The key's binary value to be stored
62 * @param[in] policy The policy about how to store a key securely
64 * @return @c 0 on success,
65 * otherwise a negative error value
67 * @retval #CKMC_ERROR_NONE Successful
68 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
69 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
71 * @retval #CKMC_ERROR_DB_ALIAS_EXISTS Alias already exists
72 * @retval #CKMC_ERROR_INVALID_FORMAT The format of raw_key is not valid
73 * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error
74 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
76 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
78 * @see ckmc_remove_key()
80 * @see ckmc_get_key_alias_list()
84 int ckmc_save_key(const char *alias, const ckmc_key_s key, const ckmc_policy_s policy);
87 * @brief Removes a key from key manager.
91 * @privilege %http://tizen.org/privilege/keymanager
93 * @remarks To remove key, client must have remove permission to the specified key.
94 * @remarks The key owner can remove by default.
96 * @param[in] alias The name of a key to be removed
98 * @return @c 0 on success,
99 * otherwise a negative error value
101 * @retval #CKMC_ERROR_NONE Successful
102 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
103 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
105 * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error
106 * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist
107 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
109 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
111 * @see ckmc_save_key()
112 * @see ckmc_get_key()
113 * @see ckmc_get_key_alias_list()
115 int ckmc_remove_key(const char *alias);
118 * @brief Gets a key from key manager.
122 * @privilege %http://tizen.org/privilege/keymanager
124 * @remarks A client can access only data stored by the client.
125 * @remarks You must destroy the newly created @a ppkey by calling ckmc_key_free() if it is no
128 * @param[in] alias The name of a key to retrieve
129 * @param[in] password The password used in decrypting a key value \n
130 * If password of policy is provided in ckmc_save_key(), the same password
131 * should be provided.
132 * @param[out] ppkey The pointer to a newly created ckmc_key_s handle
134 * @return @c 0 on success,
135 * otherwise a negative error value
137 * @retval #CKMC_ERROR_NONE Successful
138 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
139 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
141 * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error
142 * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist
143 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
145 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
147 * @see ckmc_save_key()
148 * @see ckmc_remove_key()
149 * @see ckmc_get_key_alias_list()
151 int ckmc_get_key(const char *alias, const char *password, ckmc_key_s **ppkey);
154 * @brief Gets all the alias of keys that the client can access.
158 * @privilege %http://tizen.org/privilege/keymanager
160 * @remarks A client can access only data stored by the client.
161 * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free()
162 * if it is no longer needed.
164 * @param[out] ppalias_list The pointer to a newly created ckmc_alias_list_s handle containing all
165 * available alias of keys \n
166 * If there is no available key alias, *ppalias_list will be null.
168 * @return @c 0 on success,
169 * otherwise a negative error value
171 * @retval #CKMC_ERROR_NONE Successful
172 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
173 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
175 * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error
176 * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist
177 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
179 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
181 * @see ckmc_save_key()
182 * @see ckmc_remove_key()
183 * @see ckmc_get_key()
185 int ckmc_get_key_alias_list(ckmc_alias_list_s** ppalias_list);
191 * @brief Stores a certificate inside key manager based on the provided policy.
195 * @privilege %http://tizen.org/privilege/keymanager
197 * @remarks the certificate's binary value will be converted and saved as binary DER encoded
200 * @param[in] alias The name of a certificate to be stored
201 * @param[in] cert The certificate's binary value to be stored
202 * @param[in] policy The policy about how to store a certificate securely
204 * @return @c 0 on success,
205 * otherwise a negative error value
207 * @retval #CKMC_ERROR_NONE Successful
208 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
209 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
211 * @retval #CKMC_ERROR_DB_ALIAS_EXISTS Alias already exists
212 * @retval #CKMC_ERROR_INVALID_FORMAT The format of raw_cert is not valid
213 * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error
214 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
216 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
218 * @see ckmc_remove_cert()
219 * @see ckmc_get_cert()
220 * @see ckmc_get_cert_alias_list()
222 * @see #ckmc_policy_s
224 int ckmc_save_cert(const char *alias, const ckmc_cert_s cert, const ckmc_policy_s policy);
227 * @brief Removes a certificate from key manager.
231 * @privilege %http://tizen.org/privilege/keymanager
233 * @remarks To remove certificate, client must have remove permission to the specified certificate.
234 * @remarks The key owner can remove by default.
236 * @param[in] alias The name of a certificate to be removed
238 * @return @c 0 on success,
239 * otherwise a negative error value
241 * @retval #CKMC_ERROR_NONE Successful
242 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
243 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
245 * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error
246 * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist
247 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
249 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
251 * @see ckmc_save_cert()
252 * @see ckmc_get_cert()
253 * @see ckmc_get_cert_alias_list()
255 int ckmc_remove_cert(const char *alias);
258 * @brief Gets a certificate from key manager.
262 * @privilege %http://tizen.org/privilege/keymanager
264 * @remarks A client can access only certificate stored by the client.
265 * @remarks A DER encoded certificate will be returned as a return value.
266 * @remarks You must destroy the newly created @a ppcert by calling ckmc_cert_free() if it is no
269 * @param[in] alias The name of a certificate to retrieve
270 * @param[in] password The password used in decrypting a certificate value \n
271 * If password of policy is provided in ckmc_save_cert(), the same password
272 * should be provided.
273 * @param[out] ppcert The pointer to a newly created ckmc_cert_s handle
275 * @return @c 0 on success,
276 * otherwise a negative error value
278 * @retval #CKMC_ERROR_NONE Successful
279 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
280 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
282 * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error
283 * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exists
284 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
286 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
288 * @see ckmc_save_cert()
289 * @see ckmc_remove_cert()
290 * @see ckmc_get_cert_alias_list()
292 int ckmc_get_cert(const char *alias, const char *password, ckmc_cert_s **ppcert);
295 * @brief Gets all alias of certificates which the client can access.
299 * @privilege %http://tizen.org/privilege/keymanager
301 * @remarks A client can access only data stored by the client.
302 * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free()
303 * if it is no longer needed.
305 * @param[out] ppalias_list The pointer to a newly created ckmc_alias_list_s handle containing all
306 * available alias of keys \n
307 * If there is no available key alias, *ppalias_list will be null.
309 * @return @c 0 on success,
310 * otherwise a negative error value
312 * @retval #CKMC_ERROR_NONE Successful
313 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
314 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
316 * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error
317 * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist
318 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
320 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
322 * @see ckmc_save_cert()
323 * @see ckmc_remove_cert()
324 * @see ckmc_get_cert()
326 int ckmc_get_cert_alias_list(ckmc_alias_list_s** ppalias_list);
332 * @brief Stores PKCS12's contents inside key manager based on the provided policies.
333 * All items from the PKCS12 will use the same alias.
337 * @privilege %http://tizen.org/privilege/keymanager
339 * @param[in] alias The name of a data to be stored
340 * @param[in] pkcs Pointer to the pkcs12 structure to be saved
341 * @param[in] key_policy The policy about how to store pkcs's private key
342 * @param[in] cert_policy The policy about how to store pkcs's certificate
344 * @return @c 0 on success,
345 * otherwise a negative error value
347 * @retval #CKMC_ERROR_NONE Successful
348 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
349 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
351 * @retval #CKMC_ERROR_DB_ALIAS_EXISTS Alias already exists
352 * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error
353 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
355 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
357 * @see ckmc_remove_pkcs12()
358 * @see ckmc_get_pkcs12()
359 * @see ckmc_get_data_alias_list()
360 * @see ckmc_load_from_pkcs12_file2()
361 * @see #ckmc_pkcs12_s
362 * @see #ckmc_policy_s
364 int ckmc_save_pkcs12(const char *alias,
365 const ckmc_pkcs12_s *pkcs,
366 const ckmc_policy_s key_policy,
367 const ckmc_policy_s cert_policy);
370 * @brief Removes all PKCS12 contents from key manager.
374 * @privilege %http://tizen.org/privilege/keymanager
376 * @remarks To remove PKCS12, client must have remove permission to the specified PKCS12 object.
377 * @remarks The key owner can remove by default.
379 * @param[in] alias The name of PKCS12 to be removed
381 * @return @c 0 on success,
382 * otherwise a negative error value
384 * @retval #CKMC_ERROR_NONE Successful
385 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
386 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
388 * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error
389 * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist
390 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
392 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
394 * @see ckmc_save_pkcs12()
395 * @see ckmc_get_pkcs12()
397 int ckmc_remove_pkcs12(const char *alias);
400 * @brief Gets a pkcs12 from key manager.
404 * @privilege %http://tizen.org/privilege/keymanager
406 * @remarks A client can access only data stored by the client.
407 * @remarks You must destroy the newly created @a pkcs12 by calling ckmc_pkcs12_free() if it is no
410 * @param[in] alias The name of a data to retrieve
411 * @param[out] pkcs12 The pointer to a newly created ckmc_pkcs12_s handle
413 * @return @c 0 on success,
414 * otherwise a negative error value
416 * @retval #CKMC_ERROR_NONE Successful
417 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
418 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
420 * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error
421 * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist
422 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
424 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
426 * @see ckmc_save_pkcs12()
427 * @see ckmc_remove_pkcs12()
429 int ckmc_get_pkcs12(const char *alias, ckmc_pkcs12_s **pkcs12);
435 * @brief Stores a data inside key manager based on the provided policy.
439 * @privilege %http://tizen.org/privilege/keymanager
441 * @param[in] alias The name of a data to be stored
442 * @param[in] data The binary value to be stored
443 * @param[in] policy The policy about how to store a data securely
445 * @return @c 0 on success,
446 * otherwise a negative error value
448 * @retval #CKMC_ERROR_NONE Successful
449 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
450 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
452 * @retval #CKMC_ERROR_DB_ALIAS_EXISTS Alias already exists
453 * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error
454 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
456 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
458 * @see ckmc_remove_data()
459 * @see ckmc_get_data()
460 * @see ckmc_get_data_alias_list()
461 * @see #ckmc_raw_buffer_s
462 * @see #ckmc_policy_s
464 int ckmc_save_data(const char *alias, ckmc_raw_buffer_s data, const ckmc_policy_s policy);
467 * @brief Removes a data from key manager.
471 * @privilege %http://tizen.org/privilege/keymanager
473 * @remarks To remove data, client must have remove permission to the specified data object.
474 * @remarks The data owner can remove by default.
476 * @param[in] alias The name of a data to be removed
478 * @return @c 0 on success,
479 * otherwise a negative error value
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
485 * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason
486 * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist
487 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
489 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
491 * @see ckmc_save_data()
492 * @see ckmc_get_data()
493 * @see ckmc_get_data_alias_list()
495 int ckmc_remove_data(const char *alias);
498 * @brief Gets a data from key manager.
502 * @privilege %http://tizen.org/privilege/keymanager
504 * @remarks A client can access only data stored by the client.
505 * @remarks You must destroy the newly created @a ppdata by calling ckmc_buffer_free() if it is no
508 * @param[in] alias The name of a data to retrieve
509 * @param[in] password The password used in decrypting a data value \n
510 * If password of policy is provided in ckmc_save_data(), the same password
511 * should be provided.
512 * @param[out] ppdata The pointer to a newly created ckmc_raw_buffer_s handle
514 * @return @c 0 on success,
515 * otherwise a negative error value
517 * @retval #CKMC_ERROR_NONE Successful
518 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
519 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
521 * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason
522 * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist
523 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
525 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
527 * @see ckmc_save_data()
528 * @see ckmc_remove_data()
529 * @see ckmc_get_data_alias_list()
531 int ckmc_get_data(const char *alias, const char *password, ckmc_raw_buffer_s **ppdata);
534 * @brief Gets all alias of data which the client can access.
538 * @privilege %http://tizen.org/privilege/keymanager
540 * @remarks A client can access only data stored by the client.
541 * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free()
542 * if it is no longer needed.
544 * @param[out] ppalias_list The pointer to a newly created ckmc_alias_list_s handle containing all
545 * available alias of keys \n
546 * If there is no available key alias, *ppalias_list will be null.
548 * @return @c 0 on success,
549 * otherwise a negative error value
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
555 * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason
556 * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist
557 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
559 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
561 * @see ckmc_save_data()
562 * @see ckmc_remove_data()
563 * @see ckmc_get_data()
565 int ckmc_get_data_alias_list(ckmc_alias_list_s** ppalias_list);
571 * @brief Creates RSA private/public key pair and stores them inside key manager based on each
576 * @privilege %http://tizen.org/privilege/keymanager
578 * @remarks If password in policy is provided, the key is additionally encrypted with the password
581 * @param[in] size The size of key strength to be created \n
582 * @c 1024, @c 2048, and @c 4096 are supported.
583 * @param[in] private_key_alias The name of private key to be stored
584 * @param[in] public_key_alias The name of public key to be stored
585 * @param[in] policy_private_key The policy about how to store a private key securely
586 * @param[in] policy_public_key The policy about how to store a public key securely
588 * @return @c 0 on success,
589 * otherwise a negative error value
591 * @retval #CKMC_ERROR_NONE Successful
592 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
593 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
595 * @retval #CKMC_ERROR_DB_ALIAS_EXISTS Alias already exists
596 * @retval #CKMC_ERROR_DB_ERROR Failed due to other DB transaction unexpectedly
597 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
599 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
601 * @see ckmc_create_key_pair_dsa()
602 * @see ckmc_create_key_pair_ecdsa()
603 * @see ckmc_create_signature()
604 * @see ckmc_verify_signature()
606 int ckmc_create_key_pair_rsa(const size_t size,
607 const char *private_key_alias,
608 const char *public_key_alias,
609 const ckmc_policy_s policy_private_key,
610 const ckmc_policy_s policy_public_key);
613 * @brief Creates DSA private/public key pair and stores them inside key manager based on each
618 * @privilege %http://tizen.org/privilege/keymanager
620 * @remarks If password in policy is provided, the key is additionally encrypted with the password
623 * @param[in] size The size of key strength to be created \n
624 * @c 1024, @c 2048, @c 3072 and @c 4096 are supported.
625 * @param[in] private_key_alias The name of private key to be stored
626 * @param[in] public_key_alias The name of public key to be stored
627 * @param[in] policy_private_key The policy about how to store a private key securely
628 * @param[in] policy_public_key The policy about how to store a public key securely
630 * @return @c 0 on success,
631 * otherwise a negative error value
633 * @retval #CKMC_ERROR_NONE Successful
634 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
635 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
637 * @retval #CKMC_ERROR_DB_ALIAS_EXISTS Alias already exists
638 * @retval #CKMC_ERROR_DB_ERROR Failed due to other DB transaction unexpectedly
639 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
641 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
643 * @see ckmc_create_key_pair_rsa()
644 * @see ckmc_create_key_pair_ecdsa()
645 * @see ckmc_create_signature()
646 * @see ckmc_verify_signature()
648 int ckmc_create_key_pair_dsa(const size_t size,
649 const char *private_key_alias,
650 const char *public_key_alias,
651 const ckmc_policy_s policy_private_key,
652 const ckmc_policy_s policy_public_key);
655 * @brief Creates ECDSA private/public key pair and stores them inside key manager based on each
660 * @privilege %http://tizen.org/privilege/keymanager
662 * @remarks If password in policy is provided, the key is additionally encrypted with the password
665 * @param[in] type The type of elliptic curve of ECDSA
666 * @param[in] private_key_alias The name of private key to be stored
667 * @param[in] public_key_alias The name of public key to be stored
668 * @param[in] policy_private_key The policy about how to store a private key securely
669 * @param[in] policy_public_key The policy about how to store a public key securely
671 * @return @c 0 on success,
672 * otherwise a negative error value
674 * @retval #CKMC_ERROR_NONE Successful
675 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
676 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
678 * @retval #CKMC_ERROR_DB_ALIAS_EXISTS Alias already exists
679 * @retval #CKMC_ERROR_DB_ERROR Failed due to other DB transaction unexpectedly
680 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
682 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
684 * @see ckmc_create_key_pair_rsa()
685 * @see ckmc_create_key_pair_dsa()
686 * @see ckmc_create_signature()
687 * @see ckmc_verify_signature()
688 * @see #ckmc_ec_type_e
690 int ckmc_create_key_pair_ecdsa(const ckmc_ec_type_e type,
691 const char *private_key_alias,
692 const char *public_key_alias,
693 const ckmc_policy_s policy_private_key,
694 const ckmc_policy_s policy_public_key);
697 * @brief Creates a signature on a given message using a private key and returns the signature.
701 * @privilege %http://tizen.org/privilege/keymanager
703 * @remarks If password of policy is provided during storing a key, the same password should be
705 * @remarks You must destroy the newly created @a ppsignature by calling ckmc_buffer_free() if it is
708 * @param[in] private_key_alias The name of private key
709 * @param[in] password The password used in decrypting a private key value
710 * @param[in] message The message that is signed with a private key
711 * @param[in] hash The hash algorithm used in creating signature
712 * @param[in] padding The RSA padding algorithm used in creating signature \n
713 * It is used only when the signature algorithm is RSA.
714 * @param[out] ppsignature The pointer to a newly created signature \n
715 * If an error occurs, @a *ppsignature will be null.
717 * @return @c 0 on success,
718 * otherwise a negative error value
720 * @retval #CKMC_ERROR_NONE Successful
721 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
722 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
724 * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason
725 * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist
726 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
728 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
730 * @see ckmc_create_key_pair_rsa()
731 * @see ckmc_create_key_pair_ecdsa()
732 * @see ckmc_verify_signature()
733 * @see ckmc_buffer_free()
734 * @see #ckmc_hash_algo_e
735 * @see #ckmc_rsa_padding_algo_e
737 int ckmc_create_signature(const char *private_key_alias,
738 const char *password,
739 const ckmc_raw_buffer_s message,
740 const ckmc_hash_algo_e hash,
741 const ckmc_rsa_padding_algo_e padding,
742 ckmc_raw_buffer_s **ppsignature);
745 * @brief Verifies a given signature on a given message using a public key and returns the signature
750 * @privilege %http://tizen.org/privilege/keymanager
752 * @remarks If password of policy is provided during storing a key, the same password should be
755 * @param[in] public_key_alias The name of public key
756 * @param[in] password The password used in decrypting a public key value
757 * @param[in] message The input on which the signature is created
758 * @param[in] signature The signature that is verified with public key
759 * @param[in] hash The hash algorithm used in verifying signature
760 * @param[in] padding The RSA padding algorithm used in verifying signature \n
761 * It is used only when the signature algorithm is RSA.
763 * @return @c 0 on success and the signature is valid,
764 * otherwise a negative error value
766 * @retval #CKMC_ERROR_NONE Successful
767 * @retval #CKMC_ERROR_VERIFICATION_FAILED The signature is invalid
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
771 * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason
772 * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist
773 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
775 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
777 * @see ckmc_create_key_pair_rsa()
778 * @see ckmc_create_key_pair_ecdsa()
779 * @see ckmc_verify_signature()
780 * @see #ckmc_hash_algo_e
781 * @see #ckmc_rsa_padding_algo_e
783 int ckmc_verify_signature(const char *public_key_alias,
784 const char *password,
785 const ckmc_raw_buffer_s message,
786 const ckmc_raw_buffer_s signature,
787 const ckmc_hash_algo_e hash,
788 const ckmc_rsa_padding_algo_e padding);
791 * @deprecated, see ckmc_get_certificate_chain()
792 * @brief Verifies a certificate chain and returns that chain.
796 * @privilege %http://tizen.org/privilege/keymanager
798 * @remarks The trusted root certificate of the chain should exist in the system's certificate
800 * @remarks You must destroy the newly created @a ppcert_chain_list by calling
801 * ckmc_cert_list_all_free() if it is no longer needed.
803 * @param[in] cert The certificate to be verified
804 * @param[in] untrustedcerts The untrusted CA certificates to be used in verifying a certificate
806 * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n
807 * If an error occurs, @a *ppcert_chain_list will be null.
809 * @return @c 0 on success and the signature is valid,
810 * otherwise a negative error value
812 * @retval #CKMC_ERROR_NONE Successful
813 * @retval #CKMC_ERROR_VERIFICATION_FAILED The certificate chain is not valid
814 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
815 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
817 * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason
818 * @retval #CKMC_ERROR_INVALID_FORMAT The format of certificate is not valid
819 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
821 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
823 * @see ckmc_get_cert_chain_with_alias())
824 * @see ckmc_cert_list_all_free()
826 int ckmc_get_cert_chain(const ckmc_cert_s *cert,
827 const ckmc_cert_list_s *untrustedcerts,
828 ckmc_cert_list_s **ppcert_chain_list);
831 * @deprecated, see ckmc_get_certificate_chain_with_alias()
832 * @brief Verifies a certificate chain using an alias list of untrusted certificates and return that
837 * @privilege %http://tizen.org/privilege/keymanager
839 * @remarks The trusted root certificate of the chain should exist in the system's certificate
841 * @remarks You must destroy the newly created @a ppcert_chain_list by calling
842 * ckmc_cert_list_all_free() if it is no longer needed.
844 * @param[in] cert The certificate to be verified
845 * @param[in] untrustedcerts The alias list of untrusted CA certificates stored in key manager
846 * to be used in verifying a certificate chain
847 * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n
848 * If an error occurs, @a *ppcert_chain_list will be null.
850 * @return @c 0 on success and the signature is valid,
851 * otherwise a negative error value
853 * @retval #CKMC_ERROR_NONE Successful
854 * @retval #CKMC_ERROR_VERIFICATION_FAILED The certificate chain is not valid
855 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
856 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
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_INVALID_FORMAT The format of certificate is not valid
861 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
863 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
865 * @see ckmc_get_cert_chain())
866 * @see ckmc_cert_list_all_free()
868 int ckmc_get_cert_chain_with_alias(const ckmc_cert_s *cert,
869 const ckmc_alias_list_s *untrustedcerts,
870 ckmc_cert_list_s **ppcert_chain_list);
873 * @brief Verifies a certificate chain and returns that chain using user entered trusted and
874 * untrusted CA certificates
878 * @privilege %http://tizen.org/privilege/keymanager
880 * @remarks If the trusted root certificates are provided as a user input, these certificates do not
881 * need to exist in the system's certificate storage.
882 * @remarks You must destroy the newly created @a ppcert_chain_list by calling
883 * ckmc_cert_list_all_free() if it is no longer needed.
885 * @param[in] cert The certificate to be verified
886 * @param[in] untrustedcerts The untrusted CA certificates to be used in verifying a
888 * @param[in] trustedcerts The trusted CA certificates to be used in verifying a
890 * @param[in] use_trustedsystemcerts The flag indicating the use of the trusted root certificates
891 * in the system's certificate storage.
892 * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n
893 * If an error occurs, @a *ppcert_chain_list will be null.
895 * @return @c 0 on success and the signature is valid,
896 * otherwise a negative error value
898 * @retval #CKMC_ERROR_NONE Successful
899 * @retval #CKMC_ERROR_VERIFICATION_FAILED The certificate chain is not valid
900 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
901 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
903 * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason
904 * @retval #CKMC_ERROR_INVALID_FORMAT The format of certificate is not valid
905 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
907 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
909 * @see ckmc_get_cert_chain_with_alias())
910 * @see ckmc_cert_list_all_free()
912 int ckmc_get_certificate_chain(const ckmc_cert_s *cert,
913 const ckmc_cert_list_s *untrustedcerts,
914 const ckmc_cert_list_s *trustedcerts,
915 const bool use_trustedsystemcerts,
916 ckmc_cert_list_s **ppcert_chain_list);
919 * @brief Verifies a certificate chain and returns that chain using alias lists of untrusted and
920 * trusted certificates
924 * @privilege %http://tizen.org/privilege/keymanager
926 * @remarks If the alias list of trusted root certificates is provided as a user input, these
927 * certificates do not need to exist in the system's certificate storage.
928 * @remarks You must destroy the newly created @a ppcert_chain_list by calling
929 * ckmc_cert_list_all_free() if it is no longer needed.
931 * @param[in] cert The certificate to be verified
932 * @param[in] untrustedcerts The alias list of untrusted CA certificates stored in key
933 * manager to be used in verifying a certificate chain
934 * @param[in] trustedcerts The alias list of trusted CA certificates stored in key
935 * manager to be used in verifying a certificate chain
936 * @param[in] use_trustedsystemcerts The flag indicating the use of the trusted root certificates
937 * in the system's certificate storage.
938 * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n
939 * If an error occurs, @a *ppcert_chain_list will be null.
941 * @return @c 0 on success and the signature is valid,
942 * otherwise a negative error value
944 * @retval #CKMC_ERROR_NONE Successful
945 * @retval #CKMC_ERROR_VERIFICATION_FAILED The certificate chain is not valid
946 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
947 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
949 * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason
950 * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist
951 * @retval #CKMC_ERROR_INVALID_FORMAT The format of certificate is not valid
952 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
954 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
956 * @see ckmc_get_cert_chain())
957 * @see ckmc_cert_list_all_free()
959 int ckmc_get_certificate_chain_with_alias(const ckmc_cert_s *cert,
960 const ckmc_alias_list_s *untrustedcerts,
961 const ckmc_alias_list_s *trustedcerts,
962 const bool use_trustedsystemcerts,
963 ckmc_cert_list_s **ppcert_chain_list);
966 * @brief Perform OCSP which checks certificate is whether revoked or not
970 * @privilege %http://tizen.org/privilege/keymanager
972 * @param[in] pcert_chain_list Certificate chain to perform OCSP check
973 * @param[out] ocsp_status The pointer to status result of OCSP check
975 * @return @c 0 on success, otherwise a negative error value
977 * @retval #CKMC_ERROR_NONE Successful
978 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
979 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
981 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
983 * @see ckmc_get_cert_chain())
984 * @see ckmc_cert_list_all_free()
986 int ckmc_ocsp_check(const ckmc_cert_list_s *pcert_chain_list, ckmc_ocsp_status_e *ocsp_status);
989 * @deprecated, see ckmc_set_permission()
990 * @brief Allows another application to access client's application data
994 * @privilege %http://tizen.org/privilege/keymanager
996 * @remarks Data identified by @a alias should exist
998 * @param[in] alias Data alias for which access will be granted
999 * @param[in] accessor Package id of the application that will gain access rights
1000 * @param[in] granted Rights granted for @a accessor application
1002 * @return @c 0 on success, otherwise a negative error value
1004 * @retval #CKMC_ERROR_NONE Successful
1005 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
1006 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
1008 * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason
1009 * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist
1010 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
1012 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
1014 * @see ckmc_deny_access()
1016 int ckmc_allow_access(const char *alias, const char *accessor, ckmc_access_right_e granted);
1019 * @brief Allows another application to access client's application data
1023 * @privilege %http://tizen.org/privilege/keymanager
1025 * @remarks Data identified by @a alias should exist
1027 * @param[in] alias Data alias for which access will be granted
1028 * @param[in] accessor Package id of the application that will gain access rights
1029 * @param[in] permissions Mask of permissions granted for @a accessor application
1030 * (@a ckmc_permission_e)
1031 * (previous permission mask will be replaced with the new mask value)
1033 * @return @c 0 on success, otherwise a negative error value
1035 * @retval #CKMC_ERROR_NONE Successful
1036 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
1037 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
1039 * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason
1040 * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist
1041 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
1043 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
1045 int ckmc_set_permission(const char *alias, const char *accessor, int permissions);
1048 * @deprecated, see ckmc_set_permission()
1049 * @brief Revokes another application's access to client's application data
1053 * @privilege %http://tizen.org/privilege/keymanager
1055 * @remarks Data identified by @a alias should exist
1056 * @remarks Only access previously granted with ckmc_allow_access can be revoked.
1058 * @param[in] alias Data alias for which access will be revoked
1059 * @param[in] accessor Package id of the application that will lose access rights
1061 * @return @c 0 on success, otherwise a negative error value
1063 * @retval #CKMC_ERROR_NONE Successful
1064 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid or the @a accessor doesn't
1065 * have access to @a alias
1066 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
1068 * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason
1069 * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist
1070 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
1072 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
1074 * @see ckmc_allow_access()
1075 * @see ckmc_set_permission()
1077 int ckmc_deny_access(const char *alias, const char *accessor);
1080 * @brief Removes a an entry (no matter of type) from the key manager.
1084 * @privilege %http://tizen.org/privilege/keymanager
1086 * @remarks To remove item, client must have remove permission to the specified item.
1087 * @remarks The item owner can remove by default.
1089 * @param[in] alias Item alias to be removed
1091 * @return @c 0 on success,
1092 * otherwise a negative error value
1094 * @retval #CKMC_ERROR_NONE Successful
1095 * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid
1096 * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged
1098 * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error
1099 * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist
1100 * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager
1102 * @pre User is already logged in and the user key is already loaded into memory in plain text form.
1104 * @see ckmc_save_key()
1105 * @see ckmc_save_cert
1106 * @see ckmc_save_data
1107 * @see ckmc_save_pkcs12
1108 * @see ckmc_create_key_pair_rsa
1109 * @see ckmc_create_key_pair_dsa
1110 * @see ckmc_create_key_pair_ecdsa
1112 int ckmc_remove_alias(const char *alias);
1123 #endif /* __TIZEN_CORE_CKMC_MANAGER_H */