Browse Source

Fix SSL initialization for OpenSSL >= 1.1.

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
Slávek Banko 1 month ago
parent
commit
43609c8a21
Signed by: Slávek Banko <slavek.banko@axis.cz> GPG Key ID: 608F5293A04BE668
1 changed files with 24 additions and 2 deletions
  1. 24
    2
      tdeio/kssl/kopenssl.cc

+ 24
- 2
tdeio/kssl/kopenssl.cc View File

@@ -37,6 +37,13 @@
37 37
 #define GET_CRYPTOLIB_SYMBOL(a) ((_cryptoLib->hasSymbol(a)) ? _cryptoLib->symbol(a) : NULL)
38 38
 #define GET_SSLLIB_SYMBOL(a) ((_sslLib->hasSymbol(a)) ? _sslLib->symbol(a) : NULL)
39 39
 
40
+// taken from OpenSSL 1.1 header, used to call OPENSSL_init_crypto
41
+#if !defined(OPENSSL_INIT_ADD_ALL_CIPHERS)
42
+# define OPENSSL_INIT_ADD_ALL_CIPHERS        0x00000004L
43
+# define OPENSSL_INIT_ADD_ALL_DIGESTS        0x00000008L
44
+# define OPENSSL_INIT_LOAD_CONFIG            0x00000040L
45
+#endif
46
+
40 47
 extern "C" {
41 48
 #ifdef KSSL_HAVE_SSL
42 49
 static int (*K_SSL_connect)     (SSL *) = 0L;
@@ -675,8 +682,22 @@ TDEConfig *cfg;
675 682
 
676 683
       // Initialize the library (once only!)
677 684
       void *x;
678
-      x = GET_SSLLIB_SYMBOL("SSL_library_init");
679
-      if (_cryptoLib) {
685
+      x = GET_SSLLIB_SYMBOL("OPENSSL_init_ssl");
686
+      if (x) {
687
+        // OpenSSL >= 1.1
688
+        if (_cryptoLib) {
689
+          ((int (*)(unsigned long, void*))x)(0, NULL);
690
+          x = GET_CRYPTOLIB_SYMBOL("OPENSSL_init_crypto");
691
+          if (x) ((int (*)(unsigned long, void*))x)(OPENSSL_INIT_ADD_ALL_CIPHERS
692
+                                                    | OPENSSL_INIT_ADD_ALL_DIGESTS
693
+                                                    | OPENSSL_INIT_LOAD_CONFIG,
694
+                                                    NULL);
695
+        }
696
+      }
697
+      else {
698
+        // OpenSSL < 1.1
699
+        x = GET_SSLLIB_SYMBOL("SSL_library_init");
700
+        if (_cryptoLib) {
680 701
          if (x) ((int (*)())x)();
681 702
          x = GET_CRYPTOLIB_SYMBOL("OpenSSL_add_all_algorithms");
682 703
          if (!x)
@@ -705,6 +726,7 @@ TDEConfig *cfg;
705 726
          if (!x)
706 727
             x = GET_CRYPTOLIB_SYMBOL("OPENSSL_add_all_digests");
707 728
          if (x) ((void (*)())x)();
729
+        }
708 730
       }
709 731
    }
710 732
 

Loading…
Cancel
Save