You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
4.3 KiB

  1. commit 612c05efb3c3b243da603a3a050993281888b6e3
  2. Author: Arjen de Korte <build+github@de-korte.org>
  3. Date: Fri Mar 15 10:17:32 2019 +0100
  4. Add support for openssl-1.1.0 (#504)
  5. * Add support for openssl-1.1.0
  6. * Allow TLSv1 and higher (not just TLSv1)
  7. * Fix check for empty string
  8. * Report TLS handshake in debug mode
  9. * Update nut_check_libopenssl.m4
  10. * Update upsclient.c
  11. * Update netssl.c
  12. --- a/clients/upsclient.c
  13. +++ b/clients/upsclient.c
  14. @@ -299,11 +299,6 @@ int upscli_init(int certverify, const ch
  15. {
  16. #ifdef WITH_OPENSSL
  17. int ret, ssl_mode = SSL_VERIFY_NONE;
  18. -#if OPENSSL_VERSION_NUMBER >= 0x10000000L
  19. - const SSL_METHOD *ssl_method;
  20. -#else
  21. - SSL_METHOD *ssl_method;
  22. -#endif
  23. #elif defined(WITH_NSS) /* WITH_OPENSSL */
  24. SECStatus status;
  25. #endif /* WITH_OPENSSL | WITH_NSS */
  26. @@ -315,22 +310,32 @@ int upscli_init(int certverify, const ch
  27. }
  28. #ifdef WITH_OPENSSL
  29. -
  30. - SSL_library_init();
  31. - SSL_load_error_strings();
  32. - ssl_method = TLSv1_client_method();
  33. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  34. + SSL_load_error_strings();
  35. + SSL_library_init();
  36. - if (!ssl_method) {
  37. - return 0;
  38. - }
  39. + ssl_ctx = SSL_CTX_new(SSLv23_client_method());
  40. +#else
  41. + ssl_ctx = SSL_CTX_new(TLS_client_method());
  42. +#endif
  43. - ssl_ctx = SSL_CTX_new(ssl_method);
  44. if (!ssl_ctx) {
  45. upslogx(LOG_ERR, "Can not initialize SSL context");
  46. return -1;
  47. }
  48. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  49. + /* set minimum protocol TLSv1 */
  50. + SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
  51. +#else
  52. + ret = SSL_CTX_set_min_proto_version(ssl_ctx, TLS1_VERSION);
  53. + if (ret != 1) {
  54. + upslogx(LOG_ERR, "Can not set minimum protocol to TLSv1");
  55. + return -1;
  56. + }
  57. +#endif
  58. +
  59. if (!certpath) {
  60. if (certverify == 1) {
  61. upslogx(LOG_ERR, "Can not verify certificate if any is specified");
  62. @@ -737,7 +742,7 @@ static int upscli_sslinit(UPSCONN_t *ups
  63. switch(res)
  64. {
  65. case 1:
  66. - upsdebugx(3, "SSL connected");
  67. + upsdebugx(3, "SSL connected (%s)", SSL_get_version(ups->ssl));
  68. break;
  69. case 0:
  70. upslog_with_errno(1, "SSL_connect do not accept handshake.");
  71. --- a/clients/upssched.c
  72. +++ b/clients/upssched.c
  73. @@ -794,7 +794,7 @@ static void parse_at(const char *ntype,
  74. }
  75. if (!strcmp(cmd, "EXECUTE")) {
  76. - if (ca1 == '\0') {
  77. + if (ca1[0] == '\0') {
  78. upslogx(LOG_ERR, "Empty EXECUTE command argument");
  79. return;
  80. }
  81. --- a/m4/nut_check_libopenssl.m4
  82. +++ b/m4/nut_check_libopenssl.m4
  83. @@ -58,7 +58,7 @@ if test -z "${nut_have_libopenssl_seen}"
  84. dnl check if openssl is usable
  85. AC_CHECK_HEADERS(openssl/ssl.h, [nut_have_openssl=yes], [nut_have_openssl=no], [AC_INCLUDES_DEFAULT])
  86. - AC_CHECK_FUNCS(SSL_library_init, [], [nut_have_openssl=no])
  87. + AC_CHECK_FUNCS(SSL_CTX_new, [], [nut_have_openssl=no])
  88. if test "${nut_have_openssl}" = "yes"; then
  89. nut_with_ssl="yes"
  90. --- a/server/netssl.c
  91. +++ b/server/netssl.c
  92. @@ -274,7 +274,7 @@ void net_starttls(nut_ctype_t *client, i
  93. {
  94. case 1:
  95. client->ssl_connected = 1;
  96. - upsdebugx(3, "SSL connected");
  97. + upsdebugx(3, "SSL connected (%s)", SSL_get_version(client->ssl));
  98. break;
  99. case 0:
  100. @@ -370,13 +370,7 @@ void ssl_init(void)
  101. {
  102. #ifdef WITH_NSS
  103. SECStatus status;
  104. -#elif defined(WITH_OPENSSL)
  105. -#if OPENSSL_VERSION_NUMBER >= 0x10000000L
  106. - const SSL_METHOD *ssl_method;
  107. -#else
  108. - SSL_METHOD *ssl_method;
  109. -#endif
  110. -#endif /* WITH_NSS|WITH_OPENSSL */
  111. +#endif /* WITH_NSS */
  112. if (!certfile) {
  113. return;
  114. @@ -386,18 +380,29 @@ void ssl_init(void)
  115. #ifdef WITH_OPENSSL
  116. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  117. SSL_load_error_strings();
  118. SSL_library_init();
  119. - if ((ssl_method = TLSv1_server_method()) == NULL) {
  120. + ssl_ctx = SSL_CTX_new(SSLv23_server_method());
  121. +#else
  122. + ssl_ctx = SSL_CTX_new(TLS_server_method());
  123. +#endif
  124. +
  125. + if (!ssl_ctx) {
  126. ssl_debug();
  127. - fatalx(EXIT_FAILURE, "TLSv1_server_method failed");
  128. + fatalx(EXIT_FAILURE, "SSL_CTX_new failed");
  129. }
  130. - if ((ssl_ctx = SSL_CTX_new(ssl_method)) == NULL) {
  131. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  132. + /* set minimum protocol TLSv1 */
  133. + SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
  134. +#else
  135. + if (SSL_CTX_set_min_proto_version(ssl_ctx, TLS1_VERSION) != 1) {
  136. ssl_debug();
  137. - fatalx(EXIT_FAILURE, "SSL_CTX_new failed");
  138. + fatalx(EXIT_FAILURE, "SSL_CTX_set_min_proto_version(TLS1_VERSION)");
  139. }
  140. +#endif
  141. if (SSL_CTX_use_certificate_chain_file(ssl_ctx, certfile) != 1) {
  142. ssl_debug();