Skip to content

Commit d7107c7

Browse files
author
Mateusz Kwiatkowski
committed
avs_commons 4.7
Features: - Rewritten PKCS#11-based hardware security support; the new version is included only in commercial version, includes support for both OpenSSL and Mbed TLS backends, and uses ECDSA for key generation in both backends (the OpenSSL version previously generated RSA keys) Improvements: - Made some linting checks (visibility, header and code duplication verification) more generic so that the code can be reused by other projects Bugfixes: - Fixed a problem with compiling the Mbed TLS backend when AVS_COMMONS_WITH_AVS_CRYPTO_PKI or WITH_DANE_SUPPORT is disabled - Fixed logic of detecting cryptographic file formats, which prevented PEM files with comments from being loaded - Added some missing NULL checks in atomic spinlock-based threading backend and Mbed TLS crypto backend
1 parent 112d014 commit d7107c7

File tree

261 files changed

+654
-1420
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

261 files changed

+654
-1420
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ Testing/
4040
*.tar.gz
4141
*.tgz
4242
*.deb
43+
44+
__pycache__

CMakeLists.txt

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2017-2020 AVSystem <avsystem@avsystem.com>
1+
# Copyright 2021 AVSystem <avsystem@avsystem.com>
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -16,12 +16,20 @@
1616

1717
cmake_minimum_required(VERSION 3.6.0)
1818
project(avs_commons C)
19-
set(AVS_COMMONS_VERSION SNAPSHOT)
19+
20+
set(AVS_COMMONS_VERSION "4.7")
2021

2122
################# DISTRIBUTION #################################################
2223

2324
set(AVS_COMMONS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
2425
set(AVS_COMMONS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/output")
26+
27+
if(NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
28+
set(AVS_COMMONS_VERSION "${AVS_COMMONS_VERSION}" PARENT_SCOPE)
29+
set(AVS_COMMONS_SOURCE_DIR "${AVS_COMMONS_SOURCE_DIR}" PARENT_SCOPE)
30+
set(AVS_COMMONS_BINARY_DIR "${AVS_COMMONS_BINARY_DIR}" PARENT_SCOPE)
31+
endif()
32+
2533
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${AVS_COMMONS_BINARY_DIR}/bin")
2634
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${AVS_COMMONS_BINARY_DIR}/lib")
2735
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${AVS_COMMONS_BINARY_DIR}/lib")
@@ -268,6 +276,30 @@ if(NOT HAVE_MATH_LIBRARY)
268276
endif()
269277
endif()
270278

279+
if(NOT DEFINED AVS_COMMONS_HAVE_DLSYM)
280+
# On Linux, one needs to link libdl to use dlsym(). On BSD, it is not necessary,
281+
# and even harmful, since libdl does not exist.
282+
set(DETECTED_DLSYM_LIBRARY "" CACHE STRING "" FORCE)
283+
set(CMAKE_REQUIRED_INCLUDES "dlfcn.h")
284+
foreach(lib "" dl)
285+
message(STATUS "Looking for dlsym() in library: ${lib}")
286+
set(CMAKE_REQUIRED_LIBRARIES ${lib})
287+
288+
# check_function_exists caches its result; make sure the check is
289+
# actually repeated for each lib
290+
unset(AVS_COMMONS_HAVE_DLSYM CACHE)
291+
check_function_exists(dlsym AVS_COMMONS_HAVE_DLSYM)
292+
set(CMAKE_REQUIRED_LIBRARIES)
293+
294+
if(AVS_COMMONS_HAVE_DLSYM)
295+
set(DETECTED_DLSYM_LIBRARY "${lib}" CACHE STRING "" FORCE)
296+
break()
297+
endif()
298+
endforeach()
299+
set(CMAKE_REQUIRED_INCLUDES)
300+
endif()
301+
set(DLSYM_LIBRARY "${DETECTED_DLSYM_LIBRARY}" CACHE STRING "Name of the library containing dlsym() symbol")
302+
271303
option(WITH_IPV4 "Enable IPv4 support" ON)
272304
option(WITH_IPV6 "Enable IPv6 support" ON)
273305

@@ -363,8 +395,10 @@ function(add_module_with_include_dirs)
363395
file(GLOB_RECURSE MODULE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${AMWID_PATH}/*.c
364396
${CMAKE_CURRENT_SOURCE_DIR}/${AMWID_PATH}/*.h)
365397
foreach(F ${MODULE_FILES})
366-
add_test(NAME test_${F}_visibility COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test_visibility.py ${F})
367-
add_test(NAME test_${F}_headers COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test_headers.py ${F})
398+
add_test(NAME test_${F}_visibility COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test_visibility.py ${F})
399+
add_test(NAME test_${F}_headers
400+
COMMAND ./test_headers.py ${F} conditional_headers_whitelist.json
401+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
368402
endforeach()
369403
endif()
370404
endfunction()
@@ -395,11 +429,11 @@ if(WITH_TEST)
395429

396430
# license check is only possible if running in a Git working tree
397431
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
398-
add_custom_target(license_check COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tools/check-license-headers.py" --root "${CMAKE_CURRENT_SOURCE_DIR}")
432+
add_custom_target(license_check COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tools/check_license_headers.py" --root "${CMAKE_CURRENT_SOURCE_DIR}")
399433
add_dependencies(avs_commons_check license_check)
400434
endif()
401435

402-
add_custom_target(avs_commons_extern_c_check COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tools/check-extern-c.py")
436+
add_custom_target(avs_commons_extern_c_check COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tools/check_extern_c.py")
403437
add_dependencies(avs_commons_check avs_commons_extern_c_check)
404438

405439
add_custom_target(avs_commons_symbols_check COMMAND ${CMAKE_CTEST_COMMAND} -R "'^test_.*_symbols$$'" --output-on-failure)
@@ -412,7 +446,7 @@ if(WITH_TEST)
412446
add_dependencies(avs_commons_check avs_commons_headers_check)
413447

414448
add_custom_target(avs_commons_filename_check
415-
COMMAND ! find src include_public -name "'*.[ch]'" | sed -e "'s|^.*/||'" | grep -v "'^avs_'"
449+
COMMAND ! find src include_public -name "'*.[ch]'" | sed -e "'s|^.*/||'" | grep -v "'^avs_'" | grep -v "'^pkcs11.\\?\\.h'"
416450
COMMAND ! find src include_public -name "'*.[ch]'" | sed -e "'s|^.*/||'" | sort | uniq -c | grep -v "'^ *1 '"
417451
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
418452
add_dependencies(avs_commons_check avs_commons_filename_check)
@@ -489,24 +523,9 @@ cmake_dependent_option(WITH_PKI "Enable X.509 certificate support" "${WITH_PKI_D
489523
set(AVS_COMMONS_WITH_AVS_CRYPTO_PKI ${WITH_PKI})
490524

491525
# Hardware security engines
492-
cmake_dependent_option(WITH_AVS_CRYPTO_ENGINE "Enable hardware-based security engine support" OFF WITH_OPENSSL OFF)
526+
cmake_dependent_option(WITH_AVS_CRYPTO_ENGINE "Enable hardware-based security engine support" OFF "WITH_OPENSSL OR WITH_MBEDTLS" OFF)
493527
set(AVS_COMMONS_WITH_AVS_CRYPTO_ENGINE ${WITH_AVS_CRYPTO_ENGINE})
494528

495-
# SoftHSM module
496-
# Used only in tests
497-
find_library(SOFTHSM2_LIB NAMES softhsm2 PATHS /usr/lib/softhsm)
498-
499-
# PKCS11
500-
find_package(PkgConfig)
501-
pkg_search_module(LIBP11 libp11 IMPORTED_TARGET)
502-
cmake_dependent_option(WITH_OPENSSL_PKCS11_ENGINE "Enable OpenSSL pkcs11 support" ON "WITH_AVS_CRYPTO_ENGINE;LIBP11_FOUND;WITH_PKI" OFF)
503-
set(AVS_COMMONS_WITH_OPENSSL_PKCS11_ENGINE ${WITH_OPENSSL_PKCS11_ENGINE})
504-
if(WITH_OPENSSL_PKCS11_ENGINE)
505-
avs_add_find_routine("
506-
find_package(PkgConfig REQUIRED)
507-
pkg_search_module(LIBP11 REQUIRED libp11 IMPORTED_TARGET)")
508-
endif()
509-
510529
if(WITH_OPENSSL)
511530
avs_add_find_routine("find_package(OpenSSL REQUIRED)")
512531
endif()

avs_commons-config.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2017-2020 AVSystem <avsystem@avsystem.com>
1+
# Copyright 2021 AVSystem <avsystem@avsystem.com>
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

avs_commons-version.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2017-2020 AVSystem <avsystem@avsystem.com>
1+
# Copyright 2021 AVSystem <avsystem@avsystem.com>
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

avs_commons_test.supp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -66,36 +66,3 @@
6666
fun:avs_net_socket_send
6767
fun:avs_bio_write
6868
}
69-
{
70-
# AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
71-
#
72-
# The pkcs11 engine from OpenSC is kind of insane and initializes various
73-
# OpenSSL primitives, keeping references to them in... static variables
74-
# inside functions. So there's absolutely no way to uninitialize them. And
75-
# some of them even keep circular references to the engine itself. So we're
76-
# effectively unable to uninitialize the engine. Ever.
77-
#
78-
# This shall not be a problem in practice, because engine tends to be
79-
# necessary for the entire lifetime of the application. But it makes
80-
# verifying memory correctness with Valgrind a hot mess.
81-
82-
engine-circular-references
83-
Memcheck:Leak
84-
...
85-
fun:ENGINE_new
86-
}
87-
{
88-
pkcs11-engine-allocations
89-
Memcheck:Leak
90-
...
91-
obj:*/pkcs11.so
92-
}
93-
{
94-
pkcs11-engine-verify
95-
Memcheck:Leak
96-
...
97-
fun:BN_MONT_CTX_new
98-
fun:BN_MONT_CTX_set_locked
99-
...
100-
fun:RSA_verify
101-
}

cmake/FindMbedTLS.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2017-2020 AVSystem <avsystem@avsystem.com>
1+
# Copyright 2021 AVSystem <avsystem@avsystem.com>
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

cmake/FindTinyDTLS.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2017-2020 AVSystem <avsystem@avsystem.com>
1+
# Copyright 2021 AVSystem <avsystem@avsystem.com>
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

cmake/PosixFeatures.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2017-2020 AVSystem <avsystem@avsystem.com>
1+
# Copyright 2021 AVSystem <avsystem@avsystem.com>
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

compat/lwip-posix-compat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 AVSystem <avsystem@avsystem.com>
2+
* Copyright 2021 AVSystem <avsystem@avsystem.com>
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

compat/winsock-posix-compat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 AVSystem <avsystem@avsystem.com>
2+
* Copyright 2021 AVSystem <avsystem@avsystem.com>
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)