summaryrefslogtreecommitdiff
path: root/src/lib/libtls/tls.c
diff options
context:
space:
mode:
authorjsing <>2016-08-22 14:51:37 +0000
committerjsing <>2016-08-22 14:51:37 +0000
commit74ebdd842595c2d6c66a0aa102dc5c4b98412c8d (patch)
treee04823f4dbd54041cadc277b3cfa2714bd318c36 /src/lib/libtls/tls.c
parent60132b75420595a9684003b199d3299fe13ec457 (diff)
downloadopenbsd-74ebdd842595c2d6c66a0aa102dc5c4b98412c8d.tar.gz
openbsd-74ebdd842595c2d6c66a0aa102dc5c4b98412c8d.tar.bz2
openbsd-74ebdd842595c2d6c66a0aa102dc5c4b98412c8d.zip
Create contexts for server side SNI - these include the additional SSL_CTX
that is required for certificate switching with libssl and the certificate itself so that we can match against the subject and SANs. Hook up the servername callback and switch to the appropriate SSL_CTX if we find a matching certificate. ok beck@
Diffstat (limited to 'src/lib/libtls/tls.c')
-rw-r--r--src/lib/libtls/tls.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/lib/libtls/tls.c b/src/lib/libtls/tls.c
index bf0e1f769f..df610fe238 100644
--- a/src/lib/libtls/tls.c
+++ b/src/lib/libtls/tls.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls.c,v 1.46 2016/08/15 14:04:23 jsing Exp $ */ 1/* $OpenBSD: tls.c,v 1.47 2016/08/22 14:51:37 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -177,6 +177,24 @@ tls_set_errorx(struct tls *ctx, const char *fmt, ...)
177 return (rv); 177 return (rv);
178} 178}
179 179
180struct tls_sni_ctx *
181tls_sni_ctx_new(void)
182{
183 return (calloc(1, sizeof(struct tls_sni_ctx)));
184}
185
186void
187tls_sni_ctx_free(struct tls_sni_ctx *sni_ctx)
188{
189 if (sni_ctx == NULL)
190 return;
191
192 SSL_CTX_free(sni_ctx->ssl_ctx);
193 X509_free(sni_ctx->ssl_cert);
194
195 free(sni_ctx);
196}
197
180struct tls * 198struct tls *
181tls_new(void) 199tls_new(void)
182{ 200{
@@ -376,6 +394,8 @@ tls_free(struct tls *ctx)
376void 394void
377tls_reset(struct tls *ctx) 395tls_reset(struct tls *ctx)
378{ 396{
397 struct tls_sni_ctx *sni, *nsni;
398
379 SSL_CTX_free(ctx->ssl_ctx); 399 SSL_CTX_free(ctx->ssl_ctx);
380 SSL_free(ctx->ssl_conn); 400 SSL_free(ctx->ssl_conn);
381 X509_free(ctx->ssl_peer_cert); 401 X509_free(ctx->ssl_peer_cert);
@@ -397,6 +417,12 @@ tls_reset(struct tls *ctx)
397 tls_free_conninfo(ctx->conninfo); 417 tls_free_conninfo(ctx->conninfo);
398 free(ctx->conninfo); 418 free(ctx->conninfo);
399 ctx->conninfo = NULL; 419 ctx->conninfo = NULL;
420
421 for (sni = ctx->sni_ctx; sni != NULL; sni = nsni) {
422 nsni = sni->next;
423 tls_sni_ctx_free(sni);
424 }
425 ctx->sni_ctx = NULL;
400} 426}
401 427
402int 428int