Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix make/cmake and includes. #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ if (NOT YOCTO_BUILD)

endif()

if(NOT DEFINED SECUTILS_VERSION )
set(SECUTILS_VERSION 0.9)
if(NOT DEFINED SECUTILS_VERSION)
# must be kept in sync with latest version in debian/changelog and with VERSION in Makefile
set(SECUTILS_VERSION 1.0)
endif()

set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include
Expand All @@ -43,13 +44,11 @@ set(SRC_EXAMPLE_DIR ${PROJECT_SOURCE_DIR}/test)

find_package(OpenSSL REQUIRED)

if(DEFINED ENV{NDEBUG})
add_definitions(-DNDEBUG=1 -O2)
Comment on lines -46 to -47
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that regarding (N)DEBUG, CMakeLists.txt and Makefile should remain consistent. In Makefile it now reads

ifdef DEBUG
    DEBUG_FLAGS ?= -g -O0
# Add this to get some additional runtime checks.
# Warning: it's incompatible with tools like Valgrind and you have to add it to the app using this lib too
#	DEBUG_FLAGS += -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all
    override DEBUG_FLAGS += -DNDEBUG=1
else
    DEBUG_FLAGS ?= -g -O0 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all # not every compiler(version) supports -Og
endif

else()
add_definitions(-g -O0)
add_definitions(-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all)
link_libraries("-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all")
endif()
# Add this to get some additional runtime checks.
# Warning: it's incompatible with tools like Valgrind and you have to add it to the app using this lib too.
# add_definitions("-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all")
# link_libraries("-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all")

add_definitions(-Wall -Woverflow -Wextra -Wswitch -Wmissing-prototypes -Wstrict-prototypes -Wformat -Wtype-limits -Wundef -Wconversion -Wno-shadow -Wno-conversion -Wno-sign-conversion -Wno-unused-parameter -Wno-sign-compare) # TODO enable -Wconversion -Wsign-conversion -Wsign-compare -Wunused-parameter
add_definitions(-Wformat -Wformat-security -Wno-declaration-after-statement -Wno-vla) # -Wpointer-arith -pedantic -DPEDANTIC # -Werror

Expand All @@ -75,6 +74,7 @@ set(SECUTIL_LIB_SRC ${SRC_DIR}/certstatus/certstatus.c
${SRC_DIR}/connections/conn.c
${SRC_DIR}/connections/http.c
${SRC_DIR}/connections/tls.c
${SRC_DIR}/credentials/cert.c
${SRC_DIR}/credentials/credentials.c
${SRC_DIR}/credentials/key.c
${SRC_DIR}/credentials/store.c
Expand Down
22 changes: 13 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ ROOTFS ?= $(DESTDIR)$(prefix)

OUT_DIR ?= .

# must be kept in sync with latest version in debian/changelog and with SECUTILS_VERSION in CMakeLists.txt
VERSION=1.0
# must be kept in sync with latest version in debian/changelog
# PACKAGENAME=libsecutils
# DIRNAME=$(PACKAGENAME)-$(VERSION)

SHELL=bash # This is needed for supporting extended file name globbing

Expand Down Expand Up @@ -57,12 +55,16 @@ endif
# Note: stuff for testing purposes should go here
################################################################################

ifdef NDEBUG
ifdef DEBUG
DEBUG_FLAGS ?= -g -O0
# Add this to get some additional runtime checks.
# Warning: it's incompatible with tools like Valgrind and you have to add it to the app using this lib too
# DEBUG_FLAGS += -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all
else
DEBUG_FLAGS ?= -O2
override DEBUG_FLAGS += -DNDEBUG=1
else
DEBUG_FLAGS ?= -g -O0 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all # not every compiler(version) supports -Og
endif

override CFLAGS += $(DEBUG_FLAGS) -Wall -Woverflow -Wextra -Wswitch -Wmissing-prototypes -Wstrict-prototypes -Wformat -Wtype-limits -Wundef -Wconversion
override CFLAGS += -Wno-shadow -Wno-conversion -Wno-sign-conversion -Wno-sign-compare -Wno-unused-parameter # TODO clean up code and enable -Wshadow -Wconversion -Wsign-conversion -Wsign-compare -Wunused-parameter
override CFLAGS += -Wformat -Wformat-security -Wno-declaration-after-statement -Wno-vla # -Wpointer-arith -pedantic -DPEDANTIC # -Werror
Expand Down Expand Up @@ -150,11 +152,13 @@ ifeq ($(COV_ENABLED), 1)
endif
$(MAKE) COMPILE_TYPE=$(COMPILE_TYPE) build_only

util:
util: $(OUT_DIR)/$(OUTLIB)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better:
util: build_only

$(MAKE) -C util SECUTILS_USE_UTA="$(SECUTILS_USE_UTA)" \
CFLAGS="$(CFLAGS) $(LOCAL_CFLAGS)" LDFLAGS="$(LDFLAGS)"

build_all: build util
build_all:
$(MAKE) build
$(MAKE) util
Comment on lines +159 to +161
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the advantage of this change?


# Binary output target
$(OUT_DIR)/$(OUTLIB).$(VERSION): $(OBJS)
Expand Down Expand Up @@ -219,10 +223,10 @@ clean_uta:
$(OUT_DIR)/$(OUTLIB)* $(OUT_DIR)/util/$(OUTBIN) $(OUT_DIR)/util/icvutil.o

clean:
$(MAKE) -C util clean
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is inconsistent - $(MAKE) util is still part of build_all,
but you moved $(MAKE) -C util clean from clean_all to clean.

rm -rf $(OUT_DIR)/$(OUTLIB)* $(OUT_DIR)/util/$(OUTBIN) $(BUILDDIR)

clean_all: clean clean_deb
$(MAKE) -C util clean
rm -rf doc refman.pdf *.gcov reports

doc: doc/html refman.pdf
Expand Down
3 changes: 2 additions & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ override_dh_auto_clean:

# adding compile flags as, defaults are commonly debug flags
override_dh_auto_build:
# CFLAGS="-O2 -DNDEBUG" CXXFLAGS="-O2 -DNDEBUG" DEBUG_FLAGS="" LDFLAGS="" # can be used to avoid dependency on libasan and libubsan
# clear DEBUG_FLAGS so that the default debian options get applied
DEBUG_FLAGS="" \
OPENSSL_DIR=/usr CC=$(CC) CXX=$(CXX) AR=$(AR) \
dh_auto_build -- -j1 build_only util

Expand Down
1 change: 1 addition & 0 deletions include/secutils/certstatus/certstatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define SECUTILS_CERTSTATUS_H_

#include <openssl/x509_vfy.h>

#include "../util/log.h"

#if OPENSSL_VERSION_NUMBER < 0x10101000L
Expand Down
3 changes: 2 additions & 1 deletion include/secutils/certstatus/crl_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#define SECUTILS_HEADER_CRL_MGMT_H

#include <openssl/x509.h>
#include <secutils/basic.h>

#include "../basic.h"

#ifdef __cplusplus
extern "C" {
Expand Down
2 changes: 2 additions & 0 deletions include/secutils/certstatus/crls.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#ifndef SECUTILS_CRLS_H_
#define SECUTILS_CRLS_H_

#include "../basic.h"

#include <openssl/x509.h>

/*!*****************************************************************************
Expand Down
3 changes: 1 addition & 2 deletions include/secutils/credentials/cert.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
#include <string.h> /* for strcmp, strlen */

#include "../basic.h"
#include "../operators.h"
# include "../util/log.h"
#include "../util/log.h"

#include <openssl/x509.h>

Expand Down
6 changes: 2 additions & 4 deletions include/secutils/credentials/verify.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,13 @@ bool verify_cb_cert(X509_STORE_CTX* store_ctx, X509* cert, int err);
/*!*****************************************************************************
* @brief attempt to verify certificate
*
* @param ctx (optional) pointer to UTA context, unused
* @param cert certificate to be verified
* @param untrusted (optional) intermediate certs that may be useful for building
* the chain of certificates between the cert and the trusted certs in the trust store
* @param trust_store pointer to structure containing trusted (root) certs and further verification parameters
* @note trust_store may contain CRLs loaded via STORE_load_crl_dir()
* @return < 0 on on verification error, 0 for invalid cert, 1 for vaild cert
* @return < 0 on on verification error, 0 for invalid cert, 1 for valid cert
*******************************************************************************/
int CREDENTIALS_verify_cert(OPTIONAL uta_ctx* ctx, X509* cert,
OPTIONAL const STACK_OF(X509) * untrusted, X509_STORE* trust_store);
int CREDENTIALS_verify_cert(X509* cert, OPTIONAL const STACK_OF(X509) * untrusted, X509_STORE* trust_store);

#endif /* SECUTILS_VERIFY_H_ */
2 changes: 2 additions & 0 deletions include/secutils/storage/files_dv.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include <openssl/x509.h>

#include "../util/util.h"

#include "../storage/uta_api.h"
#define MAX_UTA_PASS_LEN (MAX_B64_CHARS_PER_BYTE * TA_OUTLEN + 1)
#include "files.h"
Expand Down
1 change: 1 addition & 0 deletions include/secutils/storage/files_icv.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "../storage/uta_api.h"

#include <openssl/ossl_typ.h>
#include <openssl/safestack.h>

/*!
* @brief (re-)protect integrity of file (of any type that allows appending text) with ICV derived via UTA
Expand Down
3 changes: 2 additions & 1 deletion include/secutils/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
# include <unistd.h>

# include "../basic.h"
# include "../operators.h"

# include <openssl/err.h>
# include <openssl/x509v3.h>

# include "../storage/uta_api.h"

static const char *const
UTIL_SECUTILS_NAME = "secutils"; /*!< short name of this library */
static const int UTIL_max_path_len = 512; /*!< max length of file path name */
Expand Down
8 changes: 4 additions & 4 deletions src/certstatus/certstatus.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
/**
* @file certstatus.c
*
*
* @brief Certificate status checking using CRLs and/or OCSP
*
* @copyright Copyright (c) Siemens Mobility GmbH, 2021
*
* @author David von Oheimb <[email protected]>
*
* This work is licensed under the terms of the Apache Software License
* This work is licensed under the terms of the Apache Software License
* 2.0. See the COPYING file in the top-level directory.
*
* SPDX-License-Identifier: Apache-2.0
Expand All @@ -28,7 +28,7 @@
# include <certstatus/ocsp.h>
#endif

#include <operators.h>
#include "secutils/operators.h"

static unsigned int num_CDPs(const X509* cert)
{
Expand Down
2 changes: 1 addition & 1 deletion src/certstatus/crls.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <credentials/verify.h>
#include <connections/conn.h>

#include <operators.h>
#include "secutils/operators.h"

/* adapted from OpenSSL:crypto/x509/t_crl.c */
void UTIL_print_crl(OPTIONAL BIO* bio, OPTIONAL const X509_CRL* crl)
Expand Down
2 changes: 1 addition & 1 deletion src/certstatus/ocsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# include <connections/tls.h>
# endif

# include <operators.h>
#include "secutils/operators.h"

OCSP_RESPONSE* CONN_load_OCSP_http(const char* url, int timeout,
const OCSP_REQUEST* req,
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <credentials/verify.h>
#include <storage/files_icv.h>

#include <operators.h>
#include "secutils/operators.h"

/* adapted from OpenSSL:apps/include/apps.h */
static opt_t vpm_opts[] = { OPT_V_OPTIONS, OPT_END };
Expand Down
2 changes: 1 addition & 1 deletion src/config/config_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <storage/files_icv.h>
#include <util/log.h>

#include <operators.h>
#include "secutils/operators.h"


static void skip_space(char** p)
Expand Down
2 changes: 1 addition & 1 deletion src/config/opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <inttypes.h> /* for strtoimax on Linux */

#include <operators.h>
#include "secutils/operators.h"

const char OPT_more_str[] = "-M";
const char OPT_section_str[] = "-S";
Expand Down
2 changes: 1 addition & 1 deletion src/connections/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# include <openssl/ssl.h>
#endif

#include <operators.h>
#include "secutils/operators.h"

static const char* skip_scheme(const char* str)
{
Expand Down
3 changes: 2 additions & 1 deletion src/connections/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#if !defined(OPENSSL_NO_OCSP) && !defined(OPENSSL_NO_SOCK)

# include <util/log.h>
# include <operators.h>
# include <connections/http.h>
# include <connections/conn.h>
# ifndef SECUTILS_NO_TLS
Expand All @@ -29,6 +28,8 @@
# endif
# include <openssl/ocsp.h>

# include "secutils/operators.h"

/* TODO replace this all by new API in http.h of OpenSSL 3.0 */

static int REQ_CTX_i2d(OCSP_REQ_CTX* rctx, const char* content_type,
Expand Down
2 changes: 1 addition & 1 deletion src/connections/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <certstatus/ocsp.h>
#endif

#include <operators.h>
#include "secutils/operators.h"

bool TLS_init(void)
{
Expand Down
2 changes: 1 addition & 1 deletion src/credentials/cert.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <storage/files.h>
#include <util/log.h>

#include <operators.h>
#include "secutils/operators.h"


X509 *CERT_load(const char *file, OPTIONAL const char *source,
Expand Down
2 changes: 1 addition & 1 deletion src/credentials/credentials.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <util/log.h>
#include <util/util.h>

#include <operators.h>
#include "secutils/operators.h"

/* this type is part of the genCMPClient API */
struct credentials
Expand Down
2 changes: 1 addition & 1 deletion src/credentials/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <credentials/key.h>
#include <util/log.h>

#include <operators.h>
#include "secutils/operators.h"

EVP_PKEY* KEY_new(const char* spec)
{
Expand Down
2 changes: 1 addition & 1 deletion src/credentials/store.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <util/log.h>
#include <util/util.h>

#include <operators.h>
#include "secutils/operators.h"

typedef struct STORE_ex_st
{
Expand Down
2 changes: 1 addition & 1 deletion src/credentials/trusted.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <storage/files_icv.h>
#include <util/log.h>

#include <operators.h>
#include "secutils/operators.h"

static const char* config_file(void)
{
Expand Down
5 changes: 2 additions & 3 deletions src/credentials/verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <util/log.h>
#include <storage/uta_api.h>

#include <operators.h>
#include "secutils/operators.h"


bool STORE_CTX_tls_active(const X509_STORE_CTX* ctx)
Expand Down Expand Up @@ -183,8 +183,7 @@ bool verify_cb_cert(X509_STORE_CTX* store_ctx, X509* cert, int err)
return verify_cb != 0 and (*verify_cb)(0, store_ctx) != 0;
}

int CREDENTIALS_verify_cert(OPTIONAL uta_ctx* uta_ctx, X509* cert,
OPTIONAL const STACK_OF(X509) * untrusted_certs, X509_STORE* trust_store)
int CREDENTIALS_verify_cert(X509* cert, OPTIONAL const STACK_OF(X509) * untrusted_certs, X509_STORE* trust_store)
{
int result = -1;
X509_STORE_CTX* store_ctx = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <operators.h>
#include "secutils/operators.h"

#include <util/log.h>
#include <crypto/crypto.h>
Expand Down
2 changes: 1 addition & 1 deletion src/storage/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#include <util/log.h>
# include <connections/conn.h>

#include <operators.h>
#include "secutils/operators.h"

static file_format_t adjust_format(const char* * file, file_format_t format, bool engine_ok)
{
Expand Down
2 changes: 1 addition & 1 deletion src/storage/files_dv.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static const char* const DV_SECTION = "dv"; /*! name of DVFILE section with DV s
#include <storage/files_dv.h>
#include <util/log.h>

#include <operators.h>
#include "secutils/operators.h"

/* Get device-specific password (base64 encoded) */
static bool getBase64Password(OPTIONAL uta_ctx* ctx, const unsigned char* dv, char* pw)
Expand Down
Loading