d5d923f89d1b2e3210e6d402de8bf563ac56ba7c
[gentoo.git] /
1 Patch modified to apply to VirtualGL 2.5.2, before
2 1b82bceb3723b24ea5dc32edffbe019a8a37ab39 reformatted whitespace
3
4
5 From a974c22141d0ded9ff60a0b903f81e6b484d6ba4 Mon Sep 17 00:00:00 2001
6 From: DRC <information@virtualgl.org>
7 Date: Mon, 16 Apr 2018 15:06:07 -0500
8 Subject: [PATCH] OpenSSL improvements
9
10 - Fix build issues with OpenSSL 1.1 (OpenSSL 1.1 and later no longer
11   provides CRYPTO_set_locking_callback(), since locking is now performed
12   internally.)
13 - Detect whether the platform has /dev/urandom at compile time, rather
14   than assuming that all Sun and SGI machines don't have it (Solaris 10
15   and later supports /dev/urandom.)
16 ---
17  ChangeLog.md        |  2 ++
18  include/Socket.h    |  8 ++++++--
19  util/CMakeLists.txt |  5 +++++
20  util/Socket.cpp     | 25 ++++++++++++++++---------
21  4 files changed, 29 insertions(+), 11 deletions(-)
22
23 diff --git a/ChangeLog.md b/ChangeLog.md
24 index 3632c1d8..5c9bff84 100644
25 --- a/ChangeLog.md
26 +++ b/ChangeLog.md
27 @@ -52,6 +52,8 @@ a subsequent segfault when VTK tried to call `glBlendFuncSeparate()`.
28  VirtualGL's implementation of `glXGetVisualFromFBConfig()` now returns NULL
29  unless the FB config has a corresponding visual on the 3D X server.
30  
31 +6. VirtualGL can now be built and run with OpenSSL 1.1.
32 +
33  
34  2.5.2
35  =====
36 diff --git a/include/Socket.h b/include/Socket.h
37 index dfe45e3a..f7409956 100644
38 --- a/include/Socket.h
39 +++ b/include/Socket.h
40 @@ -1,6 +1,6 @@
41  /* Copyright (C)2004 Landmark Graphics Corporation
42   * Copyright (C)2005 Sun Microsystems, Inc.
43 - * Copyright (C)2014, 2016 D. R. Commander
44 + * Copyright (C)2014, 2016, 2018 D. R. Commander
45   *
46   * This library is free software and may be redistributed and/or modified under
47   * the terms of the wxWindows Library License, Version 3.1 or (at your option)
48 @@ -23,7 +23,7 @@
49  #endif
50  #include <openssl/ssl.h>
51  #include <openssl/err.h>
52 -#if defined(sun) || defined(sgi)
53 +#if !defined(HAVE_DEVURANDOM) && !defined(_WIN32)
54  #include <openssl/rand.h>
55  #endif
56  #endif
57 @@ -161,15 +161,19 @@ namespace vglutil
58  
59                         #ifdef USESSL
60  
61 +                       #if OPENSSL_VERSION_NUMBER < 0x10100000L
62                         static void lockingCallback(int mode, int type, const char *file,
63                                 int line)
64                         {
65                                 if(mode&CRYPTO_LOCK) cryptoLock[type].lock();
66                                 else cryptoLock[type].unlock();
67                         }
68 +                       #endif
69  
70                         static bool sslInit;
71 +                       #if OPENSSL_VERSION_NUMBER < 0x10100000L
72                         static CriticalSection cryptoLock[CRYPTO_NUM_LOCKS];
73 +                       #endif
74                         bool doSSL;  SSL_CTX *sslctx;  SSL *ssl;
75  
76                         #endif
77 diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt
78 index 65ef59e7..ed1dfb39 100644
79 --- a/util/CMakeLists.txt
80 +++ b/util/CMakeLists.txt
81 @@ -13,6 +13,11 @@ target_link_libraries(bmptest vglutil)
82  add_executable(pftest pftest.c)
83  target_link_libraries(pftest vglutil)
84  
85 +if(EXISTS /dev/urandom)
86 +       message(STATUS "Using /dev/urandom for random number generation")
87 +       add_definitions(-DHAVE_DEVURANDOM)
88 +endif()
89 +
90  add_library(vglsocket STATIC Socket.cpp)
91  target_link_libraries(vglsocket vglutil)
92  if(WIN32)
93 diff --git a/util/Socket.cpp b/util/Socket.cpp
94 index 0d230841..b41c25e9 100644
95 --- a/util/Socket.cpp
96 +++ b/util/Socket.cpp
97 @@ -1,6 +1,6 @@
98  /* Copyright (C)2004 Landmark Graphics Corporation
99   * Copyright (C)2005 Sun Microsystems, Inc.
100 - * Copyright (C)2014, 2016 D. R. Commander
101 + * Copyright (C)2014, 2016, 2018 D. R. Commander
102   *
103   * This library is free software and may be redistributed and/or modified under
104   * the terms of the wxWindows Library License, Version 3.1 or (at your option)
105 @@ -43,32 +43,37 @@ typedef socklen_t SOCKLEN_T;
106  
107  #ifdef USESSL
108  bool Socket::sslInit=false;
109 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
110  CriticalSection Socket::cryptoLock[CRYPTO_NUM_LOCKS];
111  #endif
112 +#endif
113  CriticalSection Socket::mutex;
114  int Socket::instanceCount=0;
115  
116  
117  #ifdef USESSL
118  
119 -static void progressCallback(int p, int n, void *arg)
120 -{
121 -}
122 -
123 -
124  static EVP_PKEY *newPrivateKey(int bits)
125  {
126 +       BIGNUM *bn = NULL;
127 +       RSA *rsa = NULL;
128         EVP_PKEY *pk=NULL;
129  
130         try
131         {
132 +               if(!(bn = BN_new())) _throwssl();
133 +               if(!BN_set_word(bn, RSA_F4)) _throwssl();
134 +               if(!(rsa = RSA_new())) _throwssl();
135 +               if(!RSA_generate_key_ex(rsa, bits, bn, NULL)) _throwssl();
136                 if(!(pk=EVP_PKEY_new())) _throwssl();
137 -               if(!EVP_PKEY_assign_RSA(pk, RSA_generate_key(bits, 0x10001,
138 -                       progressCallback, NULL))) _throwssl();
139 +               if(!EVP_PKEY_assign_RSA(pk, rsa)) _throwssl();
140 +               BN_free(bn);
141                 return pk;
142         }
143         catch (...)
144         {
145 +               if(bn) BN_free(bn);
146 +               if(rsa) RSA_free(rsa);
147                 if(pk) EVP_PKEY_free(pk);
148                 throw;
149         }
150 @@ -147,7 +152,7 @@ Socket::Socket(bool doSSL_)
151         #ifdef USESSL
152         if(!sslInit && doSSL)
153         {
154 -               #if defined(sun) || defined(sgi)
155 +               #if !defined(HAVE_DEVURANDOM) && !defined(_WIN32)
156                 char buf[128];  int i;
157                 srandom(getpid());
158                 for(i = 0; i < 128; i++)
159 @@ -158,7 +163,9 @@ Socket::Socket(bool doSSL_)
160                 SSL_load_error_strings();
161                 ERR_load_crypto_strings();
162                 CRYPTO_set_id_callback(Thread::threadID);
163 +               #if OPENSSL_VERSION_NUMBER < 0x10100000L
164                 CRYPTO_set_locking_callback(lockingCallback);
165 +               #endif
166                 SSL_library_init();
167                 sslInit = true;
168                 char *env = NULL;