summaryrefslogtreecommitdiff
path: root/src/lib/libssl
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
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')
-rw-r--r--src/lib/libssl/Makefile4
-rw-r--r--src/lib/libssl/Symbols.list3
-rw-r--r--src/lib/libssl/ssl.h15
-rw-r--r--src/lib/libssl/ssl_init.c50
-rw-r--r--src/lib/libssl/ssl_lib.c7
-rw-r--r--src/lib/libssl/ssl_sess.c7
6 files changed, 81 insertions, 5 deletions
diff --git a/src/lib/libssl/Makefile b/src/lib/libssl/Makefile
index 66dae58874..6a397a7df7 100644
--- a/src/lib/libssl/Makefile
+++ b/src/lib/libssl/Makefile
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile,v 1.38 2017/08/13 19:42:33 doug Exp $ 1# $OpenBSD: Makefile,v 1.39 2018/03/17 16:20:01 beck Exp $
2 2
3.include <bsd.own.mk> 3.include <bsd.own.mk>
4.ifndef NOMAN 4.ifndef NOMAN
@@ -33,7 +33,7 @@ SRCS= \
33 ssl_ciph.c ssl_stat.c ssl_rsa.c \ 33 ssl_ciph.c ssl_stat.c ssl_rsa.c \
34 ssl_asn1.c ssl_txt.c ssl_algs.c \ 34 ssl_asn1.c ssl_txt.c ssl_algs.c \
35 bio_ssl.c ssl_err.c \ 35 bio_ssl.c ssl_err.c \
36 ssl_packet.c ssl_tlsext.c ssl_versions.c pqueue.c 36 ssl_packet.c ssl_tlsext.c ssl_versions.c pqueue.c ssl_init.c
37SRCS+= s3_cbc.c 37SRCS+= s3_cbc.c
38SRCS+= bs_ber.c bs_cbb.c bs_cbs.c 38SRCS+= bs_ber.c bs_cbb.c bs_cbs.c
39 39
diff --git a/src/lib/libssl/Symbols.list b/src/lib/libssl/Symbols.list
index 581b292a74..3b513d5c28 100644
--- a/src/lib/libssl/Symbols.list
+++ b/src/lib/libssl/Symbols.list
@@ -298,3 +298,6 @@ SSL_version
298SSL_version_str 298SSL_version_str
299SSL_want 299SSL_want
300SSL_write 300SSL_write
301
302/* OpenSSL compatible init */
303OPENSSL_init_ssl
diff --git a/src/lib/libssl/ssl.h b/src/lib/libssl/ssl.h
index 05939f214d..97d1c40a66 100644
--- a/src/lib/libssl/ssl.h
+++ b/src/lib/libssl/ssl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl.h,v 1.152 2018/03/17 15:55:52 tb Exp $ */ 1/* $OpenBSD: ssl.h,v 1.153 2018/03/17 16:20:01 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -2112,6 +2112,19 @@ void ERR_load_SSL_strings(void);
2112#define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS 269 2112#define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS 269
2113#define SSL_R_PEER_BEHAVING_BADLY 666 2113#define SSL_R_PEER_BEHAVING_BADLY 666
2114 2114
2115/*
2116 * OpenSSL compatible OPENSSL_INIT options
2117 */
2118
2119/*
2120 * These are provided for compatibiliy, but have no effect
2121 * on how LibreSSL is initialized.
2122 */
2123#define OPENSSL_INIT_LOAD_SSL_STRINGS _OPENSSL_INIT_FLAG_NOOP
2124#define OPENSSL_INIT_SSL_DEFAULT _OPENSSL_INIT_FLAG_NOOP
2125
2126int OPENSSL_init_ssl(uint64_t opts, const void *settings);
2127
2115#ifdef __cplusplus 2128#ifdef __cplusplus
2116} 2129}
2117#endif 2130#endif
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}
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c
index eca3c97fac..573e63c934 100644
--- a/src/lib/libssl/ssl_lib.c
+++ b/src/lib/libssl/ssl_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_lib.c,v 1.181 2018/03/17 15:48:31 tb Exp $ */ 1/* $OpenBSD: ssl_lib.c,v 1.182 2018/03/17 16:20:01 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -1791,6 +1791,11 @@ SSL_CTX_new(const SSL_METHOD *meth)
1791{ 1791{
1792 SSL_CTX *ret; 1792 SSL_CTX *ret;
1793 1793
1794 if (!OPENSSL_init_ssl(0, NULL)) {
1795 SSLerrorx(SSL_R_LIBRARY_BUG);
1796 return (NULL);
1797 }
1798
1794 if (meth == NULL) { 1799 if (meth == NULL) {
1795 SSLerrorx(SSL_R_NULL_SSL_METHOD_PASSED); 1800 SSLerrorx(SSL_R_NULL_SSL_METHOD_PASSED);
1796 return (NULL); 1801 return (NULL);
diff --git a/src/lib/libssl/ssl_sess.c b/src/lib/libssl/ssl_sess.c
index 4903719fb3..51aa2eac04 100644
--- a/src/lib/libssl/ssl_sess.c
+++ b/src/lib/libssl/ssl_sess.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_sess.c,v 1.77 2018/03/17 15:55:53 tb Exp $ */ 1/* $OpenBSD: ssl_sess.c,v 1.78 2018/03/17 16:20:01 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -199,6 +199,11 @@ SSL_SESSION_new(void)
199{ 199{
200 SSL_SESSION *ss; 200 SSL_SESSION *ss;
201 201
202 if (!OPENSSL_init_ssl(0, NULL)) {
203 SSLerrorx(SSL_R_LIBRARY_BUG);
204 return(NULL);
205 }
206
202 if ((ss = calloc(1, sizeof(*ss))) == NULL) { 207 if ((ss = calloc(1, sizeof(*ss))) == NULL) {
203 SSLerrorx(ERR_R_MALLOC_FAILURE); 208 SSLerrorx(ERR_R_MALLOC_FAILURE);
204 return (NULL); 209 return (NULL);