Disable OpenSSL config autoload in Windows
cover Disable OpenSSL config autoload in Windows
From: Lev Stipakov <[email protected]...>
These two patches prevent OpenSSL from loading
config from a user-writable location, which may
pose a security risk.
Lev Stipakov (2):
crypto_openssl.c: disable explicit initialization on Windows contrib/vcpkg-ports: add openssl port with --no-autoload-config option
set
contrib/vcpkg-ports/openssl/portfile.cmake | 25 ++ .../vcpkg-ports/openssl/unix/CMakeLists.txt | 280 ++++++++++++++++++ .../vcpkg-ports/openssl/unix/portfile.cmake | 49 +++ .../openssl/unix/remove-deps.cmake | 7 + .../openssl/unix/vcpkg-cmake-wrapper.cmake | 18 ++ contrib/vcpkg-ports/openssl/usage | 4 + .../openssl/uwp/EnableUWPSupport.patch | 170 +++++++++++ .../vcpkg-ports/openssl/uwp/make-openssl.bat | 16 + .../vcpkg-ports/openssl/uwp/portfile.cmake | 156 ++++++++++ contrib/vcpkg-ports/openssl/vcpkg.json | 7 + .../openssl/windows/portfile.cmake | 174 +++++++++++ .../openssl/windows/vcpkg-cmake-wrapper.cmake | 10 + src/openvpn/crypto_openssl.c | 2 + 13 files changed, 918 insertions(+) create mode 100644 contrib/vcpkg-ports/openssl/portfile.cmake create mode 100644 contrib/vcpkg-ports/openssl/unix/CMakeLists.txt create mode 100644 contrib/vcpkg-ports/openssl/unix/portfile.cmake create mode 100644 contrib/vcpkg-ports/openssl/unix/remove-deps.cmake create mode 100644 contrib/vcpkg-ports/openssl/unix/vcpkg-cmake-wrapper.cmake create mode 100644 contrib/vcpkg-ports/openssl/usage create mode 100644 contrib/vcpkg-ports/openssl/uwp/EnableUWPSupport.patch create mode 100644 contrib/vcpkg-ports/openssl/uwp/make-openssl.bat create mode 100644 contrib/vcpkg-ports/openssl/uwp/portfile.cmake create mode 100644 contrib/vcpkg-ports/openssl/vcpkg.json create mode 100644 contrib/vcpkg-ports/openssl/windows/portfile.cmake create mode 100644 contrib/vcpkg-ports/openssl/windows/vcpkg-cmake-wrapper.cmake
Signature · 1 line
2.23.0.windows.1
PATCH 1/2 crypto_openssl.c: disable explicit initialization on Windows
From: Lev Stipakov <[email protected]...>
Commit a4071b ("crypto_openssl: add initialization to pick up local configuration") added openssl initialization to load configuration file. However on Windows this file is loaded from user-writable directory, such as c.\etc\ssl for mingw builds and (for example) c:\vcpkg\packages\openssl_x64-windows\openvpn.cnf for vcpkg builds. This could be a security risk.
Since aforementioned commit implements a niche feature which anyway should use CryptoAPI on Windows, make this code conditional.
--- src/openvpn/crypto_openssl.c | 2 ++ 1 file changed, 2 insertions(+)
src/openvpn/crypto_openssl.c +2 -0
@@ -154,11 +154,13 @@ crypto_init_lib_engine(const char *engine_name)void crypto_init_lib (void ) { +#ifndef _WIN32#if (OPENSSL_VERSION_NUMBER >=0x10100000L )OPENSSL_init_crypto (OPENSSL_INIT_LOAD_CONFIG ,NULL );#else OPENSSL_config (NULL );#endif +#endif /* _WIN32 */ /* * If you build the OpenSSL library and OpenVPN with * CRYPTO_MDEBUG, you will get a listing of OpenSSL
Signature · 1 line
2.23.0.windows.1
[Openvpn-devel] [PATCH applied] Re: crypto_openssl.c: disable explicit initialization on Windows (CVE-2121-3606)
As discussed in the meeting yesterday - this might break people's use of OpenSSL engines on windows, but we assume that the amount of users of that will be "close to zero". For these cases we can find a better approach after 2.5.3 release.
Your patch has been applied to the master and release/2.5 branch.
commit abd5ee9b7dc4ba85438da5d16bb7dfb31714dac7 (master) commit 447cfb4f30fd96126f7d2945cd14ef39cc13a08a (release/2.5)
Author: Lev Stipakov Date: Thu Jun 17 09:12:26 2021 +0300
crypto_openssl.c: disable explicit initialization on Windows (CVE-2121-3606)
Signed-off-by: Lev Stipakov <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg22568.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH 1/2] crypto_openssl.c: disable explicit initialization on Windows
In reply to Lev StipakovHi
Quoted 38 lines · Lev Stipakov
From: Lev Stipakov <[email protected]...>
Commit a4071b ("
crypto_openssl: add initialization to pick up local configuration")
added openssl initialization to load configuration file. However on Windows this file is loaded from user-writable directory, such as c.\etc\ssl for mingw builds
and (for example) c:\vcpkg\packages\openssl_x64-windows\openvpn.cnf for vcpkg
builds. This could be a security risk.Since aforementioned commit implements a niche feature which anyway should use CryptoAPI on Windows, make this code conditional.
Signed-off-by Lev Stipakov <[email protected]...>--- src/openvpn/crypto_openssl.c | 2 ++ 1 file changed, 2 insertions(+)src/openvpn/crypto_openssl.c +2
-1@@ -154,11 +154,13 @@ crypto_init_lib_engine(const char *engine_name)void crypto_init_lib (void ) { +#ifndef _WIN32#if (OPENSSL_VERSION_NUMBER >=0x10100000L )OPENSSL_init_crypto (OPENSSL_INIT_LOAD_CONFIG ,NULL );#else OPENSSL_config (NULL );#endif +#endif /* _WIN32 */ /* * If you build the OpenSSL library and OpenVPN with * CRYPTO_MDEBUG, you will get a listing of OpenSSL --
Quoted 2 lines
2.23.0.windows.1
This would make it impossible to use openssl.cnf on Windows, wouldn't it? I use configuraton file to restrict signature algorithms, for example. There are other uses like configuring engines.
Instead of disabling, why not make the default path a restricted location within, say, C:\Windows. The user can then override it using env variables.
What path does OpenSSL Windows binaries described in OpensSL wiki use? (
https://wiki.openssl.org/index.php/Binaries)
Selva
Re: [Openvpn-devel] [PATCH 1/2] crypto_openssl.c: disable explicit initialization on Windows
Hi,
Quoted 3 lines · Selva Nair
This would make it impossible to use openssl.cnf on Windows, wouldn't it? I use configuraton file to restrict signature algorithms, for example. There are other uses like configuring engines.
Right.
Quoted 2 lines
Instead of disabling, why not make the default path a restricted location within, say, C:\Windows. The user can then override it using env variables.
This is what we tried to achieve, but Lev could not find a way to make the MSVC build behave wrt "new ETCDIR". I have not personally investigated.
So we decided to release 2.5.3 soonish, with "disable openssl.cnf" to cover the problem reported, and then see if we can get to a better fix incrementally (while a "secured" binary is out for users to run).
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...PATCH 2/2 contrib/vcpkg-ports: add openssl port with --no-autoload-config option set
In reply to Lev StipakovFrom: Lev Stipakov <[email protected]...>
In default configuration OpenSSL loads config from certain location on disk, for example
c:\vcpkg\packages\openssl_x64-windows\openvpn.cnf
which may pose a security risk.
There is "no-autoload-config" config option for OpenSSL which disables this functionality:
https://github.com/openssl/openssl/pull/5959
however it is not "exported" to vcpkg.
This adds openssl port overlay which sets "no-autoload-config" config option. Here is the diff:
(quoted diff) +0 -0
b/ports/openssl/windows/portfile.cmake
index 7a3bf08ed..c873eb756 100644
ports/openssl/windows/portfile.cmake +1 -0
@@ -21,6 +21,7 @@ set(CONFIGURE_OPTIONS enable-capieng no-ssl2 no-tests + no-autoload-config -utf-8 ${OPENSSL_SHARED}
)
There is also corresponsing PR to vcpkg:
https://github.com/microsoft/vcpkg/pull/18389
When above PR is merged, this port overlay can be removed.
--- contrib/vcpkg-ports/openssl/portfile.cmake | 25 ++ .../vcpkg-ports/openssl/unix/CMakeLists.txt | 280 ++++++++++++++++++ .../vcpkg-ports/openssl/unix/portfile.cmake | 49 +++ .../openssl/unix/remove-deps.cmake | 7 + .../openssl/unix/vcpkg-cmake-wrapper.cmake | 18 ++ contrib/vcpkg-ports/openssl/usage | 4 + .../openssl/uwp/EnableUWPSupport.patch | 170 +++++++++++ .../vcpkg-ports/openssl/uwp/make-openssl.bat | 16 + .../vcpkg-ports/openssl/uwp/portfile.cmake | 156 ++++++++++ contrib/vcpkg-ports/openssl/vcpkg.json | 7 + .../openssl/windows/portfile.cmake | 174 +++++++++++ .../openssl/windows/vcpkg-cmake-wrapper.cmake | 10 + 12 files changed, 916 insertions(+) create mode 100644 contrib/vcpkg-ports/openssl/portfile.cmake create mode 100644 contrib/vcpkg-ports/openssl/unix/CMakeLists.txt create mode 100644 contrib/vcpkg-ports/openssl/unix/portfile.cmake create mode 100644 contrib/vcpkg-ports/openssl/unix/remove-deps.cmake create mode 100644 contrib/vcpkg-ports/openssl/unix/vcpkg-cmake-wrapper.cmake create mode 100644 contrib/vcpkg-ports/openssl/usage create mode 100644 contrib/vcpkg-ports/openssl/uwp/EnableUWPSupport.patch create mode 100644 contrib/vcpkg-ports/openssl/uwp/make-openssl.bat create mode 100644 contrib/vcpkg-ports/openssl/uwp/portfile.cmake create mode 100644 contrib/vcpkg-ports/openssl/vcpkg.json create mode 100644 contrib/vcpkg-ports/openssl/windows/portfile.cmake create mode 100644 contrib/vcpkg-ports/openssl/windows/vcpkg-cmake-wrapper.cmake
contrib/vcpkg-ports/openssl/portfile.cmake new file +25 -0
@@ -0,0 +1,25 @@ +if(EXISTS "${CURRENT_INSTALLED_DIR}/include/openssl/ssl.h") + message(FATAL_ERROR "Can't build openssl if libressl/boringssl is installed. Please remove libressl/boringssl, and try install openssl again if you need it.") +endif() + +set(OPENSSL_VERSION 1.1.1k) +vcpkg_download_distfile(ARCHIVE + URLS "https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz" "https://www.openssl.org/source/old/1.1.1/openssl-${OPENSSL_VERSION}.tar.gz" + FILENAME "openssl-${OPENSSL_VERSION}.tar.gz" + SHA512 73cd042d4056585e5a9dd7ab68e7c7310a3a4c783eafa07ab0b560e7462b924e4376436a6d38a155c687f6942a881cfc0c1b9394afcde1d8c46bf396e7d51121 +) + +vcpkg_find_acquire_program(PERL) +get_filename_component(PERL_EXE_PATH ${PERL} DIRECTORY) +vcpkg_add_to_path("${PERL_EXE_PATH}") + +if(VCPKG_TARGET_IS_UWP) + include("${CMAKE_CURRENT_LIST_DIR}/uwp/portfile.cmake") +elseif(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW) + include("${CMAKE_CURRENT_LIST_DIR}/windows/portfile.cmake") +else() + include("${CMAKE_CURRENT_LIST_DIR}/unix/portfile.cmake") +endif() + + +file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
contrib/vcpkg-ports/openssl/unix/CMakeLists.txt new file +280 -0
280 lines not on this page · raw message
contrib/vcpkg-ports/openssl/unix/portfile.cmake new file +49 -0
49 lines not on this page · raw message
contrib/vcpkg-ports/openssl/unix/remove-deps.cmake new file +7 -0
@@ -0,0 +1,7 @@ +file(GLOB_RECURSE MAKEFILES ${DIR}/*/Makefile) +foreach(MAKEFILE ${MAKEFILES}) + message("removing deps from ${MAKEFILE}") + file(READ "${MAKEFILE}" _contents) + string(REGEX REPLACE "\n# DO NOT DELETE THIS LINE.*" "" _contents "${_contents}") + file(WRITE "${MAKEFILE}" "${_contents}") +endforeach()
contrib/vcpkg-ports/openssl/unix/vcpkg-cmake-wrapper.cmake new file +18 -0
@@ -0,0 +1,18 @@ +_find_package(${ARGS}) +if(OPENSSL_FOUND) + find_library(OPENSSL_DL_LIBRARY NAMES dl) + if(OPENSSL_DL_LIBRARY) + list(APPEND OPENSSL_LIBRARIES "dl") + if(TARGET OpenSSL::Crypto) + set_property(TARGET OpenSSL::Crypto APPEND PROPERTY INTERFACE_LINK_LIBRARIES "dl") + endif() + endif() + find_package(Threads REQUIRED) + list(APPEND OPENSSL_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) + if(TARGET OpenSSL::Crypto) + set_property(TARGET OpenSSL::Crypto APPEND PROPERTY INTERFACE_LINK_LIBRARIES "Threads::Threads") + endif() + if(TARGET OpenSSL::SSL) + set_property(TARGET OpenSSL::SSL APPEND PROPERTY INTERFACE_LINK_LIBRARIES "Threads::Threads") + endif() +endif()
contrib/vcpkg-ports/openssl/usage new file +4 -0
@@ -0,0 +1,4 @@ +The package openssl is compatible with built-in CMake targets: + + find_package(OpenSSL REQUIRED) + target_link_libraries(main PRIVATE OpenSSL::SSL OpenSSL::Crypto)
contrib/vcpkg-ports/openssl/uwp/EnableUWPSupport.patch new file +170 -0
170 lines not on this page · raw message
contrib/vcpkg-ports/openssl/uwp/make-openssl.bat new file +16 -0
@@ -0,0 +1,16 @@ +set build=%1 + +perl Configure no-asm no-hw no-dso VC-WINUNIVERSAL -FS -FIWindows.h + +for /D %%f in ("%WindowsSdkDir%References\%WindowsSDKLibVersion%Windows.Foundation.FoundationContract\*") do set LibPath=%LibPath%;%%f\ +for /D %%f in ("%WindowsSdkDir%References\%WindowsSDKLibVersion%Windows.Foundation.UniversalApiContract\*") do set LibPath=%LibPath%;%%f\ +for /D %%f in ("%WindowsSdkDir%References\Windows.Foundation.FoundationContract\*") do set LibPath=%LibPath%;%%f\ +for /D %%f in ("%WindowsSdkDir%References\Windows.Foundation.UniversalApiContract\*") do set LibPath=%LibPath%;%%f\ + +call ms\do_winuniversal.bat + +mkdir inc32\openssl + +jom -j %NUMBER_OF_PROCESSORS% -k -f ms\ntdll.mak +REM due to a race condition in the build, we need to have a second single-threaded pass. +nmake -f ms\ntdll.mak
contrib/vcpkg-ports/openssl/uwp/portfile.cmake new file +156 -0
156 lines not on this page · raw message
contrib/vcpkg-ports/openssl/vcpkg.json new file +7 -0
@@ -0,0 +1,7 @@ +{ + "name": "openssl", + "version-string": "1.1.1k", + "port-version": 4, + "description": "OpenSSL is an open source project that provides a robust, commercial-grade, and full-featured toolkit for the Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols. It is also a general-purpose cryptography library.", + "homepage": "https://www.openssl.org" +}
contrib/vcpkg-ports/openssl/windows/portfile.cmake new file +174 -0
174 lines not on this page · raw message
contrib/vcpkg-ports/openssl/windows/vcpkg-cmake-wrapper.cmake new file +10 -0
@@ -0,0 +1,10 @@ +_find_package(${ARGS}) +if(OPENSSL_FOUND) + list(APPEND OPENSSL_LIBRARIES Crypt32.lib ws2_32.lib) + if(TARGET OpenSSL::Crypto) + set_property(TARGET OpenSSL::Crypto APPEND PROPERTY INTERFACE_LINK_LIBRARIES "Crypt32.lib;ws2_32.lib") + endif() + if(TARGET OpenSSL::SSL) + set_property(TARGET OpenSSL::SSL APPEND PROPERTY INTERFACE_LINK_LIBRARIES "Crypt32.lib;ws2_32.lib") + endif() +endif()
Signature · 1 line
2.23.0.windows.1
[Openvpn-devel] [PATCH applied] Re: contrib/vcpkg-ports: add openssl port with --no-autoload-config option set (CVE-2121-3606)
Not pretty, but the best we can do today.
Your patch has been applied to the master and release/2.5 branch.
commit 84d5079b0f40387317b348025c99097f7876807a (master) commit 92535b6a10865f7e6729f766dcf36e094b7f61d4 (release/2.5)
Author: Lev Stipakov Date: Thu Jun 17 09:12:59 2021 +0300
contrib/vcpkg-ports: add openssl port with --no-autoload-config option set (CVE-2121-3606)
Signed-off-by: Lev Stipakov <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg22569.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering