235 if(error) { |
235 if(error) { |
236 return NULL; |
236 return NULL; |
237 } |
237 } |
238 // TODO: cleanup on error |
238 // TODO: cleanup on error |
239 |
239 |
240 sstr_t file; |
|
241 int ret; |
240 int ret; |
242 char errbuf[512]; |
241 char errbuf[512]; |
243 |
242 |
244 if(!conf->chainfile.ptr) { |
243 if(!conf->chainfile.ptr) { |
245 file = sstrdup(conf->certfile); |
244 ret = SSL_CTX_use_certificate_file(ctx, conf->certfile.ptr, SSL_FILETYPE_PEM); |
246 ret = SSL_CTX_use_certificate_file(ctx, file.ptr, SSL_FILETYPE_PEM); |
|
247 free(file.ptr); |
|
248 if(!ret) { |
245 if(!ret) { |
249 ERR_error_string(ERR_get_error(), errbuf); |
246 ERR_error_string(ERR_get_error(), errbuf); |
250 log_ereport(LOG_MISCONFIG, "Cannot load ssl chain file: %s", errbuf); |
247 log_ereport(LOG_MISCONFIG, "Cannot load ssl chain file: %s", errbuf); |
251 return NULL; |
248 return NULL; |
252 } |
249 } |
253 } else { |
250 } else { |
254 file = sstrdup(conf->chainfile); |
251 ret = SSL_CTX_use_certificate_chain_file(ctx, conf->chainfile.ptr); |
255 ret = SSL_CTX_use_certificate_chain_file(ctx, file.ptr); |
|
256 free(file.ptr); |
|
257 if(!ret) { |
252 if(!ret) { |
258 ERR_error_string(ERR_get_error(), errbuf); |
253 ERR_error_string(ERR_get_error(), errbuf); |
259 log_ereport(LOG_MISCONFIG, "Cannot load ssl cert file: %s", errbuf); |
254 log_ereport(LOG_MISCONFIG, "Cannot load ssl cert file: %s", errbuf); |
260 return NULL; |
255 return NULL; |
261 } |
256 } |
262 } |
257 } |
263 |
258 |
264 file = sstrdup(conf->privkeyfile); |
259 ret = SSL_CTX_use_PrivateKey_file(ctx, conf->privkeyfile.ptr, SSL_FILETYPE_PEM); |
265 ret = SSL_CTX_use_PrivateKey_file(ctx, file.ptr, SSL_FILETYPE_PEM); |
|
266 free(file.ptr); |
|
267 if(!ret) { |
260 if(!ret) { |
268 ERR_error_string(ERR_get_error(), errbuf); |
261 ERR_error_string(ERR_get_error(), errbuf); |
269 log_ereport(LOG_MISCONFIG, "Cannot load ssl key file: %s", errbuf); |
262 log_ereport(LOG_MISCONFIG, "Cannot load ssl key file: %s", errbuf); |
270 return NULL; |
263 return NULL; |
271 } |
264 } |