Skip to content

Commit

Permalink
Land #972
Browse files Browse the repository at this point in the history
  • Loading branch information
botovq committed Dec 14, 2023
2 parents 05902e6 + 5bb4552 commit f1cfcd5
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 92 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,11 @@ set(LIBTLS_LIBS tls ${PLATFORM_LIBS})

# libraries for regression test
if(BUILD_SHARED_LIBS)
set(OPENSSL_TEST_LIBS ssl-static crypto-static ${PLATFORM_LIBS})
set(LIBTLS_TEST_LIBS tls-static ${OPENSSL_TEST_LIBS})
set(OPENSSL_TEST_LIBS ssl-static crypto-static ${PLATFORM_LIBS} compat_obj)
set(LIBTLS_TEST_LIBS tls-static ${OPENSSL_TEST_LIBS} tls_compat_obj)
else()
set(OPENSSL_TEST_LIBS ssl crypto ${PLATFORM_LIBS})
set(LIBTLS_TEST_LIBS tls ${PLATFORM_LIBS})
set(OPENSSL_TEST_LIBS ssl crypto ${PLATFORM_LIBS} compat_obj)
set(LIBTLS_TEST_LIBS tls ${PLATFORM_LIBS} compat_obj tls_compat_obj)
endif()

if(OPENSSLDIR STREQUAL "")
Expand Down
2 changes: 1 addition & 1 deletion apps/nc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ target_include_directories(nc
PUBLIC
../../include
${CMAKE_BINARY_DIR}/include)
target_link_libraries(nc ${LIBTLS_LIBS})
target_link_libraries(nc ${LIBTLS_LIBS} compat_obj)

if(ENABLE_NC)
if(ENABLE_LIBRESSL_INSTALL)
Expand Down
2 changes: 1 addition & 1 deletion apps/ocspcheck/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ target_include_directories(ocspcheck
PUBLIC
../../include
${CMAKE_BINARY_DIR}/include)
target_link_libraries(ocspcheck tls ${OPENSSL_LIBS})
target_link_libraries(ocspcheck tls ${OPENSSL_LIBS} compat_obj tls_compat_obj)

if(ENABLE_LIBRESSL_INSTALL)
install(TARGETS ocspcheck DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand Down
2 changes: 1 addition & 1 deletion apps/openssl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ target_include_directories(openssl
PUBLIC
../../include
${CMAKE_BINARY_DIR}/include)
target_link_libraries(openssl ${OPENSSL_LIBS})
target_link_libraries(openssl ${OPENSSL_LIBS} compat_obj)

if(ENABLE_LIBRESSL_INSTALL)
install(TARGETS openssl DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand Down
112 changes: 39 additions & 73 deletions crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,8 @@ set(
x509/x_all.c
)

set(COMPAT_SRC empty.c)

if(UNIX)
set(CRYPTO_SRC ${CRYPTO_SRC} crypto_lock.c)
set(CRYPTO_SRC ${CRYPTO_SRC} bio/b_posix.c)
Expand All @@ -749,38 +751,19 @@ if(WIN32)
endif()

if(WIN32)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/posix_win.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} gettimeofday)
set(EXTRA_EXPORT ${EXTRA_EXPORT} getuid)
set(EXTRA_EXPORT ${EXTRA_EXPORT} posix_perror)
set(EXTRA_EXPORT ${EXTRA_EXPORT} posix_fopen)
set(EXTRA_EXPORT ${EXTRA_EXPORT} posix_fgets)
set(EXTRA_EXPORT ${EXTRA_EXPORT} posix_open)
set(EXTRA_EXPORT ${EXTRA_EXPORT} posix_rename)
set(EXTRA_EXPORT ${EXTRA_EXPORT} posix_connect)
set(EXTRA_EXPORT ${EXTRA_EXPORT} posix_close)
set(EXTRA_EXPORT ${EXTRA_EXPORT} posix_read)
set(EXTRA_EXPORT ${EXTRA_EXPORT} posix_write)
set(EXTRA_EXPORT ${EXTRA_EXPORT} posix_getsockopt)
set(EXTRA_EXPORT ${EXTRA_EXPORT} posix_setsockopt)
set(COMPAT_SRC ${COMPAT_SRC} compat/posix_win.c)
endif()

if(NOT HAVE_ASPRINTF)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/bsd-asprintf.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} libressl_asprintf)
set(EXTRA_EXPORT ${EXTRA_EXPORT} libressl_vasprintf)
set(COMPAT_SRC ${COMPAT_SRC} compat/bsd-asprintf.c)
endif()

if(NOT HAVE_FREEZERO)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/freezero.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} libressl_freezero)
set(COMPAT_SRC ${COMPAT_SRC} compat/freezero.c)
endif()

if(NOT HAVE_GETOPT)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/getopt_long.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} getopt)
set(EXTRA_EXPORT ${EXTRA_EXPORT} optarg)
set(EXTRA_EXPORT ${EXTRA_EXPORT} optind)
set(COMPAT_SRC ${COMPAT_SRC} compat/getopt_long.c)
endif()

if(NOT HAVE_GETPAGESIZE)
Expand All @@ -798,105 +781,89 @@ if(NOT HAVE_GETPROGNAME)
endif()

if(NOT HAVE_REALLOCARRAY)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/reallocarray.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} libressl_reallocarray)
set(COMPAT_SRC ${COMPAT_SRC} compat/reallocarray.c)
endif()

if(NOT HAVE_RECALLOCARRAY)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/recallocarray.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} libressl_recallocarray)
set(COMPAT_SRC ${COMPAT_SRC} compat/recallocarray.c)
endif()

if(NOT HAVE_STRCASECMP)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/strcasecmp.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} libressl_strcasecmp)
set(COMPAT_SRC ${COMPAT_SRC} compat/strcasecmp.c)
endif()

if(NOT HAVE_STRLCAT)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/strlcat.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} libressl_strlcat)
set(COMPAT_SRC ${COMPAT_SRC} compat/strlcat.c)
endif()

if(NOT HAVE_STRLCPY)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/strlcpy.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} libressl_strlcpy)
set(COMPAT_SRC ${COMPAT_SRC} compat/strlcpy.c)
endif()

if(NOT HAVE_STRNDUP)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/strndup.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} libressl_strndup)
set(COMPAT_SRC ${COMPAT_SRC} compat/strndup.c)
if(NOT HAVE_STRNLEN)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/strnlen.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} libressl_strnlen)
set(COMPAT_SRC ${COMPAT_SRC} compat/strnlen.c)
endif()
endif()

if(NOT HAVE_STRSEP)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/strsep.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} libressl_strsep)
set(COMPAT_SRC ${COMPAT_SRC} compat/strsep.c)
endif()

if(NOT HAVE_STRTONUM)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/strtonum.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} libressl_strtonum)
set(COMPAT_SRC ${COMPAT_SRC} compat/strtonum.c)
endif()

if(NOT HAVE_SYSLOG_R)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/syslog_r.c)
endif()

if(NOT HAVE_TIMEGM)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/timegm.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} timegm)
# XXX - Remove after next bump once libtls, ocspcheck, and asn1time are fixed.
set(COMPAT_SRC ${COMPAT_SRC} compat/timegm.c)
endif()

if(NOT HAVE_EXPLICIT_BZERO)
if(WIN32)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/explicit_bzero_win.c)
set(COMPAT_SRC ${COMPAT_SRC} compat/explicit_bzero_win.c)
else()
set(CRYPTO_SRC ${CRYPTO_SRC} compat/explicit_bzero.c)
set(COMPAT_SRC ${COMPAT_SRC} compat/explicit_bzero.c)
set_source_files_properties(compat/explicit_bzero.c PROPERTIES COMPILE_FLAGS -O0)
endif()
set(EXTRA_EXPORT ${EXTRA_EXPORT} libressl_explicit_bzero)
endif()

if(NOT HAVE_ARC4RANDOM_BUF)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/arc4random.c)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/arc4random_uniform.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} libressl_arc4random)
set(EXTRA_EXPORT ${EXTRA_EXPORT} libressl_arc4random_buf)
set(EXTRA_EXPORT ${EXTRA_EXPORT} libressl_arc4random_uniform)
set(COMPAT_SRC ${COMPAT_SRC} compat/arc4random.c)
set(COMPAT_SRC ${COMPAT_SRC} compat/arc4random_uniform.c)

if(NOT HAVE_GETENTROPY)
if(WIN32)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/getentropy_win.c)
set(COMPAT_SRC ${COMPAT_SRC} compat/getentropy_win.c)
elseif(CMAKE_SYSTEM_NAME MATCHES "AIX")
set(CRYPTO_SRC ${CRYPTO_SRC} compat/getentropy_aix.c)
set(COMPAT_SRC ${COMPAT_SRC} compat/getentropy_aix.c)
elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set(CRYPTO_SRC ${CRYPTO_SRC} compat/getentropy_freebsd.c)
set(COMPAT_SRC ${COMPAT_SRC} compat/getentropy_freebsd.c)
elseif(CMAKE_SYSTEM_NAME MATCHES "HP-UX")
set(CRYPTO_SRC ${CRYPTO_SRC} compat/getentropy_hpux.c)
set(COMPAT_SRC ${COMPAT_SRC} compat/getentropy_hpux.c)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(CRYPTO_SRC ${CRYPTO_SRC} compat/getentropy_linux.c)
set(COMPAT_SRC ${COMPAT_SRC} compat/getentropy_linux.c)
elseif(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
set(CRYPTO_SRC ${CRYPTO_SRC} compat/getentropy_netbsd.c)
set(COMPAT_SRC ${COMPAT_SRC} compat/getentropy_netbsd.c)
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(CRYPTO_SRC ${CRYPTO_SRC} compat/getentropy_osx.c)
set(COMPAT_SRC ${COMPAT_SRC} compat/getentropy_osx.c)
elseif(CMAKE_SYSTEM_NAME MATCHES "SunOS")
set(CRYPTO_SRC ${CRYPTO_SRC} compat/getentropy_solaris.c)
set(COMPAT_SRC ${COMPAT_SRC} compat/getentropy_solaris.c)
endif()
set(EXTRA_EXPORT ${EXTRA_EXPORT} getentropy)
endif()
endif()

if(NOT HAVE_TIMINGSAFE_BCMP)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/timingsafe_bcmp.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} libressl_timingsafe_bcmp)
set(COMPAT_SRC ${COMPAT_SRC} compat/timingsafe_bcmp.c)
endif()

if(NOT HAVE_TIMINGSAFE_MEMCMP)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/timingsafe_memcmp.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} libressl_timingsafe_memcmp)
set(COMPAT_SRC ${COMPAT_SRC} compat/timingsafe_memcmp.c)
endif()

if(NOT ENABLE_ASM)
Expand All @@ -919,15 +886,14 @@ foreach(SYM IN LISTS CRYPTO_UNEXPORT)
string(REPLACE "${SYM}\n" "" SYMS ${SYMS})
endforeach()
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/crypto_p.sym ${SYMS})
# XXX should we still be doing this?
if(EXTRA_EXPORT)
list(SORT EXTRA_EXPORT)
foreach(SYM IN LISTS EXTRA_EXPORT)
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/crypto_p.sym "${SYM}\n")
endforeach()
endif()

set(LIBTLS_EXTRA_EXPORT ${EXTRA_EXPORT} PARENT_SCOPE)
add_library(compat_obj OBJECT ${COMPAT_SRC})
target_include_directories(compat_obj
PRIVATE
../include/compat
PUBLIC
../include
${CMAKE_BINARY_DIR}/include)

add_library(crypto_obj OBJECT ${CRYPTO_SRC})
target_include_directories(crypto_obj
Expand Down Expand Up @@ -977,7 +943,7 @@ elseif(HOST_X86_64)
target_include_directories(crypto_obj PRIVATE bn/arch/amd64)
endif()

add_library(crypto $<TARGET_OBJECTS:crypto_obj> empty.c)
add_library(crypto $<TARGET_OBJECTS:crypto_obj> $<TARGET_OBJECTS:compat_obj> empty.c)

export_symbol(crypto ${CMAKE_CURRENT_BINARY_DIR}/crypto_p.sym)
target_link_libraries(crypto ${PLATFORM_LIBS})
Expand Down
2 changes: 1 addition & 1 deletion ssl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ target_include_directories(bs_obj
../include/compat)

if(BUILD_SHARED_LIBS)
add_library(ssl $<TARGET_OBJECTS:ssl_obj> $<TARGET_OBJECTS:bs_obj>)
add_library(ssl $<TARGET_OBJECTS:ssl_obj> $<TARGET_OBJECTS:compat_obj> $<TARGET_OBJECTS:bs_obj>)
else()
add_library(ssl $<TARGET_OBJECTS:ssl_obj> empty.c)
endif()
Expand Down
30 changes: 19 additions & 11 deletions tls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,32 @@ set(
tls_verify.c
)

set(TLS_COMPAT_SRC empty.c)

if(WIN32)
set(
TLS_SRC
${TLS_SRC}
compat/ftruncate.c
compat/pread.c
compat/pwrite.c
)

set(LIBTLS_EXTRA_EXPORT ${LIBTLS_EXTRA_EXPORT} ftruncate)
set(TLS_COMPAT_SRC ${TLS_COMPAT_SRC} compat/ftruncate.c)
set(TLS_COMPAT_SRC ${TLS_COMPAT_SRC} compat/pread.c)
set(TLS_COMPAT_SRC ${TLS_COMPAT_SRC} compat/pwrite.c)
endif()

add_definitions(-DTLS_DEFAULT_CA_FILE=\"${OPENSSLDIR}/cert.pem\")

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/tls.sym DESTINATION
${CMAKE_CURRENT_BINARY_DIR})
if(LIBTLS_EXTRA_EXPORT)
list(SORT LIBTLS_EXTRA_EXPORT)
foreach(SYM IN LISTS LIBTLS_EXTRA_EXPORT)
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/tls.sym "${SYM}\n")
endforeach()
endif()

add_library(tls_compat_obj OBJECT ${TLS_COMPAT_SRC})
target_include_directories(tls_compat_obj
PRIVATE
.
../include/compat
PUBLIC
../include
${CMAKE_BINARY_DIR}/include)

add_library(tls_obj OBJECT ${TLS_SRC})
target_include_directories(tls_obj
Expand All @@ -46,7 +50,11 @@ target_include_directories(tls_obj
../include
${CMAKE_BINARY_DIR}/include)

add_library(tls $<TARGET_OBJECTS:tls_obj> empty.c)
if(BUILD_SHARED_LIBS)
add_library(tls $<TARGET_OBJECTS:tls_obj> $<TARGET_OBJECTS:tls_compat_obj> $<TARGET_OBJECTS:compat_obj> empty.c)
else()
add_library(tls $<TARGET_OBJECTS:tls_obj> $<TARGET_OBJECTS:tls_compat_obj> empty.c)
endif()

export_symbol(tls ${CMAKE_CURRENT_BINARY_DIR}/tls.sym)
target_link_libraries(tls ${OPENSSL_LIBS})
Expand Down

0 comments on commit f1cfcd5

Please sign in to comment.