summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2018-03-19 16:34:47 +0000
committerjsing <>2018-03-19 16:34:47 +0000
commitc7be23675a7e4a025b9e5a5375aaed6139e653db (patch)
treea3c296b727ec4d2bb5671d0189458d547b6c3865
parentd3d84b6f3e79d4f8b89ef8f2e9d67ecaf8294433 (diff)
downloadopenbsd-c7be23675a7e4a025b9e5a5375aaed6139e653db.tar.gz
openbsd-c7be23675a7e4a025b9e5a5375aaed6139e653db.tar.bz2
openbsd-c7be23675a7e4a025b9e5a5375aaed6139e653db.zip
Automatically handle library initialisation for libtls.
Now that we have tls_init() under pthread_once(), automatically initialise libtls from the entry point functions (tls_config(), tls_client() and tls_server()) - this makes an explicit tls_init() call no longer a requirement. ok bcook@ beck@ inoguchi@
-rw-r--r--src/lib/libtls/man/tls_init.37
-rw-r--r--src/lib/libtls/tls.c5
-rw-r--r--src/lib/libtls/tls_client.c5
-rw-r--r--src/lib/libtls/tls_config.c13
-rw-r--r--src/lib/libtls/tls_internal.h4
-rw-r--r--src/lib/libtls/tls_server.c5
6 files changed, 28 insertions, 11 deletions
diff --git a/src/lib/libtls/man/tls_init.3 b/src/lib/libtls/man/tls_init.3
index dfafa612c1..f5f63fa326 100644
--- a/src/lib/libtls/man/tls_init.3
+++ b/src/lib/libtls/man/tls_init.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: tls_init.3,v 1.10 2018/03/08 16:12:00 beck Exp $ 1.\" $OpenBSD: tls_init.3,v 1.11 2018/03/19 16:34:47 jsing Exp $
2.\" 2.\"
3.\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> 3.\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org>
4.\" Copyright (c) 2016 Joel Sing <jsing@openbsd.org> 4.\" Copyright (c) 2016 Joel Sing <jsing@openbsd.org>
@@ -16,7 +16,7 @@
16.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18.\" 18.\"
19.Dd $Mdocdate: March 8 2018 $ 19.Dd $Mdocdate: March 19 2018 $
20.Dt TLS_INIT 3 20.Dt TLS_INIT 3
21.Os 21.Os
22.Sh NAME 22.Sh NAME
@@ -45,7 +45,8 @@ Both clients and servers are supported.
45The 45The
46.Fn tls_init 46.Fn tls_init
47function initializes global data structures. 47function initializes global data structures.
48It should be called once before any other functions. 48It may be called once before any other functions, however this is no
49longer necessary since it will be handled internally on demand.
49It may be called more than once, and may be called concurrently. 50It may be called more than once, and may be called concurrently.
50.Pp 51.Pp
51Before a connection is created, a configuration must be created. 52Before a connection is created, a configuration must be created.
diff --git a/src/lib/libtls/tls.c b/src/lib/libtls/tls.c
index e7a485bcec..467db164d5 100644
--- a/src/lib/libtls/tls.c
+++ b/src/lib/libtls/tls.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls.c,v 1.78 2018/03/08 16:12:00 beck Exp $ */ 1/* $OpenBSD: tls.c,v 1.79 2018/03/19 16:34:47 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -47,13 +47,12 @@ tls_do_init(void)
47 if (BIO_sock_init() != 1) 47 if (BIO_sock_init() != 1)
48 return; 48 return;
49 49
50 if ((tls_config_default = tls_config_new()) == NULL) 50 if ((tls_config_default = tls_config_new_internal()) == NULL)
51 return; 51 return;
52 52
53 tls_config_default->refcount++; 53 tls_config_default->refcount++;
54 54
55 tls_init_rv = 0; 55 tls_init_rv = 0;
56 return;
57} 56}
58 57
59int 58int
diff --git a/src/lib/libtls/tls_client.c b/src/lib/libtls/tls_client.c
index 14c716fa17..04e44020ef 100644
--- a/src/lib/libtls/tls_client.c
+++ b/src/lib/libtls/tls_client.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls_client.c,v 1.44 2018/02/10 04:41:24 jsing Exp $ */ 1/* $OpenBSD: tls_client.c,v 1.45 2018/03/19 16:34:47 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -38,6 +38,9 @@ tls_client(void)
38{ 38{
39 struct tls *ctx; 39 struct tls *ctx;
40 40
41 if (tls_init() == -1)
42 return (NULL);
43
41 if ((ctx = tls_new()) == NULL) 44 if ((ctx = tls_new()) == NULL)
42 return (NULL); 45 return (NULL);
43 46
diff --git a/src/lib/libtls/tls_config.c b/src/lib/libtls/tls_config.c
index 2dab4fc7d8..02f2b3c6e9 100644
--- a/src/lib/libtls/tls_config.c
+++ b/src/lib/libtls/tls_config.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls_config.c,v 1.49 2018/02/10 04:57:35 jsing Exp $ */ 1/* $OpenBSD: tls_config.c,v 1.50 2018/03/19 16:34:47 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -77,7 +77,7 @@ tls_config_load_file(struct tls_error *error, const char *filetype,
77} 77}
78 78
79struct tls_config * 79struct tls_config *
80tls_config_new(void) 80tls_config_new_internal(void)
81{ 81{
82 struct tls_config *config; 82 struct tls_config *config;
83 unsigned char sid[TLS_MAX_SESSION_ID_LENGTH]; 83 unsigned char sid[TLS_MAX_SESSION_ID_LENGTH];
@@ -128,6 +128,15 @@ tls_config_new(void)
128 return (NULL); 128 return (NULL);
129} 129}
130 130
131struct tls_config *
132tls_config_new(void)
133{
134 if (tls_init() == -1)
135 return (NULL);
136
137 return tls_config_new_internal();
138}
139
131void 140void
132tls_config_free(struct tls_config *config) 141tls_config_free(struct tls_config *config)
133{ 142{
diff --git a/src/lib/libtls/tls_internal.h b/src/lib/libtls/tls_internal.h
index f8b9e6118e..0d7e2289d3 100644
--- a/src/lib/libtls/tls_internal.h
+++ b/src/lib/libtls/tls_internal.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls_internal.h,v 1.70 2018/02/10 04:57:35 jsing Exp $ */ 1/* $OpenBSD: tls_internal.h,v 1.71 2018/03/19 16:34:47 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org> 3 * Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org>
4 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 4 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
@@ -219,6 +219,8 @@ int tls_keypair_load_cert(struct tls_keypair *_keypair,
219struct tls_sni_ctx *tls_sni_ctx_new(void); 219struct tls_sni_ctx *tls_sni_ctx_new(void);
220void tls_sni_ctx_free(struct tls_sni_ctx *sni_ctx); 220void tls_sni_ctx_free(struct tls_sni_ctx *sni_ctx);
221 221
222struct tls_config *tls_config_new_internal(void);
223
222struct tls *tls_new(void); 224struct tls *tls_new(void);
223struct tls *tls_server_conn(struct tls *ctx); 225struct tls *tls_server_conn(struct tls *ctx);
224 226
diff --git a/src/lib/libtls/tls_server.c b/src/lib/libtls/tls_server.c
index 98b0957437..44bef6bb11 100644
--- a/src/lib/libtls/tls_server.c
+++ b/src/lib/libtls/tls_server.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls_server.c,v 1.43 2018/02/08 05:56:49 jsing Exp $ */ 1/* $OpenBSD: tls_server.c,v 1.44 2018/03/19 16:34:47 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -31,6 +31,9 @@ tls_server(void)
31{ 31{
32 struct tls *ctx; 32 struct tls *ctx;
33 33
34 if (tls_init() == -1)
35 return (NULL);
36
34 if ((ctx = tls_new()) == NULL) 37 if ((ctx = tls_new()) == NULL)
35 return (NULL); 38 return (NULL);
36 39