diff --git a/include/haproxy/ssl_ckch.h b/include/haproxy/ssl_ckch.h index 37cb4710f..1bb82a2d5 100644 --- a/include/haproxy/ssl_ckch.h +++ b/include/haproxy/ssl_ckch.h @@ -38,6 +38,7 @@ int ssl_sock_load_issuer_file_into_ckch(const char *path, char *buf, struct ckch /* ckch_store functions */ struct ckch_store *ckch_store_new_load_files_path(char *path, char **err); +struct ckch_store *ckch_store_new_load_files_conf(char *name, struct ckch_conf *conf, char **err); struct ckch_store *ckchs_lookup(char *path); struct ckch_store *ckchs_dup(const struct ckch_store *src); struct ckch_store *ckch_store_new(const char *filename); diff --git a/src/ssl_ckch.c b/src/ssl_ckch.c index b7e7ae1d4..f6e2e9a5b 100644 --- a/src/ssl_ckch.c +++ b/src/ssl_ckch.c @@ -1019,6 +1019,35 @@ struct ckch_store *ckch_store_new_load_files_path(char *path, char **err) return NULL; } +/* + * This function allocate a ckch_store and populate it with certificates using + * the ckch_conf structure. + */ +struct ckch_store *ckch_store_new_load_files_conf(char *name, struct ckch_conf *conf, char **err) +{ + struct ckch_store *ckchs; + int cfgerr = ERR_NONE; + + ckchs = ckch_store_new(name); + if (!ckchs) { + memprintf(err, "%sunable to allocate memory.\n", err && *err ? *err : ""); + goto end; + } + + cfgerr = ckch_store_load_files(conf, ckchs, err); + if (cfgerr & ERR_FATAL) + goto end; + + /* insert into the ckchs tree */ + memcpy(ckchs->path, name, strlen(name) + 1); + ebst_insert(&ckchs_tree, &ckchs->node); + return ckchs; + +end: + ckch_store_free(ckchs); + + return NULL; +} /******************** ckch_inst functions ******************************/