Skip to content

Commit 069efec

Browse files
committed
feat(build): Add option to enforce correct libcrypto feature probing
1 parent 7372079 commit 069efec

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ option(S2N_STACKTRACE "Enables stacktrace functionality in s2n-tls. Note that th
3434
only available on platforms that support execinfo." ON)
3535
option(S2N_OVERRIDE_LIBCRYPTO_RAND_ENGINE "Allow s2n-tls to override the libcrypto random implementation with the custom
3636
s2n-tls implementation, when appropriate. Disabling this flag is not recommended. See docs/BUILD.md for details." ON)
37+
option(S2N_ENFORCE_PROPER_LIBCRYPTO_FEATURE_PROBE "Assert that the feature probes are able to link to the libcrypto and
38+
properly probe for feature support. If the feature probes are unable to properly probe for support, the build will
39+
fail. This option ensures that s2n-tls doesn't silently build without properly probing for the support of important
40+
features, such as TLS 1.3 support." OFF)
3741
option(COVERAGE "Enable profiling collection for code coverage calculation" OFF)
3842
option(BUILD_TESTING "Build tests for s2n-tls. By default only unit tests are built." ON)
3943
option(S2N_INTEG_TESTS "Enable the integrationv2 tests" OFF)
@@ -352,6 +356,8 @@ function(feature_probe PROBE_NAME)
352356

353357
# Set the flags that we used for the probe
354358
set(${PROBE_NAME}_FLAGS ${PROBE_FLAGS} PARENT_SCOPE)
359+
360+
set(${PROBE_NAME}_OUTPUT "${TRY_COMPILE_OUTPUT}" PARENT_SCOPE)
355361
endfunction()
356362

357363
# Iterate over all of the features and try to compile them
@@ -362,6 +368,13 @@ foreach(file ${FEATURE_SRCS})
362368
feature_probe(${feature_name})
363369
endforeach()
364370

371+
# Ensure that the feature probes were able to properly link to the libcrypto.
372+
if(S2N_ENFORCE_PROPER_LIBCRYPTO_FEATURE_PROBE AND NOT S2N_LIBCRYPTO_SANITY_PROBE)
373+
message(FATAL_ERROR "A sanity-check libcrypto feature probe failed, which indicates that other
374+
feature probes were likely unable to probe the libcrypto for its supported features:
375+
${S2N_LIBCRYPTO_SANITY_PROBE_OUTPUT}")
376+
endif()
377+
365378
# FreeBSD might need to link to execinfo explicitly
366379
if(NOT S2N_EXECINFO_AVAILABLE AND CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
367380
feature_probe(S2N_EXECINFO_AVAILABLE LINK_LIBRARIES execinfo)

codebuild/bin/s2n_codebuild.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ run_integration_v2_tests() {
8989
run_unit_tests() {
9090
cmake . -Bbuild \
9191
-DCMAKE_PREFIX_PATH=$LIBCRYPTO_ROOT \
92-
-DBUILD_SHARED_LIBS=on
92+
-DBUILD_SHARED_LIBS=on \
93+
-DS2N_ENFORCE_PROPER_LIBCRYPTO_FEATURE_PROBE=1
9394
cmake --build ./build -- -j $(nproc)
9495
test_linked_libcrypto ./build/bin/s2nc
9596
cmake --build build/ --target test -- ARGS="-L unit --output-on-failure -j $(nproc)"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
#include <openssl/err.h>
17+
18+
int main()
19+
{
20+
/* A function that's known to exist in all OpenSSL versions and forks is used as a sanity check
21+
* to make sure the libcrypto has been properly linked.
22+
*/
23+
unsigned long error = ERR_get_error();
24+
25+
return 0;
26+
}

tests/features/S2N_LIBCRYPTO_SANITY_PROBE.flags

Whitespace-only changes.

0 commit comments

Comments
 (0)