@@ -41,7 +41,7 @@ if(VCPKG_CONCURRENCY GREATER "1")
4141 vcpkg_list (APPEND CONFIGURE_OPTIONS no -makedepend )
4242endif ()
4343
44- cmake_path (NATIVE_PATH CURRENT_PACKAGES_DIR NORMALIZE install_dir_native )
44+ cmake_path (NATIVE_PATH CURRENT_PACKAGES_DIR NORMALIZE current_packages_dir_native )
4545
4646# Clang always uses /Z7; Patching /Zi /Fd<Name> out of openssl requires more work.
4747set (OPENSSL_BUILD_MAKES_PDBS ON )
@@ -71,15 +71,19 @@ endif()
7171cmake_path (NATIVE_PATH VCPKG_DETECTED_CMAKE_AR NORMALIZE ar )
7272cmake_path (NATIVE_PATH VCPKG_DETECTED_CMAKE_LINKER NORMALIZE ld )
7373
74+ # We can't set openssldir because that would leak build machine information into the built binaries,
75+ # and introduce vulnerabilities where OpenSSL would search those locations at runtime, potentially
76+ # unexpectedly loading code from there. For example CVE-2019-12572
77+ #
78+ # Put the built bits in subdirectories with DESTDIR then move them where they go after the fact
79+ # instead.
7480vcpkg_build_nmake (
7581 SOURCE_PATH "${SOURCE_PATH} "
7682 PREFER_JOM
7783 CL_LANGUAGE NONE
7884 PRERUN_SHELL_RELEASE "${PERL} " Configure
7985 ${CONFIGURE_OPTIONS}
8086 ${OPENSSL_ARCH}
81- "--prefix=${install_dir_native} "
82- "--openssldir=${install_dir_native} "
8387 "AS=${as} "
8488 "CC=${cc} "
8589 "CFLAGS=${VCPKG_COMBINED_C_FLAGS_RELEASE} "
@@ -91,8 +95,6 @@ vcpkg_build_nmake(
9195 ${CONFIGURE_OPTIONS}
9296 ${OPENSSL_ARCH}
9397 --debug
94- "--prefix=${install_dir_native} \\ debug"
95- "--openssldir=${install_dir_native} \\ debug"
9698 "AS=${as} "
9799 "CC=${cc} "
98100 "CFLAGS=${VCPKG_COMBINED_C_FLAGS_DEBUG} "
@@ -106,53 +108,80 @@ vcpkg_build_nmake(
106108 OPTIONS
107109 "INSTALL_PDBS=${OPENSSL_BUILD_MAKES_PDBS} " # install-pdbs.patch
108110 OPTIONS_RELEASE
111+ "DESTDIR=${current_packages_dir_native} "
109112 install_runtime install_ssldirs # extra targets
113+ OPTIONS_DEBUG
114+ "DESTDIR=${current_packages_dir_native} /debug"
110115)
111116
117+ function (z_rearrange_openssl_dirs )
118+ cmake_parse_arguments (PARSE_ARGV 0 arg "" "OUT_PROGRAM_FILES_DIR;FLAVOR_PREFIX" "" )
119+
120+ if (DEFINED arg_UNPARSED_ARGUMENTS)
121+ message (FATAL_ERROR "z_rearrange_openssl_dirs was passed extra arguments: ${arg_UNPARSED_ARGUMENTS} " )
122+ endif ()
123+
124+ # The resulting directory will contain something like "Program Files" or "Program Files (x86)";
125+ # globbing here to be architecture agnostic
126+ set (prefix_packages_dir "${CURRENT_PACKAGES_DIR}${arg_FLAVOR_PREFIX} " )
127+ file (GLOB flavor_programfiles_dir LIST_DIRECTORIES true "${prefix_packages_dir} /Program*" )
128+ if (NOT flavor_programfiles_dir)
129+ message (FATAL_ERROR "${flavor_programfiles_dir} : error: couldn't find program files dir" )
130+ endif ()
131+
132+ if (DEFINED arg_OUT_PROGRAM_FILES_DIR)
133+ set ("${arg_OUT_PROGRAM_FILES_DIR} " "${flavor_programfiles_dir} " PARENT_SCOPE )
134+ endif ()
135+
136+ set (flavor_openssl_dir "${flavor_programfiles_dir} /OpenSSL" )
137+ if (NOT EXISTS "${flavor_openssl_dir} " )
138+ message (FATAL_ERROR "${flavor_openssl_dir} : should exist and be OpenSSLDir" )
139+ endif ()
140+
141+ # ideally we would use RENAME rather than COPY and REMOVE_RECURSE but CMake doesn't have an out
142+ # of the box way to do that correctly merging directories
143+ file (GLOB flavor_openssl_dirs LIST_DIRECTORIES true "${flavor_openssl_dir} /*" )
144+ file (COPY ${flavor_openssl_dirs} DESTINATION "${prefix_packages_dir} " )
145+ file (REMOVE_RECURSE "${flavor_openssl_dir} " )
146+ endfunction ()
147+
148+ z_rearrange_openssl_dirs (FLAVOR_PREFIX "" OUT_PROGRAM_FILES_DIR release_programfiles )
149+ if (NOT VCPKG_BUILD_TYPE)
150+ z_rearrange_openssl_dirs (FLAVOR_PREFIX "/debug" OUT_PROGRAM_FILES_DIR debug_programfiles )
151+ file (REMOVE_RECURSE "${CURRENT_PACKAGES_DIR} /debug/include" )
152+ file (REMOVE_RECURSE "${debug_programfiles} " )
153+ file (REMOVE "${CURRENT_PACKAGES_DIR} /debug/bin/c_rehash.pl" )
154+ endif ()
155+
112156set (scripts "bin/c_rehash.pl" "misc/CA.pl" "misc/tsget.pl" )
113157if ("tools" IN_LIST FEATURES)
114158 file (MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR} /tools/${PORT} " )
115- file (RENAME "${CURRENT_PACKAGES_DIR} /openssl.cnf" "${CURRENT_PACKAGES_DIR} /tools/${PORT} /openssl.cnf" )
159+ file (COPY_FILE "${release_programfiles} /Common Files/SSL /openssl.cnf" "${CURRENT_PACKAGES_DIR} /tools/${PORT} /openssl.cnf" )
116160 if ("fips" IN_LIST FEATURES)
117- file (RENAME "${CURRENT_PACKAGES_DIR} /fipsmodule.cnf" "${CURRENT_PACKAGES_DIR} /tools/${PORT} /fipsmodule.cnf" )
161+ file (COPY_FILE "${release_programfiles} /Common Files/SSL /fipsmodule.cnf" "${CURRENT_PACKAGES_DIR} /tools/${PORT} /fipsmodule.cnf" )
118162 endif ()
119- foreach (script IN LISTS scripts)
120- file (COPY "${CURRENT_PACKAGES_DIR} /${script} " DESTINATION "${CURRENT_PACKAGES_DIR} /tools/${PORT} " )
121- file (REMOVE "${CURRENT_PACKAGES_DIR} / ${script} " "${CURRENT_PACKAGES_DIR} /debug /${script} " )
122- endforeach ( )
163+
164+ file (RENAME "${CURRENT_PACKAGES_DIR} /bin/c_rehash.pl" "${CURRENT_PACKAGES_DIR} /tools/${PORT} /c_rehash.pl " )
165+ file (RENAME "${release_programfiles} /Common Files/SSL/misc/CA.pl " "${CURRENT_PACKAGES_DIR} /tools /${PORT} /CA.pl " )
166+ file ( RENAME " ${release_programfiles} /Common Files/SSL/misc/tsget.pl" " ${CURRENT_PACKAGES_DIR} /tools/ ${PORT} /tsget.pl" )
123167 vcpkg_copy_tools (TOOL_NAMES openssl AUTO_CLEAN )
124168else ()
125- file (REMOVE "${CURRENT_PACKAGES_DIR} /openssl.cnf" )
126- file (REMOVE "${CURRENT_PACKAGES_DIR} /fipsmodule.cnf" )
127- foreach (script IN LISTS scripts)
128- file (REMOVE "${CURRENT_PACKAGES_DIR} /${script} " "${CURRENT_PACKAGES_DIR} /debug/${script} " )
129- endforeach ()
169+ file (REMOVE
170+ "${CURRENT_PACKAGES_DIR} /bin/c_rehash.pl"
171+ "${release_programfiles} /Common Files/SSL/misc/CA.pl"
172+ "${release_programfiles} /Common Files/SSL/misc/tsget.pl"
173+ )
174+
130175 if (VCPKG_LIBRARY_LINKAGE STREQUAL "static" )
131176 file (REMOVE_RECURSE "${CURRENT_PACKAGES_DIR} /bin" "${CURRENT_PACKAGES_DIR} /debug/bin" )
132177 endif ()
133178endif ()
134179
135180vcpkg_copy_pdbs ()
181+ vcpkg_cmake_config_fixup ()
136182
137- file (REMOVE_RECURSE
138- "${CURRENT_PACKAGES_DIR} /certs"
139- "${CURRENT_PACKAGES_DIR} /misc"
140- "${CURRENT_PACKAGES_DIR} /private"
141- "${CURRENT_PACKAGES_DIR} /lib/engines-3"
142- "${CURRENT_PACKAGES_DIR} /debug/certs"
143- "${CURRENT_PACKAGES_DIR} /debug/misc"
144- "${CURRENT_PACKAGES_DIR} /debug/lib/engines-3"
145- "${CURRENT_PACKAGES_DIR} /debug/private"
146- "${CURRENT_PACKAGES_DIR} /debug/include"
147- "${CURRENT_PACKAGES_DIR} /debug/share"
148- )
149- file (REMOVE
150- "${CURRENT_PACKAGES_DIR} /ct_log_list.cnf"
151- "${CURRENT_PACKAGES_DIR} /ct_log_list.cnf.dist"
152- "${CURRENT_PACKAGES_DIR} /openssl.cnf.dist"
153- "${CURRENT_PACKAGES_DIR} /debug/ct_log_list.cnf"
154- "${CURRENT_PACKAGES_DIR} /debug/ct_log_list.cnf.dist"
155- "${CURRENT_PACKAGES_DIR} /debug/openssl.cnf"
156- "${CURRENT_PACKAGES_DIR} /debug/openssl.cnf.dist"
157- "${CURRENT_PACKAGES_DIR} /debug/fipsmodule.cnf"
183+ file (REMOVE_RECURSE # to pass empty directories check
184+ "${release_programfiles} /Common Files/SSL/certs"
185+ "${release_programfiles} /Common Files/SSL/misc"
186+ "${release_programfiles} /Common Files/SSL/private"
158187)
0 commit comments