diff options
| author | beck <> | 2018-03-17 16:20:01 +0000 | 
|---|---|---|
| committer | beck <> | 2018-03-17 16:20:01 +0000 | 
| commit | 035770aca4c8c1f0d36f1b8da62c9e1fb9a4f09b (patch) | |
| tree | 12cc674e7652f4d67e57ec9e1882e6e824b4808d /src/lib/libssl/ssl_init.c | |
| parent | 1c31745efe6ed99c3a4e427046074fc4b544f08d (diff) | |
| download | openbsd-035770aca4c8c1f0d36f1b8da62c9e1fb9a4f09b.tar.gz openbsd-035770aca4c8c1f0d36f1b8da62c9e1fb9a4f09b.tar.bz2 openbsd-035770aca4c8c1f0d36f1b8da62c9e1fb9a4f09b.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 '')
| -rw-r--r-- | src/lib/libssl/ssl_init.c | 50 | 
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 | |||
| 26 | static pthread_t ssl_init_thread; | ||
| 27 | |||
| 28 | static void | ||
| 29 | OPENSSL_init_ssl_internal(void) | ||
| 30 | { | ||
| 31 | ssl_init_thread = pthread_self(); | ||
| 32 | SSL_load_error_strings(); | ||
| 33 | SSL_library_init(); | ||
| 34 | } | ||
| 35 | |||
| 36 | int | ||
| 37 | OPENSSL_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 | } | ||
