Skip to content

Commit a9ea3b9

Browse files
committed
tls: openssl: Add setting up interface for certstore
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent e0d0179 commit a9ea3b9

File tree

3 files changed

+49
-12
lines changed

3 files changed

+49
-12
lines changed

include/fluent-bit/tls/flb_tls.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ struct flb_tls_backend {
9292
int (*net_write) (struct flb_tls_session *, const void *data,
9393
size_t len);
9494
int (*net_handshake) (struct flb_tls *, char *, void *);
95+
96+
#if defined(FLB_SYSTEM_WINDOWS)
97+
int (*set_certstore_name)(struct flb_tls *tls, const char *certstore_name);
98+
int (*set_use_enterprise_store)(struct flb_tls *tls, int use_enterprise);
99+
#endif
95100
};
96101

97102
/* Main TLS context */

src/tls/flb_tls.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -299,27 +299,19 @@ int flb_tls_set_verify_hostname(struct flb_tls *tls, int verify_hostname)
299299
#if defined(FLB_SYSTEM_WINDOWS)
300300
int flb_tls_set_certstore_name(struct flb_tls *tls, const char *certstore_name)
301301
{
302-
if (!tls) {
303-
return -1;
304-
}
305-
306-
if (tls->certstore_name) {
307-
flb_free(tls->certstore_name);
302+
if (tls) {
303+
return tls->api->set_certstore_name(tls, certstore_name);
308304
}
309305

310-
tls->certstore_name = flb_strdup(certstore_name);
311-
312306
return 0;
313307
}
314308

315309
int flb_tls_set_use_enterprise_store(struct flb_tls *tls, int use_enterprise)
316310
{
317-
if (!tls) {
318-
return -1;
311+
if (tls) {
312+
return tls->api->set_use_enterprise_store(tls, use_enterprise);
319313
}
320314

321-
tls->use_enterprise_store = !!use_enterprise;
322-
323315
return 0;
324316
}
325317
#endif

src/tls/openssl.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ static void tls_context_destroy(void *ctx_backend)
152152
ctx->alpn = NULL;
153153
}
154154

155+
#if defined(FLB_SYSTEM_WINDOWS)
156+
if (ctx->certstore_name != NULL) {
157+
flb_free(ctx->certstore_name);
158+
159+
ctx->certstore_name = NULL;
160+
}
161+
#endif
162+
155163
pthread_mutex_unlock(&ctx->mutex);
156164

157165
flb_free(ctx);
@@ -788,6 +796,34 @@ static int tls_set_ciphers(struct flb_tls *tls, const char *ciphers)
788796
return 0;
789797
}
790798

799+
#if defined(FLB_SYSTEM_WINDOWS)
800+
static int tls_set_certstore_name(struct flb_tls *tls, const char *certstore_name)
801+
{
802+
struct tls_context *ctx = tls->ctx;
803+
804+
pthread_mutex_lock(&ctx->mutex);
805+
806+
ctx->certstore_name = flb_strdup(certstore_name);
807+
808+
pthread_mutex_unlock(&ctx->mutex);
809+
810+
return 0;
811+
}
812+
813+
static int tls_set_use_enterprise_store(struct flb_tls *tls, int use_enterprise)
814+
{
815+
struct tls_context *ctx = tls->ctx;
816+
817+
pthread_mutex_lock(&ctx->mutex);
818+
819+
ctx->use_enterprise_store = !!use_enterprise;
820+
821+
pthread_mutex_unlock(&ctx->mutex);
822+
823+
return 0;
824+
}
825+
#endif
826+
791827
static void *tls_session_create(struct flb_tls *tls,
792828
int fd)
793829
{
@@ -1187,4 +1223,8 @@ static struct flb_tls_backend tls_openssl = {
11871223
.net_read = tls_net_read,
11881224
.net_write = tls_net_write,
11891225
.net_handshake = tls_net_handshake,
1226+
#if defined(FLB_SYSTEM_WINDOWS)
1227+
.set_certstore_name = tls_set_certstore_name,
1228+
.set_use_enterprise_store = tls_set_use_enterprise_store,
1229+
#endif
11901230
};

0 commit comments

Comments
 (0)