diff options
| author | jsing <> | 2017-05-06 20:59:28 +0000 |
|---|---|---|
| committer | jsing <> | 2017-05-06 20:59:28 +0000 |
| commit | 7fed4741c75d7419f23867acd8c3a1bdc866b716 (patch) | |
| tree | 657a8c245abd0d5e2045521716d7977e1dfe887f /src/lib/libtls/tls.c | |
| parent | 7046952f9f5fae47726c165667e46169d74cdfae (diff) | |
| download | openbsd-7fed4741c75d7419f23867acd8c3a1bdc866b716.tar.gz openbsd-7fed4741c75d7419f23867acd8c3a1bdc866b716.tar.bz2 openbsd-7fed4741c75d7419f23867acd8c3a1bdc866b716.zip | |
Perform reference counting for tls_config. This allows tls_config_free() to
be called as soon as it has been passed to the final tls_configure() call,
simplifying lifetime tracking for the application.
Requested some time ago by tedu@.
ok beck@
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libtls/tls.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/lib/libtls/tls.c b/src/lib/libtls/tls.c index 446f93430d..b639873df4 100644 --- a/src/lib/libtls/tls.c +++ b/src/lib/libtls/tls.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: tls.c,v 1.61 2017/04/05 03:19:22 beck Exp $ */ | 1 | /* $OpenBSD: tls.c,v 1.62 2017/05/06 20:59:28 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -50,6 +50,8 @@ tls_init(void) | |||
| 50 | if ((tls_config_default = tls_config_new()) == NULL) | 50 | if ((tls_config_default = tls_config_new()) == NULL) |
| 51 | return (-1); | 51 | return (-1); |
| 52 | 52 | ||
| 53 | tls_config_default->refcount++; | ||
| 54 | |||
| 53 | tls_initialised = 1; | 55 | tls_initialised = 1; |
| 54 | 56 | ||
| 55 | return (0); | 57 | return (0); |
| @@ -230,9 +232,8 @@ tls_new(void) | |||
| 230 | if ((ctx = calloc(1, sizeof(*ctx))) == NULL) | 232 | if ((ctx = calloc(1, sizeof(*ctx))) == NULL) |
| 231 | return (NULL); | 233 | return (NULL); |
| 232 | 234 | ||
| 233 | ctx->config = tls_config_default; | ||
| 234 | |||
| 235 | tls_reset(ctx); | 235 | tls_reset(ctx); |
| 236 | tls_configure(ctx, tls_config_default); | ||
| 236 | 237 | ||
| 237 | return (ctx); | 238 | return (ctx); |
| 238 | } | 239 | } |
| @@ -243,6 +244,9 @@ tls_configure(struct tls *ctx, struct tls_config *config) | |||
| 243 | if (config == NULL) | 244 | if (config == NULL) |
| 244 | config = tls_config_default; | 245 | config = tls_config_default; |
| 245 | 246 | ||
| 247 | config->refcount++; | ||
| 248 | |||
| 249 | tls_config_free(ctx->config); | ||
| 246 | ctx->config = config; | 250 | ctx->config = config; |
| 247 | 251 | ||
| 248 | if ((ctx->flags & TLS_SERVER) != 0) | 252 | if ((ctx->flags & TLS_SERVER) != 0) |
| @@ -521,6 +525,9 @@ tls_reset(struct tls *ctx) | |||
| 521 | { | 525 | { |
| 522 | struct tls_sni_ctx *sni, *nsni; | 526 | struct tls_sni_ctx *sni, *nsni; |
| 523 | 527 | ||
| 528 | tls_config_free(ctx->config); | ||
| 529 | ctx->config = NULL; | ||
| 530 | |||
| 524 | SSL_CTX_free(ctx->ssl_ctx); | 531 | SSL_CTX_free(ctx->ssl_ctx); |
| 525 | SSL_free(ctx->ssl_conn); | 532 | SSL_free(ctx->ssl_conn); |
| 526 | X509_free(ctx->ssl_peer_cert); | 533 | X509_free(ctx->ssl_peer_cert); |
