]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 3095] Compatibility with openssl 1.1
authorJuergen Perlinger <perlinger@ntp.org>
Sun, 2 Oct 2016 07:01:53 +0000 (09:01 +0200)
committerJuergen Perlinger <perlinger@ntp.org>
Sun, 2 Oct 2016 07:01:53 +0000 (09:01 +0200)
 - add autolib hader
 - fix linker input selection

bk: 57f0b0e1o_rUHYk9FtY_XDNPZ5kkpA

19 files changed:
include/ssl_applink.c
libntp/libssl_compat.c
ports/winnt/include/msvc_ssl_autolib.h [new file with mode: 0644]
ports/winnt/vs2008/debug-x64.vsprops
ports/winnt/vs2008/debug.vsprops
ports/winnt/vs2008/release-x64.vsprops
ports/winnt/vs2008/release.vsprops
ports/winnt/vs2013/debug-x64.props
ports/winnt/vs2013/debug.props
ports/winnt/vs2013/libntp/libntp.vcxproj
ports/winnt/vs2013/libntp/libntp.vcxproj.filters
ports/winnt/vs2013/release-x64.props
ports/winnt/vs2013/release.props
ports/winnt/vs2015/debug-x64.props
ports/winnt/vs2015/debug.props
ports/winnt/vs2015/libntp/libntp.vcxproj
ports/winnt/vs2015/libntp/libntp.vcxproj.filters
ports/winnt/vs2015/release-x64.props
ports/winnt/vs2015/release.props

index ba1f4a8fe91680c6349b1a52b5ccedafc87755a4..e409f3421f8209d35f096ecb2cc239c688f15742 100644 (file)
@@ -10,6 +10,9 @@
 # ifdef _MSC_VER
 #  pragma warning(push)
 #  pragma warning(disable: 4152)
+#  ifndef OPENSSL_NO_AUTOLINK
+#   include "msvc_ssl_autolib.h"
+#  endif
 # endif
 # include <openssl/applink.c>
 # ifdef _MSC_VER
@@ -29,16 +32,25 @@ void wrap_dbg_free(void *p);
 
 
 #if defined(OPENSSL) && defined(SYS_WINNT)
+
 void ssl_applink(void);
 
 void
 ssl_applink(void)
 {
-#ifdef WRAP_DBG_MALLOC
-       CRYPTO_set_mem_ex_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free);
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+#   ifdef WRAP_DBG_MALLOC
+       CRYPTO_set_mem_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free);
+#   else
+       OPENSSL_malloc_init();
+#   endif
 #else
+#   ifdef WRAP_DBG_MALLOC
+       CRYPTO_set_mem_ex_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free);
+#   else
        CRYPTO_malloc_init();
-#endif
+#   endif
+#endif /* OpenSSL version cascade */
 }
 #else  /* !OPENSSL || !SYS_WINNT */
 #define ssl_applink()  do {} while (0)
index ce6acb7d3c78374874b9d11bbee907d7fd976ac4..2e4f2eec62c886b6081a3deed40e57dc97474f07 100644 (file)
 #include "config.h"
 
 #include <string.h>
+#if defined(HAVE_INTTYPES_H) || _MSC_VER >= _MSC_VER == 1800
+# include <inttypes.h>
+#endif
+
 #include <openssl/bn.h>
 #include <openssl/evp.h>
 
diff --git a/ports/winnt/include/msvc_ssl_autolib.h b/ports/winnt/include/msvc_ssl_autolib.h
new file mode 100644 (file)
index 0000000..688b5e2
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * msvc_ssl_autolib.h -- automatic link library selection
+ *
+ * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project.
+ * The contents of 'html/copyright.html' apply.
+ * --------------------------------------------------------------------
+ *
+ * OpenSSL library names changed over time, at least once when v1.1.0
+ * emerged. For systems where the build system is inspected before
+ * the build environment is created (autconf, CMake, SCONS,...) this
+ * would be harmless, once it's known what libraries should be looked
+ * for. With MSVC / MSBUILD that's much trickier.
+ *
+ * So instead of manipulating the build environment we use the build
+ * tools themselves to create requests for linking the right library.
+ *
+ * To use this feature, it is recommended to use the precompiled
+ * VC binaries from Shining Light Productions:
+ *   https://slproweb.com/products/Win32OpenSSL.html
+ * These are installed in (OPENSSL_LIB)/vc.
+ *
+ * As an alternative, create the set of build variants of OpenSSL you
+ * need, implementing the following naming scheme:
+ *
+ *  basename<width><RT><DebRel>.lib
+ *
+ * so that e.g. libcrypto64MTd.lib is a 64bit binary, using a static
+ * multithreaded runtime in debug version. See the code below how this
+ * is handled.
+ * --------------------------------------------------------------------
+ */
+#pragma once
+
+#if !defined(_MSC_VER)
+# error use this header only with Micro$oft Visual C compilers!
+#elif defined(OPENSSL_NO_AUTOLINK)
+# pragma message("automatic OpenSSL library selection disabled")
+#else
+/* ---------------------------------------------------------------- */
+/*  selection dance to get the right libraries linked               */
+/* ---------------------------------------------------------------- */
+
+/* --*-- check if this a DEBUG or a RELEASE build --*--
+ * The '_DEBUG' macro is only set for DEBUG build variants
+ */
+# ifdef _DEBUG
+#  define LTAG_DEBUG "d"
+# else
+#  define LTAG_DEBUG ""
+# endif
+
+/* --*-- check platform (32 bit vs. 64 bit) --*--
+ * '_WIN64' is defined for X64 Platform only
+ */
+# ifdef _WIN64
+#  define LTAG_SIZE "64"
+# else
+#  define LTAG_SIZE "32"
+# endif
+
+/* --*-- check VC runtime model --*--
+ * '_DLL' is set if a runtime-in-a-dll code generation model is chosen.
+ * Note that we do not check for the single-threaded static runtime.
+ * This would make no sense, since the Windows Build *uses* threads and
+ * therefore needs a multithread runtime anyway. And Micro$oft decided
+ * somewhere after VS2008 to drop that model anyway, so it's no longer
+ * available on newer platforms.
+ */
+# ifdef _DLL
+#  #define LTAG_RTLIB "MD"
+# else
+#  define LTAG_RTLIB "MT"
+# endif
+
+/* --*-- place linker request in object file --*--
+ * Here we come to the reason for all that trouble: the library names
+ * to link depend on the OpenSSL version...
+ *
+ * Before v1.1.0, the 'old' (ancient?) name 'libeay32' was used,
+ * no matter what platform. (The corresponding 'ssleay32.lib' was/is
+ * not used by NTP.) Since v1.1.0, the name stems are libcrypto
+ * and libssl, and they contain the platform size (32 or 64).
+ *
+ * So we use '#pragma comment(lib,...)' to place a proper linker
+ * request in the object file, depending on the SSL version and the
+ * build variant.
+ */
+# if OPENSSL_VERSION_NUMBER >= 0x10100000L
+#  pragma comment(lib, "libcrypto" LTAG_SIZE LTAG_RTLIB LTAG_DEBUG ".lib")
+# else
+#  pragma comment(lib, "libeay32" LTAG_RTLIB LTAG_DEBUG ".lib")
+# endif
+
+#endif /*!defined(OPENSSL_NO_AUTOLINK)*/
index 06f6f204e19788dc200d7a0ed4a0491735a726e8..3f241c2c8692065e44fb1acbf86eb8559f36ae26 100644 (file)
@@ -14,7 +14,7 @@
        />
        <Tool
                Name="VCLinkerTool"
-               AdditionalDependencies=" $(OPENSSL64_LIB)\libeay32.lib"
+               AdditionalLibraryDirectories=" $(OPENSSL64_LIB)\vc"
                TargetMachine="17"
-/>
+       />
 </VisualStudioPropertySheet>
index 0a1619748dbb1f5df93b11e7b7ae5f1747b851dc..0cbd9f4ae79251b6d57ce9193888a6c7e5ee417d 100644 (file)
@@ -14,7 +14,7 @@
        />
        <Tool
                Name="VCLinkerTool"
-               AdditionalDependencies=" $(OPENSSL_LIB)\libeay32.lib"
+               AdditionalLibraryDirectories=" $(OPENSSL_LIB)\vc"
                TargetMachine="1"
        />
 </VisualStudioPropertySheet>
index 23cb8a8cbeb94d4c1acc156c2fcc4b2bc9aee590..8c0ee80b0be4cb0785c392c0fc393b313c84e76b 100644 (file)
@@ -15,7 +15,7 @@
        />
        <Tool
                Name="VCLinkerTool"
-               AdditionalDependencies=" $(OPENSSL64_LIB)\libeay32.lib"
+               AdditionalLibraryDirectories=" $(OPENSSL64_LIB)\vc"
                TargetMachine="17"
        />
 </VisualStudioPropertySheet>
index 4c7c513ad713c616ff39225fdbf0b95f8c696eae..498779578f8596be9918b8a6554979e171697d02 100644 (file)
@@ -15,7 +15,7 @@
        />
        <Tool
                Name="VCLinkerTool"
-               AdditionalDependencies=" $(OPENSSL_LIB)\libeay32.lib"
+               AdditionalLibraryDirectories=" $(OPENSSL_LIB)\vc"
                TargetMachine="1"
        />
 </VisualStudioPropertySheet>
index ac72381aef9765d208a001103d6452ee3c7c620d..65d4f863f42ac17186e35abe785e29e447d96646 100644 (file)
@@ -16,8 +16,8 @@
       <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
     </ClCompile>
     <Link>
-      <AdditionalDependencies>$(OPENSSL64_LIB)\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <TargetMachine>MachineX64</TargetMachine>
+      <AdditionalLibraryDirectories>$(OPENSSL64_LIB)\vc</AdditionalLibraryDirectories>
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup />
index 3808859088cf2555a89c5e6cd69667b0a1b832fe..46792f84587ff9ab64b7e01624ca67bf0c63a3a4 100644 (file)
@@ -16,8 +16,8 @@
       <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
     </ClCompile>
     <Link>
-      <AdditionalDependencies>$(OPENSSL_LIB)\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <TargetMachine>MachineX86</TargetMachine>
+      <AdditionalLibraryDirectories>$(OPENSSL_LIB)\vc</AdditionalLibraryDirectories>
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup />
index 5171e948a09b0352112f3f0d772189d215551e6a..26a13c21f7555767440172e28d3830182991f192 100644 (file)
     <ClInclude Include="..\..\include\clockstuff.h" />
     <ClInclude Include="..\..\include\config.h" />
     <ClInclude Include="..\..\include\gaa_compat.h" />
+    <ClInclude Include="..\..\include\msvc_ssl_autolib.h" />
     <ClInclude Include="..\..\include\netdb.h" />
     <ClInclude Include="..\..\include\ntp_iocompletionport.h" />
     <ClInclude Include="..\..\include\ntp_timer.h" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
index 022ccf4a12c9d073ddf1b57bb4e21a34c871d1fe..9839bbd8349acd78dec143b002d7b3b2bcd801bf 100644 (file)
     <ClInclude Include="..\..\..\..\include\libssl_compat.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\include\msvc_ssl_autolib.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <CustomBuild Include="..\..\libntp\messages.mc">
index dcd725557f1655b5bce2760b5e8795d5691e59cd..2bb07cb37d3d5cea57b956c93bbcb974096f0846 100644 (file)
@@ -17,8 +17,8 @@
       <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
     </ClCompile>
     <Link>
-      <AdditionalDependencies>$(OPENSSL64_LIB)\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <TargetMachine>MachineX64</TargetMachine>
+      <AdditionalLibraryDirectories>$(OPENSSL64_LIB)\vc</AdditionalLibraryDirectories>
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup />
index d32ea70c15a666310d04d628319e1b4baef70e09..f6382dfbac38c4f52b85804af833f57b445d1ad1 100644 (file)
@@ -17,8 +17,8 @@
       <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
     </ClCompile>
     <Link>
-      <AdditionalDependencies>$(OPENSSL_LIB)\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <TargetMachine>MachineX86</TargetMachine>
+      <AdditionalLibraryDirectories>$(OPENSSL_LIB)\vc</AdditionalLibraryDirectories>
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup />
index ac72381aef9765d208a001103d6452ee3c7c620d..65d4f863f42ac17186e35abe785e29e447d96646 100644 (file)
@@ -16,8 +16,8 @@
       <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
     </ClCompile>
     <Link>
-      <AdditionalDependencies>$(OPENSSL64_LIB)\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <TargetMachine>MachineX64</TargetMachine>
+      <AdditionalLibraryDirectories>$(OPENSSL64_LIB)\vc</AdditionalLibraryDirectories>
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup />
index 3808859088cf2555a89c5e6cd69667b0a1b832fe..46792f84587ff9ab64b7e01624ca67bf0c63a3a4 100644 (file)
@@ -16,8 +16,8 @@
       <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
     </ClCompile>
     <Link>
-      <AdditionalDependencies>$(OPENSSL_LIB)\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <TargetMachine>MachineX86</TargetMachine>
+      <AdditionalLibraryDirectories>$(OPENSSL_LIB)\vc</AdditionalLibraryDirectories>
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup />
index 6f6899f9cc4f50174cc94ff7449a3d1c7cf11f0c..a93e97015f988c3d4ff921bcf543268c3f4db0cf 100644 (file)
     <ClInclude Include="..\..\include\clockstuff.h" />
     <ClInclude Include="..\..\include\config.h" />
     <ClInclude Include="..\..\include\gaa_compat.h" />
+    <ClInclude Include="..\..\include\msvc_ssl_autolib.h" />
     <ClInclude Include="..\..\include\netdb.h" />
     <ClInclude Include="..\..\include\ntp_iocompletionport.h" />
     <ClInclude Include="..\..\include\ntp_timer.h" />
index 022ccf4a12c9d073ddf1b57bb4e21a34c871d1fe..9839bbd8349acd78dec143b002d7b3b2bcd801bf 100644 (file)
     <ClInclude Include="..\..\..\..\include\libssl_compat.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\include\msvc_ssl_autolib.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <CustomBuild Include="..\..\libntp\messages.mc">
index dcd725557f1655b5bce2760b5e8795d5691e59cd..2bb07cb37d3d5cea57b956c93bbcb974096f0846 100644 (file)
@@ -17,8 +17,8 @@
       <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
     </ClCompile>
     <Link>
-      <AdditionalDependencies>$(OPENSSL64_LIB)\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <TargetMachine>MachineX64</TargetMachine>
+      <AdditionalLibraryDirectories>$(OPENSSL64_LIB)\vc</AdditionalLibraryDirectories>
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup />
index d32ea70c15a666310d04d628319e1b4baef70e09..f6382dfbac38c4f52b85804af833f57b445d1ad1 100644 (file)
@@ -17,8 +17,8 @@
       <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
     </ClCompile>
     <Link>
-      <AdditionalDependencies>$(OPENSSL_LIB)\libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <TargetMachine>MachineX86</TargetMachine>
+      <AdditionalLibraryDirectories>$(OPENSSL_LIB)\vc</AdditionalLibraryDirectories>
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup />