Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/libfido2/dist Import libfido2 1.7.0; changes:



details:   https://anonhg.NetBSD.org/src/rev/f5c396d5fbdc
branches:  trunk
changeset: 1021774:f5c396d5fbdc
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jun 17 00:38:06 2021 +0000

description:
Import libfido2 1.7.0; changes:

Version 1.7.0 (2021-03-29)
- New dependency on zlib.
- Fixed musl build; gh#259.
- hid_win: detect devices with vendor or product IDs > 0x7fff; gh#264.
- Support for FIDO 2.1 authenticator configuration.
- Support for FIDO 2.1 UV token permissions.
- Support for FIDO 2.1 "credBlobs" and "largeBlobs" extensions.
- New API calls:
    fido_assert_blob_len;
    fido_assert_blob_ptr;
    fido_assert_largeblob_key_len;
    fido_assert_largeblob_key_ptr;
    fido_assert_set_hmac_secret;
    fido_cbor_info_maxcredbloblen;
    fido_cred_largeblob_key_len;
    fido_cred_largeblob_key_ptr;
    fido_cred_set_blob;
    fido_dev_enable_entattest;
    fido_dev_force_pin_change;
    fido_dev_has_uv;
    fido_dev_largeblob_get;
    fido_dev_largeblob_get_array;
    fido_dev_largeblob_remove;
    fido_dev_largeblob_set;
    fido_dev_largeblob_set_array;
    fido_dev_set_pin_minlen;
    fido_dev_set_sigmask;
    fido_dev_supports_credman;
    fido_dev_supports_permissions;
    fido_dev_supports_uv;
    fido_dev_toggle_always_uv.
- New fido_init flag to disable fido_dev_open's U2F fallback; gh#282.
- Experimental NFC support on Linux; enable with -DNFC_LINUX.

Version 1.6.0 (2020-12-22)
- Fix OpenSSL 1.0 and Cygwin builds.
- hid_linux: fix build on 32-bit systems.
- hid_osx: allow reads from spawned threads.
- Documentation and reliability fixes.
- New API calls:
    fido_cred_authdata_raw_len;
    fido_cred_authdata_raw_ptr;
    fido_cred_sigcount;
    fido_dev_get_uv_retry_count;
    fido_dev_supports_credman.
- Hardened Windows build.
- Native FreeBSD and NetBSD support.
- Use CTAP2 canonical CBOR when combining hmac-secret and credProtect.

diffstat:

 external/bsd/libfido2/dist/CMakeLists.txt                     |   426 +--
 external/bsd/libfido2/dist/LICENSE                            |     2 +-
 external/bsd/libfido2/dist/NEWS                               |    49 +
 external/bsd/libfido2/dist/README.adoc                        |    21 +-
 external/bsd/libfido2/dist/examples/CMakeLists.txt            |    31 +-
 external/bsd/libfido2/dist/examples/README.adoc               |    16 +-
 external/bsd/libfido2/dist/examples/assert.c                  |    32 +-
 external/bsd/libfido2/dist/examples/cred.c                    |    26 +-
 external/bsd/libfido2/dist/examples/info.c                    |     2 +-
 external/bsd/libfido2/dist/examples/manifest.c                |     3 +-
 external/bsd/libfido2/dist/examples/reset.c                   |     6 +-
 external/bsd/libfido2/dist/examples/retries.c                 |     3 +-
 external/bsd/libfido2/dist/examples/select.c                  |     3 +-
 external/bsd/libfido2/dist/examples/setpin.c                  |     4 +-
 external/bsd/libfido2/dist/examples/util.c                    |    15 +-
 external/bsd/libfido2/dist/fuzz/CMakeLists.txt                |    20 +
 external/bsd/libfido2/dist/fuzz/Dockerfile                    |     7 +-
 external/bsd/libfido2/dist/fuzz/Makefile                      |     9 +-
 external/bsd/libfido2/dist/fuzz/README                        |     6 +-
 external/bsd/libfido2/dist/fuzz/build-coverage                |     7 +-
 external/bsd/libfido2/dist/fuzz/export.gnu                    |    35 +
 external/bsd/libfido2/dist/fuzz/functions.txt                 |  1058 +++++----
 external/bsd/libfido2/dist/fuzz/fuzz_assert.c                 |    52 +-
 external/bsd/libfido2/dist/fuzz/fuzz_bio.c                    |    24 +-
 external/bsd/libfido2/dist/fuzz/fuzz_cred.c                   |    74 +-
 external/bsd/libfido2/dist/fuzz/fuzz_credman.c                |    20 +-
 external/bsd/libfido2/dist/fuzz/fuzz_hid.c                    |   173 +
 external/bsd/libfido2/dist/fuzz/fuzz_largeblob.c              |   270 ++
 external/bsd/libfido2/dist/fuzz/fuzz_mgmt.c                   |   162 +-
 external/bsd/libfido2/dist/fuzz/fuzz_netlink.c                |   249 ++
 external/bsd/libfido2/dist/fuzz/libfuzzer.c                   |     5 +-
 external/bsd/libfido2/dist/fuzz/mutator_aux.c                 |   167 +-
 external/bsd/libfido2/dist/fuzz/mutator_aux.h                 |    18 +-
 external/bsd/libfido2/dist/fuzz/report.tgz                    |   Bin 
 external/bsd/libfido2/dist/fuzz/summary.txt                   |    58 +-
 external/bsd/libfido2/dist/fuzz/wiredata_fido2.h              |    86 +-
 external/bsd/libfido2/dist/fuzz/wrap.c                        |    41 +-
 external/bsd/libfido2/dist/fuzz/wrapped.sym                   |     4 +
 external/bsd/libfido2/dist/man/CMakeLists.txt                 |    31 +-
 external/bsd/libfido2/dist/man/fido2-assert.1                 |    13 +-
 external/bsd/libfido2/dist/man/fido2-cred.1                   |    25 +-
 external/bsd/libfido2/dist/man/fido2-token.1                  |   207 +-
 external/bsd/libfido2/dist/man/fido_assert_new.3              |    32 +-
 external/bsd/libfido2/dist/man/fido_assert_set_authdata.3     |    20 +-
 external/bsd/libfido2/dist/man/fido_cbor_info_new.3           |     9 +
 external/bsd/libfido2/dist/man/fido_cred_new.3                |    37 +-
 external/bsd/libfido2/dist/man/fido_cred_set_authdata.3       |    29 +-
 external/bsd/libfido2/dist/man/fido_cred_verify.3             |     2 +-
 external/bsd/libfido2/dist/man/fido_credman_metadata_new.3    |     4 +
 external/bsd/libfido2/dist/man/fido_dev_enable_entattest.3    |    95 +
 external/bsd/libfido2/dist/man/fido_dev_largeblob_get.3       |   194 +
 external/bsd/libfido2/dist/man/fido_dev_make_cred.3           |     2 +-
 external/bsd/libfido2/dist/man/fido_dev_open.3                |    49 +-
 external/bsd/libfido2/dist/man/fido_dev_set_io_functions.3    |   172 +-
 external/bsd/libfido2/dist/man/fido_dev_set_pin.3             |    15 +
 external/bsd/libfido2/dist/man/fido_init.3                    |    14 +-
 external/bsd/libfido2/dist/openbsd-compat/endian_win32.c      |    51 +
 external/bsd/libfido2/dist/openbsd-compat/freezero.c          |    30 +
 external/bsd/libfido2/dist/openbsd-compat/hkdf.c              |   124 +
 external/bsd/libfido2/dist/openbsd-compat/hkdf.h              |    65 +
 external/bsd/libfido2/dist/openbsd-compat/openbsd-compat.h    |    24 +
 external/bsd/libfido2/dist/openbsd-compat/posix_ioctl_check.c |     7 +
 external/bsd/libfido2/dist/openbsd-compat/time.h              |    33 +-
 external/bsd/libfido2/dist/openbsd-compat/types.h             |     5 +
 external/bsd/libfido2/dist/regress/assert.c                   |    48 +-
 external/bsd/libfido2/dist/regress/cred.c                     |    46 +
 external/bsd/libfido2/dist/regress/dev.c                      |   192 +-
 external/bsd/libfido2/dist/src/CMakeLists.txt                 |    88 +-
 external/bsd/libfido2/dist/src/aes256.c                       |   235 +-
 external/bsd/libfido2/dist/src/assert.c                       |   197 +-
 external/bsd/libfido2/dist/src/authkey.c                      |     3 +-
 external/bsd/libfido2/dist/src/bio.c                          |    28 +-
 external/bsd/libfido2/dist/src/blob.c                         |    89 +-
 external/bsd/libfido2/dist/src/blob.h                         |     4 +-
 external/bsd/libfido2/dist/src/buf.c                          |     1 -
 external/bsd/libfido2/dist/src/cbor.c                         |   473 ++-
 external/bsd/libfido2/dist/src/compress.c                     |    49 +
 external/bsd/libfido2/dist/src/config.c                       |   193 +
 external/bsd/libfido2/dist/src/cred.c                         |   129 +-
 external/bsd/libfido2/dist/src/credman.c                      |    53 +-
 external/bsd/libfido2/dist/src/dev.c                          |   250 +-
 external/bsd/libfido2/dist/src/ecdh.c                         |   152 +-
 external/bsd/libfido2/dist/src/eddsa.c                        |     7 +-
 external/bsd/libfido2/dist/src/err.c                          |    10 +
 external/bsd/libfido2/dist/src/es256.c                        |    11 +-
 external/bsd/libfido2/dist/src/export.gnu                     |    27 +
 external/bsd/libfido2/dist/src/export.llvm                    |    27 +
 external/bsd/libfido2/dist/src/export.msvc                    |    27 +
 external/bsd/libfido2/dist/src/extern.h                       |   102 +-
 external/bsd/libfido2/dist/src/fido.h                         |    41 +-
 external/bsd/libfido2/dist/src/fido/config.h                  |    34 +
 external/bsd/libfido2/dist/src/fido/err.h                     |     7 +-
 external/bsd/libfido2/dist/src/fido/param.h                   |    16 +
 external/bsd/libfido2/dist/src/fido/types.h                   |    70 +-
 external/bsd/libfido2/dist/src/hid.c                          |   110 +-
 external/bsd/libfido2/dist/src/hid_freebsd.c                  |   253 ++
 external/bsd/libfido2/dist/src/hid_hidapi.c                   |   102 +-
 external/bsd/libfido2/dist/src/hid_linux.c                    |   249 +-
 external/bsd/libfido2/dist/src/hid_netbsd.c                   |   259 +-
 external/bsd/libfido2/dist/src/hid_openbsd.c                  |    72 +-
 external/bsd/libfido2/dist/src/hid_osx.c                      |    59 +-
 external/bsd/libfido2/dist/src/hid_unix.c                     |    76 +
 external/bsd/libfido2/dist/src/hid_win.c                      |    18 +-
 external/bsd/libfido2/dist/src/info.c                         |     9 +-
 external/bsd/libfido2/dist/src/io.c                           |    28 +-
 external/bsd/libfido2/dist/src/iso7816.c                      |    30 +-
 external/bsd/libfido2/dist/src/iso7816.h                      |     2 +-
 external/bsd/libfido2/dist/src/largeblob.c                    |   881 ++++++++
 external/bsd/libfido2/dist/src/libfido2.pc.in                 |     1 +
 external/bsd/libfido2/dist/src/log.c                          |    63 +-
 external/bsd/libfido2/dist/src/netlink.c                      |   782 +++++++
 external/bsd/libfido2/dist/src/netlink.h                      |    44 +
 external/bsd/libfido2/dist/src/nfc_linux.c                    |   631 +++++
 external/bsd/libfido2/dist/src/pin.c                          |   637 +++--
 external/bsd/libfido2/dist/src/random.c                       |    82 +
 external/bsd/libfido2/dist/src/reset.c                        |     6 +-
 external/bsd/libfido2/dist/src/rs256.c                        |     6 +-
 external/bsd/libfido2/dist/src/u2f.c                          |    60 +-
 external/bsd/libfido2/dist/tools/CMakeLists.txt               |    29 +-
 external/bsd/libfido2/dist/tools/assert_get.c                 |    19 +-
 external/bsd/libfido2/dist/tools/assert_verify.c              |     1 -
 external/bsd/libfido2/dist/tools/bio.c                        |   178 +-
 external/bsd/libfido2/dist/tools/config.c                     |   149 +
 external/bsd/libfido2/dist/tools/cred_make.c                  |    19 +-
 external/bsd/libfido2/dist/tools/credman.c                    |   245 +-
 external/bsd/libfido2/dist/tools/extern.h                     |    49 +-
 external/bsd/libfido2/dist/tools/fido2-assert.c               |     2 +-
 external/bsd/libfido2/dist/tools/fido2-cred.c                 |     2 +-
 external/bsd/libfido2/dist/tools/fido2-token.c                |    28 +-
 external/bsd/libfido2/dist/tools/largeblob.c                  |   593 +++++
 external/bsd/libfido2/dist/tools/pin.c                        |     3 -
 external/bsd/libfido2/dist/tools/test.sh                      |   364 ++-
 external/bsd/libfido2/dist/tools/token.c                      |   162 +-
 external/bsd/libfido2/dist/tools/util.c                       |   164 +-
 external/bsd/libfido2/dist/udev/70-u2f.rules                  |    60 +-
 external/bsd/libfido2/dist/udev/fidodevs                      |    36 +-
 external/bsd/libfido2/dist/windows/build.ps1                  |   128 +-
 137 files changed, 10760 insertions(+), 3013 deletions(-)

diffs (truncated from 19811 to 300 lines):

diff -r 0fb27b686ee3 -r f5c396d5fbdc external/bsd/libfido2/dist/CMakeLists.txt
--- a/external/bsd/libfido2/dist/CMakeLists.txt Thu Jun 17 00:03:05 2021 +0000
+++ b/external/bsd/libfido2/dist/CMakeLists.txt Thu Jun 17 00:38:06 2021 +0000
@@ -7,6 +7,10 @@
 
 project(libfido2 C)
 cmake_minimum_required(VERSION 3.0)
+# Set PIE flags for POSITION_INDEPENDENT_CODE targets, added in CMake 3.14.
+if(POLICY CMP0083)
+  cmake_policy(SET CMP0083 NEW)
+endif()
 
 include(CheckCCompilerFlag)
 include(CheckFunctionExists)
@@ -15,16 +19,29 @@
 include(CheckIncludeFiles)
 include(CheckTypeSize)
 include(GNUInstallDirs)
+include(CheckPIESupported OPTIONAL RESULT_VARIABLE CHECK_PIE_SUPPORTED)
+if(CHECK_PIE_SUPPORTED)
+  check_pie_supported(LANGUAGES C)
+endif()
 
-set(CMAKE_COLOR_MAKEFILE off)
-set(CMAKE_VERBOSE_MAKEFILE on)
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
-
+set(CMAKE_COLOR_MAKEFILE OFF)
+set(CMAKE_VERBOSE_MAKEFILE ON)
 set(FIDO_MAJOR "1")
-set(FIDO_MINOR "5")
+set(FIDO_MINOR "7")
 set(FIDO_PATCH "0")
 set(FIDO_VERSION ${FIDO_MAJOR}.${FIDO_MINOR}.${FIDO_PATCH})
 
+option(BUILD_EXAMPLES    "Build example programs"             ON)
+option(BUILD_MANPAGES    "Build man pages"                    ON)
+option(BUILD_SHARED_LIBS "Build the shared library"           ON)
+option(BUILD_STATIC_LIBS "Build the static library"           ON)
+option(BUILD_TOOLS       "Build tool programs"                ON)
+option(FUZZ              "Enable fuzzing instrumentation"     OFF)
+option(LIBFUZZER         "Build libfuzzer harnesses"          OFF)
+option(USE_HIDAPI        "Use hidapi as the HID backend"      OFF)
+option(NFC_LINUX         "Experimental NFC support on Linux"  OFF)
+
 add_definitions(-D_FIDO_MAJOR=${FIDO_MAJOR})
 add_definitions(-D_FIDO_MINOR=${FIDO_MINOR})
 add_definitions(-D_FIDO_PATCH=${FIDO_PATCH})
@@ -43,14 +60,116 @@
            "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
 endif()
 
+if(NOT MSVC)
+       set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_POSIX_C_SOURCE=200809L")
+       set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_BSD_SOURCE")
+       if(APPLE)
+               set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_DARWIN_C_SOURCE")
+               set(FIDO_CFLAGS "${FIDO_CFLAGS} -D__STDC_WANT_LIB_EXT1__=1")
+       elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+               set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_GNU_SOURCE")
+               set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_DEFAULT_SOURCE")
+       elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
+               set(FIDO_CFLAGS "${FIDO_CFLAGS} -D__BSD_VISIBLE=1")
+       endif()
+       set(FIDO_CFLAGS "${FIDO_CFLAGS} -std=c99")
+       set(CMAKE_C_FLAGS "${FIDO_CFLAGS} ${CMAKE_C_FLAGS}")
+endif()
+
+check_c_compiler_flag("-Wshorten-64-to-32" HAVE_SHORTEN_64_TO_32)
+check_c_compiler_flag("-fstack-protector-all" HAVE_STACK_PROTECTOR_ALL)
+
+check_include_files(cbor.h HAVE_CBOR_H)
+check_include_files(endian.h HAVE_ENDIAN_H)
+check_include_files(err.h HAVE_ERR_H)
+check_include_files(openssl/opensslv.h HAVE_OPENSSLV_H)
+check_include_files(signal.h HAVE_SIGNAL_H)
+check_include_files(sys/random.h HAVE_SYS_RANDOM_H)
+check_include_files(unistd.h HAVE_UNISTD_H)
+
+check_symbol_exists(arc4random_buf stdlib.h HAVE_ARC4RANDOM_BUF)
+check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
+check_symbol_exists(explicit_bzero string.h HAVE_EXPLICIT_BZERO)
+check_symbol_exists(freezero stdlib.h HAVE_FREEZERO)
+check_symbol_exists(getline stdio.h HAVE_GETLINE)
+check_symbol_exists(getopt unistd.h HAVE_GETOPT)
+check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)
+check_symbol_exists(getrandom sys/random.h HAVE_GETRANDOM)
+check_symbol_exists(memset_s string.h HAVE_MEMSET_S)
+check_symbol_exists(readpassphrase readpassphrase.h HAVE_READPASSPHRASE)
+check_symbol_exists(recallocarray stdlib.h HAVE_RECALLOCARRAY)
+check_symbol_exists(sigaction signal.h HAVE_SIGACTION)
+check_symbol_exists(strlcat string.h HAVE_STRLCAT)
+check_symbol_exists(strlcpy string.h HAVE_STRLCPY)
+check_symbol_exists(sysconf unistd.h HAVE_SYSCONF)
+check_symbol_exists(timespecsub sys/time.h HAVE_TIMESPECSUB)
+check_symbol_exists(timingsafe_bcmp string.h HAVE_TIMINGSAFE_BCMP)
+
+set(CMAKE_EXTRA_INCLUDE_FILES signal.h)
+check_type_size("sig_atomic_t" HAVE_SIG_ATOMIC_T)
+set(CMAKE_EXTRA_INCLUDE_FILES)
+
+set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+try_compile(HAVE_POSIX_IOCTL
+    "${CMAKE_CURRENT_BINARY_DIR}/posix_ioctl_check.o"
+    "${CMAKE_CURRENT_SOURCE_DIR}/openbsd-compat/posix_ioctl_check.c"
+    COMPILE_DEFINITIONS "-Werror -Woverflow -Wsign-conversion")
+
+list(APPEND CHECK_VARIABLES
+       HAVE_ARC4RANDOM_BUF
+       HAVE_CBOR_H
+       HAVE_CLOCK_GETTIME
+       HAVE_ENDIAN_H
+       HAVE_ERR_H
+       HAVE_FREEZERO
+       HAVE_GETLINE
+       HAVE_GETOPT
+       HAVE_GETPAGESIZE
+       HAVE_GETRANDOM
+       HAVE_MEMSET_S
+       HAVE_OPENSSLV_H
+       HAVE_POSIX_IOCTL
+       HAVE_READPASSPHRASE
+       HAVE_RECALLOCARRAY
+       HAVE_SIGACTION
+       HAVE_SIGNAL_H
+       HAVE_STRLCAT
+       HAVE_STRLCPY
+       HAVE_SYSCONF
+       HAVE_SYS_RANDOM_H
+       HAVE_TIMESPECSUB
+       HAVE_TIMINGSAFE_BCMP
+       HAVE_UNISTD_H
+)
+
+foreach(v ${CHECK_VARIABLES})
+       if (${v})
+               add_definitions(-D${v})
+       endif()
+endforeach()
+
+if(HAVE_EXPLICIT_BZERO AND NOT LIBFUZZER)
+       add_definitions(-DHAVE_EXPLICIT_BZERO)
+endif()
+
+if(HAVE_SIGACTION AND (NOT HAVE_SIG_ATOMIC_T STREQUAL ""))
+       add_definitions(-DSIGNAL_EXAMPLE)
+endif()
+
+if(UNIX)
+       add_definitions(-DHAVE_DEV_URANDOM)
+endif()
+
 if(MSVC)
        if((NOT CBOR_INCLUDE_DIRS) OR (NOT CBOR_LIBRARY_DIRS) OR
-          (NOT CRYPTO_INCLUDE_DIRS) OR (NOT CRYPTO_LIBRARY_DIRS))
+          (NOT CRYPTO_INCLUDE_DIRS) OR (NOT CRYPTO_LIBRARY_DIRS) OR
+          (NOT ZLIB_INCLUDE_DIRS) OR (NOT ZLIB_LIBRARY_DIRS))
                message(FATAL_ERROR "please provide definitions for "
-                   "{CBOR,CRYPTO}_{INCLUDE,LIBRARY}_DIRS when building "
+                  "{CBOR,CRYPTO,ZLIB}_{INCLUDE,LIBRARY}_DIRS when building "
                    "under msvc")
        endif()
        set(CBOR_LIBRARIES cbor)
+       set(ZLIB_LIBRARIES zlib)
        set(CRYPTO_LIBRARIES crypto-46)
        set(MSVC_DISABLED_WARNINGS_LIST
                "C4200" # nonstandard extension used: zero-sized array in
@@ -67,45 +186,40 @@
            ${MSVC_DISABLED_WARNINGS_LIST})
        string(REGEX REPLACE "[/-]W[1234][ ]?" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MP -W4 -WX ${MSVC_DISABLED_WARNINGS_STR}")
-       set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Z7")
-       set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi")
+       set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Z7 /guard:cf /sdl /RTCcsu")
+       set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi /guard:cf /sdl")
 else()
        include(FindPkgConfig)
        pkg_search_module(CBOR libcbor)
        pkg_search_module(CRYPTO libcrypto)
+       pkg_search_module(ZLIB zlib)
 
-       # XXX workaround libcbor's missing .pc file
-       if(NOT CBOR_FOUND)
-               check_include_files(cbor.h HAVE_CBOR_H)
-               if(NOT HAVE_CBOR_H)
-                       message(FATAL_ERROR "could not find cbor header files")
-               endif()
-               set(CBOR_LIBRARIES "cbor")
+       if(NOT CBOR_FOUND AND NOT HAVE_CBOR_H)
+               message(FATAL_ERROR "could not find libcbor")
+       endif()
+       if(NOT CRYPTO_FOUND AND NOT HAVE_OPENSSLV_H)
+               message(FATAL_ERROR "could not find libcrypto")
+       endif()
+       if(NOT ZLIB_FOUND)
+               message(FATAL_ERROR "could not find zlib")
        endif()
 
-       # XXX workaround libcrypto's missing .pc file
-       if(NOT CRYPTO_FOUND)
-               check_include_files(openssl/opensslv.h HAVE_OPENSSLV_H)
-               if(NOT HAVE_OPENSSLV_H)
-                       message(FATAL_ERROR "could not find crypto header files")
-               endif()
-               set(CRYPTO_LIBRARIES "crypto")
-       endif()
+       set(CBOR_LIBRARIES "cbor")
+       set(CRYPTO_LIBRARIES "crypto")
 
        if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
                pkg_search_module(UDEV libudev REQUIRED)
                set(UDEV_NAME "udev")
-               include_directories(${UDEV_INCLUDE_DIRS})
-               link_directories(${UDEV_LIBRARY_DIRS})
-               # Define be32toh().
-               add_definitions(-D_GNU_SOURCE)
                # If using hidapi, use hidapi-hidraw.
                set(HIDAPI_SUFFIX -hidraw)
-               # Look for clock_gettime in librt.
-               check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
-               if(HAVE_CLOCK_GETTIME)
-                       set(BASE_LIBRARIES ${BASE_LIBRARIES} rt)
-                       add_definitions(-DHAVE_CLOCK_GETTIME)
+               if(NOT HAVE_CLOCK_GETTIME)
+                       # Look for clock_gettime in librt.
+                       check_library_exists(rt clock_gettime "time.h"
+                           HAVE_CLOCK_GETTIME)
+                       if (HAVE_CLOCK_GETTIME)
+                               add_definitions(-DHAVE_CLOCK_GETTIME)
+                               set(BASE_LIBRARIES ${BASE_LIBRARIES} rt)
+                       endif()
                endif()
        endif()
 
@@ -113,57 +227,56 @@
                # MinGW is stuck with a flavour of C89.
                add_definitions(-DFIDO_NO_DIAGNOSTIC)
                add_definitions(-DWC_ERR_INVALID_CHARS=0x80)
-               set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter")
+               add_compile_options(-Wno-unused-parameter)
        endif()
 
        if(USE_HIDAPI)
                add_definitions(-DUSE_HIDAPI)
                pkg_search_module(HIDAPI hidapi${HIDAPI_SUFFIX} REQUIRED)
-               if(HIDAPI_FOUND)
-                       include_directories(${HIDAPI_INCLUDE_DIRS})
-                       link_directories(${HIDAPI_LIBRARY_DIRS})
-                       set(HIDAPI_LIBRARIES hidapi${HIDAPI_SUFFIX})
-               endif()
+               set(HIDAPI_LIBRARIES hidapi${HIDAPI_SUFFIX})
+       endif()
+
+       if(FUZZ)
+               set(NFC_LINUX ON)
+       endif()
+
+       if(NFC_LINUX)
+               add_definitions(-DNFC_LINUX)
        endif()
 
-       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
-       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra")
-       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
-       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
-       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wwrite-strings")
-       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-prototypes")
-       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wbad-function-cast")
-       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic")
-       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic-errors")
-       check_c_compiler_flag("-fstack-protector-all" HAVE_STACK_PROTECTOR_ALL)
+       add_compile_options(-Wall)
+       add_compile_options(-Wextra)
+       add_compile_options(-Werror)
+       add_compile_options(-Wshadow)
+       add_compile_options(-Wcast-qual)
+       add_compile_options(-Wwrite-strings)
+       add_compile_options(-Wmissing-prototypes)
+       add_compile_options(-Wbad-function-cast)
+       add_compile_options(-pedantic)
+       add_compile_options(-pedantic-errors)
+
+       if(HAVE_SHORTEN_64_TO_32)
+               add_compile_options(-Wshorten-64-to-32)
+       endif()
        if(HAVE_STACK_PROTECTOR_ALL)
-               set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all")
+               add_compile_options(-fstack-protector-all)
        endif()
 
-       add_definitions(-D_DEFAULT_SOURCE)
-       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
-
        set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g2")
        set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fno-omit-frame-pointer")
+       set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -D_FORTIFY_SOURCE=2")
 
        if(FUZZ)
-               if(LIBFUZZER)
-                       set(FUZZ_LDFLAGS "-fsanitize=fuzzer")



Home | Main Index | Thread Index | Old Index