Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
vcpkg*
build_*
cmake-build-*
*.o
*.a
*.dylib
Expand Down
140 changes: 85 additions & 55 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,24 @@ option(SECCOMP "Link with seccomp and run seccomp tests" OFF)
file(GLOB API_HEADERS "api/*.h")
file(GLOB API_UNSTABLE_HEADERS "api/unstable/*.h")

file(GLOB CRYPTO_HEADERS "crypto/*.h")
file(GLOB CRYPTO_SRC "crypto/*.c")
file(GLOB CRYPTO_HEADERS "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/crypto/*.h")
file(GLOB CRYPTO_SRC "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/crypto/*.c")

file(GLOB ERROR_HEADERS "error/*.h")
file(GLOB ERROR_SRC "error/*.c")
file(GLOB ERROR_HEADERS "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/error/*.h")
file(GLOB ERROR_SRC "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/error/*.c")

file(GLOB STUFFER_HEADERS "stuffer/*.h")
file(GLOB STUFFER_SRC "stuffer/*.c")
file(GLOB STUFFER_HEADERS "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/stuffer/*.h")
file(GLOB STUFFER_SRC "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/stuffer/*.c")

file(GLOB_RECURSE TLS_HEADERS "tls/*.h")
file(GLOB_RECURSE TLS_SRC "tls/*.c")
file(GLOB_RECURSE TLS_HEADERS "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/tls/*.h")
file(GLOB_RECURSE TLS_SRC "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/tls/*.c")

file(GLOB UTILS_HEADERS "utils/*.h")
file(GLOB UTILS_SRC "utils/*.c")
file(GLOB UTILS_HEADERS "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/utils/*.h")
file(GLOB UTILS_SRC "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/utils/*.c")
if (WINDOWS)
list(APPEND UTILS_HEADERS "win_shim/win_shim.h")
list(APPEND UTILS_SRC "win_shim/mmap-windows.c")
endif (WINDOWS)

message(STATUS "Detected CMAKE_SYSTEM_PROCESSOR as ${CMAKE_SYSTEM_PROCESSOR}")

Expand Down Expand Up @@ -93,6 +97,9 @@ else()
find_package(Threads REQUIRED)
endif()

set(gcc_like "$<COMPILE_LANG_AND_ID:C,CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
set(msvc "$<COMPILE_LANG_AND_ID:C,CXX,MSVC>")

if(APPLE)
set(OS_LIBS c Threads::Threads)
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
Expand All @@ -103,6 +110,9 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
set(OS_LIBS Threads::Threads kvm)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
set(OS_LIBS Threads::Threads dl)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(OS_LIBS bcrypt)
# pthreads is stubbed for native MSVC
else()
set(OS_LIBS Threads::Threads dl rt)
endif()
Expand Down Expand Up @@ -134,37 +144,45 @@ set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR})

set(CMAKE_C_FLAGS_DEBUGOPT "")

target_compile_options(${PROJECT_NAME} PRIVATE
-pedantic
-std=gnu99
-Wall
-Wcast-align
-Wcast-qual
-Wchar-subscripts
-Wcomment
-Wformat-security
-Wimplicit
-Wshadow
-Wsign-compare
-Wuninitialized
-Wunused
-Wwrite-strings

# Assembler Options
-Wa,--noexecstack

# Suppressed Warnings
-Wno-deprecated-declarations
# GCC 4 fails to parse our macros with a "missing-braces" error
-Wno-missing-braces
-Wno-strict-prototypes
-Wno-unknown-pragmas
)
if (NOT MSVC AND NOT CYGWIN AND NOT MSYS AND NOT MINGW)
target_compile_options(${PROJECT_NAME} PRIVATE
-pedantic
-std=gnu99
-Wall
-Wcast-align
-Wcast-qual
-Wchar-subscripts
-Wcomment
-Wformat-security
-Wimplicit
-Wshadow
-Wsign-compare
-Wuninitialized
-Wunused
-Wwrite-strings

# Assembler Options
-Wa,--noexecstack

# Suppressed Warnings
-Wno-deprecated-declarations
# GCC 4 fails to parse our macros with a "missing-braces" error
-Wno-missing-braces
-Wno-strict-prototypes
-Wno-unknown-pragmas
)
endif ()

if (S2N_WERROR_ALL)
target_compile_options(${PROJECT_NAME} PUBLIC -Werror)
target_compile_options(${PROJECT_NAME} PUBLIC
"$<${gcc_like}:$<BUILD_INTERFACE:-Werror>>"
"$<${msvc}:$<BUILD_INTERFACE:-W3;-Zi;-permissive->>"
)
elseif (UNSAFE_TREAT_WARNINGS_AS_ERRORS)
target_compile_options(${PROJECT_NAME} PRIVATE -Werror )
target_compile_options(${PROJECT_NAME} PRIVATE
"$<${gcc_like}:$<BUILD_INTERFACE:-Werror>>"
"$<${msvc}:$<BUILD_INTERFACE:-W3;-Zi;-permissive->>"
)
endif ()

if(BUILD_TESTING AND BUILD_SHARED_LIBS OR S2N_FUZZ_TEST)
Expand All @@ -181,7 +199,7 @@ if(S2N_LTO)
endif()
endif()

if(NOT APPLE AND NOT CMAKE_SYSTEM_NAME STREQUAL "AIX")
if(NOT APPLE AND NOT WINDOWS AND NOT CMAKE_SYSTEM_NAME STREQUAL "AIX")
set(CMAKE_SHARED_LINKER_FLAGS -Wl,-z,noexecstack,-z,relro,-z,now)
endif()

Expand Down Expand Up @@ -235,7 +253,8 @@ if(TSAN OR ASAN OR UBSAN)
target_compile_options(${PROJECT_NAME} PUBLIC -fno-omit-frame-pointer -fno-optimize-sibling-calls)
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
file(TO_CMAKE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules" MODULE_PATH)
set(CMAKE_MODULE_PATH "${MODULE_PATH}")

if (COVERAGE)
# https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html
Expand Down Expand Up @@ -269,6 +288,10 @@ endif()
if (TARGET crypto)
message(STATUS "S2N found target: crypto")
set(LINK_LIB "crypto")
elseif(DEFINED Z_VCPKG_EXECUTABLE)
find_package(OpenSSL REQUIRED)
message(STATUS "Using libcrypto from vcpkg")
set(LINK_LIB "OpenSSL::Crypto")
else()
find_package(crypto REQUIRED)
message(STATUS "Using libcrypto from the cmake path")
Expand Down Expand Up @@ -479,17 +502,17 @@ endif()

target_link_libraries(${PROJECT_NAME} PUBLIC ${OS_LIBS} m)

target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../auto-win-msvc/rewritten_src> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/api> $<INSTALL_INTERFACE:include>)

if (BUILD_TESTING)
if (BUILD_TESTING AND NOT MSVC)
enable_testing()

############################################################################
################### build testlib (utility library) ########################
############################################################################

file(GLOB TESTLIB_SRC "tests/testlib/*.c")
file(GLOB TESTLIB_SRC "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/tests/testlib/*.c")
file(GLOB EXAMPLES_SRC "docs/examples/*.c")

add_library(testss2n STATIC ${TESTLIB_SRC} ${EXAMPLES_SRC})
Expand Down Expand Up @@ -576,7 +599,7 @@ if (BUILD_TESTING)
############################ build unit tests ##############################
############################################################################

file(GLOB UNITTESTS_SRC "tests/unit/*.c")
file(GLOB UNITTESTS_SRC "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/tests/unit/*.c")
foreach(test_case ${UNITTESTS_SRC})
# NAME_WE: name without extension
get_filename_component(test_case_name ${test_case} NAME_WE)
Expand All @@ -591,13 +614,18 @@ if (BUILD_TESTING)
find . -name '${test_case_name}.c.o' -exec objcopy --redefine-syms libcrypto.symbols {} \\\;
)
endif()
target_compile_options(${test_case_name} PRIVATE
-Wall -Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized
-Wshadow -Wcast-align -Wwrite-strings -Wformat-security
-Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-deprecated -std=gnu99 -Wno-missing-braces
)
if (NOT MSVC AND NOT CYGWIN AND NOT MSYS AND NOT MINGW)
target_compile_options(${test_case_name} PRIVATE
-Wall -Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized
-Wshadow -Wcast-align -Wwrite-strings -Wformat-security
-Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-deprecated -std=gnu99 -Wno-missing-braces
)
endif()
if (UNSAFE_TREAT_WARNINGS_AS_ERRORS)
target_compile_options(${test_case_name} PRIVATE -Werror)
target_compile_options(${test_case_name} PRIVATE
"$<${gcc_like}:$<BUILD_INTERFACE:-Werror>>"
"$<${msvc}:$<BUILD_INTERFACE:-W3;-Zi;-permissive->>"
)
endif()
if (S2N_LTO)
target_compile_options(${test_case_name} PRIVATE -flto)
Expand All @@ -617,22 +645,24 @@ if (BUILD_TESTING)
######################### build utility binaries ###########################
############################################################################

add_executable(s2nc "bin/s2nc.c" "bin/echo.c" "bin/https.c" "bin/common.c")
if (NOT MSVC)
add_executable(s2nc "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/bin/s2nc.c" "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/bin/echo.c" "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/bin/https.c" "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/bin/common.c")
target_link_libraries(s2nc ${PROJECT_NAME})
target_compile_options(s2nc PRIVATE -std=gnu99)

add_executable(s2nd "bin/s2nd.c" "bin/echo.c" "bin/https.c" "bin/common.c")
add_executable(s2nd "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/bin/s2nd.c" "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/bin/echo.c" "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/bin/https.c" "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/bin/common.c")
target_link_libraries(s2nd ${PROJECT_NAME})
target_compile_options(s2nd PRIVATE -std=gnu99)

add_executable(policy "bin/policy.c")
add_executable(policy "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/bin/policy.c")
target_link_libraries(policy ${PROJECT_NAME})
target_compile_options(policy PRIVATE -std=gnu99)

if(S2N_LTO)
target_compile_options(s2nc PRIVATE -flto)
target_compile_options(s2nd PRIVATE -flto)
endif()
endif()

if (S2N_INTEG_TESTS)
find_package (Python3 COMPONENTS Interpreter Development)
Expand Down Expand Up @@ -689,8 +719,8 @@ if (BUILD_TESTING)
set(SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tests/fuzz/runFuzzTest.sh")
file(GLOB FUZZ_TEST_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/tests/fuzz/*.c")

file(GLOB TESTLIB_SRC "tests/testlib/*.c")
file(GLOB TESTLIB_HEADERS "tests/testlib/*.h" "tests/s2n_test.h")
file(GLOB TESTLIB_SRC "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/tests/testlib/*.c")
file(GLOB TESTLIB_HEADERS "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/tests/testlib/*.h" "${CMAKE_CURRENT_LIST_DIR}/../auto-win-msvc/rewritten_src/tests/s2n_test.h")

# This must be a shared object so that symbols can be overridden by the
# fuzz test specific LD_PRELOAD libraries.
Expand Down
14 changes: 4 additions & 10 deletions api/s2n.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,10 @@ extern "C" {
#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>
#ifndef _WIN32
#include <sys/uio.h>
#if defined(_MSC_VER) || defined(__MINGW32__)
#include <win_shim/win_shim.h>
#else
/* struct iovec equivalent for Windows */
struct iovec {
void *iov_base;
size_t iov_len;
};
#include <sys/uio.h>
#endif

/**
Expand Down Expand Up @@ -123,7 +119,7 @@ struct iovec {
*
* @warning To avoid possible confusion, s2n_errno should be cleared after processing an error: `s2n_errno = S2N_ERR_T_OK`
*/
S2N_API extern __thread int s2n_errno;
extern __thread int s2n_errno;

/**
* This function can be used instead of trying to resolve `s2n_errno` directly
Expand Down Expand Up @@ -2281,7 +2277,6 @@ S2N_API extern int s2n_negotiate(struct s2n_connection *conn, s2n_blocked_status
*/
S2N_API extern ssize_t s2n_send(struct s2n_connection *conn, const void *buf, ssize_t size, s2n_blocked_status *blocked);

#ifndef _WIN32
/**
* Works in the same way as s2n_sendv_with_offset() but with the `offs` parameter implicitly assumed to be 0.
* Therefore in the partial write case, the caller would have to make sure that the `bufs` and `count` fields are modified in a way that takes
Expand Down Expand Up @@ -2313,7 +2308,6 @@ S2N_API extern ssize_t s2n_sendv(struct s2n_connection *conn, const struct iovec
* @returns The number of bytes written on success, which may indicate a partial write. S2N_FAILURE on failure.
*/
S2N_API extern ssize_t s2n_sendv_with_offset(struct s2n_connection *conn, const struct iovec *bufs, ssize_t count, ssize_t offs, s2n_blocked_status *blocked);
#endif

/**
* Decrypts and reads **size* to `buf` data from the associated
Expand Down
7 changes: 7 additions & 0 deletions bin/common.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "utils/s2n_prelude.h"
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
Expand All @@ -21,10 +22,16 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if !defined(_MSC_VER)
#include <strings.h>
#endif
#if !defined(_MSC_VER)
#include <sys/mman.h>
#endif
#include <sys/stat.h>
#if !defined(_MSC_VER)
#include <unistd.h>
#endif

#include "api/s2n.h"
#include "error/s2n_errno.h"
Expand Down
2 changes: 2 additions & 0 deletions bin/echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/select.h>
#if !defined(_MSC_VER)
#include <unistd.h>
#endif

#include "api/s2n.h"
#include "api/unstable/fingerprint.h"
Expand Down
2 changes: 2 additions & 0 deletions bin/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

#include <stdint.h>
#include <stdlib.h>
#if !defined(_MSC_VER)
#include <unistd.h>
#endif

#include "api/s2n.h"
#include "tls/policy/s2n_policy_feature.h"
Expand Down
5 changes: 5 additions & 0 deletions bin/s2nc.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "utils/s2n_prelude.h"
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
Expand All @@ -21,8 +22,12 @@
#include <stdint.h>
#include <stdlib.h>
#include <sys/param.h>
#if !defined(_MSC_VER)
#include <sys/socket.h>
#endif
#if !defined(_MSC_VER)
#include <unistd.h>
#endif

#ifndef S2N_INTERN_LIBCRYPTO
#include <openssl/crypto.h>
Expand Down
7 changes: 7 additions & 0 deletions bin/s2nd.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "utils/s2n_prelude.h"
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
Expand All @@ -21,10 +22,16 @@
#include <signal.h>
#include <stdint.h>
#include <stdlib.h>
#if !defined(_MSC_VER)
#include <sys/mman.h>
#endif
#if !defined(_MSC_VER)
#include <sys/socket.h>
#endif
#include <sys/stat.h>
#if !defined(_MSC_VER)
#include <unistd.h>
#endif

#ifndef S2N_INTERN_LIBCRYPTO
#include <openssl/crypto.h>
Expand Down
Loading
Loading