1 /*
2 * This file is part of the openHiTLS project.
3 *
4 * openHiTLS is licensed under the Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 *
8 * http://license.coscl.org.cn/MulanPSL2
9 *
10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13 * See the Mulan PSL v2 for more details.
14 */
15
16 #include <stddef.h>
17 #include "hitls_build.h"
18 #include "bsl_err_internal.h"
19 #include "hitls_error.h"
20 #include "hitls_type.h"
21 #include "hitls_cert_type.h"
22 #include "hitls_cert.h"
23 #include "tls.h"
24
HITLS_SetVerifyStore(HITLS_Ctx * ctx,HITLS_CERT_Store * store,bool isClone)25 int32_t HITLS_SetVerifyStore(HITLS_Ctx *ctx, HITLS_CERT_Store *store, bool isClone)
26 {
27 if (ctx == NULL) {
28 return HITLS_NULL_INPUT;
29 }
30
31 return HITLS_CFG_SetVerifyStore(&(ctx->config.tlsConfig), store, isClone);
32 }
33
HITLS_GetVerifyStore(const HITLS_Ctx * ctx)34 HITLS_CERT_Store *HITLS_GetVerifyStore(const HITLS_Ctx *ctx)
35 {
36 if (ctx == NULL) {
37 return NULL;
38 }
39
40 return HITLS_CFG_GetVerifyStore(&(ctx->config.tlsConfig));
41 }
42
HITLS_SetChainStore(HITLS_Ctx * ctx,HITLS_CERT_Store * store,bool isClone)43 int32_t HITLS_SetChainStore(HITLS_Ctx *ctx, HITLS_CERT_Store *store, bool isClone)
44 {
45 if (ctx == NULL) {
46 return HITLS_NULL_INPUT;
47 }
48
49 return HITLS_CFG_SetChainStore(&(ctx->config.tlsConfig), store, isClone);
50 }
51
HITLS_GetChainStore(const HITLS_Ctx * ctx)52 HITLS_CERT_Store *HITLS_GetChainStore(const HITLS_Ctx *ctx)
53 {
54 if (ctx == NULL) {
55 return NULL;
56 }
57
58 return HITLS_CFG_GetChainStore(&(ctx->config.tlsConfig));
59 }
60
HITLS_SetCertStore(HITLS_Ctx * ctx,HITLS_CERT_Store * store,bool isClone)61 int32_t HITLS_SetCertStore(HITLS_Ctx *ctx, HITLS_CERT_Store *store, bool isClone)
62 {
63 if (ctx == NULL) {
64 return HITLS_NULL_INPUT;
65 }
66
67 return HITLS_CFG_SetCertStore(&(ctx->config.tlsConfig), store, isClone);
68 }
69
HITLS_GetCertStore(const HITLS_Ctx * ctx)70 HITLS_CERT_Store *HITLS_GetCertStore(const HITLS_Ctx *ctx)
71 {
72 if (ctx == NULL) {
73 return NULL;
74 }
75
76 return HITLS_CFG_GetCertStore(&(ctx->config.tlsConfig));
77 }
78
HITLS_SetVerifyDepth(HITLS_Ctx * ctx,uint32_t depth)79 int32_t HITLS_SetVerifyDepth(HITLS_Ctx *ctx, uint32_t depth)
80 {
81 if (ctx == NULL) {
82 return HITLS_NULL_INPUT;
83 }
84
85 return HITLS_CFG_SetVerifyDepth(&(ctx->config.tlsConfig), depth);
86 }
87
HITLS_GetVerifyDepth(const HITLS_Ctx * ctx,uint32_t * depth)88 int32_t HITLS_GetVerifyDepth(const HITLS_Ctx *ctx, uint32_t *depth)
89 {
90 if (ctx == NULL) {
91 return HITLS_NULL_INPUT;
92 }
93
94 return HITLS_CFG_GetVerifyDepth(&(ctx->config.tlsConfig), depth);
95 }
96
HITLS_SetDefaultPasswordCb(HITLS_Ctx * ctx,HITLS_PasswordCb cb)97 int32_t HITLS_SetDefaultPasswordCb(HITLS_Ctx *ctx, HITLS_PasswordCb cb)
98 {
99 if (ctx == NULL) {
100 return HITLS_NULL_INPUT;
101 }
102
103 return HITLS_CFG_SetDefaultPasswordCb(&(ctx->config.tlsConfig), cb);
104 }
105
HITLS_GetDefaultPasswordCb(HITLS_Ctx * ctx)106 HITLS_PasswordCb HITLS_GetDefaultPasswordCb(HITLS_Ctx *ctx)
107 {
108 if (ctx == NULL) {
109 return NULL;
110 }
111
112 return HITLS_CFG_GetDefaultPasswordCb(&(ctx->config.tlsConfig));
113 }
114
HITLS_SetDefaultPasswordCbUserdata(HITLS_Ctx * ctx,void * userdata)115 int32_t HITLS_SetDefaultPasswordCbUserdata(HITLS_Ctx *ctx, void *userdata)
116 {
117 if (ctx == NULL) {
118 return HITLS_NULL_INPUT;
119 }
120
121 return HITLS_CFG_SetDefaultPasswordCbUserdata(&(ctx->config.tlsConfig), userdata);
122 }
123
HITLS_GetDefaultPasswordCbUserdata(HITLS_Ctx * ctx)124 void *HITLS_GetDefaultPasswordCbUserdata(HITLS_Ctx *ctx)
125 {
126 if (ctx == NULL) {
127 return NULL;
128 }
129
130 return HITLS_CFG_GetDefaultPasswordCbUserdata(&(ctx->config.tlsConfig));
131 }
132
HITLS_SetCertificate(HITLS_Ctx * ctx,HITLS_CERT_X509 * cert,bool isClone)133 int32_t HITLS_SetCertificate(HITLS_Ctx *ctx, HITLS_CERT_X509 *cert, bool isClone)
134 {
135 if (ctx == NULL) {
136 return HITLS_NULL_INPUT;
137 }
138
139 return HITLS_CFG_SetCertificate(&(ctx->config.tlsConfig), cert, isClone);
140 }
141
142 #ifdef HITLS_TLS_CONFIG_CERT_LOAD_FILE
HITLS_LoadCertFile(HITLS_Ctx * ctx,const char * file,HITLS_ParseFormat format)143 int32_t HITLS_LoadCertFile(HITLS_Ctx *ctx, const char *file, HITLS_ParseFormat format)
144 {
145 if (ctx == NULL) {
146 return HITLS_NULL_INPUT;
147 }
148
149 return HITLS_CFG_LoadCertFile(&(ctx->config.tlsConfig), file, format);
150 }
151 #endif
152
HITLS_LoadCertBuffer(HITLS_Ctx * ctx,const uint8_t * buf,uint32_t bufLen,HITLS_ParseFormat format)153 int32_t HITLS_LoadCertBuffer(HITLS_Ctx *ctx, const uint8_t *buf, uint32_t bufLen, HITLS_ParseFormat format)
154 {
155 if (ctx == NULL) {
156 return HITLS_NULL_INPUT;
157 }
158
159 return HITLS_CFG_LoadCertBuffer(&(ctx->config.tlsConfig), buf, bufLen, format);
160 }
161
HITLS_GetCertificate(const HITLS_Ctx * ctx)162 HITLS_CERT_X509 *HITLS_GetCertificate(const HITLS_Ctx *ctx)
163 {
164 if (ctx == NULL) {
165 return NULL;
166 }
167
168 return HITLS_CFG_GetCertificate(&(ctx->config.tlsConfig));
169 }
170
HITLS_SetPrivateKey(HITLS_Ctx * ctx,HITLS_CERT_Key * key,bool isClone)171 int32_t HITLS_SetPrivateKey(HITLS_Ctx *ctx, HITLS_CERT_Key *key, bool isClone)
172 {
173 if (ctx == NULL) {
174 return HITLS_NULL_INPUT;
175 }
176
177 return HITLS_CFG_SetPrivateKey(&(ctx->config.tlsConfig), key, isClone);
178 }
179
180 #ifdef HITLS_TLS_CONFIG_CERT_LOAD_FILE
HITLS_ProviderLoadKeyFile(HITLS_Ctx * ctx,const char * file,const char * format,const char * type)181 int32_t HITLS_ProviderLoadKeyFile(HITLS_Ctx *ctx, const char *file, const char *format, const char *type)
182 {
183 if (ctx == NULL) {
184 return HITLS_NULL_INPUT;
185 }
186
187 return HITLS_CFG_ProviderLoadKeyFile(&(ctx->config.tlsConfig), file, format, type);
188 }
189
HITLS_LoadKeyFile(HITLS_Ctx * ctx,const char * file,HITLS_ParseFormat format)190 int32_t HITLS_LoadKeyFile(HITLS_Ctx *ctx, const char *file, HITLS_ParseFormat format)
191 {
192 if (ctx == NULL) {
193 return HITLS_NULL_INPUT;
194 }
195
196 return HITLS_CFG_LoadKeyFile(&(ctx->config.tlsConfig), file, format);
197 }
198 #endif /* HITLS_TLS_CONFIG_CERT_LOAD_FILE */
199
HITLS_ProviderLoadKeyBuffer(HITLS_Ctx * ctx,const uint8_t * buf,uint32_t bufLen,const char * format,const char * type)200 int32_t HITLS_ProviderLoadKeyBuffer(HITLS_Ctx *ctx, const uint8_t *buf, uint32_t bufLen, const char *format,
201 const char *type)
202 {
203 if (ctx == NULL) {
204 return HITLS_NULL_INPUT;
205 }
206
207 return HITLS_CFG_ProviderLoadKeyBuffer(&(ctx->config.tlsConfig), buf, bufLen, format, type);
208
209 }
210
HITLS_LoadKeyBuffer(HITLS_Ctx * ctx,const uint8_t * buf,uint32_t bufLen,HITLS_ParseFormat format)211 int32_t HITLS_LoadKeyBuffer(HITLS_Ctx *ctx, const uint8_t *buf, uint32_t bufLen, HITLS_ParseFormat format)
212 {
213 if (ctx == NULL) {
214 return HITLS_NULL_INPUT;
215 }
216
217 return HITLS_CFG_LoadKeyBuffer(&(ctx->config.tlsConfig), buf, bufLen, format);
218 }
219
HITLS_GetPrivateKey(HITLS_Ctx * ctx)220 HITLS_CERT_Key *HITLS_GetPrivateKey(HITLS_Ctx *ctx)
221 {
222 if (ctx == NULL) {
223 return NULL;
224 }
225
226 return HITLS_CFG_GetPrivateKey(&(ctx->config.tlsConfig));
227 }
228
HITLS_CheckPrivateKey(HITLS_Ctx * ctx)229 int32_t HITLS_CheckPrivateKey(HITLS_Ctx *ctx)
230 {
231 if (ctx == NULL) {
232 return HITLS_NULL_INPUT;
233 }
234
235 return HITLS_CFG_CheckPrivateKey(&(ctx->config.tlsConfig));
236 }
237
HITLS_RemoveCertAndKey(HITLS_Ctx * ctx)238 int32_t HITLS_RemoveCertAndKey(HITLS_Ctx *ctx)
239 {
240 if (ctx == NULL) {
241 return HITLS_NULL_INPUT;
242 }
243
244 return HITLS_CFG_RemoveCertAndKey(&(ctx->config.tlsConfig));
245 }
246
HITLS_SetVerifyCb(HITLS_Ctx * ctx,HITLS_VerifyCb callback)247 int32_t HITLS_SetVerifyCb(HITLS_Ctx *ctx, HITLS_VerifyCb callback)
248 {
249 if (ctx == NULL) {
250 return HITLS_NULL_INPUT;
251 }
252
253 return HITLS_CFG_SetVerifyCb(&(ctx->config.tlsConfig), callback);
254 }
255
HITLS_GetVerifyCb(HITLS_Ctx * ctx)256 HITLS_VerifyCb HITLS_GetVerifyCb(HITLS_Ctx *ctx)
257 {
258 if (ctx == NULL) {
259 return NULL;
260 }
261
262 return HITLS_CFG_GetVerifyCb(&(ctx->config.tlsConfig));
263 }