diff --git a/CMAKE-NOTES.md b/CMAKE-NOTES.md new file mode 100644 index 000000000..0ed35b8de --- /dev/null +++ b/CMAKE-NOTES.md @@ -0,0 +1,35 @@ +# Building SoftHSMv2 with CMake + +## Configure + +CMake can be configured using the following command: + + cmake -H. -Bbuild + +Some options (more can be found in CMakeLists.txt): + + -DBUILD_TESTS=ON Compile tests along with libraries + -DDISABLE_NON_PAGED_MEMORY=ON Disable non-paged memory for secure storage + -DENABLE_EDDSA=ON Enable support for EDDSA + -DWITH_MIGRATE=ON Build migration tool + -DWITH_CRYPTO_BACKEND=openssl Select crypto backend (openssl|botan) + +## Compile + +Compile the source code using the following command: + + make -C build + +## Test + +The tests can be run from the build directory: + + cd build + ctest -V + +## Install + +Install the library using the follow command: + + cd .. + sudo make -C build install diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..bc47f260c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,120 @@ +cmake_minimum_required(VERSION 3.5) + +project(softhsm2 C CXX) + +# Build Options +option(BUILD_TESTS "Compile tests along with libraries" OFF) +option(DISABLE_NON_PAGED_MEMORY "Disable non-paged memory for secure storage" OFF) +option(DISABLE_VISIBILITY "Disables and unsets -fvisibility=hidden" OFF) +option(ENABLE_64bit "Enable 64-bit compiling" OFF) +option(ENABLE_ECC "Enable support for ECC" ON) +option(ENABLE_EDDSA "Enable support for EDDSA" OFF) +option(ENABLE_GOST "Enable support for GOST" ON) +option(ENABLE_FIPS "Enable support for FIPS 140-2 mode" OFF) +option(ENABLE_P11_KIT "Enable p11-kit integration" ON) +option(ENABLE_PEDANTIC "Enable pedantic compile mode" OFF) +option(ENABLE_STRICT "Enable strict compile mode" ON) +option(ENABLE_SHARED "Build shared libraries" ON) +option(ENABLE_STATIC "Build static libraries" ON) +option(WITH_OBJECTSTORE_BACKEND_DB "Build with object store backend database (SQLite3)" OFF) +option(WITH_MIGRATE "Build migration tool. Requires SQLite3." OFF) +set(WITH_CRYPTO_BACKEND "openssl" + CACHE STRING "Select crypto backend (openssl|botan)") +set(WITH_P11_KIT "" + CACHE STRING "Specify install path of the p11-kit module, will override path given by pkg-config") + +if(WITH_OBJECTSTORE_BACKEND_DB) + set(HAVE_OBJECTSTORE_BACKEND_DB 1) + set(WITH_MIGRATE ON) + set(WITH_SQLITE3 ON) + message(STATUS "Building with support for object store backend database") +else(WITH_OBJECTSTORE_BACKEND_DB) + message(STATUS "Building with no support for object store backend database") +endif(WITH_OBJECTSTORE_BACKEND_DB) + +if(WITH_MIGRATE) + set(BUILD_MIGRATE ON) + set(WITH_SQLITE3 ON) + message(STATUS "Building with migration tool") +else(WITH_MIGRATE) + message(STATUS "Building with no migration tool") +endif(WITH_MIGRATE) + +if(NOT DEFINED CMAKE_INSTALL_SYSCONFDIR) + set(CMAKE_INSTALL_SYSCONFDIR "/etc") +endif() +if(NOT DEFINED CMAKE_INSTALL_LOCALSTATEDIR) + set(CMAKE_INSTALL_LOCALSTATEDIR "/var") +endif() +include(GNUInstallDirs) + +set(DEFAULT_LOG_LEVEL "INFO" + CACHE STRING "The default log level") +set(DEFAULT_OBJECTSTORE_BACKEND "file" + CACHE STRING "Default storage backend for token objects") +set(DEFAULT_PKCS11_LIB "${CMAKE_INSTALL_FULL_LIBDIR}/softhsm/libsofthsm2.so" + CACHE STRING "The default PKCS#11 library") +set(DEFAULT_SOFTHSM2_CONF "${CMAKE_INSTALL_FULL_SYSCONFDIR}/softhsm2.conf" + CACHE STRING "The default location of softhsm.conf") +set(DEFAULT_TOKENDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/softhsm/tokens/" + CACHE STRING "The default location of the token directory") + +set(MAX_PIN_LEN 255 CACHE STRING "Maximum PIN length") +set(MIN_PIN_LEN 4 CACHE STRING "Minimum PIN length") + +set(VERSION "2.5.0") +set(VERSION_MAJOR 2) +set(VERSION_MINOR 5) +set(VERSION_PATCH 0) + +set(PACKAGE "softhsm") +set(PACKAGE_BUGREPORT) +set(PACKAGE_NAME "SoftHSM") +set(PACKAGE_VERSION "${VERSION}") +set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +set(PACKAGE_TARNAME "${PACKAGE}") +set(PACKAGE_URL) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Default build type for SoftHSMv2 project" FORCE) +endif(NOT CMAKE_BUILD_TYPE) + +message(STATUS "Build Configuration: ${CMAKE_BUILD_TYPE}") + +# Build Modules Path +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} + ${CMAKE_SOURCE_DIR}/modules + ) + +# Custom Modules +include(CompilerOptions) +include(GenerateExportHeader) + +# Enable CTest +enable_testing() + +# config.h include path +include_directories(${CMAKE_BINARY_DIR}) + +add_subdirectory(src) + +# p11-kit +set(default_softhsm2_lib ${DEFAULT_PKCS11_LIB}) +configure_file(softhsm2.module.in softhsm2.module) +if(ENABLE_P11_KIT) + install(FILES ${PROJECT_BINARY_DIR}/softhsm2.module + DESTINATION ${P11KIT_PATH} + ) +endif(ENABLE_P11_KIT) + +# Packaging +set(CPACK_PACKAGE_NAME ${PACKAGE_NAME}) +set(CPACK_PACKAGE_VENDOR "OpenDNSSEC") +set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH}) +set(CPACK_GENERATOR "TGZ") +set(CPACK_SOURCE_GENERATOR "TGZ") +set(CPACK_SOURCE_IGNORE_FILES "build/*;\.git/*") + +include(CPack) diff --git a/Makefile.am b/Makefile.am index a6573a3a1..282f060b3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,9 +18,15 @@ endif EXTRA_DIST = $(srcdir)/aes_wrap_key_with_pad/botan-diff \ $(srcdir)/aes_wrap_key_with_pad/README \ + $(srcdir)/CMakeLists.txt \ + $(srcdir)/CMAKE-NOTES.md \ + $(srcdir)/config.h.in.cmake \ $(srcdir)/FIPS-NOTES.md \ $(srcdir)/LICENSE \ $(srcdir)/m4/*.m4 \ + $(srcdir)/modules/*.cmake \ + $(srcdir)/modules/tests/*.c \ + $(srcdir)/modules/tests/*.cpp \ $(srcdir)/OSX-NOTES.md \ $(srcdir)/README.md \ $(srcdir)/win32/config.h.in \ diff --git a/config.h.in.cmake b/config.h.in.cmake new file mode 100644 index 000000000..d19380115 --- /dev/null +++ b/config.h.in.cmake @@ -0,0 +1,161 @@ +/* DO NOT MODIFY! config.h: autogenerated by CMake from config.h.in.cmake. */ + +/* Define to default visibility of PKCS#11 entry points */ +#cmakedefine CRYPTOKI_VISIBILITY @CRYPTOKI_VISIBILITY@ + +/* The default log level */ +#cmakedefine DEFAULT_LOG_LEVEL "@DEFAULT_LOG_LEVEL@" + +/* Default storage backend for token objects */ +#cmakedefine DEFAULT_OBJECTSTORE_BACKEND "@DEFAULT_OBJECTSTORE_BACKEND@" + +/* The default PKCS#11 library */ +#cmakedefine DEFAULT_PKCS11_LIB "@DEFAULT_PKCS11_LIB@" + +/* The default location of softhsm2.conf */ +#cmakedefine DEFAULT_SOFTHSM2_CONF "@DEFAULT_SOFTHSM2_CONF@" + +/* The default location of the token directory */ +#cmakedefine DEFAULT_TOKENDIR "@DEFAULT_TOKENDIR@" + +/* Define if advanced AES key wrap without pad is supported */ +#cmakedefine HAVE_AES_KEY_WRAP @HAVE_AES_KEY_WRAP@ + +/* Define if advanced AES key wrap with pad is supported */ +#cmakedefine HAVE_AES_KEY_WRAP_PAD @HAVE_AES_KEY_WRAP_PAD@ + +/* define if the compiler supports basic C++11 syntax */ +#cmakedefine HAVE_CXX11 @HAVE_CXX11@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DLFCN_H @HAVE_DLFCN_H@ + +/* Define if you have dlopen */ +#cmakedefine HAVE_DLOPEN @HAVE_DLOPEN@ + +/* Define to 1 if you have the `getpwuid_r' function. */ +#cmakedefine HAVE_GETPWUID_R @HAVE_GETPWUID_R@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_INTTYPES_H @HAVE_INTTYPES_H@ + +/* Define to 1 if you have the `crypto' library (-lcrypto). */ +#cmakedefine HAVE_LIBCRYPTO @HAVE_LIBCRYPTO@ + +/* Define to 1 if you have the `sqlite3' library (-lsqlite3). */ +#cmakedefine HAVE_LIBSQLITE3 @HAVE_LIBSQLITE3@ + +/* Whether LoadLibrary is available */ +#cmakedefine HAVE_LOADLIBRARY @HAVE_LOADLIBRARY@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_MEMORY_H @HAVE_MEMORY_H@ + +/* Build with object store database backend. */ +#cmakedefine HAVE_OBJECTSTORE_BACKEND_DB @HAVE_OBJECTSTORE_BACKEND_DB@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_OPENSSL_SSL_H @HAVE_OPENSSL_SSL_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_PTHREAD_H @HAVE_PTHREAD_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SQLITE3_H @HAVE_SQLITE3_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDINT_H @HAVE_STDLIB_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDLIB_H @HAVE_STDLIB_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRINGS_H @HAVE_STRINGS_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRING_H @HAVE_STRING_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_MMAN_H @HAVE_SYS_MMAN_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@ + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#cmakedefine LT_OBJDIR "@LT_OBJDIR@" + +/* Maximum PIN length */ +#cmakedefine MAX_PIN_LEN @MAX_PIN_LEN@ + +/* Minimum PIN length */ +#cmakedefine MIN_PIN_LEN @MIN_PIN_LEN@ + +/* Name of package */ +#cmakedefine PACKAGE "@PACKAGE@" + +/* Define to the address where bug reports for this package should be sent. */ +#cmakedefine PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@" + +/* Define to the full name of this package. */ +#cmakedefine PACKAGE_NAME "@PACKAGE_NAME@" + +/* Define to the full name and version of this package. */ +#cmakedefine PACKAGE_STRING "@PACKAGE_STRING@" + +/* Define to the one symbol short name of this package. */ +#cmakedefine PACKAGE_TARNAME "@PACKAGE_TARNAME@" + +/* Define to the home page for this package. */ +#cmakedefine PACKAGE_URL "@PACKAGE_URL@" + +/* Define to the version of this package. */ +#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@" + +/* Non-paged memory for secure storage */ +#cmakedefine SENSITIVE_NON_PAGE @SENSITIVE_NON_PAGE@ + +/* Define to 1 if you have the ANSI C header files. + * + * FIXME: CMake currently does not implement a way to detect STDC_HEADERS like + * autotools, so we're setting it to '1' by default. + */ + #cmakedefine STDC_HEADERS @STDC_HEADERS@ + +/* Version number of package */ +#cmakedefine VERSION "@VERSION@" + +/* SoftHSM major version number via PKCS#11 */ +#cmakedefine VERSION_MAJOR @VERSION_MAJOR@ + +/* SoftHSM minor version number via PKCS#11 */ +#cmakedefine VERSION_MINOR @VERSION_MINOR@ + +/* Compile with AES GCM */ +#cmakedefine WITH_AES_GCM @WITH_AES_GCM@ + +/* Compile with Botan support */ +#cmakedefine WITH_BOTAN @WITH_BOTAN@ + +/* Compile with ECC support */ +#cmakedefine WITH_ECC @WITH_ECC@ + +/* Compile with EDDSA support */ +#cmakedefine WITH_EDDSA @WITH_EDDSA@ + +/* Compile with FIPS 140-2 mode */ +#cmakedefine WITH_FIPS @WITH_FIPS@ + +/* Compile with GOST support */ +#cmakedefine WITH_GOST @WITH_GOST@ + +/* Compile with OpenSSL support */ +#cmakedefine WITH_OPENSSL @WITH_OPENSSL@ + +/* Compile with raw RSA PKCS PSS */ +#cmakedefine WITH_RAW_PSS @WITH_RAW_PSS@ diff --git a/modules/CompilerOptions.cmake b/modules/CompilerOptions.cmake new file mode 100644 index 000000000..2eab806c1 --- /dev/null +++ b/modules/CompilerOptions.cmake @@ -0,0 +1,508 @@ +include(CheckCXXCompilerFlag) +include(CheckFunctionExists) +include(CheckIncludeFiles) +include(CheckLibraryExists) +include(CheckSymbolExists) +include(CheckTypeSize) + +function(enable_cxx_compiler_flag_if_supported flag) + string(FIND "${CMAKE_CXX_FLAGS}" "${flag}" flag_already_set) + if(flag_already_set EQUAL -1) + check_cxx_compiler_flag("${flag}" flag_supported) + if(flag_supported) + add_compile_options(${flag}) + elseif(flag_supported) + message(WARNING "unsupported compiler flag: ${flag}") + endif(flag_supported) + unset(flag_supported CACHE) + endif() +endfunction() + +# Configures C++11 +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(HAVE_CXX11 1) + +if(ENABLE_PEDANTIC) + enable_cxx_compiler_flag_if_supported(-pedantic) + set(ENABLE_STRICT ON) +endif(ENABLE_PEDANTIC) + +if(ENABLE_STRICT) + set(CMAKE_CXX_EXTENSIONS OFF) +endif(ENABLE_STRICT) + +if(ENABLE_SHARED) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif(ENABLE_SHARED) + +# Compiler Options/Macros + +# FIXME: These options need to be set on a per object file basis (*.o). Do not belong here. +# Are these even required? They just modify the Makefile representation of the target. +#add_compile_options(-MD) +#add_compile_options(-MP) +#add_compile_options(-MF) +#add_compile_options(-MT) + +# FIXME: [Implement AC_HEADER_STDC]: +# Find a CMake mechanism performs the check as defined in +# AC_HEADER_STDC: +# https://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Particular-Headers.html +# +# Not sure if this is a legacy check, or it's something that we need to +# continue to check with modern compiler versions. +set(STDC_HEADERS 1) + +# acx_strict.m4 +if(ENABLE_STRICT) + enable_cxx_compiler_flag_if_supported(-Wall) + enable_cxx_compiler_flag_if_supported(-Wextra) +endif(ENABLE_STRICT) + +# acx_64bit.m4 +if(ENABLE_64BIT) + if(CMAKE_SIZEOF_VOID_P STREQUAL "8") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64") + else(CMAKE_SIZEOF_VOID_P STREQUAL "8") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") + endif(CMAKE_SIZEOF_VOID_P STREQUAL "8") +endif(ENABLE_64BIT) + +# Equivalent of acx_visibility.m4 +if(DISABLE_VISIBILITY) + message(STATUS "-fvisibility=hidden has been disabled") +else(DISABLE_VISIBILITY) + set(CRYPTOKI_VISIBILITY 1) + set(CMAKE_CXX_VISIBILITY_PRESET hidden) +endif(DISABLE_VISIBILITY) + +# acx_non_paged_memory.m4 +if(DISABLE_NON_PAGED_MEMORY) + message(STATUS "non-paged-memory disabled") +else(DISABLE_NON_PAGED_MEMORY) + set(SENSITIVE_NON_PAGE 1) + check_include_files(sys/mman.h HAVE_SYS_MMAN_H) + execute_process(COMMAND bash -c "ulimit -l" + OUTPUT_VARIABLE MLOCK_SIZE + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT "${MLOCK_SIZE}" STREQUAL "unlimited") + message(WARNING "\ + ====================================================================== + SoftHSM has been configured to store sensitive data in non-page RAM + (i.e. memory that is not swapped out to disk). This is the default and + most secure configuration. Your system, however, is not configured to + support this model in non-privileged accounts (i.e. user accounts). + + You can check the setting on your system by running the following + command in a shell: + + ulimit -l + + If this does not return \"unlimited\" and you plan to run SoftHSM from + non-privileged accounts then you should edit the configuration file + /etc/security/limits.conf (on most systems). + + You will need to add the following lines to this file: + + # + * - memlock unlimited + + Alternatively, you can elect to disable this feature of SoftHSM by + re-running cmake with the option \"-DDISABLE_NON_PAGED_MEMORY=ON\". + Please be advised that this may seriously degrade the security of + SoftHSM. + ======================================================================") + endif(NOT "${MLOCK_SIZE}" STREQUAL "unlimited") +endif(DISABLE_NON_PAGED_MEMORY) + +# Check if -ldl exists (equivalent of acx_dlopen.m4) +check_library_exists(dl dlopen "" HAVE_DLOPEN) +check_function_exists(LoadLibrary HAVE_LOADLIBRARY) + +# acx_libtool.m4 +check_include_files(dlfcn.h HAVE_DLFCN_H) + +# configure: + +# STDC_HEADERS +check_include_files(sys/types.h HAVE_SYS_TYPES_H) +check_include_files(sys/stat.h HAVE_SYS_STAT_H) +check_include_files(stdlib.h HAVE_STDLIB_H) +check_include_files(stddef.h HAVE_STDDEF_H) +check_include_files(string.h HAVE_STRING_H) +check_include_files(strings.h HAVE_STRINGS_H) +check_include_files(inttypes.h HAVE_INTTYPES_H) +check_include_files(stdint.h HAVE_STDINT_H) +check_include_files(unistd.h HAVE_UNISTD_H) + +check_include_files(memory.h HAVE_MEMORY_H) +check_include_files(pthread.h HAVE_PTHREAD_H) +check_function_exists(getpwuid_r HAVE_GETPWUID_R) + +# Find Botan Crypto Backend +if(WITH_CRYPTO_BACKEND STREQUAL "botan") + set(WITH_BOTAN 1) + + include(FindBotan) + if(NOT BOTAN_FOUND) + message(FATAL_ERROR "Failed to find Botan!") + endif() + + set(CRYPTO_INCLUDES ${BOTAN_INCLUDE_DIRS}) + set(CRYPTO_LIBS ${BOTAN_LIBRARIES}) + message(STATUS "Botan: Includes: ${CRYPTO_INCLUDES}") + message(STATUS "Botan: Libs: ${CRYPTO_LIBS}") + + # CXX11 flag is not added to try_run, so set it locally. + CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) + CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) + set(TMP_CXX_FLAGS ${CMAKE_CXX_FLAGS}) + if(COMPILER_SUPPORTS_CXX11) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + elseif(COMPILER_SUPPORTS_CXX0X) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") + endif() + + # acx_botan_ecc.m4 + if(ENABLE_ECC) + set(testfile ${CMAKE_SOURCE_DIR}/modules/tests/test_botan_ecc.cpp) + try_run(RUN_ECC COMPILE_RESULT + "${CMAKE_BINARY_DIR}/prebuild_santity_tests" ${testfile} + LINK_LIBRARIES ${CRYPTO_LIBS} + CMAKE_FLAGS + "-DINCLUDE_DIRECTORIES=${CRYPTO_INCLUDES}" + ) + if(COMPILE_RESULT AND RUN_ECC EQUAL 0) + set(WITH_ECC 1) + message(STATUS "Botan: Found P-256") + else() + set(error_msg "Botan: Cannot find P-256! Botan library has no ECC support!") + message(FATAL_ERROR ${error_msg}) + endif() + else(ENABLE_ECC) + message(STATUS "Botan: Support for ECC is disabled") + endif(ENABLE_ECC) + + # acx_botan_eddsa.m4 + if(ENABLE_EDDSA) + # ED25519 + set(testfile ${CMAKE_SOURCE_DIR}/modules/tests/test_botan_ed25519.cpp) + try_run(RUN_ED25519 COMPILE_RESULT + "${CMAKE_BINARY_DIR}/prebuild_santity_tests" ${testfile} + LINK_LIBRARIES ${CRYPTO_LIBS} + CMAKE_FLAGS + "-DINCLUDE_DIRECTORIES=${CRYPTO_INCLUDES}" + ) + if(COMPILE_RESULT AND RUN_ED25519 EQUAL 0) + set(WITH_EDDSA 1) + message(STATUS "Botan: Found ED25519") + else() + set(error_msg "Botan: Cannot find ED25519! Botan library has no EDDSA support!") + message(FATAL_ERROR ${error_msg}) + endif() + else(ENABLE_EDDSA) + message(STATUS "Botan: Support for EDDSA is disabled") + endif(ENABLE_EDDSA) + + # acx_botan_gost.m4 + if(ENABLE_GOST) + set(testfile ${CMAKE_SOURCE_DIR}/modules/tests/test_botan_gost.cpp) + try_run(RUN_GOST COMPILE_RESULT + "${CMAKE_BINARY_DIR}/prebuild_santity_tests" ${testfile} + LINK_LIBRARIES ${CRYPTO_LIBS} + CMAKE_FLAGS + "-DINCLUDE_DIRECTORIES=${CRYPTO_INCLUDES}" + ) + if(COMPILE_RESULT AND RUN_GOST EQUAL 0) + set(WITH_GOST 1) + message(STATUS "Botan: Found GOST") + else() + set(error_msg "Botan: Cannot find GOST! Botan library has no GOST support!") + message(FATAL_ERROR ${error_msg}) + endif() + else(ENABLE_GOST) + message(STATUS "Botan: Support for GOST is disabled") + endif(ENABLE_GOST) + + if(ENABLE_FIPS) + message(FATAL_ERROR "Botan does not support FIPS 140-2 mode") + endif(ENABLE_FIPS) + + # Compile with AES KEY WRAP + set(HAVE_AES_KEY_WRAP 1) + + # acx_botan_rfc5649.m4 + set(testfile ${CMAKE_SOURCE_DIR}/modules/tests/test_botan_rfc5649.cpp) + try_run(RUN_AES_KEY_WRAP_PAD COMPILE_RESULT + "${CMAKE_BINARY_DIR}/prebuild_santity_tests" ${testfile} + LINK_LIBRARIES ${CRYPTO_LIBS} + CMAKE_FLAGS + "-DINCLUDE_DIRECTORIES=${CRYPTO_INCLUDES}" + ) + if(COMPILE_RESULT AND RUN_AES_KEY_WRAP_PAD EQUAL 0) + set(HAVE_AES_KEY_WRAP_PAD 1) + message(STATUS "Botan: RFC 5649 is supported") + else() + message(STATUS "Botan: RFC 5649 is not supported") + endif() + + # acx_botan_rawpss.m4 + set(testfile ${CMAKE_SOURCE_DIR}/modules/tests/test_botan_rawpss.cpp) + try_run(RUN_RAWPSS COMPILE_RESULT + "${CMAKE_BINARY_DIR}/prebuild_santity_tests" ${testfile} + LINK_LIBRARIES ${CRYPTO_LIBS} + CMAKE_FLAGS + "-DINCLUDE_DIRECTORIES=${CRYPTO_INCLUDES}" + ) + if(COMPILE_RESULT AND RUN_RAWPSS EQUAL 0) + set(WITH_RAW_PSS 1) + message(STATUS "Botan: Found raw PSS") + else() + message(STATUS "Botan: Cannot find raw PSS support, upgrade to Botan >= v2.3.0") + endif() + + # acx_botan_aes_gcm.m4 + set(testfile ${CMAKE_SOURCE_DIR}/modules/tests/test_botan_aes_gcm.cpp) + try_run(RUN_AESGCM COMPILE_RESULT + "${CMAKE_BINARY_DIR}/prebuild_santity_tests" ${testfile} + LINK_LIBRARIES ${CRYPTO_LIBS} + CMAKE_FLAGS + "-DINCLUDE_DIRECTORIES=${CRYPTO_INCLUDES}" + ) + if(COMPILE_RESULT AND RUN_AESGCM EQUAL 0) + set(WITH_AES_GCM 1) + message(STATUS "Botan: Found AES GCM") + else() + message(STATUS "Botan: Cannot find AES GCM support, upgrade to Botan >= v2.0.0") + endif() + + # Restore flags + set(CMAKE_CXX_FLAGS ${TMP_CXX_FLAGS}) + +# Find OpenSSL Crypto Backend +elseif(WITH_CRYPTO_BACKEND STREQUAL "openssl") + set(WITH_OPENSSL 1) + + include(FindOpenSSL) + if(NOT OPENSSL_FOUND) + message(FATAL_ERROR "Failed to find OpenSSL!") + endif() + + set(CRYPTO_INCLUDES ${OPENSSL_INCLUDE_DIR}) + set(CRYPTO_LIBS ${OPENSSL_LIBRARIES}) + message(STATUS "OpenSSL: Found version ${OPENSSL_VERSION}") + message(STATUS "OpenSSL: Includes: ${CRYPTO_INCLUDES}") + message(STATUS "OpenSSL: Libs: ${CRYPTO_LIBS}") + + check_include_files(openssl/ssl.h HAVE_OPENSSL_SSL_H) + get_filename_component(CRYPTO_LIB_DIR "${OPENSSL_CRYPTO_LIBRARY}" DIRECTORY) + check_library_exists(crypto "BN_new" "${CRYPTO_LIB_DIR}" HAVE_LIBCRYPTO) + + # acx_openssl_ecc.m4 + if(ENABLE_ECC) + set(testfile ${CMAKE_SOURCE_DIR}/modules/tests/test_openssl_ecc.c) + try_run(RUN_ECC COMPILE_RESULT + "${CMAKE_BINARY_DIR}/prebuild_santity_tests" ${testfile} + LINK_LIBRARIES ${CRYPTO_LIBS} + CMAKE_FLAGS + "-DINCLUDE_DIRECTORIES=${CRYPTO_INCLUDES}" + ) + if(COMPILE_RESULT AND RUN_ECC EQUAL 0) + set(WITH_ECC 1) + message(STATUS "OpenSSL: Found P-256, P-384, and P-521") + else() + set(error_msg "OpenSSL: Cannot find P-256, P-384, or P-521! OpenSSL library has no ECC support!") + message(FATAL_ERROR ${error_msg}) + endif() + else(ENABLE_ECC) + message(STATUS "OpenSSL: Support for ECC is disabled") + endif(ENABLE_ECC) + + # acx_openssl_eddsa.m4 + if(ENABLE_EDDSA) + # ED25519 + set(testfile ${CMAKE_SOURCE_DIR}/modules/tests/test_openssl_ed25519.c) + try_run(RUN_ED25519 COMPILE_RESULT + "${CMAKE_BINARY_DIR}/prebuild_santity_tests" ${testfile} + LINK_LIBRARIES ${CRYPTO_LIBS} + CMAKE_FLAGS + "-DINCLUDE_DIRECTORIES=${CRYPTO_INCLUDES}" + ) + if(COMPILE_RESULT AND RUN_ED25519 EQUAL 0) + set(WITH_EDDSA 1) + message(STATUS "OpenSSL: Found ED25519") + else() + set(error_msg "OpenSSL: Cannot find ED25519! OpenSSL library has no EDDSA support!") + message(FATAL_ERROR ${error_msg}) + endif() + # ED448 + set(testfile ${CMAKE_SOURCE_DIR}/modules/tests/test_openssl_ed448.c) + try_run(RUN_ED448 COMPILE_RESULT + "${CMAKE_BINARY_DIR}/prebuild_santity_tests" ${testfile} + LINK_LIBRARIES ${CRYPTO_LIBS} + CMAKE_FLAGS + "-DINCLUDE_DIRECTORIES=${CRYPTO_INCLUDES}" + ) + if(COMPILE_RESULT AND RUN_ED448 EQUAL 0) + message(STATUS "OpenSSL: Found ED448") + else() + # Not used in SoftHSM + message(STATUS "OpenSSL: Cannot find ED448!") + endif() + else(ENABLE_EDDSA) + message(STATUS "OpenSSL: Support for EDDSA is disabled") + endif(ENABLE_EDDSA) + + # acx_openssl_gost.m4 + if(ENABLE_GOST) + set(testfile ${CMAKE_SOURCE_DIR}/modules/tests/test_openssl_gost.c) + try_run(RUN_GOST COMPILE_RESULT + "${CMAKE_BINARY_DIR}/prebuild_santity_tests" ${testfile} + LINK_LIBRARIES ${CRYPTO_LIBS} + CMAKE_FLAGS + "-DINCLUDE_DIRECTORIES=${CRYPTO_INCLUDES}" + ) + if(COMPILE_RESULT AND RUN_GOST EQUAL 0) + set(WITH_GOST 1) + message(STATUS "OpenSSL: Found GOST engine") + else() + set(error_msg "OpenSSL: Cannot find GOST engine! OpenSSL library has no GOST support!") + message(FATAL_ERROR ${error_msg}) + endif() + else(ENABLE_GOST) + message(STATUS "OpenSSL: Support for GOST is disabled") + endif(ENABLE_GOST) + + # acx_openssl_fips.m4 + if(ENABLE_FIPS) + set(testfile ${CMAKE_SOURCE_DIR}/modules/tests/test_openssl_fips.c) + try_run(RUN_FIPS COMPILE_RESULT + "${CMAKE_BINARY_DIR}/prebuild_santity_tests" ${testfile} + LINK_LIBRARIES ${CRYPTO_LIBS} + CMAKE_FLAGS + "-DINCLUDE_DIRECTORIES=${CRYPTO_INCLUDES}" + ) + if(COMPILE_RESULT AND RUN_FIPS EQUAL 0) + set(WITH_FIPS 1) + message(STATUS "OpenSSL: Found working FIPS_mode_set()") + else() + set(error_msg "OpenSSL: FIPS_mode_set(1) failed. OpenSSL library is not FIPS capable!") + message(FATAL_ERROR ${error_msg}) + endif() + else(ENABLE_FIPS) + message(STATUS "OpenSSL: Support for FIPS 140-2 mode is disabled") + endif(ENABLE_FIPS) + + # acx_openssl_rfc3349 + set(testfile ${CMAKE_SOURCE_DIR}/modules/tests/test_openssl_rfc3394.c) + try_run(RUN_AES_KEY_WRAP COMPILE_RESULT + "${CMAKE_BINARY_DIR}/prebuild_santity_tests" ${testfile} + LINK_LIBRARIES ${CRYPTO_LIBS} + CMAKE_FLAGS + "-DINCLUDE_DIRECTORIES=${CRYPTO_INCLUDES}" + ) + if(COMPILE_RESULT AND RUN_AES_KEY_WRAP EQUAL 0) + set(HAVE_AES_KEY_WRAP 1) + message(STATUS "OpenSSL: RFC 3394 is supported") + else() + message(STATUS "OpenSSL: RFC 3394 is not supported") + endif() + + # acx_openssl_rfc5649 + set(testfile ${CMAKE_SOURCE_DIR}/modules/tests/test_openssl_rfc5649.c) + try_run(RUN_AES_KEY_WRAP_PAD COMPILE_RESULT + "${CMAKE_BINARY_DIR}/prebuild_santity_tests" ${testfile} + LINK_LIBRARIES ${CRYPTO_LIBS} + CMAKE_FLAGS + "-DINCLUDE_DIRECTORIES=${CRYPTO_INCLUDES}" + ) + if(COMPILE_RESULT AND RUN_AES_KEY_WRAP_PAD EQUAL 0) + set(HAVE_AES_KEY_WRAP_PAD 1) + message(STATUS "OpenSSL: RFC 5649 is supported") + else() + message(STATUS "OpenSSL: RFC 5649 is not supported") + endif() + + # Compile with RAW PKCS PSS + set(WITH_RAW_PSS 1) + # Compile with AES_GCM + set(WITH_AES_GCM 1) + +else() + message(FATAL_ERROR "Crypto backend '${WITH_CRYPTO_BACKEND}' not supported. Use openssl or botan.") +endif() + +# Find SQLite3 +if(WITH_SQLITE3) + include(FindSQLite3) + if(NOT SQLITE3_FOUND) + message(FATAL_ERROR "Failed to find SQLite3!") + endif(NOT SQLITE3_FOUND) + + set(SQLITE3_INCLUDES ${SQLITE3_INCLUDE_DIRS}) + set(SQLITE3_LIBS ${SQLITE3_LIBRARIES}) + message(STATUS "SQLite3: Includes: ${SQLITE3_INCLUDES}") + message(STATUS "SQLite3: Libs: ${SQLITE3_LIBS}") + + check_include_files(sqlite3.h HAVE_SQLITE3_H) + check_library_exists(sqlite3 sqlite3_prepare_v2 "" HAVE_LIBSQLITE3) + find_program(SQLITE3_COMMAND NAMES sqlite3) + if(SQLITE3_COMMAND MATCHES "-NOTFOUND") + message(FATAL_ERROR "SQLite3: Command was not found") + endif(SQLITE3_COMMAND MATCHES "-NOTFOUND") +else(WITH_SQLITE3) + message(STATUS "Not including SQLite3 in build") +endif(WITH_SQLITE3) + +# acx_p11kit.m4 +if(ENABLE_P11_KIT) + if("${WITH_P11_KIT}" STREQUAL "") + find_package(PkgConfig) + if(PKG_CONFIG_FOUND) + function(pkg_check_variable _pkg _name) + string(TOUPPER ${_pkg} _pkg_upper) + string(TOUPPER ${_name} _name_upper) + string(REPLACE "-" "_" _pkg_upper ${_pkg_upper}) + string(REPLACE "-" "_" _name_upper ${_name_upper}) + set(_output_name "${_pkg_upper}_${_name_upper}") + + execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=${_name} ${_pkg} OUTPUT_VARIABLE _pkg_result OUTPUT_STRIP_TRAILING_WHITESPACE) + set("${_output_name}" "${_pkg_result}" CACHE STRING "pkg-config variable ${_name} of ${_pkg}") + endfunction() + pkg_check_modules(PC_p11kit QUIET p11-kit-1) + pkg_check_variable(p11-kit-1 p11_module_configs) + set(P11KIT_PATH ${P11_KIT_1_P11_MODULE_CONFIGS}) + endif(PKG_CONFIG_FOUND) + else() + set(P11KIT_PATH ${WITH_P11_KIT}) + endif() + message(STATUS "P11-kit: Install path: ${P11KIT_PATH}") + if("${P11KIT_PATH}" STREQUAL "") + message(WARNING "P11-kit: Missing install path for the p11-kit module, skipping module") + SET(ENABLE_P11_KIT OFF) + endif() +else(ENABLE_P11_KIT) + message(STATUS "P11-kit: No integration") +endif(ENABLE_P11_KIT) + +if(BUILD_TESTS) + # Find CppUnit (equivalent of acx_cppunit.m4) + set(CppUnit_FIND_QUIETLY ON) + include(FindCppUnit) + if(NOT CPPUNIT_FOUND) + message(FATAL_ERROR "Failed to find CppUnit!") + endif(NOT CPPUNIT_FOUND) + + set(CPPUNIT_INCLUDES ${CPPUNIT_INCLUDE_DIR}) + set(CPPUNIT_LIBS ${CPPUNIT_LIBRARY}) + message(STATUS "CppUnit: Includes: ${CPPUNIT_INCLUDES}") + message(STATUS "CppUnit: Libs: ${CPPUNIT_LIBS}") +else(BUILD_TESTS) + message(STATUS "Not building tests") +endif(BUILD_TESTS) + +configure_file(config.h.in.cmake ${CMAKE_BINARY_DIR}/config.h) diff --git a/modules/FindBotan.cmake b/modules/FindBotan.cmake new file mode 100644 index 000000000..6cb85a69d --- /dev/null +++ b/modules/FindBotan.cmake @@ -0,0 +1,46 @@ +# - Try to find the Botan library +# +# Once done this will define +# +# BOTAN_FOUND - System has Botan +# BOTAN_INCLUDE_DIR - The Botan include directory +# BOTAN_LIBRARIES - The libraries needed to use Botan +# BOTAN_DEFINITIONS - Compiler switches required for using Botan + +IF (BOTAN_INCLUDE_DIR AND BOTAN_LIBRARY) + # in cache already + SET(Botan_FIND_QUIETLY TRUE) +ENDIF (BOTAN_INCLUDE_DIR AND BOTAN_LIBRARY) + +IF (NOT WIN32) + # try using pkg-config to get the directories and then use these values + # in the FIND_PATH() and FIND_LIBRARY() calls + # also fills in BOTAN_DEFINITIONS, although that isn't normally useful + FIND_PACKAGE(PkgConfig) + PKG_SEARCH_MODULE(PC_BOTAN botan-2 botan-1.11 botan-1.10) + SET(BOTAN_DEFINITIONS ${PC_BOTAN_CFLAGS}) +ENDIF (NOT WIN32) + +FIND_PATH(BOTAN_INCLUDE_DIR botan/botan.h + HINTS + ${PC_BOTAN_INCLUDEDIR} + ${PC_BOTAN_INCLUDE_DIRS} + ) + +FIND_LIBRARY(BOTAN_LIBRARY NAMES ${PC_BOTAN_LIBRARIES} + HINTS + ${PC_BOTAN_LIBDIR} + ${PC_BOTAN_LIBRARY_DIRS} + ) + +MARK_AS_ADVANCED(BOTAN_INCLUDE_DIR BOTAN_LIBRARY) + +# handle the QUIETLY and REQUIRED arguments and set BOTAN_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Botan DEFAULT_MSG BOTAN_LIBRARY BOTAN_INCLUDE_DIR) + +IF(BOTAN_FOUND) + SET(BOTAN_LIBRARIES ${BOTAN_LIBRARY}) + SET(BOTAN_INCLUDE_DIRS ${BOTAN_INCLUDE_DIR}) +ENDIF(BOTAN_FOUND) diff --git a/modules/FindCppUnit.cmake b/modules/FindCppUnit.cmake new file mode 100644 index 000000000..0980d1da2 --- /dev/null +++ b/modules/FindCppUnit.cmake @@ -0,0 +1,33 @@ +# +# http://root.cern.ch/viewvc/trunk/cint/reflex/cmake/modules/FindCppUnit.cmake +# +# - Find CppUnit +# This module finds an installed CppUnit package. +# +# It sets the following variables: +# CPPUNIT_FOUND - Set to false, or undefined, if CppUnit isn't found. +# CPPUNIT_INCLUDE_DIR - The CppUnit include directory. +# CPPUNIT_LIBRARY - The CppUnit library to link against. + +FIND_PATH(CPPUNIT_INCLUDE_DIR cppunit/Test.h) +FIND_LIBRARY(CPPUNIT_LIBRARY NAMES cppunit) + +IF (CPPUNIT_INCLUDE_DIR AND CPPUNIT_LIBRARY) + SET(CPPUNIT_FOUND TRUE) +ENDIF (CPPUNIT_INCLUDE_DIR AND CPPUNIT_LIBRARY) + +IF (CPPUNIT_FOUND) + + # show which CppUnit was found only if not quiet + IF (NOT CppUnit_FIND_QUIETLY) + MESSAGE(STATUS "Found CppUnit: ${CPPUNIT_LIBRARY}") + ENDIF (NOT CppUnit_FIND_QUIETLY) + +ELSE (CPPUNIT_FOUND) + + # fatal error if CppUnit is required but not found + IF (CppUnit_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find CppUnit") + ENDIF (CppUnit_FIND_REQUIRED) + +ENDIF (CPPUNIT_FOUND) diff --git a/modules/FindSQLite3.cmake b/modules/FindSQLite3.cmake new file mode 100644 index 000000000..dc7a3b38c --- /dev/null +++ b/modules/FindSQLite3.cmake @@ -0,0 +1,37 @@ +# Copyright (C) 2007-2009 LuaDist. +# Created by Peter Kapec +# Redistribution and use of this file is allowed according to the terms of the MIT license. +# For details see the COPYRIGHT file distributed with LuaDist. +# Note: +# Searching headers and libraries is very simple and is NOT as powerful as scripts +# distributed with CMake, because LuaDist defines directories to search for. +# Everyone is encouraged to contact the author with improvements. Maybe this file +# becomes part of CMake distribution sometimes. + +# - Find sqlite3 +# Find the native SQLITE3 headers and libraries. +# +# SQLITE3_INCLUDE_DIRS - where to find sqlite3.h, etc. +# SQLITE3_LIBRARIES - List of libraries when using sqlite. +# SQLITE3_FOUND - True if sqlite found. + +# Look for the header file. +FIND_PATH(SQLITE3_INCLUDE_DIR NAMES sqlite3.h) + +# Look for the library. +FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite sqlite3) + +# Handle the QUIETLY and REQUIRED arguments and set SQLITE3_FOUND to TRUE if all listed variables are TRUE. +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SQLITE3 DEFAULT_MSG SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR) + +# Copy the results to the output variables. +IF(SQLITE3_FOUND) + SET(SQLITE3_LIBRARIES ${SQLITE3_LIBRARY}) + SET(SQLITE3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR}) +ELSE(SQLITE3_FOUND) + SET(SQLITE3_LIBRARIES) + SET(SQLITE3_INCLUDE_DIRS) +ENDIF(SQLITE3_FOUND) + +MARK_AS_ADVANCED(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES) diff --git a/modules/tests/test_botan_aes_gcm.cpp b/modules/tests/test_botan_aes_gcm.cpp new file mode 100644 index 000000000..3769342ba --- /dev/null +++ b/modules/tests/test_botan_aes_gcm.cpp @@ -0,0 +1,11 @@ +#include +#include +int main() +{ + using namespace Botan; + +#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(2,0,0) + return 0; +#endif + return 1; +} diff --git a/modules/tests/test_botan_ecc.cpp b/modules/tests/test_botan_ecc.cpp new file mode 100644 index 000000000..cb1be2118 --- /dev/null +++ b/modules/tests/test_botan_ecc.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include +int main() +{ + Botan::LibraryInitializer::initialize(); + const std::string name("secp256r1"); + const Botan::OID oid(Botan::OIDS::lookup(name)); + const Botan::EC_Group ecg(oid); + try { +#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,11,0) + const std::vector der = + ecg.DER_encode(Botan::EC_DOMPAR_ENC_OID); +#else + const Botan::SecureVector der = + ecg.DER_encode(Botan::EC_DOMPAR_ENC_OID); +#endif + } catch(...) { + return 1; + } + return 0; +} diff --git a/modules/tests/test_botan_ed25519.cpp b/modules/tests/test_botan_ed25519.cpp new file mode 100644 index 000000000..8ac4bac2b --- /dev/null +++ b/modules/tests/test_botan_ed25519.cpp @@ -0,0 +1,14 @@ +#include +#include +#include +int main() +{ + Botan::secure_vector k(32); + try { + Botan::Ed25519_PrivateKey* key = + new Botan::Ed25519_PrivateKey(k); + } catch(...) { + return 1; + } + return 0; +} diff --git a/modules/tests/test_botan_gost.cpp b/modules/tests/test_botan_gost.cpp new file mode 100644 index 000000000..a141e4bc8 --- /dev/null +++ b/modules/tests/test_botan_gost.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include +int main() +{ + Botan::LibraryInitializer::initialize(); + const std::string name("gost_256A"); + const Botan::OID oid(Botan::OIDS::lookup(name)); + const Botan::EC_Group ecg(oid); + try { +#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,11,0) + const std::vector der = + ecg.DER_encode(Botan::EC_DOMPAR_ENC_OID); +#else + const Botan::SecureVector der = + ecg.DER_encode(Botan::EC_DOMPAR_ENC_OID); +#endif + } catch(...) { + return 1; + } + + return 0; +} diff --git a/modules/tests/test_botan_rawpss.cpp b/modules/tests/test_botan_rawpss.cpp new file mode 100644 index 000000000..ba7ad011d --- /dev/null +++ b/modules/tests/test_botan_rawpss.cpp @@ -0,0 +1,11 @@ +#include +#include +int main() +{ + using namespace Botan; + +#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(2,3,0) + return 0; +#endif + return 1; +} diff --git a/modules/tests/test_botan_rfc5649.cpp b/modules/tests/test_botan_rfc5649.cpp new file mode 100644 index 000000000..7f1fae437 --- /dev/null +++ b/modules/tests/test_botan_rfc5649.cpp @@ -0,0 +1,19 @@ +#include +#include +#include +int main() +{ + using namespace Botan; + +#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,11,0) + secure_vector key(10); + SymmetricKey kek("AABB"); + secure_vector x = rfc5649_keywrap(key, kek); +#else + SecureVector key(10); + SymmetricKey kek("AABB"); + Algorithm_Factory& af = global_state().algorithm_factory(); + SecureVector x = rfc5649_keywrap(key, kek, af); +#endif + return 0; +} diff --git a/modules/tests/test_openssl_ecc.c b/modules/tests/test_openssl_ecc.c new file mode 100644 index 000000000..d1eb22b6f --- /dev/null +++ b/modules/tests/test_openssl_ecc.c @@ -0,0 +1,13 @@ +#include +#include +int main() +{ + EC_KEY *ec256, *ec384, *ec521; + + ec256 = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); + ec384 = EC_KEY_new_by_curve_name(NID_secp384r1); + ec521 = EC_KEY_new_by_curve_name(NID_secp521r1); + if (ec256 == NULL || ec384 == NULL || ec521 == NULL) + return 1; + return 0; +} diff --git a/modules/tests/test_openssl_ed25519.c b/modules/tests/test_openssl_ed25519.c new file mode 100644 index 000000000..70dd92f5d --- /dev/null +++ b/modules/tests/test_openssl_ed25519.c @@ -0,0 +1,11 @@ +#include +#include +int main() +{ + EVP_PKEY_CTX *ctx; + + ctx = EVP_PKEY_CTX_new_id(NID_ED25519, NULL); + if (ctx == NULL) + return 1; + return 0; +} diff --git a/modules/tests/test_openssl_ed448.c b/modules/tests/test_openssl_ed448.c new file mode 100644 index 000000000..c97b09421 --- /dev/null +++ b/modules/tests/test_openssl_ed448.c @@ -0,0 +1,11 @@ +#include +#include +int main() +{ + EVP_PKEY_CTX *ctx; + + ctx = EVP_PKEY_CTX_new_id(NID_ED448, NULL); + if (ctx == NULL) + return 1; + return 0; +} diff --git a/modules/tests/test_openssl_fips.c b/modules/tests/test_openssl_fips.c new file mode 100644 index 000000000..51e75cdd7 --- /dev/null +++ b/modules/tests/test_openssl_fips.c @@ -0,0 +1,5 @@ +#include +int main() +{ + return !FIPS_mode_set(1); +} diff --git a/modules/tests/test_openssl_gost.c b/modules/tests/test_openssl_gost.c new file mode 100644 index 000000000..33487e115 --- /dev/null +++ b/modules/tests/test_openssl_gost.c @@ -0,0 +1,41 @@ +#include +#include +#include +int main() +{ + ENGINE* eg; + const EVP_MD* EVP_GOST_34_11; + + /* Initialise OpenSSL */ + OpenSSL_add_all_algorithms(); + + /* Load engines */ +#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) + ENGINE_load_builtin_engines(); +#else + OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_ALL_BUILTIN | OPENSSL_INIT_LOAD_CONFIG, NULL); +#endif + + /* Initialise the GOST engine */ + eg = ENGINE_by_id("gost"); + if (eg == NULL) + return 1; + if (ENGINE_init(eg) <= 0) + return 1; + + /* better than digest_gost */ + EVP_GOST_34_11 = ENGINE_get_digest(eg, NID_id_GostR3411_94); + if (EVP_GOST_34_11 == NULL) + return 1; + + /* from the openssl.cnf */ + if (ENGINE_register_pkey_asn1_meths(eg) <= 0) + return 1; + if (ENGINE_ctrl_cmd_string(eg, + "CRYPT_PARAMS", + "id-Gost28147-89-CryptoPro-A-ParamSet", + 0) <= 0) + return 1; + + return 0; +} diff --git a/modules/tests/test_openssl_rfc3394.c b/modules/tests/test_openssl_rfc3394.c new file mode 100644 index 000000000..97343eea1 --- /dev/null +++ b/modules/tests/test_openssl_rfc3394.c @@ -0,0 +1,7 @@ +#include +int main() +{ + EVP_aes_128_wrap(); + return 0; +} + diff --git a/modules/tests/test_openssl_rfc5649.c b/modules/tests/test_openssl_rfc5649.c new file mode 100644 index 000000000..17d63bab6 --- /dev/null +++ b/modules/tests/test_openssl_rfc5649.c @@ -0,0 +1,6 @@ +#include +int main() +{ + EVP_aes_128_wrap_pad(); + return 0; +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000..1d235e17d --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(lib) +add_subdirectory(bin) diff --git a/src/Makefile.am b/src/Makefile.am index 7f51142b5..09853258b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,3 +1,5 @@ MAINTAINERCLEANFILES = $(srcdir)/Makefile.in SUBDIRS = lib bin + +EXTRA_DIST = $(srcdir)/CMakeLists.txt diff --git a/src/bin/CMakeLists.txt b/src/bin/CMakeLists.txt new file mode 100644 index 000000000..e41531665 --- /dev/null +++ b/src/bin/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(dump) +add_subdirectory(keyconv) +add_subdirectory(migrate) +add_subdirectory(util) diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 354c27231..851b91c38 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -6,5 +6,6 @@ if BUILD_MIGRATE SUBDIRS += migrate endif -EXTRA_DIST = $(srcdir)/win32/*.cpp \ +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/win32/*.cpp \ $(srcdir)/win32/*.h diff --git a/src/bin/dump/CMakeLists.txt b/src/bin/dump/CMakeLists.txt new file mode 100644 index 000000000..f789dd8d5 --- /dev/null +++ b/src/bin/dump/CMakeLists.txt @@ -0,0 +1,30 @@ +project(softhsm2-dump) + +set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/../../lib + ${PROJECT_SOURCE_DIR}/../../lib/object_store + ${PROJECT_SOURCE_DIR}/../../lib/pkcs11 + ${SQLITE3_INCLUDES} + ) + +set(INSTALL_TARGETS ${PROJECT_NAME}-file) +set(INSTALL_MAN_FILES ${PROJECT_NAME}-file.1) + +include_directories(${INCLUDE_DIRS}) + +add_executable(${PROJECT_NAME}-file softhsm2-dump-file.cpp) + +if(WITH_OBJECTSTORE_BACKEND_DB) + add_executable(${PROJECT_NAME}-db softhsm2-dump-db.cpp) + target_link_libraries(${PROJECT_NAME}-db ${SQLITE3_LIBS} ${YIELD_LIB}) + list(APPEND INSTALL_TARGETS ${PROJECT_NAME}-db) + list(APPEND INSTALL_MAN_FILES ${PROJECT_NAME}-db.1) +endif(WITH_OBJECTSTORE_BACKEND_DB) + +install(TARGETS ${INSTALL_TARGETS} + DESTINATION ${CMAKE_INSTALL_BINDIR} + ) + +install(FILES ${INSTALL_MAN_FILES} + DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 + ) + diff --git a/src/bin/dump/Makefile.am b/src/bin/dump/Makefile.am index c70d6f648..64bfa8c1b 100644 --- a/src/bin/dump/Makefile.am +++ b/src/bin/dump/Makefile.am @@ -20,5 +20,6 @@ softhsm2_dump_db_SOURCES = softhsm2-dump-db.cpp softhsm2_dump_db_LDADD = @SQLITE3_LIBS@ @YIELD_LIB@ -EXTRA_DIST = $(srcdir)/*.h \ +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h \ softhsm2-dump-db.1 diff --git a/src/bin/keyconv/CMakeLists.txt b/src/bin/keyconv/CMakeLists.txt new file mode 100644 index 000000000..578f657a2 --- /dev/null +++ b/src/bin/keyconv/CMakeLists.txt @@ -0,0 +1,31 @@ +project(softhsm2-keyconv) + +set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/../../lib/crypto + ${CRYPTO_INCLUDES} + ) + +set(SOURCES softhsm2-keyconv.cpp + base64.c + ) + +if(WITH_OPENSSL) + list(APPEND SOURCES softhsm2-keyconv-ossl.cpp + ${PROJECT_SOURCE_DIR}/../../lib/crypto/OSSLComp.cpp + ) +endif(WITH_OPENSSL) + +if(WITH_BOTAN) + list(APPEND SOURCES softhsm2-keyconv-botan.cpp) +endif(WITH_BOTAN) + +include_directories(${INCLUDE_DIRS}) +add_executable(${PROJECT_NAME} ${SOURCES}) +target_link_libraries(${PROJECT_NAME} ${CRYPTO_LIBS}) + +install(TARGETS ${PROJECT_NAME} + DESTINATION ${CMAKE_INSTALL_BINDIR} + ) + +install(FILES ${PROJECT_NAME}.1 + DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 + ) diff --git a/src/bin/keyconv/Makefile.am b/src/bin/keyconv/Makefile.am index b4268c242..556501775 100644 --- a/src/bin/keyconv/Makefile.am +++ b/src/bin/keyconv/Makefile.am @@ -22,5 +22,6 @@ if WITH_BOTAN softhsm2_keyconv_SOURCES += softhsm2-keyconv-botan.cpp endif -EXTRA_DIST = $(srcdir)/*.h \ +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h \ $(srcdir)/*.cpp diff --git a/src/bin/migrate/CMakeLists.txt b/src/bin/migrate/CMakeLists.txt new file mode 100644 index 000000000..671ad62ed --- /dev/null +++ b/src/bin/migrate/CMakeLists.txt @@ -0,0 +1,26 @@ +project(softhsm2-migrate) + +if(BUILD_MIGRATE) + set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/../../lib/pkcs11 + ${PROJECT_SOURCE_DIR}/../common + ${SQLITE3_INCLUDES} + ) + + set(SOURCES softhsm2-migrate.cpp + ${PROJECT_SOURCE_DIR}/../common/findslot.cpp + ${PROJECT_SOURCE_DIR}/../common/getpw.cpp + ${PROJECT_SOURCE_DIR}/../common/library.cpp + ) + + include_directories(${INCLUDE_DIRS}) + add_executable(${PROJECT_NAME} ${SOURCES}) + target_link_libraries(${PROJECT_NAME} ${SQLITE3_LIBS} ${YIELD_LIB} ${CMAKE_DL_LIBS}) + + install(TARGETS ${PROJECT_NAME} + DESTINATION ${CMAKE_INSTALL_BINDIR} + ) + + install(FILES ${PROJECT_NAME}.1 + DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 + ) +endif(BUILD_MIGRATE) diff --git a/src/bin/migrate/Makefile.am b/src/bin/migrate/Makefile.am index 020c6a71e..d9037647c 100644 --- a/src/bin/migrate/Makefile.am +++ b/src/bin/migrate/Makefile.am @@ -17,4 +17,5 @@ softhsm2_migrate_SOURCES = softhsm2-migrate.cpp \ softhsm2_migrate_LDADD = @SQLITE3_LIBS@ \ @YIELD_LIB@ -EXTRA_DIST = $(srcdir)/*.h +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h diff --git a/src/bin/util/CMakeLists.txt b/src/bin/util/CMakeLists.txt new file mode 100644 index 000000000..c2171546b --- /dev/null +++ b/src/bin/util/CMakeLists.txt @@ -0,0 +1,39 @@ +project(softhsm2-util) + +set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/../common + ${PROJECT_SOURCE_DIR}/../../lib/common + ${PROJECT_SOURCE_DIR}/../../lib/crypto + ${PROJECT_SOURCE_DIR}/../../lib/data_mgr + ${PROJECT_SOURCE_DIR}/../../lib/object_store + ${PROJECT_SOURCE_DIR}/../../lib/pkcs11 + ${CRYPTO_INCLUDES} + ${SQLITE3_INCLUDES} + ) + +set(SOURCES softhsm2-util.cpp + ${PROJECT_SOURCE_DIR}/../common/findslot.cpp + ${PROJECT_SOURCE_DIR}/../common/getpw.cpp + ${PROJECT_SOURCE_DIR}/../common/library.cpp + ) + +if(WITH_OPENSSL) + list(APPEND SOURCES softhsm2-util-ossl.cpp + ${PROJECT_SOURCE_DIR}/../../lib/crypto/OSSLComp.cpp + ) +endif(WITH_OPENSSL) + +if(WITH_BOTAN) + list(APPEND SOURCES softhsm2-util-botan.cpp) +endif(WITH_BOTAN) + +include_directories(${INCLUDE_DIRS}) +add_executable(${PROJECT_NAME} ${SOURCES}) +target_link_libraries(${PROJECT_NAME} softhsm2-static ${CRYPTO_LIBS} ${SQLITE3_LIBS} ${CMAKE_DL_LIBS}) + +install(TARGETS ${PROJECT_NAME} + DESTINATION ${CMAKE_INSTALL_BINDIR} + ) + +install(FILES ${PROJECT_NAME}.1 + DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 + ) diff --git a/src/bin/util/Makefile.am b/src/bin/util/Makefile.am index a552e1415..788ea874f 100644 --- a/src/bin/util/Makefile.am +++ b/src/bin/util/Makefile.am @@ -36,5 +36,6 @@ if WITH_BOTAN softhsm2_util_SOURCES += softhsm2-util-botan.cpp endif -EXTRA_DIST = $(srcdir)/*.h \ +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h \ $(srcdir)/*.cpp diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt new file mode 100644 index 000000000..fb03c2ab2 --- /dev/null +++ b/src/lib/CMakeLists.txt @@ -0,0 +1,83 @@ +############################################################################### +# Dependencies +############################################################################### +add_subdirectory(common) +add_subdirectory(crypto) +add_subdirectory(data_mgr) +add_subdirectory(handle_mgr) +add_subdirectory(object_store) +add_subdirectory(session_mgr) +add_subdirectory(slot_mgr) + +############################################################################### +# SoftHSMv2 Config +############################################################################### +set(INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/common + ${CMAKE_CURRENT_SOURCE_DIR}/crypto + ${CMAKE_CURRENT_SOURCE_DIR}/data_mgr + ${CMAKE_CURRENT_SOURCE_DIR}/handle_mgr + ${CMAKE_CURRENT_SOURCE_DIR}/object_store + ${CMAKE_CURRENT_SOURCE_DIR}/pkcs11 + ${CMAKE_CURRENT_SOURCE_DIR}/session_mgr + ${CMAKE_CURRENT_SOURCE_DIR}/slot_mgr + ${CRYPTO_INCLUDES} + ) + +include_directories(${INCLUDE_DIRS}) + +set(SOURCES access.cpp + main.cpp + P11Attributes.cpp + P11Objects.cpp + SoftHSM.cpp + ) + +set(DEPENDENCIES softhsm_common-obj + softhsm_crypto-obj + softhsm_datamgr-obj + softhsm_handlemgr-obj + softhsm_objectstore-obj + softhsm_sessionmgr-obj + softhsm_slotmgr-obj + ) + +set(OBJECT_FILES $ + $ + $ + $ + $ + $ + $ + ) + + +############################################################################### +# Static Library Config +############################################################################### +add_library(${PROJECT_NAME}-static STATIC ${SOURCES} ${OBJECT_FILES}) +add_dependencies(${PROJECT_NAME}-static ${DEPENDENCIES}) +set_target_properties(${PROJECT_NAME}-static + PROPERTIES OUTPUT_NAME ${PROJECT_NAME} + ) +generate_export_header(${PROJECT_NAME}-static) + +############################################################################### +# Shared Library Config +############################################################################### +add_library(${PROJECT_NAME} SHARED ${SOURCES} ${OBJECT_FILES}) +add_dependencies(${PROJECT_NAME} ${DEPENDENCIES}) +generate_export_header(${PROJECT_NAME}) + +############################################################################### +# Tests +############################################################################### +if(BUILD_TESTS) + add_subdirectory(test) +endif(BUILD_TESTS) + +############################################################################### +# Install +############################################################################### +install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}-static + DESTINATION ${CMAKE_INSTALL_LIBDIR}/softhsm + ) diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index f3f5bb489..89b1a8d2d 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -45,7 +45,8 @@ SUBDIRS = common \ handle_mgr \ test -EXTRA_DIST = $(srcdir)/*.h \ +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h \ $(srcdir)/pkcs11/*.h \ $(srcdir)/win32/*.cc \ $(srcdir)/win32/*.cpp \ diff --git a/src/lib/common/CMakeLists.txt b/src/lib/common/CMakeLists.txt new file mode 100644 index 000000000..4dc1294a6 --- /dev/null +++ b/src/lib/common/CMakeLists.txt @@ -0,0 +1,47 @@ +project(softhsm_common) + +set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/../crypto + ${PROJECT_SOURCE_DIR}/../data_mgr + ${PROJECT_SOURCE_DIR}/../pkcs11 + ) + +set(SOURCES Configuration.cpp + fatal.cpp + log.cpp + MutexFactory.cpp + osmutex.cpp + SimpleConfigLoader.cpp + ) + +include_directories(${INCLUDE_DIRS}) + +add_library(${PROJECT_NAME}-obj OBJECT ${SOURCES}) +add_library(${PROJECT_NAME} STATIC $) + +set(softhsmtokendir ${DEFAULT_TOKENDIR}) +set(default_softhsm2_conf ${CMAKE_INSTALL_FULL_SYSCONFDIR}/softhsm2.conf) +configure_file(softhsm2.conf.in ${PROJECT_BINARY_DIR}/etc/softhsm2.conf) +configure_file(softhsm2.conf.in ${PROJECT_BINARY_DIR}/etc/softhsm2.conf.sample) +configure_file(softhsm2.conf.5.in ${PROJECT_BINARY_DIR}/man5/softhsm2.conf.5) + +install(CODE " + if(NOT EXISTS ${CMAKE_INSTALL_SYSCONFDIR}/softhsm2.conf) + file(INSTALL ${PROJECT_BINARY_DIR}/etc/softhsm2.conf + DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}) + endif() + ") + +install(FILES ${PROJECT_BINARY_DIR}/etc/softhsm2.conf.sample + DESTINATION ${CMAKE_INSTALL_SYSCONFDIR} + ) + +install(FILES ${PROJECT_BINARY_DIR}/man5/softhsm2.conf.5 + DESTINATION ${CMAKE_INSTALL_MANDIR}/man5 + ) + +install(DIRECTORY DESTINATION ${CMAKE_INSTALL_LOCALSTATEDIR}/lib/softhsm/tokens) + +install(CODE + "execute_process( + COMMAND chmod 1777 ${CMAKE_INSTALL_LOCALSTATEDIR}/lib/softhsm/tokens)") diff --git a/src/lib/common/Makefile.am b/src/lib/common/Makefile.am index bf18b1a00..29f5c7aa3 100644 --- a/src/lib/common/Makefile.am +++ b/src/lib/common/Makefile.am @@ -15,7 +15,8 @@ libsofthsm_common_la_SOURCES = Configuration.cpp \ man_MANS = softhsm2.conf.5 -EXTRA_DIST = $(srcdir)/*.h \ +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h \ $(srcdir)/softhsm2.conf.5.in install-data-hook: diff --git a/src/lib/crypto/CMakeLists.txt b/src/lib/crypto/CMakeLists.txt new file mode 100644 index 000000000..e175541d4 --- /dev/null +++ b/src/lib/crypto/CMakeLists.txt @@ -0,0 +1,143 @@ +project(softhsm_crypto) + +set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/../common + ${PROJECT_SOURCE_DIR}/../data_mgr + ${PROJECT_SOURCE_DIR}/../pkcs11 + ${CRYPTO_INCLUDES} + ) + +set(SOURCES AESKey.cpp + AsymmetricAlgorithm.cpp + AsymmetricKeyPair.cpp + CryptoFactory.cpp + DerUtil.cpp + DESKey.cpp + DHParameters.cpp + DHPrivateKey.cpp + DHPublicKey.cpp + DSAParameters.cpp + DSAPrivateKey.cpp + DSAPublicKey.cpp + ECParameters.cpp + ECPrivateKey.cpp + ECPublicKey.cpp + EDPrivateKey.cpp + EDPublicKey.cpp + GOSTPrivateKey.cpp + GOSTPublicKey.cpp + HashAlgorithm.cpp + MacAlgorithm.cpp + RSAParameters.cpp + RSAPrivateKey.cpp + RSAPublicKey.cpp + SymmetricAlgorithm.cpp + SymmetricKey.cpp + ) + +if(WITH_OPENSSL) + list(APPEND SOURCES OSSLAES.cpp + OSSLCMAC.cpp + OSSLComp.cpp + OSSLCryptoFactory.cpp + OSSLDES.cpp + OSSLDH.cpp + OSSLDHKeyPair.cpp + OSSLDHPrivateKey.cpp + OSSLDHPublicKey.cpp + OSSLDSA.cpp + OSSLDSAKeyPair.cpp + OSSLDSAPrivateKey.cpp + OSSLDSAPublicKey.cpp + OSSLECDH.cpp + OSSLECDSA.cpp + OSSLECKeyPair.cpp + OSSLECPrivateKey.cpp + OSSLECPublicKey.cpp + OSSLEDDSA.cpp + OSSLEDKeyPair.cpp + OSSLEDPrivateKey.cpp + OSSLEDPublicKey.cpp + OSSLEVPCMacAlgorithm.cpp + OSSLEVPHashAlgorithm.cpp + OSSLEVPMacAlgorithm.cpp + OSSLEVPSymmetricAlgorithm.cpp + OSSLGOST.cpp + OSSLGOSTKeyPair.cpp + OSSLGOSTPrivateKey.cpp + OSSLGOSTPublicKey.cpp + OSSLGOSTR3411.cpp + OSSLHMAC.cpp + OSSLMD5.cpp + OSSLRNG.cpp + OSSLRSA.cpp + OSSLRSAKeyPair.cpp + OSSLRSAPrivateKey.cpp + OSSLRSAPublicKey.cpp + OSSLSHA1.cpp + OSSLSHA224.cpp + OSSLSHA256.cpp + OSSLSHA384.cpp + OSSLSHA512.cpp + OSSLUtil.cpp + ) +endif(WITH_OPENSSL) + +if(WITH_BOTAN) + list(APPEND SOURCES BotanAES.cpp + BotanCryptoFactory.cpp + BotanDES.cpp + BotanDH.cpp + BotanDHKeyPair.cpp + BotanDHPrivateKey.cpp + BotanDHPublicKey.cpp + BotanDSA.cpp + BotanDSAKeyPair.cpp + BotanDSAPrivateKey.cpp + BotanDSAPublicKey.cpp + Botan_ecb.cpp + BotanECDH.cpp + BotanECDHKeyPair.cpp + BotanECDHPrivateKey.cpp + BotanECDHPublicKey.cpp + BotanECDSA.cpp + BotanECDSAKeyPair.cpp + BotanECDSAPrivateKey.cpp + BotanECDSAPublicKey.cpp + BotanEDDSA.cpp + BotanEDKeyPair.cpp + BotanEDPrivateKey.cpp + BotanEDPublicKey.cpp + BotanGOST.cpp + BotanGOSTKeyPair.cpp + BotanGOSTPrivateKey.cpp + BotanGOSTPublicKey.cpp + BotanGOSTR3411.cpp + BotanHashAlgorithm.cpp + BotanMacAlgorithm.cpp + BotanMAC.cpp + BotanMD5.cpp + BotanRNG.cpp + BotanRSA.cpp + BotanRSAKeyPair.cpp + BotanRSAPrivateKey.cpp + BotanRSAPublicKey.cpp + BotanSHA1.cpp + BotanSHA224.cpp + BotanSHA256.cpp + BotanSHA384.cpp + BotanSHA512.cpp + BotanSymmetricAlgorithm.cpp + BotanUtil.cpp + ) +endif(WITH_BOTAN) + +include_directories(${INCLUDE_DIRS}) + +add_library(${PROJECT_NAME}-obj OBJECT ${SOURCES}) +add_library(${PROJECT_NAME} STATIC $) +target_link_libraries(${PROJECT_NAME} ${CRYPTO_LIBS}) + +if(BUILD_TESTS) + add_subdirectory(test) +endif(BUILD_TESTS) diff --git a/src/lib/crypto/Makefile.am b/src/lib/crypto/Makefile.am index 634a6c65d..e23848fa2 100644 --- a/src/lib/crypto/Makefile.am +++ b/src/lib/crypto/Makefile.am @@ -37,7 +37,9 @@ libsofthsm_crypto_la_LIBADD = @CRYPTO_LIBS@ SUBDIRS = test -EXTRA_DIST = $(srcdir)/*.h $(srcdir)/*.cpp +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h \ + $(srcdir)/*.cpp # Compile with support of OpenSSL if WITH_OPENSSL diff --git a/src/lib/crypto/test/CMakeLists.txt b/src/lib/crypto/test/CMakeLists.txt new file mode 100644 index 000000000..d91ba9a11 --- /dev/null +++ b/src/lib/crypto/test/CMakeLists.txt @@ -0,0 +1,39 @@ +project(cryptotest) + +set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/.. + ${PROJECT_SOURCE_DIR}/../.. + ${PROJECT_SOURCE_DIR}/../../common + ${PROJECT_SOURCE_DIR}/../../data_mgr + ${PROJECT_SOURCE_DIR}/../../object_store + ${PROJECT_SOURCE_DIR}/../../pkcs11 + ${PROJECT_SOURCE_DIR}/../../session_mgr + ${PROJECT_SOURCE_DIR}/../../slot_mgr + ${CPPUNIT_INCLUDES} + ${CRYPTO_INCLUDES} + ) + +set(SOURCES cryptotest.cpp + AESTests.cpp + DESTests.cpp + DHTests.cpp + DSATests.cpp + ECDHTests.cpp + ECDSATests.cpp + EDDSATests.cpp + GOSTTests.cpp + HashTests.cpp + MacTests.cpp + RNGTests.cpp + RSATests.cpp + chisq.c + ent.c + iso8859.c + randtest.c + ) + +include_directories(${INCLUDE_DIRS}) + +add_executable(${PROJECT_NAME} ${SOURCES}) +target_link_libraries(${PROJECT_NAME} softhsm2-static ${CRYPTO_LIBS} ${CPPUNIT_LIBS}) + +add_test(${PROJECT_NAME} ${PROJECT_NAME}) diff --git a/src/lib/crypto/test/Makefile.am b/src/lib/crypto/test/Makefile.am index 48be5af01..4065ef9ce 100644 --- a/src/lib/crypto/test/Makefile.am +++ b/src/lib/crypto/test/Makefile.am @@ -37,4 +37,5 @@ cryptotest_LDFLAGS = @CRYPTO_LIBS@ @CPPUNIT_LIBS@ -no-install TESTS = cryptotest -EXTRA_DIST = $(srcdir)/*.h +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h diff --git a/src/lib/data_mgr/CMakeLists.txt b/src/lib/data_mgr/CMakeLists.txt new file mode 100644 index 000000000..802fe5159 --- /dev/null +++ b/src/lib/data_mgr/CMakeLists.txt @@ -0,0 +1,23 @@ +project(softhsm_datamgr) + +set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/../crypto + ${PROJECT_SOURCE_DIR}/../common + ${PROJECT_SOURCE_DIR}/../pkcs11 + ) + +set(SOURCES ByteString.cpp + RFC4880.cpp + salloc.cpp + SecureDataManager.cpp + SecureMemoryRegistry.cpp + ) + +include_directories(${INCLUDE_DIRS}) + +add_library(${PROJECT_NAME}-obj OBJECT ${SOURCES}) +add_library(${PROJECT_NAME} STATIC $) + +if(BUILD_TESTS) + add_subdirectory(test) +endif(BUILD_TESTS) diff --git a/src/lib/data_mgr/Makefile.am b/src/lib/data_mgr/Makefile.am index 85aa4d755..0c21bdb9d 100644 --- a/src/lib/data_mgr/Makefile.am +++ b/src/lib/data_mgr/Makefile.am @@ -14,4 +14,5 @@ libsofthsm_datamgr_la_SOURCES = ByteString.cpp \ SUBDIRS = test -EXTRA_DIST = $(srcdir)/*.h +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h diff --git a/src/lib/data_mgr/test/CMakeLists.txt b/src/lib/data_mgr/test/CMakeLists.txt new file mode 100644 index 000000000..e1b14259b --- /dev/null +++ b/src/lib/data_mgr/test/CMakeLists.txt @@ -0,0 +1,26 @@ +project(datamgrtest) + +set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/.. + ${PROJECT_SOURCE_DIR}/../.. + ${PROJECT_SOURCE_DIR}/../../common + ${PROJECT_SOURCE_DIR}/../../crypto + ${PROJECT_SOURCE_DIR}/../../object_store + ${PROJECT_SOURCE_DIR}/../../pkcs11 + ${PROJECT_SOURCE_DIR}/../../session_mgr + ${PROJECT_SOURCE_DIR}/../../slot_mgr + ${CPPUNIT_INCLUDES} + ${CRYPTO_INCLUDES} + ) + +set(SOURCES datamgrtest.cpp + ByteStringTests.cpp + RFC4880Tests.cpp + SecureDataMgrTests.cpp + ) + +include_directories(${INCLUDE_DIRS}) + +add_executable(${PROJECT_NAME} ${SOURCES}) +target_link_libraries(${PROJECT_NAME} softhsm2-static ${CRYPTO_LIBS} ${CPPUNIT_LIBS}) + +add_test(${PROJECT_NAME} ${PROJECT_NAME}) diff --git a/src/lib/data_mgr/test/Makefile.am b/src/lib/data_mgr/test/Makefile.am index e1ebcdd24..59039cbd8 100644 --- a/src/lib/data_mgr/test/Makefile.am +++ b/src/lib/data_mgr/test/Makefile.am @@ -18,10 +18,11 @@ datamgrtest_SOURCES = datamgrtest.cpp \ RFC4880Tests.cpp \ SecureDataMgrTests.cpp -datamgrtest_LDADD = ../../libsofthsm_convarch.la +datamgrtest_LDADD = ../../libsofthsm_convarch.la datamgrtest_LDFLAGS = @CRYPTO_LIBS@ @CPPUNIT_LIBS@ -no-install TESTS = datamgrtest -EXTRA_DIST = $(srcdir)/*.h +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h diff --git a/src/lib/handle_mgr/CMakeLists.txt b/src/lib/handle_mgr/CMakeLists.txt new file mode 100644 index 000000000..a89c5d629 --- /dev/null +++ b/src/lib/handle_mgr/CMakeLists.txt @@ -0,0 +1,23 @@ +project(softhsm_handlemgr) + +set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/../common + ${PROJECT_SOURCE_DIR}/../crypto + ${PROJECT_SOURCE_DIR}/../data_mgr + ${PROJECT_SOURCE_DIR}/../object_store + ${PROJECT_SOURCE_DIR}/../pkcs11 + ${PROJECT_SOURCE_DIR}/../slot_mgr + ) + +set(SOURCES HandleManager.cpp + Handle.cpp + ) + +include_directories(${INCLUDE_DIRS}) + +add_library(${PROJECT_NAME}-obj OBJECT ${SOURCES}) +add_library(${PROJECT_NAME} STATIC $) + +if(BUILD_TESTS) + add_subdirectory(test) +endif(BUILD_TESTS) diff --git a/src/lib/handle_mgr/Makefile.am b/src/lib/handle_mgr/Makefile.am index 108f74d29..b588009fa 100644 --- a/src/lib/handle_mgr/Makefile.am +++ b/src/lib/handle_mgr/Makefile.am @@ -14,4 +14,5 @@ libsofthsm_handlemgr_la_SOURCES = HandleManager.cpp \ SUBDIRS = test -EXTRA_DIST = $(srcdir)/*.h +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h diff --git a/src/lib/handle_mgr/test/CMakeLists.txt b/src/lib/handle_mgr/test/CMakeLists.txt new file mode 100644 index 000000000..8faf95992 --- /dev/null +++ b/src/lib/handle_mgr/test/CMakeLists.txt @@ -0,0 +1,24 @@ +project(handlemgrtest) + +set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/.. + ${PROJECT_SOURCE_DIR}/../.. + ${PROJECT_SOURCE_DIR}/../../common + ${PROJECT_SOURCE_DIR}/../../crypto + ${PROJECT_SOURCE_DIR}/../../data_mgr + ${PROJECT_SOURCE_DIR}/../../object_store + ${PROJECT_SOURCE_DIR}/../../pkcs11 + ${PROJECT_SOURCE_DIR}/../../session_mgr + ${PROJECT_SOURCE_DIR}/../../slot_mgr + ${CPPUNIT_INCLUDES} + ) + +set(SOURCES handlemgrtest.cpp + HandleManagerTests.cpp + ) + +include_directories(${INCLUDE_DIRS}) + +add_executable(${PROJECT_NAME} ${SOURCES}) +target_link_libraries(${PROJECT_NAME} softhsm2-static ${CRYPTO_LIBS} ${CPPUNIT_LIBS}) + +add_test(${PROJECT_NAME} ${PROJECT_NAME}) diff --git a/src/lib/handle_mgr/test/Makefile.am b/src/lib/handle_mgr/test/Makefile.am index 8d110b090..536a7b5a9 100644 --- a/src/lib/handle_mgr/test/Makefile.am +++ b/src/lib/handle_mgr/test/Makefile.am @@ -16,11 +16,12 @@ check_PROGRAMS = handlemgrtest handlemgrtest_SOURCES = handlemgrtest.cpp \ HandleManagerTests.cpp -handlemgrtest_LDADD = ../../libsofthsm_convarch.la +handlemgrtest_LDADD = ../../libsofthsm_convarch.la handlemgrtest_LDFLAGS = @CRYPTO_LIBS@ @CPPUNIT_LIBS@ -no-install TESTS = handlemgrtest -EXTRA_DIST = $(srcdir)/*.h +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h diff --git a/src/lib/object_store/CMakeLists.txt b/src/lib/object_store/CMakeLists.txt new file mode 100644 index 000000000..dac6813ab --- /dev/null +++ b/src/lib/object_store/CMakeLists.txt @@ -0,0 +1,41 @@ +project(softhsm_objectstore) + +set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/../common + ${PROJECT_SOURCE_DIR}/../crypto + ${PROJECT_SOURCE_DIR}/../data_mgr + ${PROJECT_SOURCE_DIR}/../pkcs11 + ${SQLITE3_INCLUDES} + ) + +set(SOURCES Directory.cpp + File.cpp + FindOperation.cpp + Generation.cpp + ObjectFile.cpp + ObjectStore.cpp + ObjectStoreToken.cpp + OSAttribute.cpp + OSToken.cpp + SessionObject.cpp + SessionObjectStore.cpp + UUID.cpp + ) + +if(WITH_OBJECTSTORE_BACKEND_DB) + list(APPEND SOURCES DB.cpp + DBObject.cpp + DBToken.cpp + ) +endif(WITH_OBJECTSTORE_BACKEND_DB) + + +include_directories(${INCLUDE_DIRS}) + +add_library(${PROJECT_NAME}-obj OBJECT ${SOURCES}) +add_library(${PROJECT_NAME} STATIC $) +target_link_libraries(${PROJECT_NAME} ${SQLITE3_LIBS}) + +if(BUILD_TESTS) + add_subdirectory(test) +endif(BUILD_TESTS) diff --git a/src/lib/object_store/Makefile.am b/src/lib/object_store/Makefile.am index d3e89d30b..6af0d2cfb 100644 --- a/src/lib/object_store/Makefile.am +++ b/src/lib/object_store/Makefile.am @@ -31,4 +31,5 @@ libsofthsm_objectstore_la_LDFLAGS = @SQLITE3_LIBS@ SUBDIRS = test -EXTRA_DIST = $(srcdir)/*.h +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h diff --git a/src/lib/object_store/test/CMakeLists.txt b/src/lib/object_store/test/CMakeLists.txt new file mode 100644 index 000000000..7ceb38ca9 --- /dev/null +++ b/src/lib/object_store/test/CMakeLists.txt @@ -0,0 +1,39 @@ +project(objstoretest) + +set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/.. + ${PROJECT_SOURCE_DIR}/../.. + ${PROJECT_SOURCE_DIR}/../../common + ${PROJECT_SOURCE_DIR}/../../crypto + ${PROJECT_SOURCE_DIR}/../../data_mgr + ${PROJECT_SOURCE_DIR}/../../pkcs11 + ${PROJECT_SOURCE_DIR}/../../session_mgr + ${PROJECT_SOURCE_DIR}/../../slot_mgr + ${CPPUNIT_INCLUDES} + ${CRYPTO_INCLUDES} + ) + +set(SOURCES objstoretest.cpp + DirectoryTests.cpp + UUIDTests.cpp + FileTests.cpp + ObjectFileTests.cpp + OSTokenTests.cpp + ObjectStoreTests.cpp + SessionObjectTests.cpp + SessionObjectStoreTests.cpp + ) + +if(WITH_OBJECTSTORE_BACKEND_DB) + list(APPEND SOURCES DBTests.cpp + DBObjectTests.cpp + DBTokenTests.cpp + DBObjectStoreTests.cpp + ) +endif(WITH_OBJECTSTORE_BACKEND_DB) + +include_directories(${INCLUDE_DIRS}) + +add_executable(${PROJECT_NAME} ${SOURCES}) +target_link_libraries(${PROJECT_NAME} softhsm2-static ${CRYPTO_LIBS} ${CPPUNIT_LIBS} ${SQLITE3_LIBS}) + +add_test(${PROJECT_NAME} ${PROJECT_NAME}) diff --git a/src/lib/object_store/test/Makefile.am b/src/lib/object_store/test/Makefile.am index 71de7dd35..0ba05c136 100644 --- a/src/lib/object_store/test/Makefile.am +++ b/src/lib/object_store/test/Makefile.am @@ -30,10 +30,11 @@ objstoretest_SOURCES += DBTests.cpp \ DBObjectStoreTests.cpp endif -objstoretest_LDADD = ../../libsofthsm_convarch.la +objstoretest_LDADD = ../../libsofthsm_convarch.la objstoretest_LDFLAGS = @CRYPTO_LIBS@ @CPPUNIT_LIBS@ -no-install -pthread TESTS = objstoretest -EXTRA_DIST = $(srcdir)/*.h +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h diff --git a/src/lib/session_mgr/CMakeLists.txt b/src/lib/session_mgr/CMakeLists.txt new file mode 100644 index 000000000..58a72df17 --- /dev/null +++ b/src/lib/session_mgr/CMakeLists.txt @@ -0,0 +1,23 @@ +project(softhsm_sessionmgr) + +set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/../common + ${PROJECT_SOURCE_DIR}/../crypto + ${PROJECT_SOURCE_DIR}/../data_mgr + ${PROJECT_SOURCE_DIR}/../object_store + ${PROJECT_SOURCE_DIR}/../pkcs11 + ${PROJECT_SOURCE_DIR}/../slot_mgr + ) + +set(SOURCES SessionManager.cpp + Session.cpp + ) + +include_directories(${INCLUDE_DIRS}) + +add_library(${PROJECT_NAME}-obj OBJECT ${SOURCES}) +add_library(${PROJECT_NAME} STATIC $) + +if(BUILD_TESTS) + add_subdirectory(test) +endif(BUILD_TESTS) diff --git a/src/lib/session_mgr/Makefile.am b/src/lib/session_mgr/Makefile.am index 5186d333b..f696b14c1 100644 --- a/src/lib/session_mgr/Makefile.am +++ b/src/lib/session_mgr/Makefile.am @@ -14,4 +14,5 @@ libsofthsm_sessionmgr_la_SOURCES = SessionManager.cpp \ SUBDIRS = test -EXTRA_DIST = $(srcdir)/*.h +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h diff --git a/src/lib/session_mgr/test/CMakeLists.txt b/src/lib/session_mgr/test/CMakeLists.txt new file mode 100644 index 000000000..040fb14b5 --- /dev/null +++ b/src/lib/session_mgr/test/CMakeLists.txt @@ -0,0 +1,24 @@ +project(sessionmgrtest) + +set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/.. + ${PROJECT_SOURCE_DIR}/../.. + ${PROJECT_SOURCE_DIR}/../../common + ${PROJECT_SOURCE_DIR}/../../crypto + ${PROJECT_SOURCE_DIR}/../../data_mgr + ${PROJECT_SOURCE_DIR}/../../object_store + ${PROJECT_SOURCE_DIR}/../../pkcs11 + ${PROJECT_SOURCE_DIR}/../../slot_mgr + ${CPPUNIT_INCLUDES} + ${CRYPTO_INCLUDES} + ) + +set(SOURCES sessionmgrtest.cpp + SessionManagerTests.cpp + ) + +include_directories(${INCLUDE_DIRS}) + +add_executable(${PROJECT_NAME} ${SOURCES}) +target_link_libraries(${PROJECT_NAME} softhsm2-static ${CRYPTO_LIBS} ${CPPUNIT_LIBS} ${SQLITE3_LIBS}) + +add_test(${PROJECT_NAME} ${PROJECT_NAME}) diff --git a/src/lib/session_mgr/test/Makefile.am b/src/lib/session_mgr/test/Makefile.am index 6395038ed..36233b981 100644 --- a/src/lib/session_mgr/test/Makefile.am +++ b/src/lib/session_mgr/test/Makefile.am @@ -17,10 +17,11 @@ check_PROGRAMS = sessionmgrtest sessionmgrtest_SOURCES = sessionmgrtest.cpp \ SessionManagerTests.cpp -sessionmgrtest_LDADD = ../../libsofthsm_convarch.la +sessionmgrtest_LDADD = ../../libsofthsm_convarch.la sessionmgrtest_LDFLAGS = @CRYPTO_LIBS@ @CPPUNIT_LIBS@ -no-install -pthread TESTS = sessionmgrtest -EXTRA_DIST = $(srcdir)/*.h +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h diff --git a/src/lib/slot_mgr/CMakeLists.txt b/src/lib/slot_mgr/CMakeLists.txt new file mode 100644 index 000000000..f8d4049ac --- /dev/null +++ b/src/lib/slot_mgr/CMakeLists.txt @@ -0,0 +1,24 @@ +project(softhsm_slotmgr) + +set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/../common + ${PROJECT_SOURCE_DIR}/../crypto + ${PROJECT_SOURCE_DIR}/../data_mgr + ${PROJECT_SOURCE_DIR}/../object_store + ${PROJECT_SOURCE_DIR}/../pkcs11 + ${PROJECT_SOURCE_DIR}/../session_mgr + ) + +set(SOURCES SlotManager.cpp + Slot.cpp + Token.cpp + ) + +include_directories(${INCLUDE_DIRS}) + +add_library(${PROJECT_NAME}-obj OBJECT ${SOURCES}) +add_library(${PROJECT_NAME} STATIC $) + +if(BUILD_TESTS) + add_subdirectory(test) +endif(BUILD_TESTS) diff --git a/src/lib/slot_mgr/Makefile.am b/src/lib/slot_mgr/Makefile.am index 1e8cf33bf..db407faae 100644 --- a/src/lib/slot_mgr/Makefile.am +++ b/src/lib/slot_mgr/Makefile.am @@ -15,4 +15,5 @@ libsofthsm_slotmgr_la_SOURCES = SlotManager.cpp \ SUBDIRS = test -EXTRA_DIST = $(srcdir)/*.h +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h diff --git a/src/lib/slot_mgr/test/CMakeLists.txt b/src/lib/slot_mgr/test/CMakeLists.txt new file mode 100644 index 000000000..2284c4ddc --- /dev/null +++ b/src/lib/slot_mgr/test/CMakeLists.txt @@ -0,0 +1,24 @@ +project(slotmgrtest) + +set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/.. + ${PROJECT_SOURCE_DIR}/../.. + ${PROJECT_SOURCE_DIR}/../../common + ${PROJECT_SOURCE_DIR}/../../crypto + ${PROJECT_SOURCE_DIR}/../../data_mgr + ${PROJECT_SOURCE_DIR}/../../object_store + ${PROJECT_SOURCE_DIR}/../../pkcs11 + ${PROJECT_SOURCE_DIR}/../../session_mgr + ${CPPUNIT_INCLUDES} + ${CRYPTO_INCLUDES} + ) + +set(SOURCES slotmgrtest.cpp + SlotManagerTests.cpp + ) + +include_directories(${INCLUDE_DIRS}) + +add_executable(${PROJECT_NAME} ${SOURCES}) +target_link_libraries(${PROJECT_NAME} softhsm2-static ${CRYPTO_LIBS} ${CPPUNIT_LIBS} ${SQLITE3_LIBS}) + +add_test(${PROJECT_NAME} ${PROJECT_NAME}) diff --git a/src/lib/slot_mgr/test/Makefile.am b/src/lib/slot_mgr/test/Makefile.am index 8e2d161dd..3793cf9aa 100644 --- a/src/lib/slot_mgr/test/Makefile.am +++ b/src/lib/slot_mgr/test/Makefile.am @@ -16,10 +16,11 @@ check_PROGRAMS = slotmgrtest slotmgrtest_SOURCES = slotmgrtest.cpp \ SlotManagerTests.cpp -slotmgrtest_LDADD = ../../libsofthsm_convarch.la +slotmgrtest_LDADD = ../../libsofthsm_convarch.la slotmgrtest_LDFLAGS = @CRYPTO_LIBS@ @CPPUNIT_LIBS@ -no-install -pthread TESTS = slotmgrtest -EXTRA_DIST = $(srcdir)/*.h +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h diff --git a/src/lib/test/CMakeLists.txt b/src/lib/test/CMakeLists.txt new file mode 100644 index 000000000..8d811a1da --- /dev/null +++ b/src/lib/test/CMakeLists.txt @@ -0,0 +1,43 @@ +project(p11test) + +set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/.. + ${PROJECT_SOURCE_DIR}/../common + ${PROJECT_SOURCE_DIR}/../pkcs11 + ${CPPUNIT_INCLUDES} + ) + +set(SOURCES p11test.cpp + SymmetricAlgorithmTests.cpp + DigestTests.cpp + InitTests.cpp + InfoTests.cpp + RandomTests.cpp + SessionTests.cpp + TokenTests.cpp + UserTests.cpp + ObjectTests.cpp + DeriveTests.cpp + SignVerifyTests.cpp + AsymEncryptDecryptTests.cpp + AsymWrapUnwrapTests.cpp + TestsBase.cpp + TestsNoPINInitBase.cpp + ../common/log.cpp + ../common/osmutex.cpp + ) + +include_directories(${INCLUDE_DIRS}) + +add_executable(${PROJECT_NAME} ${SOURCES}) +target_link_libraries(${PROJECT_NAME} softhsm2-static ${CRYPTO_LIBS} ${CPPUNIT_LIBS} ${SQLITE3_LIBS}) +set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS -pthread) + +add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME} + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + ) + +set(builddir ${PROJECT_BINARY_DIR}) +configure_file(softhsm2.conf.in softhsm2.conf) +configure_file(softhsm2-alt.conf.in softhsm2-alt.conf) +configure_file(tokens/dummy.in tokens/dummy) diff --git a/src/lib/test/Makefile.am b/src/lib/test/Makefile.am index 434587846..77d4df58b 100644 --- a/src/lib/test/Makefile.am +++ b/src/lib/test/Makefile.am @@ -28,13 +28,14 @@ p11test_SOURCES = p11test.cpp \ ../common/log.cpp \ ../common/osmutex.cpp -p11test_LDADD = ../libsofthsm2.la +p11test_LDADD = ../libsofthsm2.la p11test_LDFLAGS = @CRYPTO_LIBS@ @CPPUNIT_LIBS@ -no-install -pthread -static TESTS = p11test -EXTRA_DIST = $(srcdir)/*.h \ +EXTRA_DIST = $(srcdir)/CMakeLists.txt \ + $(srcdir)/*.h \ $(srcdir)/softhsm2-alt.conf.win32 \ $(srcdir)/softhsm2.conf.win32 \ $(srcdir)/tokens/dummy.in