wrappers/openssl: the version number comes from the utility library

Previously we loaded the SSL library for this, but that's not where the
symbol resides.
This commit is contained in:
Leorize 2020-06-04 09:22:41 -05:00 • committed by Andreas Rumpf
commit d406f588d8

View file

@ -264,7 +264,7 @@ when compileOption("dynlibOverride", "ssl") or defined(noOpenSSLHacks):
proc SSL_library_init*(): cint {.cdecl, dynlib: DLLSSLName, importc, discardable.} proc SSL_library_init*(): cint {.cdecl, dynlib: DLLSSLName, importc, discardable.}
proc SSL_load_error_strings*() {.cdecl, dynlib: DLLSSLName, importc.} proc SSL_load_error_strings*() {.cdecl, dynlib: DLLSSLName, importc.}
proc SSLv23_method*(): PSSL_METHOD {.cdecl, dynlib: DLLSSLName, importc.} proc SSLv23_method*(): PSSL_METHOD {.cdecl, dynlib: DLLSSLName, importc.}
proc SSLeay(): culong {.cdecl, dynlib: DLLSSLName, importc.} proc SSLeay(): culong {.cdecl, dynlib: DLLUtilName, importc.}
proc getOpenSSLVersion*(): culong = proc getOpenSSLVersion*(): culong =
SSLeay() SSLeay()
@ -278,7 +278,7 @@ when compileOption("dynlibOverride", "ssl") or defined(noOpenSSLHacks):
proc SSLv23_method*(): PSSL_METHOD = proc SSLv23_method*(): PSSL_METHOD =
TLS_method() TLS_method()
proc OpenSSL_version_num(): culong {.cdecl, dynlib: DLLSSLName, importc.} proc OpenSSL_version_num(): culong {.cdecl, dynlib: DLLUtilName, importc.}
proc getOpenSSLVersion*(): culong = proc getOpenSSLVersion*(): culong =
## Return OpenSSL version as unsigned long ## Return OpenSSL version as unsigned long
@ -318,13 +318,18 @@ else:
result = sslMod result = sslMod
proc sslSymNullable(name: string, alternativeName = ""): pointer = proc utilModule(): LibHandle {.inline.} =
var utilMod {.global.}: LibHandle
if utilMod.isNil: utilMod = loadLibPattern(DLLUtilName)
result = utilMod
proc symNullable(dll: LibHandle, name: string, alternativeName = ""): pointer =
# Load from DLL. # Load from DLL.
var sslDynlib = sslModule() if not dll.isNil:
if not sslDynlib.isNil: result = symAddr(dll, name)
result = symAddr(sslDynlib, name)
if result.isNil and alternativeName.len > 0: if result.isNil and alternativeName.len > 0:
result = symAddr(sslDynlib, alternativeName) result = symAddr(dll, alternativeName)
# Attempt to load from current exe. # Attempt to load from current exe.
if result.isNil: if result.isNil:
@ -332,12 +337,18 @@ else:
if thisDynlib.isNil: return nil if thisDynlib.isNil: return nil
result = symAddr(thisDynlib, name) result = symAddr(thisDynlib, name)
if result.isNil and alternativeName.len > 0: if result.isNil and alternativeName.len > 0:
result = symAddr(sslDynlib, alternativeName) result = symAddr(thisDynlib, alternativeName)
proc sslSymNullable(name: string, alternativeName = ""): pointer =
sslModule().symNullable(name, alternativeName)
proc sslSymThrows(name: string, alternativeName = ""): pointer = proc sslSymThrows(name: string, alternativeName = ""): pointer =
result = sslSymNullable(name, alternativeName) result = sslSymNullable(name, alternativeName)
if result.isNil: raiseInvalidLibrary(name) if result.isNil: raiseInvalidLibrary(name)
proc utilSymNullable(name: string, alternativeName = ""): pointer =
utilModule().symNullable(name, alternativeName)
proc loadPSSLMethod(method1, method2: string): PSSL_METHOD = proc loadPSSLMethod(method1, method2: string): PSSL_METHOD =
## Load <method1> from OpenSSL if available, otherwise <method2> ## Load <method1> from OpenSSL if available, otherwise <method2>
## ##
@ -392,7 +403,7 @@ else:
proc getOpenSSLVersion*(): culong = proc getOpenSSLVersion*(): culong =
## Return OpenSSL version as unsigned long or 0 if not available ## Return OpenSSL version as unsigned long or 0 if not available
let theProc = cast[proc(): culong {.cdecl.}](sslSymNullable("OpenSSL_version_num", "SSLeay")) let theProc = cast[proc(): culong {.cdecl.}](utilSymNullable("OpenSSL_version_num", "SSLeay"))
{.gcsafe.}: {.gcsafe.}:
result = result =
if theProc.isNil: 0.culong if theProc.isNil: 0.culong