@@ -244,7 +244,7 @@ proc TLSv1_method*(): PSSL_METHOD{.cdecl, dynlib: DLLSSLName, importc.}
244
244
# and support SSLv3, TLSv1, TLSv1.1 and TLSv1.2
245
245
# SSLv23_method(), SSLv23_server_method(), SSLv23_client_method() are removed in 1.1.0
246
246
247
- when compileOption(" dynlibOverride" , " ssl" ):
247
+ when compileOption(" dynlibOverride" , " ssl" ) or defined(noOpenSSLHacks) :
248
248
# Static linking
249
249
250
250
when defined(openssl10):
@@ -285,28 +285,39 @@ else:
285
285
proc thisModule(): LibHandle {.inline.} =
286
286
var thisMod {.global.}: LibHandle
287
287
if thisMod.isNil: thisMod = loadLib()
288
+
288
289
result = thisMod
289
290
290
291
proc sslModule(): LibHandle {.inline.} =
291
292
var sslMod {.global.}: LibHandle
292
293
if sslMod.isNil: sslMod = loadLibPattern(DLLSSLName)
294
+
293
295
result = sslMod
294
296
295
- proc sslSym(name: string ): pointer =
296
- var dl = thisModule()
297
- if not dl.isNil:
298
- result = symAddr(dl, name)
297
+ proc sslSym(name: string , alternativeName = " " ): pointer =
298
+ # Load from DLL.
299
+ var sslDynlib = sslModule()
300
+ if not sslDynlib.isNil:
301
+ result = symAddr(sslDynlib, name)
302
+ if result .isNil and alternativeName.len > 0 :
303
+ result = symAddr(sslDynlib, alternativeName)
304
+
305
+ # Attempt to load from current exe.
299
306
if result .isNil:
300
- dl = sslModule()
301
- if not dl.isNil:
302
- result = symAddr(dl, name)
307
+ let thisDynlib = thisModule()
308
+ if thisDynlib.isNil: raiseInvalidLibrary(name)
309
+ result = symAddr(thisDynlib, name)
310
+ if result .isNil and alternativeName.len > 0 :
311
+ result = symAddr(sslDynlib, alternativeName)
303
312
304
313
proc loadPSSLMethod(method1, method2: string ): PSSL_METHOD =
305
314
# # Load <method1> from OpenSSL if available, otherwise <method2>
306
- let m1 = cast [proc (): PSSL_METHOD {.cdecl, gcsafe.}](sslSym(method1))
307
- if not m1.isNil:
308
- return m1()
309
- cast [proc (): PSSL_METHOD {.cdecl, gcsafe.}](sslSym(method2))()
315
+ let methodSym = sslSym(method1, method2)
316
+ if methodSym.isNil:
317
+ raise newException(LibraryError, " Could not load " & method1 & " nor " & method2)
318
+ else :
319
+ let method2Proc = cast [proc (): PSSL_METHOD {.cdecl, gcsafe.}](methodSym)
320
+ return method2Proc()
310
321
311
322
proc SSL_library_init* (): cint {.discardable.} =
312
323
# # Initialize SSL using OPENSSL_init_ssl for OpenSSL >= 1.1.0 otherwise
@@ -325,7 +336,7 @@ else:
325
336
loadPSSLMethod(" SSLv23_client_method" , " TLS_client_method" )
326
337
327
338
proc SSLv23_method * (): PSSL_METHOD =
328
- loadPSSLMethod(" SSLv23_method" , " TLS_method" )
339
+ result = loadPSSLMethod(" SSLv23_method" , " TLS_method" )
329
340
330
341
proc SSLv2_method * (): PSSL_METHOD =
331
342
loadPSSLMethod(" SSLv2_method" , " TLS_method" )
0 commit comments