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 some crypto issues #177

Merged
merged 5 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
29 changes: 23 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ endfunction()
# Function to log a option and its value
function(log_option name description default)
option(${name} ${description} ${default})
if(${value})
if(${name})
message(STATUS "[*] ${name}")
else()
message(STATUS "[ ] ${name}")
Expand All @@ -41,6 +41,7 @@ log_option(OPENSSL "Use OpenSSL" OFF)
log_option(EXAMPLES "Build all examples" OFF)
log_option(SHARED_LIB "Library type. [SHARED=ON STATIC=OFF]" OFF)
log_option(WITH_CPP "Build the CPP headers" OFF)
log_option(ASAN "Use Address sanitizer" OFF)

if (WITH_CPP)
set(DEFAULT_USE_CALLBACK_API ON)
Expand All @@ -67,6 +68,7 @@ num_option(USE_CALLBACK_API "Use callback API [CALLBACK=ON SYNC=OFF]" ${DEFAULT_
num_option(USE_IPV6 "Use IPv6 [CALLBACK=ON]" ${DEFAULT_USE_CALLBACK_API})
num_option(USE_SET_DNS_SERVERS "Use set DNS servers [CALLBACK=ON]" ${DEFAULT_USE_CALLBACK_API})
num_option(USE_EXTERN_API "Use extern C API [WITH_CPP=ON]" ON)
num_option(USE_LEGACY_CRYPTO_RANDOM_IV "Use random IV for legacy crypto module [OpenSSL only]" ON)
log_set(OPENSSL_ROOT_DIR "" "OpenSSL root directory (leave empty for find_package function)[OPENSSL=ON needed]")
log_set(EXAMPLE "all" "Build example with provided name (use 'all' for all examples) [EXAMPLES=ON needed]")
log_set(CGREEN_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/cgreen" "CGreen root directory [UNIT_TEST=ON needed]")
Expand All @@ -89,7 +91,11 @@ set(FLAGS "\
-D PUBNUB_USE_AUTO_HEARTBEAT=${USE_AUTO_HEARTBEAT} \
-D PUBNUB_USE_GRANT_TOKEN_API=${USE_GRANT_TOKEN_API} \
-D PUBNUB_USE_REVOKE_TOKEN_API=${USE_REVOKE_TOKEN_API} \
-D PUBNUB_USE_FETCH_HISTORY=${USE_FETCH_HISTORY}")
-D PUBNUB_USE_FETCH_HISTORY=${USE_FETCH_HISTORY} \
-D PUBNUB_RAND_INIT_VECTOR=${USE_LEGACY_CRYPTO_RANDOM_IV}")

set(LDLIBS)
set(OS_SOURCEFILES)

if (${USE_CALLBACK_API})
set(FLAGS "\
Expand All @@ -99,6 +105,15 @@ if (${USE_CALLBACK_API})
-D PUBNUB_CALLBACK_API")
endif()

if (${ASAN})
set(FLAGS "\
${FLAGS} \
-fsanitize=address")
set(LDLIBS "\
${LDLIBS} \
-fsanitize=address")
endif()

set(CMAKE_C_FLAGS "\
${FLAGS} \
${CMAKE_C_FLAGS}")
Expand Down Expand Up @@ -145,11 +160,8 @@ set(LIB_SOURCEFILES
${CMAKE_CURRENT_LIST_DIR}/lib/sockets/pbpal_adns_sockets.c
${CMAKE_CURRENT_LIST_DIR}/lib/pubnub_dns_codec.c)

set(LDLIBS)
set(OS_SOURCEFILES)

if(UNIX)
set(LDLIBS "-lpthread")
set(LDLIBS "-lpthread ${LDLIBS}")
set(OS_SOURCEFILES
${CMAKE_CURRENT_LIST_DIR}/posix/posix_socket_blocking_io.c
${CMAKE_CURRENT_LIST_DIR}/posix/pubnub_version_posix.c
Expand Down Expand Up @@ -529,6 +541,11 @@ if(${EXAMPLES})
pubnub_advanced_history_sample
pubnub_fetch_history_sample
cancel_subscribe_sync_sample)
if (OPENSSL)
set(EXAMPLE_LIST
pubnub_crypto_module_sample
${EXAMPLE_LIST})
endif()
endif()
else()
message(STATUS "Building example ${EXAMPLE}")
Expand Down
6 changes: 5 additions & 1 deletion core/pbcc_crypto_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ static size_t estimated_enc_buffer_size(size_t n) {
}

static size_t estimated_dec_buffer_size(size_t n) {
return n + 1; // for the terminating array
// In most cases formula (n + 1) is enough to
// handle the amount of decrypted bytes.
// Addition AES_BLOCK_SIZE just to be sure if message
// contains very specific padding.
return n + AES_BLOCK_SIZE + 1;
}

static int legacy_encrypt(
Expand Down
Loading