2 * Copyright (c) 2015 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.
18 * @author Jacek Migacz (j.migacz@samsung.com)
20 * @brief PKCS#12 container manipulation routines.
25 #include <cert-svc/ccert.h>
32 * To import the p12/pfx/crt/pem file to specified store (WIFI_STORE/VPN_STORE/EMAIL_STORE).
34 * @param[in] storeType Refers to WIFI_STORE / VPN_STORE / EMAIL_STORE / ALL_STORE.
35 * @param[in] path Path to file.
36 * @param[in] password Password for opening the file.
37 * @param[in] alias Logical name for certificate bundle identification (can't be empty).
38 * @return CERTSVC_SUCCESS, CERTSVC_FAIL, CERTSVC_DUPLICATED_ALIAS, CERTSVC_IO_ERROR, CERTSVC_WRONG_ARGUMENT, CERTSVC_BAD_ALLOC.
40 int c_certsvc_pkcs12_import_from_file_to_store(CertStoreType storeType, const char *path, const char *password, const char *alias);
43 * To get the list of certificate information present in a store. User will be getting
44 * the information in a linked list where every list will contain Alias, Path to certificate,
45 * Certificate status of all the certificates present in the specified store.
47 * @param[in] storeType Refers to VPN_STORE / WIFI_STORE / EMAIL_STORE / SYSTEM_STORE / ALL_STORE.
48 * @param[in] is_root_app If set to ENABLED, can get all the certs without any restriction (should be used only by master application).
49 * If set to DISABLED, only certs which are enabled by master application can only be retrieved.
50 * @param[out] certList Linked-list having all the information about each certificate present in a store.
51 * @param[out] length provides the length of the linked list.
52 * @return CERTSVC_SUCCESS, CERTSVC_FAIL, CERTSVC_IO_ERROR, CERTSVC_WRONG_ARGUMENT, CERTSVC_INVALID_STORE_TYPE.
54 int c_certsvc_pkcs12_get_certificate_list_from_store(CertStoreType storeType, int is_root_app, CertSvcStoreCertList **certList, size_t *length);
57 * To set the status for a specified certificate in a particular store to enabled / disabled.
58 * The gname is the key for accessing the certificate.
60 * @param[in] storeType Refers to VPN_STORE / WIFI_STORE / EMAIL_STORE / SYSTEM_STORE / ALL_STORE.
61 * @param[in] gname Referred as group name, is the key for accessing the certificate.
62 * @param[in] is_root_app Set as ENABLED/DISABLED. Enabled, if used by master application is changing the status. Disabled, should be used by other applications.
63 * @param[in] status Allows to set the status of the certificate to enabled / disabled.
64 * @return CERTSVC_SUCCESS, CERTSVC_FAIL, CERTSVC_IO_ERROR, CERTSVC_WRONG_ARGUMENT, CERTSVC_INVALID_STORE_TYPE.
66 int c_certsvc_pkcs12_set_certificate_status_to_store(CertStoreType storeType, int is_root_app, const char *gname, CertStatus status);
69 * To get the status (enabled/disabled) for the specified certificate in a particular store.
71 * @param[in] storeType Refers to VPN_STORE / WIFI_STORE / EMAIL_STORE / SYSTEM_STORE / ALL_STORE.
72 * @param[in] gname Referred as group name, is the key for accessing the certificate.
73 * @param[out] status Returns the status of the certificate. It will be set Disable=0, Enable=1, Fail=-1.
74 * @return CERTSVC_SUCCESS, CERTSVC_FAIL, CERTSVC_ALIAS_DOES_NOT_EXIST, CERTSVC_IO_ERROR
76 int c_certsvc_pkcs12_get_certificate_status_from_store(CertStoreType storeType, const char *gname, CertStatus *status);
79 * To get the encoded form of the specified certificate from the specified store.
81 * @param[in] storeType Refers to VPN_STORE / WIFI_STORE / EMAIL_STORE / SYSTEM_STORE / ALL_STORE.
82 * @param[in] gname Referred as group name, is the key for accessing the certificate.
83 * @param[out] certBuffer Which will be having the encoded value of the certificate requested.
84 * @param[out] certSize Which will be having the size of the buffer.
85 * @return CERTSVC_SUCCESS, CERTSVC_FAIL, CERTSVC_IO_ERROR, CERTSVC_WRONG_ARGUMENT, CERTSVC_INVALID_STORE_TYPE.
87 int c_certsvc_pkcs12_get_certificate_buffer_from_store(CertStoreType storeType, const char *gname, char **certBuffer, size_t *certSize);
90 * To delete the certificate from the specified store (VPN_STORE, WIFI_STORE, EMAIL_STORE, SYSTEM_STORE, ALL_STORE).
92 * @param[in] storeType Refers to VPN_STORE / WIFI_STORE / EMAIL_STORE / SYSTEM_STORE / ALL_STORE.
93 * @param[in] gname Referred as group name, is the key for accessing the certificate.
94 * @return CERTSVC_SUCCESS, CERTSVC_FAIL, CERTSVC_IO_ERROR, CERTSVC_INVALID_STORE_TYPE.
96 int c_certsvc_pkcs12_delete_certificate_from_store(CertStoreType storeType, const char* gname);
99 * To free the certificate list which got generated from
100 * c_certsvc_pkcs12_get_certificate_list_from_store() function.
102 * @param[in] certList Linked-list having all the information about each certificate present in a store.
103 * @return CERTSVC_SUCCESS, CERTSVC_FAIL.
105 int c_certsvc_pkcs12_free_aliases_loaded_from_store(CertSvcStoreCertList **certList);
108 * Checks if the alias exist in the user store or not.
110 * @param[in] storeType Refers to VPN_STORE / WIFI_STORE / EMAIL_STORE / SYSTEM_STORE / ALL_STORE.
111 * @param[in] Alias Logical name for certificate bundle identification (can't be empty).
112 * @param[out] isUnique A Boolean value which states if the alias is unique or not.
113 * @return CERTSVC_SUCCESS, CERTSVC_IO_ERROR, CERTSVC_WRONG_ARGUMENT.
115 int c_certsvc_pkcs12_alias_exists_in_store(CertStoreType storeType, const char *alias, int *isUnique);
118 * Function to get the size of the file passed.
120 * @param[in] storeType Refers to VPN_STORE / WIFI_STORE / EMAIL_STORE / SYSTEM_STORE / ALL_STORE.
121 * @param[in] gname Refers to unique name referring to the certificate.
122 * @param[out] certs Provides the list of certificates matching the unique name provided.
123 * @param[out] ncerts Provides the number of certs in certs.
124 * @return CERTSVC_SUCCESS, CERTSVC_FAIL, CERTSVC_IO_ERROR, CERTSVC_WRONG_ARGUMENT, CERTSVC_INVALID_STORE_TYPE.
126 int c_certsvc_pkcs12_load_certificates_from_store(CertStoreType storeType, const char *gname, char ***certs, size_t *ncerts);
129 * To load the private key for the specified certificate mapped by an Alias.
131 * @param[in] alias Logical name for certificate bundle identification (can't be empty).
132 * @param[out] pkey Will hold the private key value of the certificate.
133 * @param[out] count Will hold the siz of the private key buffer.
134 * @return CERTSVC_SUCCESS, CERTSVC_FAIL, CERTSVC_IO_ERROR, CERTSVC_WRONG_ARGUMENT, CERTSVC_BAD_ALLOC.
136 int c_certsvc_pkcs12_private_key_load_from_store(CertStoreType storeType, const char *gname, char **pkey, size_t *count);
139 * Gets the alias name for the gname passed.
141 * @param[in] instance CertSvcInstance object.
142 * @param[in] gname Certificate identification of pfx/pkcs file.
143 * @param[out] alias Alias name for the given gname.
144 * @return CERTSVC_SUCCESS, CERTSVC_FAIL, CERTSVC_WRONG_ARGUMENT
146 int c_certsvc_pkcs12_get_certificate_alias_from_store(CertStoreType storeType, const char *gname, char **alias);
149 * To get the list of only end user certificate information present in a store. User will be getting
150 * the information in a linked list where every list will contain Alias, Path to certificate,
151 * Certificate status of all the certificates present in the specified store.
153 * @param[in] storeType Refers to VPN_STORE / WIFI_STORE / EMAIL_STORE / SYSTEM_STORE / ALL_STORE.
154 * @param[out] certList Linked-list having all the information about each certificate present in a store.
155 * @param[out] length provides the length of the linked list.
156 * @return CERTSVC_SUCCESS, CERTSVC_FAIL, CERTSVC_IO_ERROR, CERTSVC_WRONG_ARGUMENT, CERTSVC_INVALID_STORE_TYPE.
158 int c_certsvc_pkcs12_get_end_user_certificate_list_from_store(CertStoreType storeType, CertSvcStoreCertList **certList, size_t *length);
161 * To get the list of only root/trusted certificate information present in a store. User will be getting
162 * the information in a linked list where every list will contain Alias, Path to certificate,
163 * Certificate status of all the certificates present in the specified store.
165 * @param[in] storeType Refers to VPN_STORE / WIFI_STORE / EMAIL_STORE / SYSTEM_STORE / ALL_STORE.
166 * @param[out] certList Linked-list having all the information about each certificate present in a store.
167 * @param[out] length provides the length of the linked list.
168 * @return CERTSVC_SUCCESS, CERTSVC_FAIL, CERTSVC_IO_ERROR, CERTSVC_WRONG_ARGUMENT, CERTSVC_INVALID_STORE_TYPE.
170 int c_certsvc_pkcs12_get_root_certificate_list_from_store(CertStoreType storeType, CertSvcStoreCertList **certList, size_t *length);
173 * TO check if the p12/pfx file is protected by password or not.
175 * @param[in] filePath Where the file is located.
176 * @param[out] passworded A boolean value to state if the file is protected by password or not.
177 * @return CERTSVC_SUCCESS, CERTSVC_FAIL, CERTSVC_IO_ERROR, CERTSVC_WRONG_ARGUMENT.
179 int c_certsvc_pkcs12_has_password(const char *filepath, int *passworded);
182 * To free the certificates from memory which was loaded by
183 * c_certsvc_pkcs12_load_certificates() functon.
185 * @param[in] certs A pointer holding all the certificates in memory.
186 * @return CERTSVC_SUCCESS, CERTSVC_FAIL, CERTSVC_IO_ERROR.
188 void c_certsvc_pkcs12_free_certificates(char **certs);