Skip to content

Commit a3f40ef

Browse files
committed
Replace Mbed TLS source code in repository with a submodule
- Updated to latest Mbed TLS version (v3.6.0)
1 parent 7732b5e commit a3f40ef

File tree

19 files changed

+62
-4789
lines changed

19 files changed

+62
-4789
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
[submodule "bindings/python"]
88
path = bindings/python
99
url = https://github.com/owasp-modsecurity/ModSecurity-Python-bindings.git
10+
[submodule "others/mbedtls"]
11+
path = others/mbedtls
12+
url = https://github.com/Mbed-TLS/mbedtls.git

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ cppcheck:
6363
--enable=warning,style,performance,portability,unusedFunction,missingInclude \
6464
--inconclusive \
6565
--template="warning: {file},{line},{severity},{id},{message}" \
66-
-I headers -I . -I others -I src -I others/mbedtls -I src/parser \
66+
-I headers -I . -I others -I src -I others/mbedtls/include -I src/parser \
6767
--error-exitcode=1 \
6868
-i "src/parser/seclang-parser.cc" -i "src/parser/seclang-scanner.cc" \
6969
--force --verbose .

build/win32/CMakeLists.txt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ option(USE_ASAN "Build with Address Sanitizer" OFF)
1414

1515
# NOTE: MBEDTLS_CONFIG_FILE is not only required to compile the mbedtls subset in others, but also
1616
# when their headers are included while compiling libModSecurity
17-
add_compile_definitions(WIN32 _CRT_SECURE_NO_WARNINGS MBEDTLS_CONFIG_FILE="mbed-tls-config.h")
17+
add_compile_definitions(WIN32 _CRT_SECURE_NO_WARNINGS MBEDTLS_CONFIG_FILE="mbedtls/mbedtls_config.h")
1818

1919
# set standards conformance preprocessor & compiler to align with cross-compiled codebase
2020
# NOTE: otherwise visual c++'s default compiler/preprocessor behaviour generates C4067 warnings
@@ -46,13 +46,25 @@ message("-- Detecting libinjection version - ${LIBINJECTION_VERSION}")
4646

4747
target_compile_definitions(libinjection PRIVATE LIBINJECTION_VERSION="${LIBINJECTION_VERSION}")
4848

49-
# mbedtls
49+
# mbedtls (mbedcrypto)
5050

51-
project(mbedtls C)
51+
project(mbedcrypto C)
5252

53-
add_library(mbedtls STATIC ${BASE_DIR}/others/mbedtls/base64.c ${BASE_DIR}/others/mbedtls/sha1.c ${BASE_DIR}/others/mbedtls/md5.c)
53+
set(MBEDTLS_DIR ${BASE_DIR}/others/mbedtls)
5454

55-
target_include_directories(mbedtls PRIVATE ${BASE_DIR}/others)
55+
add_library(mbedcrypto STATIC ${MBEDTLS_DIR}/library/base64.c ${MBEDTLS_DIR}/library/sha1.c ${MBEDTLS_DIR}/library/md5.c ${MBEDTLS_DIR}/library/platform_util.c ${MBEDTLS_DIR}/library/constant_time.c)
56+
57+
target_include_directories(mbedcrypto PRIVATE ${MBEDTLS_DIR}/include)
58+
59+
# get mbedtls version with git describe
60+
execute_process(
61+
COMMAND git describe
62+
WORKING_DIRECTORY ${MBEDTLS_DIR}
63+
OUTPUT_VARIABLE MBEDTLS_VERSION
64+
OUTPUT_STRIP_TRAILING_WHITESPACE
65+
)
66+
67+
message("-- Detecting Mbed TLS version - ${MBEDTLS_VERSION}")
5668

5769
#
5870
# libModSecurity
@@ -126,8 +138,8 @@ file(GLOB_RECURSE libModSecuritySources ${BASE_DIR}/src/*.cc)
126138
add_library(libModSecurity SHARED ${libModSecuritySources})
127139

128140
target_compile_definitions(libModSecurity PRIVATE WITH_PCRE2)
129-
target_include_directories(libModSecurity PRIVATE ${BASE_DIR} ${BASE_DIR}/headers ${BASE_DIR}/others)
130-
target_link_libraries(libModSecurity PRIVATE pcre2::pcre2 pthreads4w::pthreads4w libinjection mbedtls Poco::Poco Iphlpapi.lib)
141+
target_include_directories(libModSecurity PRIVATE ${BASE_DIR} ${BASE_DIR}/headers ${BASE_DIR}/others ${MBEDTLS_DIR}/include)
142+
target_link_libraries(libModSecurity PRIVATE pcre2::pcre2 pthreads4w::pthreads4w libinjection mbedcrypto Poco::Poco Iphlpapi.lib)
131143

132144
macro(add_package_dependency project compile_definition link_library flag)
133145
if(${flag})

configure.ac

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,27 @@ fi
7777
AC_DEFUN([LIBINJECTION_VERSION], m4_esyscmd_s(cd "others/libinjection" && git describe && cd ../..))
7878
AC_SUBST([LIBINJECTION_VERSION])
7979

80+
# Check for Mbed TLS
81+
if ! test -f "${srcdir}/others/mbedtls/library/base64.c"; then
82+
AC_MSG_ERROR([\
83+
84+
85+
Mbed TLS was not found within ModSecurity source directory.
86+
87+
Mbed TLS code is available as part of ModSecurity source code in a format
88+
of a git-submodule. git-submodule allow us to specify the correct version of
89+
Mbed TLS and still uses the Mbed TLS repository to download it.
90+
91+
You can download Mbed TLS using git:
92+
93+
$ git submodule init
94+
$ git submodule update
95+
96+
])
97+
fi
98+
# Mbed TLS version
99+
AC_DEFUN([MBEDTLS_VERSION], m4_esyscmd_s(cd "others/mbedtls" && git describe && cd ../..))
100+
80101
# SecLang test version
81102
AC_DEFUN([SECLANG_TEST_VERSION], m4_esyscmd_s(cd "test/test-cases/secrules-language-tests" && git log -1 --format="%h" --abbrev-commit && cd ../../..))
82103

@@ -426,6 +447,8 @@ echo " "
426447
echo " Mandatory dependencies"
427448
AS_ECHO_N(" + libInjection ....")
428449
echo LIBINJECTION_VERSION
450+
AS_ECHO_N(" + Mbed TLS ....")
451+
echo MBEDTLS_VERSION
429452
AS_ECHO_N(" + SecLang tests ....")
430453
echo SECLANG_TEST_VERSION
431454

others/Makefile.am

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ noinst_HEADERS = \
1515
libinjection/src/libinjection_sqli.h \
1616
libinjection/src/libinjection_sqli_data.h \
1717
libinjection/src/libinjection_xss.h \
18-
mbedtls/base64.h \
19-
mbedtls/check_config.h \
20-
mbedtls/mbed-tls-config.h \
21-
mbedtls/md5.h \
22-
mbedtls/platform.h \
23-
mbedtls/sha1.h
18+
mbedtls/include/mbedtls/base64.h \
19+
mbedtls/include/mbedtls/check_config.h \
20+
mbedtls/include/mbedtls/mbedtls_config.h \
21+
mbedtls/include/mbedtls/md5.h \
22+
mbedtls/include/mbedtls/platform.h \
23+
mbedtls/include/mbedtls/sha1.h
2424

2525
libmbedtls_la_SOURCES = \
26-
mbedtls/base64.c \
27-
mbedtls/md5.c \
28-
mbedtls/sha1.c
26+
mbedtls/library/base64.c \
27+
mbedtls/library/md5.c \
28+
mbedtls/library/sha1.c \
29+
mbedtls/library/platform_util.c
2930

30-
libmbedtls_la_CFLAGS = -D MBEDTLS_CONFIG_FILE=\"mbed-tls-config.h\" -Iothers
31+
libmbedtls_la_CFLAGS = -DMBEDTLS_CONFIG_FILE=\"mbedtls/mbedtls_config.h\" -Imbedtls/include
3132
libmbedtls_la_CPPFLAGS =
3233
libmbedtls_la_LIBADD =

others/mbedtls

Submodule mbedtls added at 2ca6c28

0 commit comments

Comments
 (0)