Skip to content

Commit

Permalink
merged develop into KAA-1146
Browse files Browse the repository at this point in the history
  • Loading branch information
vchizhevsky committed Jul 26, 2016
1 parent e072eed commit 91641cd
Show file tree
Hide file tree
Showing 318 changed files with 27,287 additions and 4,511 deletions.
52 changes: 45 additions & 7 deletions client/client-multi/client-c/CMakeLists.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
# #
# - `cc32xx` # - `cc32xx`
# - `esp8266` # - `esp8266`
# - `x86-64` # - `posix`
# #
# Default: `x86-64` # Default: `posix`
# #
# - `KAA_UNITETESTS_COMPILE` - compile unit tests. # - `KAA_UNITETESTS_COMPILE` - compile unit tests.
# #
Expand All @@ -73,12 +73,15 @@ cmake_minimum_required(VERSION 2.8.12)


project(Kaa-c C) project(Kaa-c C)


include(ExternalProject)

option(WITH_EXTENSION_PROFILE "Enable profile extension" ON) option(WITH_EXTENSION_PROFILE "Enable profile extension" ON)
option(WITH_EXTENSION_CONFIGURATION "Enable configuration extension" ON) option(WITH_EXTENSION_CONFIGURATION "Enable configuration extension" ON)
option(WITH_EXTENSION_EVENT "Enable event extension" ON) option(WITH_EXTENSION_EVENT "Enable event extension" ON)
option(WITH_EXTENSION_LOGGING "Enable logging extension" ON) option(WITH_EXTENSION_LOGGING "Enable logging extension" ON)
option(WITH_EXTENSION_NOTIFICATION "Enable notification extension" ON) option(WITH_EXTENSION_NOTIFICATION "Enable notification extension" ON)
option(WITH_EXTENSION_USER "Enable user extension" ON) option(WITH_EXTENSION_USER "Enable user extension" ON)
option(WITH_ENCRYPTION "Enable encryption" ON)


# Expose Kaa SDK directory to all modules # Expose Kaa SDK directory to all modules
set(KAA_SDK_DIR ${CMAKE_CURRENT_LIST_DIR}) set(KAA_SDK_DIR ${CMAKE_CURRENT_LIST_DIR})
Expand All @@ -94,7 +97,7 @@ set(CMAKE_MODULE_PATH
# #
# NOTE: Platform specific compilation flags should be set # NOTE: Platform specific compilation flags should be set
# in the corresponding platform CMake script(s). # in the corresponding platform CMake script(s).
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -pedantic") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -pedantic -D_GNU_SOURCE")


set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -Os") set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -Os")


Expand All @@ -116,7 +119,7 @@ set(KAA_THIRDPARTY_LIBRARIES "")


# Sets the default build platform to POSIX. # Sets the default build platform to POSIX.
if (NOT DEFINED KAA_PLATFORM) if (NOT DEFINED KAA_PLATFORM)
set(KAA_PLATFORM "x86-64") set(KAA_PLATFORM "posix")
endif () endif ()


# #
Expand Down Expand Up @@ -174,15 +177,34 @@ set(KAA_SOURCE_FILES
${KAA_SRC_FOLDER}/kaa.c ${KAA_SRC_FOLDER}/kaa.c
${KAA_SRC_FOLDER}/kaa_extension.c ${KAA_SRC_FOLDER}/kaa_extension.c
${KAA_SRC_FOLDER}/platform-impl/common/kaa_htonll.c ${KAA_SRC_FOLDER}/platform-impl/common/kaa_htonll.c
) ${CMAKE_CURRENT_LIST_DIR}/thirdparty/mbedtls/aes.c
${CMAKE_CURRENT_LIST_DIR}/thirdparty/mbedtls/asn1parse.c
${CMAKE_CURRENT_LIST_DIR}/thirdparty/mbedtls/asn1write.c
${CMAKE_CURRENT_LIST_DIR}/thirdparty/mbedtls/bignum.c
${CMAKE_CURRENT_LIST_DIR}/thirdparty/mbedtls/ctr_drbg.c
${CMAKE_CURRENT_LIST_DIR}/thirdparty/mbedtls/entropy.c
${CMAKE_CURRENT_LIST_DIR}/thirdparty/mbedtls/entropy_poll.c
${CMAKE_CURRENT_LIST_DIR}/thirdparty/mbedtls/md.c
${CMAKE_CURRENT_LIST_DIR}/thirdparty/mbedtls/md_wrap.c
${CMAKE_CURRENT_LIST_DIR}/thirdparty/mbedtls/oid.c
${CMAKE_CURRENT_LIST_DIR}/thirdparty/mbedtls/pk.c
${CMAKE_CURRENT_LIST_DIR}/thirdparty/mbedtls/pkwrite.c
${CMAKE_CURRENT_LIST_DIR}/thirdparty/mbedtls/pk_wrap.c
${CMAKE_CURRENT_LIST_DIR}/thirdparty/mbedtls/rsa.c
${CMAKE_CURRENT_LIST_DIR}/thirdparty/mbedtls/sha256.c
${CMAKE_CURRENT_LIST_DIR}/thirdparty/mbedtls/pkparse.c
${CMAKE_CURRENT_LIST_DIR}/thirdparty/mbedtls/sha1.c
)



# Includes auto-generated Cmake's scripts. # Includes auto-generated Cmake's scripts.
include(${CMAKE_CURRENT_LIST_DIR}/listfiles/CMakeGen.cmake) include(${CMAKE_CURRENT_LIST_DIR}/listfiles/CMakeGen.cmake)


# Kaa include directories # Kaa include directories
set(KAA_INCLUDE_DIRS set(KAA_INCLUDE_DIRS
${KAA_INCLUDE_PATHS} # Provided by platform cmake ${KAA_INCLUDE_PATHS} # Provided by platform cmake
${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_LIST_DIR}/src
${CMAKE_CURRENT_LIST_DIR}/thirdparty/mbedtls
${KAA_SRC_FOLDER} ${KAA_SRC_FOLDER}
${KAA_THIRDPARTY_INCLUDE_DIR}) ${KAA_THIRDPARTY_INCLUDE_DIR})


Expand All @@ -194,6 +216,8 @@ add_library(kaac ${KAA_SOURCE_FILES})
target_include_directories(kaac PUBLIC ${KAA_INCLUDE_DIRS}) target_include_directories(kaac PUBLIC ${KAA_INCLUDE_DIRS})
target_link_libraries(kaac PRIVATE ${KAA_THIRDPARTY_LIBRARIES}) target_link_libraries(kaac PRIVATE ${KAA_THIRDPARTY_LIBRARIES})


add_dependencies(kaac kaa_rsa_keygen)

message("BOOTSTRAP ENABLED") message("BOOTSTRAP ENABLED")
include(${CMAKE_CURRENT_LIST_DIR}/src/extensions/bootstrap/CMakeLists.txt) include(${CMAKE_CURRENT_LIST_DIR}/src/extensions/bootstrap/CMakeLists.txt)
target_link_libraries(kaac PUBLIC extension_bootstrap) target_link_libraries(kaac PUBLIC extension_bootstrap)
Expand Down Expand Up @@ -252,7 +276,13 @@ else()
add_definitions(-DKAA_DISABLE_FEATURE_NOTIFICATION) add_definitions(-DKAA_DISABLE_FEATURE_NOTIFICATION)
endif() endif()


message("KAA WILL BE INSTALLED TO ${CMAKE_INSTALL_PREFIX} ") if(WITH_ENCRYPTION)
message("ENCRYPTION ENABLED")

add_definitions(-DKAA_ENCRYPTION)
endif()

message("KAA WILL BE INSTALLED TO ${CMAKE_INSTALL_PREFIX}")
install(DIRECTORY ${KAA_SRC_FOLDER}/ DESTINATION include/kaa install(DIRECTORY ${KAA_SRC_FOLDER}/ DESTINATION include/kaa
FILES_MATCHING PATTERN *.h) FILES_MATCHING PATTERN *.h)


Expand All @@ -261,3 +291,11 @@ install(TARGETS kaac DESTINATION lib)
add_subdirectory(Modules/doxygen) add_subdirectory(Modules/doxygen)


add_subdirectory(Modules/cppcheck) add_subdirectory(Modules/cppcheck)

externalproject_add(kaa_rsa_keygen SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/tools/kaa_encryption"
INSTALL_COMMAND "./generate_rsa_keys" COMMENT "Generating RSA headers"
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/kaa_keys)

externalproject_add_step(kaa_rsa_keygen "Copying generated files"
COMMAND mv -f "${CMAKE_CURRENT_BINARY_DIR}/kaa_keys/kaa_keys_gen.h"
"${KAA_SRC_FOLDER}/gen" DEPENDEES install)
3 changes: 2 additions & 1 deletion client/client-multi/client-c/Modules/cppcheck/CMakeLists.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ if(CPPCHECK_COMMAND)
COMMAND ${CPPCHECK_COMMAND} --quiet --enable=all --std=c99 --suppress=unusedFunction COMMAND ${CPPCHECK_COMMAND} --quiet --enable=all --std=c99 --suppress=unusedFunction
--force --error-exitcode=1 --template=gcc -I src/kaa --force --error-exitcode=1 --template=gcc -I src/kaa
--inline-suppr src/ test/ --inline-suppr src/ test/
-ithirdparty/
WORKING_DERICTORY ${KAA_SDK_DIR} WORKING_DERICTORY ${KAA_SDK_DIR}
COMMENT "Running cppcheck" COMMENT "Running cppcheck"
VERBATIM VERBATIM
) )
else() else()
message (STATUS "Could NOT find cppcheck") message (STATUS "Could NOT find cppcheck")
endif() endif()
4 changes: 4 additions & 0 deletions client/client-multi/client-c/assembly/client-c-sdk.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
<directory>${project.basedir}/Modules</directory> <directory>${project.basedir}/Modules</directory>
<outputDirectory>Modules</outputDirectory> <outputDirectory>Modules</outputDirectory>
</fileSet> </fileSet>
<fileSet>
<directory>${project.basedir}/thirdparty</directory>
<outputDirectory>thirdparty</outputDirectory>
</fileSet>
<fileSet> <fileSet>
<directory>${project.basedir}/tools</directory> <directory>${project.basedir}/tools</directory>
<outputDirectory>tools</outputDirectory> <outputDirectory>tools</outputDirectory>
Expand Down
2 changes: 1 addition & 1 deletion client/client-multi/client-c/build.sh
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fi
prepare_build() { prepare_build() {
mkdir -p build-posix mkdir -p build-posix
cd build-posix cd build-posix
cmake -DCMAKE_BUILD_TYPE=Debug -DKAA_MAX_LOG_LEVEL=$MAX_LOG_LEVEL -DKAA_UNITTESTS_COMPILE=1 -DKAA_COLLECT_COVERAGE=1 .. -DCMAKE_C_FLAGS="-Werror" cmake -DCMAKE_BUILD_TYPE=Debug -DKAA_MAX_LOG_LEVEL=$MAX_LOG_LEVEL -DKAA_UNITTESTS_COMPILE=1 -DKAA_COLLECT_COVERAGE=1 -DKAA_ENCRYPTION=1 .. -DCMAKE_C_FLAGS="-Werror"
cd .. cd ..
} }


Expand Down
11 changes: 5 additions & 6 deletions client/client-multi/client-c/listfiles/UnitTest.cmake
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -214,9 +214,8 @@ kaa_add_unit_test(NAME test_kaa_extension_private
# INC_DIRS # INC_DIRS
# test) # test)


# KAA-988 kaa_add_unit_test(NAME test_kaa_channel_manager
#kaa_add_unit_test(NAME test_kaa_channel_manager SOURCES
# SOURCES test/test_kaa_channel_manager.c
# test/test_kaa_channel_manager.c DEPENDS
# DEPENDS kaac ${OPENSSL_LIBRARIES})
# kaac ${OPENSSL_LIBRARIES})
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ set(KAA_SOURCE_FILES
${KAA_SRC_FOLDER}/platform-impl/posix/kaa_client.c ${KAA_SRC_FOLDER}/platform-impl/posix/kaa_client.c
${KAA_SRC_FOLDER}/platform-impl/common/kaa_failover_strategy.c ${KAA_SRC_FOLDER}/platform-impl/common/kaa_failover_strategy.c
${KAA_SRC_FOLDER}/platform-impl/common/sha.c ${KAA_SRC_FOLDER}/platform-impl/common/sha.c
${KAA_SRC_FOLDER}/platform-impl/common/sha1.c
${KAA_SRC_FOLDER}/platform-impl/cc32xx/logger.c ${KAA_SRC_FOLDER}/platform-impl/cc32xx/logger.c
${KAA_SRC_FOLDER}/platform-impl/cc32xx/file_utils.c ${KAA_SRC_FOLDER}/platform-impl/cc32xx/file_utils.c
${KAA_SRC_FOLDER}/platform-impl/cc32xx/key_utils.c
${KAA_SRC_FOLDER}/platform-impl/cc32xx/status.c ${KAA_SRC_FOLDER}/platform-impl/cc32xx/status.c
${KAA_SRC_FOLDER}/platform-impl/cc32xx/configuration_persistence.c ${KAA_SRC_FOLDER}/platform-impl/cc32xx/configuration_persistence.c
${KAA_SRC_FOLDER}/platform-impl/cc32xx/time.c ${KAA_SRC_FOLDER}/platform-impl/cc32xx/time.c
${KAA_SRC_FOLDER}/platform-impl/cc32xx/reboot.c ${KAA_SRC_FOLDER}/platform-impl/cc32xx/reboot.c
${KAA_SRC_FOLDER}/platform-impl/common/common_key_utils.c
${KAA_SRC_FOLDER}/platform-impl/common/ext_log_storage_memory.c ${KAA_SRC_FOLDER}/platform-impl/common/ext_log_storage_memory.c
${KAA_SRC_FOLDER}/platform-impl/common/ext_log_upload_strategies.c ${KAA_SRC_FOLDER}/platform-impl/common/ext_log_upload_strategies.c
) )
Expand Down Expand Up @@ -69,9 +68,3 @@ add_definitions(-DCC32XX_PLATFORM)
set(KAA_THIRDPARTY_LIBRARIES driver simplelink_nonos) set(KAA_THIRDPARTY_LIBRARIES driver simplelink_nonos)


set(KAA_BUILD_STATIC_ONLY 1) set(KAA_BUILD_STATIC_ONLY 1)

set(CC32XX_RSA_KEY ${CMAKE_CURRENT_BINARY_DIR}/cc32xx_rsa_key.h)

execute_process(COMMAND rm ${CC32XX_RSA_KEY})
execute_process(COMMAND java -jar ${KAA_SDK_DIR}/tools/pub_key_generator.jar ${CC32XX_RSA_KEY})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ set(ESP8266_SRC
${ESP8266_SRC_FOLDER}/kaa_client.c ${ESP8266_SRC_FOLDER}/kaa_client.c
${ESP8266_SRC_FOLDER}/configuration_persistence.c ${ESP8266_SRC_FOLDER}/configuration_persistence.c
${ESP8266_SRC_FOLDER}/status.c ${ESP8266_SRC_FOLDER}/status.c
${ESP8266_SRC_FOLDER}/key_utils.c
${ESP8266_SRC_FOLDER}/tcp_utils.c ${ESP8266_SRC_FOLDER}/tcp_utils.c
${ESP8266_SRC_FOLDER}/time.c ${ESP8266_SRC_FOLDER}/time.c
${KAA_SRC_FOLDER}/platform-impl/common/common_key_utils.c
${ESP8266_SRC_FOLDER}/exit.c ${ESP8266_SRC_FOLDER}/exit.c
${ESP8266_SRC_FOLDER}/snprintf.c ${ESP8266_SRC_FOLDER}/snprintf.c
${KAA_SRC_FOLDER}/platform-impl/common/sha.c ${KAA_SRC_FOLDER}/platform-impl/common/sha.c
${KAA_SRC_FOLDER}/platform-impl/common/sha1.c
${KAA_SRC_FOLDER}/platform-impl/common/kaa_failover_strategy.c ${KAA_SRC_FOLDER}/platform-impl/common/kaa_failover_strategy.c
${KAA_SRC_FOLDER}/platform-impl/common/ext_log_storage_memory.c ${KAA_SRC_FOLDER}/platform-impl/common/ext_log_storage_memory.c
${KAA_SRC_FOLDER}/platform-impl/common/ext_log_upload_strategies.c ${KAA_SRC_FOLDER}/platform-impl/common/ext_log_upload_strategies.c
Expand All @@ -46,7 +45,3 @@ set(KAA_SOURCE_FILES ${KAA_SOURCE_FILES} ${ESP8266_SRC})
set(KAA_INCLUDE_PATHS ${KAA_INCLUDE_PATHS} ${ESP8266_INCDIRS} ${ESP8266_SRC_FOLDER}) set(KAA_INCLUDE_PATHS ${KAA_INCLUDE_PATHS} ${ESP8266_INCDIRS} ${ESP8266_SRC_FOLDER})


set(KAA_BUILD_STATIC_ONLY 1) set(KAA_BUILD_STATIC_ONLY 1)

execute_process(COMMAND java -jar ${CMAKE_CURRENT_SOURCE_DIR}/tools/pub_key_generator.jar
${CMAKE_CURRENT_BINARY_DIR}/rsa.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,24 +14,22 @@
# limitations under the License. # limitations under the License.
# #


find_package(OpenSSL REQUIRED) set(KAA_SOURCE_FILES

set(KAA_SOURCE_FILES
${KAA_SOURCE_FILES} ${KAA_SOURCE_FILES}
${KAA_SRC_FOLDER}/platform-impl/posix/kaa_client.c ${KAA_SRC_FOLDER}/platform-impl/posix/kaa_client.c
${KAA_SRC_FOLDER}/platform-impl/posix/sha.c
${KAA_SRC_FOLDER}/platform-impl/posix/logger.c ${KAA_SRC_FOLDER}/platform-impl/posix/logger.c
${KAA_SRC_FOLDER}/platform-impl/posix/file_utils.c ${KAA_SRC_FOLDER}/platform-impl/posix/file_utils.c
${KAA_SRC_FOLDER}/platform-impl/posix/key_utils.c
${KAA_SRC_FOLDER}/platform-impl/posix/status.c ${KAA_SRC_FOLDER}/platform-impl/posix/status.c
${KAA_SRC_FOLDER}/platform-impl/posix/configuration_persistence.c ${KAA_SRC_FOLDER}/platform-impl/posix/configuration_persistence.c
${KAA_SRC_FOLDER}/platform-impl/common/sha.c
${KAA_SRC_FOLDER}/platform-impl/common/common_key_utils.c
${KAA_SRC_FOLDER}/platform-impl/common/kaa_failover_strategy.c ${KAA_SRC_FOLDER}/platform-impl/common/kaa_failover_strategy.c
${KAA_SRC_FOLDER}/platform-impl/common/ext_log_storage_memory.c ${KAA_SRC_FOLDER}/platform-impl/common/ext_log_storage_memory.c
${KAA_SRC_FOLDER}/platform-impl/common/ext_log_upload_strategies.c ${KAA_SRC_FOLDER}/platform-impl/common/ext_log_upload_strategies.c
) )


if(NOT KAA_WITHOUT_TCP_CHANNEL) if(NOT KAA_WITHOUT_TCP_CHANNEL)
set(KAA_SOURCE_FILES set(KAA_SOURCE_FILES
${KAA_SOURCE_FILES} ${KAA_SOURCE_FILES}
${KAA_SRC_FOLDER}/kaa_protocols/kaa_tcp/kaatcp_parser.c ${KAA_SRC_FOLDER}/kaa_protocols/kaa_tcp/kaatcp_parser.c
${KAA_SRC_FOLDER}/kaa_protocols/kaa_tcp/kaatcp_request.c ${KAA_SRC_FOLDER}/kaa_protocols/kaa_tcp/kaatcp_request.c
Expand All @@ -40,11 +38,4 @@ if(NOT KAA_WITHOUT_TCP_CHANNEL)
) )
endif() endif()


set(KAA_THIRDPARTY_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR})

set(KAA_INCLUDE_PATHS ${KAA_SRC_FOLDER}/platform-impl/posix) set(KAA_INCLUDE_PATHS ${KAA_SRC_FOLDER}/platform-impl/posix)

set(KAA_THIRDPARTY_LIBRARIES
${KAA_THIRDPARTY_LIBRARIES}
${OPENSSL_LIBRARIES}
)
7 changes: 2 additions & 5 deletions client/client-multi/client-c/pom.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -77,17 +77,15 @@


<exclude>build-posix/gcovr-report.xml</exclude> <exclude>build-posix/gcovr-report.xml</exclude>


<!-- SHA implementation from RFC 3174 -->
<exclude>src/kaa/platform-impl/common/sha1.h</exclude>
<exclude>src/kaa/platform-impl/common/sha1.c</exclude>

<exclude>src/kaa/platform-impl/esp8266/snprintf.c</exclude> <exclude>src/kaa/platform-impl/esp8266/snprintf.c</exclude>


<exclude>gcovr</exclude> <exclude>gcovr</exclude>


<exclude>docs/</exclude> <exclude>docs/</exclude>
<exclude>thirdparty/</exclude>
<exclude>nix/astyle/max_indent.patch</exclude> <exclude>nix/astyle/max_indent.patch</exclude>


<exclude>src/kaa/gen/kaa_keys_gen.h</exclude>
<!-- Temporary build files --> <!-- Temporary build files -->
<exclude>build-*/</exclude> <exclude>build-*/</exclude>
<exclude>Makefile</exclude> <exclude>Makefile</exclude>
Expand All @@ -110,7 +108,6 @@
<configuration> <configuration>
<excludes> <excludes>
<exclude>**/avro_src/**</exclude> <exclude>**/avro_src/**</exclude>
<exclude>**/platform-impl/common/sha1.h</exclude>
<exclude>**/sha1.c</exclude> <exclude>**/sha1.c</exclude>
<exclude>**/snprintf.c</exclude> <exclude>**/snprintf.c</exclude>
</excludes> </excludes>
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -250,21 +250,15 @@ kaa_error_t kaa_profile_request_get_size(kaa_profile_manager_t *self, size_t *ex
#endif #endif


if (!self->status->is_registered) { if (!self->status->is_registered) {
bool need_deallocation = false;

if (!self->extension_data->public_key.buffer) { if (!self->extension_data->public_key.buffer) {
ext_get_endpoint_public_key((char **)&self->extension_data->public_key.buffer ext_get_endpoint_public_key((uint8_t **)&self->extension_data->public_key.buffer,
, (size_t *)&self->extension_data->public_key.size (size_t *)&self->extension_data->public_key.size);
, &need_deallocation);
} }


if (self->extension_data->public_key.buffer && self->extension_data->public_key.size > 0) { if (self->extension_data->public_key.buffer && self->extension_data->public_key.size > 0) {
*expected_size += sizeof(uint32_t); // public key size *expected_size += sizeof(uint32_t); // public key size
*expected_size += kaa_aligned_size_get(self->extension_data->public_key.size); // public key *expected_size += kaa_aligned_size_get(self->extension_data->public_key.size); // public key


if (need_deallocation) {
self->extension_data->public_key.destroy = kaa_data_destroy;
}
} else { } else {
return KAA_ERR_BADDATA; return KAA_ERR_BADDATA;
} }
Expand Down
35 changes: 11 additions & 24 deletions client/client-multi/client-c/src/kaa/kaa.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ kaa_error_t kaa_init(kaa_context_t **kaa_context_p)
// Initialize logger // Initialize logger
kaa_logger_t *logger = NULL; kaa_logger_t *logger = NULL;
kaa_error_t error = kaa_log_create(&logger, KAA_MAX_LOG_MESSAGE_LENGTH, KAA_MAX_LOG_LEVEL, NULL); // TODO: make log destination configurable kaa_error_t error = kaa_log_create(&logger, KAA_MAX_LOG_MESSAGE_LENGTH, KAA_MAX_LOG_LEVEL, NULL); // TODO: make log destination configurable
if (error) if (error) {
return error; return error;
}


KAA_LOG_INFO(logger, KAA_ERR_NONE, "Kaa SDK version %s, commit hash %s", KAA_BUILD_VERSION, KAA_BUILD_COMMIT_HASH); KAA_LOG_INFO(logger, KAA_ERR_NONE, "Kaa SDK version %s, commit hash %s", KAA_BUILD_VERSION, KAA_BUILD_COMMIT_HASH);


Expand All @@ -133,35 +134,19 @@ kaa_error_t kaa_init(kaa_context_t **kaa_context_p)
} }


// Initialize endpoint identity // Initialize endpoint identity
char *pub_key_buffer = NULL; uint8_t *sha1 = NULL;
size_t pub_key_buffer_size = 0; size_t sha1_size = 0;
bool need_deallocation = false;

ext_get_endpoint_public_key(&pub_key_buffer, &pub_key_buffer_size, &need_deallocation);

kaa_digest pub_key_hash;
error = ext_calculate_sha_hash(pub_key_buffer, pub_key_buffer_size, pub_key_hash);

if (need_deallocation && pub_key_buffer_size > 0) {
KAA_FREE(pub_key_buffer);
}


error = kaa_init_keys();
if (error) { if (error) {
KAA_LOG_FATAL(logger, error, "Failed to calculate EP ID"); KAA_LOG_ERROR(logger, error, "Failed to initialize keys");
kaa_context_destroy(*kaa_context_p); kaa_context_destroy(*kaa_context_p);
*kaa_context_p = NULL;
kaa_log_destroy(logger); kaa_log_destroy(logger);
return error; return error;
} }


error = ext_copy_sha_hash((*kaa_context_p)->status->status_instance->endpoint_public_key_hash, pub_key_hash); ext_get_sha1_public(&sha1, &sha1_size);
if (error) { ext_copy_sha_hash((*kaa_context_p)->status->status_instance->endpoint_public_key_hash, sha1);
KAA_LOG_FATAL(logger, error, "Failed to set Endpoint public key");
kaa_context_destroy(*kaa_context_p);
*kaa_context_p = NULL;
kaa_log_destroy(logger);
return error;
}


return kaa_status_set_updated((*kaa_context_p)->status->status_instance, true); return kaa_status_set_updated((*kaa_context_p)->status->status_instance, true);
} }
Expand Down Expand Up @@ -201,9 +186,11 @@ kaa_error_t kaa_deinit(kaa_context_t *kaa_context)


kaa_logger_t *logger = kaa_context->logger; kaa_logger_t *logger = kaa_context->logger;
kaa_error_t error = kaa_context_destroy(kaa_context); kaa_error_t error = kaa_context_destroy(kaa_context);
if (error) if (error) {
KAA_LOG_ERROR(logger, error, "Failed to destroy Kaa context"); KAA_LOG_ERROR(logger, error, "Failed to destroy Kaa context");
}
kaa_log_destroy(logger); kaa_log_destroy(logger);
kaa_deinit_keys();
return error; return error;
} }


Expand Down
Loading

0 comments on commit 91641cd

Please sign in to comment.