1 Patch modified to apply to VirtualGL 2.5.2, before
2 1b82bceb3723b24ea5dc32edffbe019a8a37ab39 reformatted whitespace
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
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
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.)
18 include/Socket.h | 8 ++++++--
19 util/CMakeLists.txt | 5 +++++
20 util/Socket.cpp | 25 ++++++++++++++++---------
21 4 files changed, 29 insertions(+), 11 deletions(-)
23 diff --git a/ChangeLog.md b/ChangeLog.md
24 index 3632c1d8..5c9bff84 100644
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.
31 +6. VirtualGL can now be built and run with OpenSSL 1.1.
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
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
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)
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>
57 @@ -161,15 +161,19 @@ namespace vglutil
61 + #if OPENSSL_VERSION_NUMBER < 0x10100000L
62 static void lockingCallback(int mode, int type, const char *file,
65 if(mode&CRYPTO_LOCK) cryptoLock[type].lock();
66 else cryptoLock[type].unlock();
71 + #if OPENSSL_VERSION_NUMBER < 0x10100000L
72 static CriticalSection cryptoLock[CRYPTO_NUM_LOCKS];
74 bool doSSL; SSL_CTX *sslctx; SSL *ssl;
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)
85 +if(EXISTS /dev/urandom)
86 + message(STATUS "Using /dev/urandom for random number generation")
87 + add_definitions(-DHAVE_DEVURANDOM)
90 add_library(vglsocket STATIC Socket.cpp)
91 target_link_libraries(vglsocket vglutil)
93 diff --git a/util/Socket.cpp b/util/Socket.cpp
94 index 0d230841..b41c25e9 100644
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
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;
108 bool Socket::sslInit=false;
109 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
110 CriticalSection Socket::cryptoLock[CRYPTO_NUM_LOCKS];
113 CriticalSection Socket::mutex;
114 int Socket::instanceCount=0;
119 -static void progressCallback(int p, int n, void *arg)
124 static EVP_PKEY *newPrivateKey(int bits)
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();
145 + if(bn) BN_free(bn);
146 + if(rsa) RSA_free(rsa);
147 if(pk) EVP_PKEY_free(pk);
150 @@ -147,7 +152,7 @@ Socket::Socket(bool doSSL_)
152 if(!sslInit && doSSL)
154 - #if defined(sun) || defined(sgi)
155 + #if !defined(HAVE_DEVURANDOM) && !defined(_WIN32)
156 char buf[128]; int i;
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);