1 From da1f5aa699f54e0f6977ab64a3bc2f90a51c3104 Mon Sep 17 00:00:00 2001
2 From: Arjen de Korte <build+lede@de-korte.org>
3 Date: Mon, 27 Nov 2017 21:10:13 +0100
4 Subject: [PATCH] Add support for openssl-1.1.0
6 --- a/clients/upsclient.c
7 +++ b/clients/upsclient.c
11 int ret, ssl_mode = SSL_VERIFY_NONE;
12 -#if OPENSSL_VERSION_NUMBER >= 0x10000000L
13 - const SSL_METHOD *ssl_method;
15 - SSL_METHOD *ssl_method;
17 #elif defined(WITH_NSS) /* WITH_OPENSSL */
19 #endif /* WITH_OPENSSL | WITH_NSS */
26 - SSL_load_error_strings();
28 - ssl_method = TLSv1_client_method();
29 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
30 + SSL_load_error_strings();
36 + ssl_ctx = SSL_CTX_new(SSLv23_client_method());
38 + ssl_ctx = SSL_CTX_new(TLS_client_method());
41 - ssl_ctx = SSL_CTX_new(ssl_method);
43 upslogx(LOG_ERR, "Can not initialize SSL context");
47 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
48 + /* set minimum protocol TLSv1 */
49 + SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
51 + ret = SSL_CTX_set_min_proto_version(ssl_ctx, TLS1_VERSION);
53 + upslogx(LOG_ERR, "Can not set minimum protocol to TLSv1");
59 if (certverify == 1) {
60 upslogx(LOG_ERR, "Can not verify certificate if any is specified");
65 - upsdebugx(3, "SSL connected");
66 + upsdebugx(3, "SSL connected (%s)", SSL_get_version(ups->ssl));
69 upslog_with_errno(1, "SSL_connect do not accept handshake.");
70 --- a/clients/upssched.c
71 +++ b/clients/upssched.c
75 if (!strcmp(cmd, "EXECUTE")) {
77 + if (ca1[0] == '\0') {
78 upslogx(LOG_ERR, "Empty EXECUTE command argument");
81 --- a/m4/nut_check_libopenssl.m4
82 +++ b/m4/nut_check_libopenssl.m4
85 dnl check if openssl is usable
86 AC_CHECK_HEADERS(openssl/ssl.h, [nut_have_openssl=yes], [nut_have_openssl=no], [AC_INCLUDES_DEFAULT])
87 - AC_CHECK_FUNCS(SSL_library_init, [], [nut_have_openssl=no])
88 + AC_CHECK_FUNCS(SSL_CTX_new, [], [nut_have_openssl=no])
90 if test "${nut_have_openssl}" = "yes"; then
97 client->ssl_connected = 1;
98 - upsdebugx(3, "SSL connected");
99 + upsdebugx(3, "SSL connected (%s)", SSL_get_version(client->ssl));
107 -#elif defined(WITH_OPENSSL)
108 -#if OPENSSL_VERSION_NUMBER >= 0x10000000L
109 - const SSL_METHOD *ssl_method;
111 - SSL_METHOD *ssl_method;
113 -#endif /* WITH_NSS|WITH_OPENSSL */
114 +#endif /* WITH_NSS */
118 @@ -386,18 +380,29 @@
122 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
123 SSL_load_error_strings();
126 - if ((ssl_method = TLSv1_server_method()) == NULL) {
127 + ssl_ctx = SSL_CTX_new(SSLv23_server_method());
129 + ssl_ctx = SSL_CTX_new(TLS_server_method());
134 - fatalx(EXIT_FAILURE, "TLSv1_server_method failed");
135 + fatalx(EXIT_FAILURE, "SSL_CTX_new failed");
138 - if ((ssl_ctx = SSL_CTX_new(ssl_method)) == NULL) {
139 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
140 + /* set minimum protocol TLSv1 */
141 + SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
143 + if (SSL_CTX_set_min_proto_version(ssl_ctx, TLS1_VERSION) != 1) {
145 - fatalx(EXIT_FAILURE, "SSL_CTX_new failed");
146 + fatalx(EXIT_FAILURE, "SSL_CTX_set_min_proto_version(TLS1_VERSION)");
150 if (SSL_CTX_use_certificate_chain_file(ssl_ctx, certfile) != 1) {