summaryrefslogtreecommitdiff
path: root/src/lib/libssl/ssl_init.c
diff options
context:
space:
mode:
authorbeck <>2018-03-17 16:20:01 +0000
committerbeck <>2018-03-17 16:20:01 +0000
commitd18ae25f28e72831dc3c51f78e0735342540098b (patch)
tree12cc674e7652f4d67e57ec9e1882e6e824b4808d /src/lib/libssl/ssl_init.c
parent736fdc7bedf7fe8b17717032f7380c5c6e247d0d (diff)
downloadopenbsd-d18ae25f28e72831dc3c51f78e0735342540098b.tar.gz
openbsd-d18ae25f28e72831dc3c51f78e0735342540098b.tar.bz2
openbsd-d18ae25f28e72831dc3c51f78e0735342540098b.zip
Bring in compatibility for OpenSSL 1.1 style init functions.
This adds OPENSSL_init_crypto and OPENSSL_init_ssl, as well thread safety modifications for the existing LibreSSL init functions. The initialization routines are called automatically by the normal entry points into the library, as in newer OpenSSL ok jsing@, nits by tb@ and deraadt@
Diffstat (limited to 'src/lib/libssl/ssl_init.c')
-rw-r--r--src/lib/libssl/ssl_init.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/lib/libssl/ssl_init.c b/src/lib/libssl/ssl_init.c
new file mode 100644
index 0000000000..0ef80956ed
--- /dev/null
+++ b/src/lib/libssl/ssl_init.c
@@ -0,0 +1,50 @@
1/*
2 * Copyright (c) 2018 Bob Beck <beck@openbsd.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17/* OpenSSL style init */
18
19#include <pthread.h>
20#include <stdio.h>
21
22#include <openssl/objects.h>
23
24#include "ssl_locl.h"
25
26static pthread_t ssl_init_thread;
27
28static void
29OPENSSL_init_ssl_internal(void)
30{
31 ssl_init_thread = pthread_self();
32 SSL_load_error_strings();
33 SSL_library_init();
34}
35
36int
37OPENSSL_init_ssl(uint64_t opts, const void *settings)
38{
39 static pthread_once_t once = PTHREAD_ONCE_INIT;
40
41 if (pthread_equal(pthread_self(), ssl_init_thread))
42 return 1; /* don't recurse */
43
44 OPENSSL_init_crypto(opts, settings);
45
46 if (pthread_once(&once, OPENSSL_init_ssl_internal) != 0)
47 return 0;
48
49 return 1;
50}