Refactor SignatureValidator and reduce interface headers
[platform/core/security/cert-svc.git] / vcore / src / vcore / pkcs12.h
1 /**
2  * Copyright (c) 2015 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        pkcs12.c
18  * @author      Jacek Migacz (j.migacz@samsung.com)
19  * @version     1.0
20  * @brief       PKCS#12 container manipulation routines.
21  */
22 #ifndef _PKCS12_H_
23 #define _PKCS12_H_
24
25 #include <cert-svc/ccert.h>
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 /**
32  * To import the p12/pfx/crt/pem file to specified store (WIFI_STORE/VPN_STORE/EMAIL_STORE).
33  *
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.
39  */
40 int  c_certsvc_pkcs12_import_from_file_to_store(CertStoreType storeType, const char *path, const char *password, const char *alias);
41
42 /**
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.
46  *
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.
53  */
54 int  c_certsvc_pkcs12_get_certificate_list_from_store(CertStoreType storeType, int is_root_app, CertSvcStoreCertList **certList, size_t *length);
55
56 /**
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.
59  *
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.
65  */
66 int  c_certsvc_pkcs12_set_certificate_status_to_store(CertStoreType storeType, int is_root_app, const char *gname, CertStatus status);
67
68 /**
69  * To get the status (enabled/disabled) for the specified certificate in a particular store.
70  *
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
75  */
76 int  c_certsvc_pkcs12_get_certificate_status_from_store(CertStoreType storeType, const char *gname, CertStatus *status);
77
78 /**
79  * To get the encoded form of the specified certificate from the specified store.
80  *
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.
86  */
87 int  c_certsvc_pkcs12_get_certificate_buffer_from_store(CertStoreType storeType, const char *gname, char **certBuffer, size_t *certSize);
88
89 /**
90  * To delete the certificate from the specified store (VPN_STORE, WIFI_STORE, EMAIL_STORE, SYSTEM_STORE, ALL_STORE).
91  *
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.
95  */
96 int  c_certsvc_pkcs12_delete_certificate_from_store(CertStoreType storeType, const char* gname);
97
98 /**
99  * To free the certificate list which got generated from
100  * c_certsvc_pkcs12_get_certificate_list_from_store() function.
101  *
102  * @param[in] certList Linked-list having all the information about each certificate present in a store.
103  * @return CERTSVC_SUCCESS, CERTSVC_FAIL.
104  */
105 int  c_certsvc_pkcs12_free_aliases_loaded_from_store(CertSvcStoreCertList **certList);
106
107 /**
108  * Checks if the alias exist in the user store or not.
109  *
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.
114  */
115 int  c_certsvc_pkcs12_alias_exists_in_store(CertStoreType storeType, const char *alias, int *isUnique);
116
117 /**
118  * Function to get the size of the file passed.
119  *
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.
125  */
126 int c_certsvc_pkcs12_load_certificates_from_store(CertStoreType storeType, const char *gname, char ***certs, size_t *ncerts);
127
128 /**
129  * To load the private key for the specified certificate mapped by an Alias.
130  *
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.
135  */
136 int  c_certsvc_pkcs12_private_key_load_from_store(CertStoreType storeType, const char *gname, char **pkey, size_t *count);
137
138 /**
139  * Gets the alias name for the gname passed.
140  *
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
145  */
146 int c_certsvc_pkcs12_get_certificate_alias_from_store(CertStoreType storeType, const char *gname, char **alias);
147
148 /**
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.
152  *
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.
157  */
158 int c_certsvc_pkcs12_get_end_user_certificate_list_from_store(CertStoreType storeType, CertSvcStoreCertList **certList, size_t *length);
159
160 /**
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.
164  *
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.
169  */
170 int c_certsvc_pkcs12_get_root_certificate_list_from_store(CertStoreType storeType, CertSvcStoreCertList **certList, size_t *length);
171
172 /**
173  * TO check if the p12/pfx file is protected by password or not.
174  *
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.
178  */
179 int  c_certsvc_pkcs12_has_password(const char *filepath, int *passworded);
180
181 /**
182  * To free the certificates from memory which was loaded by
183  * c_certsvc_pkcs12_load_certificates() functon.
184  *
185  * @param[in] certs A pointer holding all the certificates in memory.
186  * @return CERTSVC_SUCCESS, CERTSVC_FAIL, CERTSVC_IO_ERROR.
187  */
188 void c_certsvc_pkcs12_free_certificates(char **certs);
189
190 #ifdef __cplusplus
191 }
192 #endif
193
194 #endif