diff --git a/CMakeLists.txt b/CMakeLists.txt index 08f7819a..e3cdfd43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,26 +1,6 @@ # Configurable options set(TARGET_ESPIDF FALSE CACHE BOOL "Build for the espidf platform") - -option(ATSDK_BUILD_TESTS "Build tests for atsdk ON | \"unit\" | \"func\" " OFF) - -# to avoid caching issues -if(ATSDK_BUILD_TESTS STREQUAL "func") - message("FUNCTIONAL TESTING ENABLED") - set(ATSDK_BUILD_UNIT_TESTS OFF) - set(ATSDK_BUILD_FUNCTIONAL_TESTS ON) -elseif(ATSDK_BUILD_TESTS STREQUAL "unit") - message("UNIT TESTING ENABLED") - set(ATSDK_BUILD_UNIT_TESTS ON) - set(ATSDK_BUILD_FUNCTIONAL_TESTS OFF) -elseif(ATSDK_BUILD_TESTS) - message("ALL TESTING ENABLED") - set(ATSDK_BUILD_FUNCTIONAL_TESTS ON) - set(ATSDK_BUILD_UNIT_TESTS ON) -else() - message("TESTING DISABLED") - set(ATSDK_BUILD_UNIT_TESTS OFF) - set(ATSDK_BUILD_FUNCTIONAL_TESTS OFF) -endif() +option(ATSDK_BUILD_TESTS "Build tests for atsdk" OFF) # Basic project setup cmake_minimum_required(VERSION 3.24) @@ -29,20 +9,20 @@ cmake_policy(SET CMP0135 NEW) include(GNUInstallDirs) project( - atsdk - VERSION 0.0.1 - DESCRIPTION "Atsign's atSDK library" - HOMEPAGE_URL https://atsign.com - LANGUAGES C + atsdk + VERSION 0.0.1 + DESCRIPTION "Atsign's atSDK library" + HOMEPAGE_URL https://atsign.com + LANGUAGES C ) # Determine if atchops is being built as a subproject using add_subdirectory() -if(NOT DEFINED ATSDK_AS_SUBPROJECT) - set(ATSDK_AS_SUBPROJECT ON) - if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) - set(ATSDK_AS_SUBPROJECT OFF) - endif() -endif() +if (NOT DEFINED ATSDK_AS_SUBPROJECT) + set(ATSDK_AS_SUBPROJECT ON) + if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + set(ATSDK_AS_SUBPROJECT OFF) + endif () +endif () message(STATUS "[ATSDK] ATSDK_AS_SUBPROJECT: ${ATSDK_AS_SUBPROJECT}") # install each package @@ -50,66 +30,62 @@ message(STATUS "Building atlogger") add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/packages/atlogger) message(STATUS "Building atchops") -set(ATCHOPS_BUILD_TESTS ${ATSDK_BUILD_UNIT_TESTS}) +set(ATCHOPS_BUILD_TESTS ${ATSDK_BUILD_TESTS}) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/packages/atchops) message(STATUS "Building atclient") -set(ATCLIENT_BUILD_TESTS ${ATSDK_BUILD_UNIT_TESTS}) +set(ATCLIENT_BUILD_TESTS ${ATSDK_BUILD_TESTS}) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/packages/atclient) +message(STATUS "Building atcommons") +set(ATCOMMONS_BUILD_TESTS ${ATSDK_BUILD_TESTS}) +add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/packages/atcommons) + message(STATUS "Building atauth") -set(ATAUTH_BUILD_TESTS ${ATSDK_BUILD_UNIT_TESTS}) +set(ATAUTH_BUILD_TESTS ${ATSDK_BUILD_TESTS}) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/packages/atauth) -if(NOT ESP_PLATFORM) - # install dependencies - set( - ATSDK_TARGETS - mbedtls - mbedx509 - mbedcrypto - everest - p256m - atchops - cjson - atlogger - atclient - atcommons - atauth - ) - - install( - TARGETS ${ATSDK_TARGETS} - EXPORT ${PROJECT_NAME}-config - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) - - # export dependencies - if(NOT ATSDK_AS_SUBPROJECT) - export(PACKAGE ${PROJECT_NAME}) - - # install as a config.cmake - install( - EXPORT ${PROJECT_NAME}-config - NAMESPACE ${PROJECT_NAME}:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} - FILE ${PROJECT_NAME}-config.cmake +if (NOT ESP_PLATFORM) + # install dependencies + set( + ATSDK_TARGETS + mbedtls + mbedx509 + mbedcrypto + everest + p256m + uuid4-static + atchops + cjson + atlogger + atclient + atcommons + atauth ) - # export the config.cmake - export( - EXPORT ${PROJECT_NAME}-config - NAMESPACE ${PROJECT_NAME}:: - FILE "cmake/${PROJECT_NAME}-config.cmake" + install( + TARGETS ${ATSDK_TARGETS} + EXPORT ${PROJECT_NAME}-config + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) - endif() -endif() - -if(ATSDK_BUILD_FUNCTIONAL_TESTS) - message(STATUS "Building functional tests") - add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tests/functional_tests) -endif() -if(ATSDK_BUILD_UNIT_TESTS OR ATSDK_BUILD_FUNCTIONAL_TESTS) - enable_testing() -endif() + # export dependencies + if (NOT ATSDK_AS_SUBPROJECT) + export(PACKAGE ${PROJECT_NAME}) + + # install as a config.cmake + install( + EXPORT ${PROJECT_NAME}-config + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + FILE ${PROJECT_NAME}-config.cmake + ) + + # export the config.cmake + export( + EXPORT ${PROJECT_NAME}-config + NAMESPACE ${PROJECT_NAME}:: + FILE "cmake/${PROJECT_NAME}-config.cmake" + ) + endif () +endif () diff --git a/examples/desktop/at_talk/src/main.c b/examples/desktop/at_talk/src/main.c index a7521e90..8face76d 100644 --- a/examples/desktop/at_talk/src/main.c +++ b/examples/desktop/at_talk/src/main.c @@ -15,6 +15,7 @@ #include #include #include +#include #define ROOT_HOST "root.atsign.org" #define ROOT_PORT 64 diff --git a/examples/desktop/repl/src/main.c b/examples/desktop/repl/src/main.c index 41aa9707..11cf71b6 100644 --- a/examples/desktop/repl/src/main.c +++ b/examples/desktop/repl/src/main.c @@ -133,12 +133,12 @@ static int set_up_pkam_auth_options(atclient_authenticate_options *pkam_authenti goto exit; } - if ((ret = atclient_authenticate_options_set_atdirectory_host(pkam_authenticate_options, root_host)) != 0) { + if ((ret = atclient_authenticate_options_set_at_directory_host(pkam_authenticate_options, root_host)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to set at directory host\n"); goto exit; } - if ((ret = atclient_authenticate_options_set_atdirectory_port(pkam_authenticate_options, root_port)) != 0) { + if ((ret = atclient_authenticate_options_set_at_directory_port(pkam_authenticate_options, root_port)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to set at directory port\n"); goto exit; } diff --git a/packages/atauth/CMakeLists.txt b/packages/atauth/CMakeLists.txt index 1c8f343d..19fee328 100644 --- a/packages/atauth/CMakeLists.txt +++ b/packages/atauth/CMakeLists.txt @@ -3,14 +3,13 @@ option(ATAUTH_BUILD_TESTS "Build tests for atauth" OFF) option(ATAUTH_BUILD_EXECUTABLES "Build executables in atauth" ON) # Set include directory and file sources -set(ATAUTH_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include) -set( - ATAUTH_SOURCES - ${CMAKE_CURRENT_LIST_DIR}/src/send_enroll_request.c - ${CMAKE_CURRENT_LIST_DIR}/src/atactivate_arg_parser.c - ${CMAKE_CURRENT_LIST_DIR}/src/atactivate.c - ${CMAKE_CURRENT_LIST_DIR}/src/atauth_build_atkeys_file_path.c - ${CMAKE_CURRENT_LIST_DIR}/src/atauth_fetch_home_dir.c +set (ATAUTH_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include) +set (ATAUTH_SOURCES + ${CMAKE_CURRENT_LIST_DIR}/src/send_enroll_request.c + ${CMAKE_CURRENT_LIST_DIR}/src/atactivate_arg_parser.c + ${CMAKE_CURRENT_LIST_DIR}/src/atactivate.c + ${CMAKE_CURRENT_LIST_DIR}/src/atauth_build_atkeys_file_path.c + ${CMAKE_CURRENT_LIST_DIR}/src/atauth_fetch_home_dir.c ) # Project setup @@ -21,134 +20,131 @@ cmake_policy(SET CMP0135 NEW) ## not adding the esp target yet project( - atauth - VERSION 0.0.1 - DESCRIPTION "Atsign technology authentication library" - HOMEPAGE_URL https://atsign.com - LANGUAGES C + atauth + VERSION 0.0.1 + DESCRIPTION "Atsign technology authentication library" + HOMEPAGE_URL https://atsign.com + LANGUAGES C ) if(NOT ESP_PLATFORM) - include(GNUInstallDirs) + include(GNUInstallDirs) - # Determine if atchops is being built as a subproject using add_subdirectory() - if(NOT DEFINED ATAUTH_AS_SUBPROJECT) - set(ATAUTH_AS_SUBPROJECT ON) + # Determine if atchops is being built as a subproject using add_subdirectory() + if(NOT DEFINED ATAUTH_AS_SUBPROJECT) + set(ATAUTH_AS_SUBPROJECT ON) - if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) - set(ATAUTH_AS_SUBPROJECT OFF) + if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + set(ATAUTH_AS_SUBPROJECT OFF) + endif () + endif () + + message(STATUS "[ATAUTH] ATAUTH_AS_SUBPROJECT: ${ATAUTH_AS_SUBPROJECT}") + + # Import cjson + if (NOT TARGET cjson) + include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/find_cjson.cmake) + endif () + + # Import mbedtls + if(NOT TARGET mbedcrypto OR NOT TARGET everest OR NOT TARGET p256m) + include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/find_mbedtls.cmake) endif() - endif() - - message(STATUS "[ATAUTH] ATAUTH_AS_SUBPROJECT: ${ATAUTH_AS_SUBPROJECT}") - - # Import cjson - if(NOT TARGET cjson) - include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/find_cjson.cmake) - endif() - - # Import mbedtls - if(NOT TARGET mbedcrypto OR NOT TARGET everest OR NOT TARGET p256m) - include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/find_mbedtls.cmake) - endif() - - # Import atlogger - if(NOT TARGET atlogger) - set(atlogger_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../atlogger) - include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/atlogger.cmake) - endif() - - # Import atcommons - if(NOT TARGET atcommons) - set(atcommons_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../atcommons) - include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/atcommons.cmake) - endif() - - # Import atclient - if(NOT TARGET atclient) - set(atclient_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../atclient) - include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/atclient.cmake) - endif() - - # Create library targets - add_library(${PROJECT_NAME} STATIC ${ATAUTH_SOURCES}) - add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) - - # LINK - # Link include headers to library targets - target_include_directories( - ${PROJECT_NAME} - PUBLIC - $ - $ - $ - ) - - set( - ATAUTH_INSTALL_TARGETS - cjson - mbedtls - mbedx509 - mbedcrypto - everest - p256m - atclient - atcommons - atlogger - atchops - ) - target_link_libraries(${PROJECT_NAME} PUBLIC ${ATAUTH_INSTALL_TARGETS}) - - # INSTALL - # Install the include headers - install( - DIRECTORY ${ATAUTH_INCLUDE_DIR}/${PROJECT_NAME} - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - ) - - install( - FILES ${cJSON_SOURCE_DIR}/cJSON.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - ) - - # Install libraries to config target - install( - TARGETS ${PROJECT_NAME} ${ATAUTH_INSTALL_TARGETS} - EXPORT ${PROJECT_NAME}-config - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) - - # Build atactivate executable - if(ATAUTH_BUILD_EXECUTABLES) - add_executable(atactivate ${CMAKE_CURRENT_LIST_DIR}/src/atactivate.c) - target_link_libraries( - atactivate - PRIVATE cjson atlogger atcommons atchops atclient atauth + + # Import atlogger + if (NOT TARGET atlogger) + set(atlogger_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../atlogger) + include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/atlogger.cmake) + endif () + + # Import atcommons + if(NOT TARGET atcommons) + set(atcommons_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../atcommons) + include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/atcommons.cmake) + endif () + + # Import atclient + if(NOT TARGET atclient) + set(atclient_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../atclient) + include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/atclient.cmake) + endif () + + # Create library targets + add_library(${PROJECT_NAME} STATIC ${ATAUTH_SOURCES}) + add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) + + # LINK + # Link include headers to library targets + target_include_directories( + ${PROJECT_NAME} + PUBLIC + $ + $ + $ ) - endif() - # EXPORT - if(NOT ATAUTH_AS_SUBPROJECT) - # install as a config.make + set( + ATAUTH_INSTALL_TARGETS + cjson + mbedtls + mbedx509 + mbedcrypto + everest + p256m + uuid4-static + atclient + atcommons + atlogger + atchops + ) + target_link_libraries(${PROJECT_NAME} PUBLIC ${ATAUTH_INSTALL_TARGETS}) + + # INSTALL + # Install the include headers install( - EXPORT ${PROJECT_NAME}-config - NAMESPACE ${PROJECT_NAME}:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} - FILE ${PROJECT_NAME}-config.cmake + DIRECTORY ${ATAUTH_INCLUDE_DIR}/${PROJECT_NAME} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) - #export the config.cmake - export( - EXPORT ${PROJECT_NAME}-config - NAMESPACE ${PROJECT_NAME}:: - FILE ${PROJECT_NAME}-config.cmake + install( + FILES ${cJSON_SOURCE_DIR}/cJSON.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) - endif() - # Build the tests - No tests for ATAUTH yet - # if(ATAUTH_BUILD_TESTS) - # enable_testing() - # add_subdirectory(tests) - # endif() -endif() + # Install libraries to config target + install( + TARGETS ${PROJECT_NAME} ${ATAUTH_INSTALL_TARGETS} + EXPORT ${PROJECT_NAME}-config + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) + # Build atactivate executable + if (ATAUTH_BUILD_EXECUTABLES) + add_executable(atactivate ${CMAKE_CURRENT_LIST_DIR}/src/atactivate.c) + target_link_libraries(atactivate PRIVATE cjson atlogger atcommons atchops atclient atauth) + endif () + + # EXPORT + if (NOT ATAUTH_AS_SUBPROJECT) + # install as a config.make + install( + EXPORT ${PROJECT_NAME}-config + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + FILE ${PROJECT_NAME}-config.cmake + ) + + #export the config.cmake + export( + EXPORT ${PROJECT_NAME}-config + NAMESPACE ${PROJECT_NAME}:: + FILE ${PROJECT_NAME}-config.cmake + ) + endif () + + # Build the tests - No tests for ATAUTH yet + # if(ATAUTH_BUILD_TESTS) + # enable_testing() + # add_subdirectory(tests) + # endif() +endif () \ No newline at end of file diff --git a/packages/atchops/CMakeLists.txt b/packages/atchops/CMakeLists.txt index f064f1fe..90e5f096 100644 --- a/packages/atchops/CMakeLists.txt +++ b/packages/atchops/CMakeLists.txt @@ -24,11 +24,11 @@ set(CMAKE_C_STANDARD 99) cmake_policy(SET CMP0135 NEW) # register as an espidf component -if(ESP_PLATFORM) +if(ESP_PLATFORM) idf_component_register( SRCS ${ATCHOPS_SOURCES} INCLUDE_DIRS ${ATCHOPS_INCLUDE_DIR} - REQUIRES mbedtls atlogger + REQUIRES mbedtls atlogger uuid4 ) add_custom_command( @@ -65,10 +65,15 @@ if(NOT ESP_PLATFORM) message(STATUS "[ATCHOPS] ATCHOPS_AS_SUBPROJECT: ${ATCHOPS_AS_SUBPROJECT}") # Import mbedtls - if(NOT TARGET mbedcrypto) + if(NOT TARGET mbedcrypto OR NOT TARGET everest OR NOT TARGET p256m) include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/find_mbedtls.cmake) endif() + # Import uuid4 + if(NOT TARGET uuid4-static) + include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/find_uuid4.cmake) + endif() + # Import atlogger if(NOT TARGET atlogger) set(atlogger_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../atlogger) @@ -85,12 +90,18 @@ if(NOT ESP_PLATFORM) ${PROJECT_NAME} PUBLIC $ # when `cmake ..` look for headers when building in ./packages/atchops/include/atchops/*.h - $ $ # when `make install` look inside of something like /usr/local/include/** ) # Link dependencies to library targets - set(ATCHOPS_INSTALL_TARGETS atlogger mbedcrypto everest p256m) + set( + ATCHOPS_INSTALL_TARGETS + atlogger + mbedcrypto + everest + p256m + uuid4-static + ) target_link_libraries(${PROJECT_NAME} PUBLIC ${ATCHOPS_INSTALL_TARGETS}) # INSTALL diff --git a/packages/atchops/include/atchops/hex.h b/packages/atchops/include/atchops/hex.h index 180f04e5..f336a1be 100644 --- a/packages/atchops/include/atchops/hex.h +++ b/packages/atchops/include/atchops/hex.h @@ -3,7 +3,6 @@ #ifdef __cplusplus extern "C" { #endif -#include // IWYU pragma: keep #include /** diff --git a/packages/atchops/include/atchops/utf8.h b/packages/atchops/include/atchops/utf8.h index 37dad714..4bb5b2a7 100644 --- a/packages/atchops/include/atchops/utf8.h +++ b/packages/atchops/include/atchops/utf8.h @@ -3,7 +3,6 @@ #ifdef __cplusplus extern "C" { #endif -#include // IWYU pragma: keep #include /** diff --git a/packages/atchops/src/aes.c b/packages/atchops/src/aes.c index d0f05919..85f8eb41 100644 --- a/packages/atchops/src/aes.c +++ b/packages/atchops/src/aes.c @@ -2,10 +2,9 @@ #include "atchops/base64.h" #include "atchops/constants.h" #include "atchops/mbedtls.h" -#include -#include -#include #include +#include +#include #define TAG "aes" @@ -15,13 +14,13 @@ int atchops_aes_generate_key(unsigned char *key, const enum atchops_aes_size key /* * 1. Validate arguments */ - if (key == NULL) { + if(key == NULL) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "key is NULL\n"); return ret; } - if (keybits != ATCHOPS_AES_256) { + if(keybits != ATCHOPS_AES_256) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Unsupported keybits\n"); return ret; @@ -46,8 +45,7 @@ int atchops_aes_generate_key(unsigned char *key, const enum atchops_aes_size key /* * 3. Seed the random number generator */ - if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (unsigned char *)personlization, - strlen(personlization))) != 0) { + if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (unsigned char *)personlization, strlen(personlization))) != 0) { goto exit; } diff --git a/packages/atchops/src/hex.c b/packages/atchops/src/hex.c index b6cef8ca..f6e0b8f2 100644 --- a/packages/atchops/src/hex.c +++ b/packages/atchops/src/hex.c @@ -1,5 +1,4 @@ #include "atchops/hex.h" -#include #include #include @@ -30,7 +29,7 @@ int atchops_hex_to_bytes(unsigned char *bytes, const size_t byte_len, const char int atchops_bytes_to_hex(char *hex_str, const size_t hex_str_len, const unsigned char *bytes, const size_t bytes_len) { // Ensure the hex string buffer is large enough: 2 chars for each byte + 1 for null terminator if (hex_str_len < (bytes_len * 2 + 1)) { - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Insufficient space for hex string\n"); + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Insufficient space for hex string\n"); return -1; } @@ -40,4 +39,4 @@ int atchops_bytes_to_hex(char *hex_str, const size_t hex_str_len, const unsigned hex_str[bytes_len * 2] = '\0'; return 0; -} +} \ No newline at end of file diff --git a/packages/atchops/src/utf8.c b/packages/atchops/src/utf8.c index 62f7e657..9f04c0ad 100644 --- a/packages/atchops/src/utf8.c +++ b/packages/atchops/src/utf8.c @@ -1,4 +1,3 @@ -#include #include #include #include diff --git a/packages/atclient/CMakeLists.txt b/packages/atclient/CMakeLists.txt index 89bcb655..c625dd4a 100644 --- a/packages/atclient/CMakeLists.txt +++ b/packages/atclient/CMakeLists.txt @@ -81,7 +81,7 @@ if(NOT ESP_PLATFORM) message(STATUS "[ATCLIENT] ATCLIENT_AS_SUBPROJECT: ${ATCLIENT_AS_SUBPROJECT}") # Import mbedtls - if(NOT TARGET mbedcrypto) + if(NOT TARGET mbedcrypto OR NOT TARGET everest OR NOT TARGET p256m) include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/find_mbedtls.cmake) endif() @@ -106,7 +106,7 @@ if(NOT ESP_PLATFORM) if(NOT TARGET atcommons) set(atcommons_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../atcommons) include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/atcommons.cmake) - endif() + endif () # Create library targets add_library(${PROJECT_NAME} STATIC ${ATCLIENT_SOURCES}) @@ -126,13 +126,13 @@ if(NOT ESP_PLATFORM) set( ATCLIENT_INSTALL_TARGETS atlogger - atcommons atchops mbedtls mbedx509 mbedcrypto everest p256m + uuid4-static cjson ) target_link_libraries(${PROJECT_NAME} PUBLIC ${ATCLIENT_INSTALL_TARGETS}) diff --git a/packages/atclient/include/atclient/atkey.h b/packages/atclient/include/atclient/atkey.h index 5f1ffca9..504dd0a5 100644 --- a/packages/atclient/include/atclient/atkey.h +++ b/packages/atclient/include/atclient/atkey.h @@ -5,7 +5,6 @@ extern "C" { #endif #include "atclient/metadata.h" -#include // IWYU pragma: keep #include #include @@ -275,8 +274,8 @@ int atclient_atkey_create_shared_key(atclient_atkey *atkey, const char *name, co const char *shared_with, const char *namespace_str); /** - * @brief Populates the atclient_key struct with the reserved key name provided. Reserved keys are usually restricted - * keys that are required the server for proper functioning and sometimes might not follow the standard atkey fomrmat + * @brief Populates the atclient_key struct with the reserved key name provided. Reserved keys are usually restricted keys + * that are required the server for proper functioning and sometimes might not follow the standard atkey fomrmat * * @param atkey the atkey struct to populate, assumed that this was already initialized via atclient_atkey_init * @param name name of your key, e.g. "privatekey:at_secret" diff --git a/packages/atclient/include/atclient/atkeys_file.h b/packages/atclient/include/atclient/atkeys_file.h index 00e71596..526e5448 100644 --- a/packages/atclient/include/atclient/atkeys_file.h +++ b/packages/atclient/include/atclient/atkeys_file.h @@ -3,7 +3,6 @@ #ifdef __cplusplus extern "C" { #endif -#include // IWYU pragma: keep #include #include #include diff --git a/packages/atclient/include/atclient/request_options.h b/packages/atclient/include/atclient/request_options.h index 69741cda..2fbb15bc 100644 --- a/packages/atclient/include/atclient/request_options.h +++ b/packages/atclient/include/atclient/request_options.h @@ -4,7 +4,6 @@ extern "C" { #endif -#include // IWYU pragma: keep #include #include #include @@ -40,12 +39,12 @@ extern "C" { #define ATCLIENT_GET_ATKEYS_REQUEST_OPTIONS_REGEX_INITIALIZED (VALUE_INITIALIZED << 0) #define ATCLIENT_GET_ATKEYS_REQUEST_OPTIONS_SHOW_HIDDEN_INITIALIZED (VALUE_INITIALIZED << 1) -#define ATCLIENT_AUTHENTICATE_OPTIONS_ATDIRECTORY_HOST_INDEX 0 -#define ATCLIENT_AUTHENTICATE_OPTIONS_ATDIRECTORY_PORT_INDEX 0 +#define ATCLIENT_AUTHENTICATE_OPTIONS_AT_DIRECTORY_HOST_INDEX 0 +#define ATCLIENT_AUTHENTICATE_OPTIONS_AT_DIRECTORY_PORT_INDEX 0 #define ATCLIENT_AUTHENTICATE_OPTIONS_ATSERVER_HOST_INDEX 0 #define ATCLIENT_AUTHENTICATE_OPTIONS_ATSERVER_PORT_INDEX 0 -#define ATCLIENT_AUTHENTICATE_OPTIONS_ATDIRECTORY_HOST_INITIALIZED (VALUE_INITIALIZED << 0) -#define ATCLIENT_AUTHENTICATE_OPTIONS_ATDIRECTORY_PORT_INITIALIZED (VALUE_INITIALIZED << 1) +#define ATCLIENT_AUTHENTICATE_OPTIONS_AT_DIRECTORY_HOST_INITIALIZED (VALUE_INITIALIZED << 0) +#define ATCLIENT_AUTHENTICATE_OPTIONS_AT_DIRECTORY_PORT_INITIALIZED (VALUE_INITIALIZED << 1) #define ATCLIENT_AUTHENTICATE_OPTIONS_ATSERVER_HOST_INITIALIZED (VALUE_INITIALIZED << 2) #define ATCLIENT_AUTHENTICATE_OPTIONS_ATSERVER_PORT_INITIALIZED (VALUE_INITIALIZED << 3) @@ -261,12 +260,12 @@ void atclient_authenticate_options_init(atclient_authenticate_options *options); void atclient_authenticate_options_free(atclient_authenticate_options *options); bool atclient_authenticate_options_is_atdirectory_host_initialized(const atclient_authenticate_options *options); -int atclient_authenticate_options_set_atdirectory_host(atclient_authenticate_options *options, char *atdirectory_host); -void atclient_authenticate_options_unset_atdirectory_host(atclient_authenticate_options *options); +int atclient_authenticate_options_set_at_directory_host(atclient_authenticate_options *options, char *atdirectory_host); +void atclient_authenticate_options_unset_at_directory_host(atclient_authenticate_options *options); bool atclient_authenticate_options_is_atdirectory_port_initialized(const atclient_authenticate_options *options); -int atclient_authenticate_options_set_atdirectory_port(atclient_authenticate_options *options, int atdirectory_port); -void atclient_authenticate_options_unset_atdirectory_port(atclient_authenticate_options *options); +int atclient_authenticate_options_set_at_directory_port(atclient_authenticate_options *options, int atdirectory_port); +void atclient_authenticate_options_unset_at_directory_port(atclient_authenticate_options *options); bool atclient_authenticate_options_is_atserver_host_initialized(const atclient_authenticate_options *options); int atclient_authenticate_options_set_atserver_host(atclient_authenticate_options *options, char *atserver_host); diff --git a/packages/atclient/src/atclient.c b/packages/atclient/src/atclient.c index d14c5809..e3845c31 100755 --- a/packages/atclient/src/atclient.c +++ b/packages/atclient/src/atclient.c @@ -11,7 +11,6 @@ #include "atclient/request_options.h" #include "atclient/string_utils.h" #include "atlogger/atlogger.h" -#include #include #include #include @@ -455,7 +454,7 @@ int atclient_cram_authenticate(atclient *ctx, const char *atsign, const char *cr goto exit; } char *atsign_without_at = malloc(sizeof(char) * strlen(atsign_with_at) + 1); - if (atsign_without_at == NULL) { + if(atsign_without_at == NULL) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Could not allocate memory for atsign_without_at"); ret = -1; goto exit; @@ -575,7 +574,7 @@ int atclient_cram_authenticate(atclient *ctx, const char *atsign, const char *cr * 10a. Build `cram:` noop_cmd */ cram_cmd = malloc(sizeof(char) * ATCLIENT_CRAM_COMMAND_LEN + 1); // free later - if (cram_cmd == NULL) { + if(cram_cmd == NULL) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Could not allocate memory for cram_cmd"); ret = -1; goto exit; diff --git a/packages/atclient/src/atclient_delete.c b/packages/atclient/src/atclient_delete.c index d2e799f1..d2c11d82 100755 --- a/packages/atclient/src/atclient_delete.c +++ b/packages/atclient/src/atclient_delete.c @@ -3,7 +3,6 @@ #include "atclient/constants.h" #include "atclient/string_utils.h" #include "atlogger/atlogger.h" -#include #include #include #include @@ -19,7 +18,7 @@ int atclient_delete(atclient *atclient, const atclient_atkey *atkey, const atcli /* * 1. Check arguments */ - if ((ret = atclient_delete_validate_arguments(atclient, atkey, (atclient_delete_request_options *)options)) != 0) { + if ((ret = atclient_delete_validate_arguments(atclient, atkey, (atclient_delete_request_options*)options)) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_delete_validate_arguments: %d\n", ret); return ret; @@ -66,8 +65,8 @@ int atclient_delete(atclient *atclient, const atclient_atkey *atkey, const atcli /* * 4. Send command */ - if ((ret = atclient_connection_send(&atclient->atserver_connection, (unsigned char *)delete_cmd, delete_cmd_size - 1, - recv, recv_size, &recv_len)) != 0) { + if ((ret = atclient_connection_send(&atclient->atserver_connection, (unsigned char *)delete_cmd, + delete_cmd_size - 1, recv, recv_size, &recv_len)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_connection_send: %d\n", ret); goto exit; } @@ -135,8 +134,7 @@ static int atclient_delete_validate_arguments(const atclient *atclient, const at } // skip atclient_atkey_is_shared_by_initialized() if atclient_delete_request_options->skip_shared_by_check is true - if (atclient_delete_request_options_is_skip_shared_by_check_flag_initialized(options) && - options->skip_shared_by_check) { + if(atclient_delete_request_options_is_skip_shared_by_check_flag_initialized(options) && options->skip_shared_by_check) { ret = 0; goto exit; } @@ -149,4 +147,4 @@ static int atclient_delete_validate_arguments(const atclient *atclient, const at ret = 0; exit: { return ret; } -} +} \ No newline at end of file diff --git a/packages/atclient/src/atclient_get_atkeys.c b/packages/atclient/src/atclient_get_atkeys.c index f8ea08e3..3a2604d0 100755 --- a/packages/atclient/src/atclient_get_atkeys.c +++ b/packages/atclient/src/atclient_get_atkeys.c @@ -1,25 +1,22 @@ -#include #include -#include #include #include #include #include #include +#include #define TAG "atclient_get_atkeys" -static int atclient_get_atkeys_validate_arguments(const atclient *atclient, const atclient_atkey **atkey, - const size_t *output_array_len); +static int atclient_get_atkeys_validate_arguments(const atclient *atclient, const atclient_atkey **atkey, const size_t *output_array_len); -int atclient_get_atkeys(atclient *atclient, atclient_atkey **atkey, size_t *output_array_len, - const atclient_get_atkeys_request_options *request_options) { +int atclient_get_atkeys(atclient *atclient, atclient_atkey **atkey, size_t *output_array_len, const atclient_get_atkeys_request_options *request_options) { int ret = 1; /* * 1. Validate arguments */ - if ((ret = atclient_get_atkeys_validate_arguments(atclient, (const atclient_atkey **)atkey, output_array_len)) != 0) { + if ((ret = atclient_get_atkeys_validate_arguments(atclient, (const atclient_atkey **) atkey, output_array_len)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_get_atkeys_validate_arguments: %d\n", ret); return ret; } @@ -29,21 +26,22 @@ int atclient_get_atkeys(atclient *atclient, atclient_atkey **atkey, size_t *outp */ size_t scan_cmd_size = strlen("scan"); - if (request_options != NULL) { - if (atclient_get_atkeys_request_options_is_show_hidden_initialized(request_options)) { - if (request_options->show_hidden) { + if(request_options != NULL) { + if(atclient_get_atkeys_request_options_is_show_hidden_initialized(request_options)) { + if(request_options->show_hidden) { scan_cmd_size += strlen(":showHidden:true"); } else { scan_cmd_size += strlen(":showHidden:false"); } } - if (atclient_get_atkeys_request_options_is_regex_initialized(request_options)) { + if(atclient_get_atkeys_request_options_is_regex_initialized(request_options)) { scan_cmd_size += strlen(" ") + strlen(request_options->regex); } } scan_cmd_size += strlen("\r\n") + 1; + char scan_cmd[scan_cmd_size]; const size_t recv_size = 8192; // TODO change using atclient_connection_read which will handle realloc @@ -57,15 +55,15 @@ int atclient_get_atkeys(atclient *atclient, atclient_atkey **atkey, size_t *outp */ size_t pos = 0; pos += snprintf(scan_cmd + pos, scan_cmd_size - pos, "scan"); - if (request_options != NULL) { - if (atclient_get_atkeys_request_options_is_show_hidden_initialized(request_options)) { - if (request_options->show_hidden) { + if(request_options != NULL) { + if(atclient_get_atkeys_request_options_is_show_hidden_initialized(request_options)) { + if(request_options->show_hidden) { pos += snprintf(scan_cmd + pos, scan_cmd_size - pos, ":showHidden:true"); } else { pos += snprintf(scan_cmd + pos, scan_cmd_size - pos, ":showHidden:false"); } } - if (atclient_get_atkeys_request_options_is_regex_initialized(request_options)) { + if(atclient_get_atkeys_request_options_is_regex_initialized(request_options)) { pos += snprintf(scan_cmd + pos, scan_cmd_size - pos, " %s", request_options->regex); } } @@ -90,7 +88,7 @@ int atclient_get_atkeys(atclient *atclient, atclient_atkey **atkey, size_t *outp char *response = (char *)recv; char *response_trimmed = NULL; // below method points the response_trimmed variable to the position of 'data:' substring - if (atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { + if(atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recv was \"%.*s\" and did not have prefix \"data:\"\n", (int)recv_len, recv); @@ -160,8 +158,7 @@ exit: { } } -static int atclient_get_atkeys_validate_arguments(const atclient *atclient, const atclient_atkey **atkey, - const size_t *output_array_len) { +static int atclient_get_atkeys_validate_arguments(const atclient *atclient, const atclient_atkey **atkey, const size_t *output_array_len) { int ret = 1; // check to make sure atclient is not null @@ -183,13 +180,13 @@ static int atclient_get_atkeys_validate_arguments(const atclient *atclient, cons goto exit; } - if (atkey == NULL) { + if(atkey == NULL) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey is NULL\n"); goto exit; } - if (output_array_len == NULL) { + if(output_array_len == NULL) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "output_array_len is NULL\n"); goto exit; @@ -198,4 +195,4 @@ static int atclient_get_atkeys_validate_arguments(const atclient *atclient, cons ret = 0; goto exit; exit: { return ret; } -} +} \ No newline at end of file diff --git a/packages/atclient/src/atclient_get_public_key.c b/packages/atclient/src/atclient_get_public_key.c index 887ce8d5..4af9ccc4 100755 --- a/packages/atclient/src/atclient_get_public_key.c +++ b/packages/atclient/src/atclient_get_public_key.c @@ -2,24 +2,22 @@ #include "atclient/atkey.h" #include "atclient/constants.h" #include "atclient/string_utils.h" -#include #include #include #include #define TAG "atclient_get_public_key" -static int atclient_get_public_key_validate_arguments(const atclient *atclient, const atclient_atkey *atkey, - const char **value); +static int atclient_get_public_key_validate_arguments(const atclient *atclient, const atclient_atkey *atkey, const char **value); -int atclient_get_public_key(atclient *atclient, atclient_atkey *atkey, char **value, - atclient_get_public_key_request_options *request_options) { +int atclient_get_public_key(atclient *atclient, atclient_atkey *atkey, char **value, atclient_get_public_key_request_options *request_options) { int ret = 1; /* * 1. Validate arguments */ - if ((ret = atclient_get_public_key_validate_arguments(atclient, atkey, (const char **)value)) != 0) { + if ((ret = atclient_get_public_key_validate_arguments(atclient, atkey, (const char **) value)) != + 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_get_public_key_validate_arguments: %d\n", ret); return ret; } @@ -56,9 +54,7 @@ int atclient_get_public_key(atclient *atclient, atclient_atkey *atkey, char **va goto exit; } - const bool bypass_cache = request_options != NULL && - atclient_get_public_key_request_options_is_bypass_cache_initialized(request_options) && - request_options->bypass_cache; + const bool bypass_cache = request_options != NULL && atclient_get_public_key_request_options_is_bypass_cache_initialized(request_options) && request_options->bypass_cache; const size_t plookup_cmd_size = strlen("plookup:all:\r\n") + (bypass_cache ? strlen("bypassCache:true:") : 0) + strlen(atkey_str_without_public) + 1; @@ -87,7 +83,7 @@ int atclient_get_public_key(atclient *atclient, atclient_atkey *atkey, char **va char *response = (char *)recv; char *response_trimmed = NULL; // below method points the response_trimmed variable to the position of 'data:' substring - if (atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { + if(atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recv was \"%.*s\" and did not have prefix \"data:\"\n", (int)recv_len, recv); @@ -112,11 +108,8 @@ int atclient_get_public_key(atclient *atclient, atclient_atkey *atkey, char **va * 6. Return data to caller */ - bool write_metadata_to_atkey = - request_options != NULL && - atclient_get_public_key_request_options_is_store_atkey_metadata_initialized(request_options) && - request_options->store_atkey_metadata; - if (write_metadata_to_atkey) { + bool write_metadata_to_atkey = request_options != NULL && atclient_get_public_key_request_options_is_store_atkey_metadata_initialized(request_options) && request_options->store_atkey_metadata; + if(write_metadata_to_atkey) { cJSON *metadata = cJSON_GetObjectItem(root, "metaData"); if (metadata == NULL) { ret = 1; @@ -132,7 +125,7 @@ int atclient_get_public_key(atclient *atclient, atclient_atkey *atkey, char **va } } - if (value != NULL) { + if(value != NULL) { if ((*value = malloc(sizeof(char) * (strlen(data->valuestring) + 1))) == NULL) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to allocate memory for value\n"); @@ -155,8 +148,7 @@ exit: { } } -static int atclient_get_public_key_validate_arguments(const atclient *atclient, const atclient_atkey *atkey, - const char **value) { +static int atclient_get_public_key_validate_arguments(const atclient *atclient, const atclient_atkey *atkey, const char **value) { int ret = 1; if (atclient == NULL) { @@ -183,13 +175,13 @@ static int atclient_get_public_key_validate_arguments(const atclient *atclient, goto exit; } - if (!atclient_atkey_is_key_initialized(atkey)) { + if(!atclient_atkey_is_key_initialized(atkey)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey is not initialized\n"); goto exit; } - if (!atclient_atkey_is_shared_by_initialized(atkey)) { + if(!atclient_atkey_is_shared_by_initialized(atkey)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey is not shared by initialized\n"); goto exit; @@ -212,4 +204,4 @@ static int atclient_get_public_key_validate_arguments(const atclient *atclient, ret = 0; goto exit; exit: { return ret; } -} +} \ No newline at end of file diff --git a/packages/atclient/src/atclient_get_self_key.c b/packages/atclient/src/atclient_get_self_key.c index 6c91d5c0..09408d8e 100755 --- a/packages/atclient/src/atclient_get_self_key.c +++ b/packages/atclient/src/atclient_get_self_key.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -92,7 +91,7 @@ int atclient_get_self_key(atclient *atclient, atclient_atkey *atkey, char **valu char *response = (char *)recv; char *response_trimmed = NULL; // below method points the response_trimmed variable to the position of 'data:' substring - if (atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { + if(atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recv was \"%.*s\" and did not have prefix \"data:\"\n", (int)recv_len, recv); @@ -272,4 +271,4 @@ static int atclient_get_self_key_validate_arguments(const atclient *atclient, co ret = 0; exit: { return ret; } -} +} \ No newline at end of file diff --git a/packages/atclient/src/atclient_get_shared_key.c b/packages/atclient/src/atclient_get_shared_key.c index c7982e1c..667f3438 100755 --- a/packages/atclient/src/atclient_get_shared_key.c +++ b/packages/atclient/src/atclient_get_shared_key.c @@ -5,12 +5,11 @@ #include #include #include -#include -#include #include #include #include #include +#include #define TAG "atclient_get_sharedkey" @@ -25,11 +24,11 @@ static int atclient_get_shared_key_shared_by_other_with_me(atclient *atclient, atclient_atkey *atkey, char **value, const atclient_get_shared_key_request_options *request_options); -int atclient_get_shared_key(atclient *atclient, atclient_atkey *atkey, char **value, - const atclient_get_shared_key_request_options *request_options) { +int atclient_get_shared_key(atclient *atclient, atclient_atkey *atkey, + char **value, const atclient_get_shared_key_request_options *request_options) { int ret = 1; - if ((ret = atclient_get_shared_key_validate_arguments(atclient, atkey, (const char **)value)) != 0) { + if ((ret = atclient_get_shared_key_validate_arguments(atclient, atkey, (const char **) value)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_get_shared_key_validate_arguments: %d\n", ret); return ret; } @@ -131,9 +130,9 @@ static int atclient_get_shared_key_validate_arguments(const atclient *atclient, exit: { return ret; } } -static int -atclient_get_shared_key_shared_by_me_with_other(atclient *atclient, atclient_atkey *atkey, char **value, - const atclient_get_shared_key_request_options *request_options) { +static int atclient_get_shared_key_shared_by_me_with_other( + atclient *atclient, atclient_atkey *atkey, + char **value, const atclient_get_shared_key_request_options *request_options) { int ret = 1; /* @@ -230,7 +229,7 @@ atclient_get_shared_key_shared_by_me_with_other(atclient *atclient, atclient_atk char *response = (char *)recv; char *response_trimmed = NULL; // below method points the response_trimmed variable to the position of 'data:' substring - if (atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { + if(atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recv was \"%.*s\" and did not have prefix \"data:\"\n", (int)recv_len, recv); @@ -456,7 +455,7 @@ atclient_get_shared_key_shared_by_other_with_me(atclient *atclient, atclient_atk char *response = (char *)recv; char *response_trimmed = NULL; // below method points the response_trimmed variable to the position of 'data:' substring - if (atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { + if(atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recv was \"%.*s\" and did not have prefix \"data:\"\n", (int)recv_len, recv); diff --git a/packages/atclient/src/atclient_put_public_key.c b/packages/atclient/src/atclient_put_public_key.c index 52e912bc..b246d05d 100755 --- a/packages/atclient/src/atclient_put_public_key.c +++ b/packages/atclient/src/atclient_put_public_key.c @@ -1,13 +1,12 @@ #include -#include #include #include -#include #include #include #include #include #include +#include #define TAG "atclient_put_public_key" @@ -87,7 +86,7 @@ int atclient_put_public_key(atclient *ctx, atclient_atkey *atkey, const char *va char *response = (char *)recv; char *response_trimmed = NULL; // below method points the response_trimmed variable to the position of 'data:' substring - if (atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { + if(atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recv was \"%.*s\" and did not have prefix \"data:\"\n", (int)recv_len, recv); @@ -126,13 +125,13 @@ static int atclient_put_public_key_validate_arguments(const atclient *ctx, const goto exit; } - if (!atclient_is_atserver_connection_started(ctx)) { + if(!atclient_is_atserver_connection_started(ctx)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "ctx.atserver_connection is not started\n"); goto exit; } - if (!atclient_is_atsign_initialized(ctx)) { + if(!atclient_is_atsign_initialized(ctx)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "ctx->atsign is not intiialized\n"); goto exit; diff --git a/packages/atclient/src/atclient_put_self_key.c b/packages/atclient/src/atclient_put_self_key.c index ab4d6f6d..3ad09345 100755 --- a/packages/atclient/src/atclient_put_self_key.c +++ b/packages/atclient/src/atclient_put_self_key.c @@ -1,15 +1,14 @@ #include #include #include -#include #include #include -#include #include #include #include #include #include +#include #define TAG "atclient_put_self_key" @@ -88,7 +87,7 @@ int atclient_put_self_key(atclient *ctx, atclient_atkey *atkey, const char *valu } memset(iv_base64, 0, sizeof(unsigned char) * iv_base64_size); - if ((ret = atchops_base64_encode(iv, iv_size, (unsigned char *)iv_base64, iv_base64_size, NULL)) != 0) { + if ((ret = atchops_base64_encode(iv, iv_size, (unsigned char *) iv_base64, iv_base64_size, NULL)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_base64_encode: %d\n", ret); goto exit; } @@ -110,7 +109,7 @@ int atclient_put_self_key(atclient *ctx, atclient_atkey *atkey, const char *valu size_t value_encrypted_base64_len = 0; memset(value_encrypted_base64, 0, sizeof(char) * value_encrypted_base64_size); - if ((ret = atchops_base64_encode(value_encrypted, value_encrypted_len, (unsigned char *)value_encrypted_base64, + if ((ret = atchops_base64_encode(value_encrypted, value_encrypted_len, (unsigned char *) value_encrypted_base64, value_encrypted_base64_size, &value_encrypted_base64_len)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_base64_encode: %d\n", ret); goto exit; @@ -162,7 +161,7 @@ int atclient_put_self_key(atclient *ctx, atclient_atkey *atkey, const char *valu char *response = (char *)recv; char *response_trimmed = NULL; // below method points the response_trimmed variable to the position of 'data:' substring - if (atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { + if(atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recv was \"%.*s\" and did not have prefix \"data:\"\n", (int)recv_len, recv); @@ -197,13 +196,13 @@ static int atclient_put_self_key_validate_arguments(atclient *ctx, atclient_atke goto exit; } - if (!atclient_is_atserver_connection_started(ctx)) { + if(!atclient_is_atserver_connection_started(ctx)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "ctx.atserver_connection is not started\n"); goto exit; } - if (!atclient_is_atsign_initialized(ctx)) { + if(!atclient_is_atsign_initialized(ctx)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "ctx->atsign is not intiialized\n"); goto exit; @@ -215,13 +214,13 @@ static int atclient_put_self_key_validate_arguments(atclient *ctx, atclient_atke goto exit; } - if (!atclient_atkey_is_key_initialized(atkey)) { + if(!atclient_atkey_is_key_initialized(atkey)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey is not initialized\n"); goto exit; } - if (!atclient_atkey_is_shared_by_initialized(atkey)) { + if(!atclient_atkey_is_shared_by_initialized(atkey)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey.shared_by is not initialized\n"); goto exit; @@ -236,4 +235,4 @@ static int atclient_put_self_key_validate_arguments(atclient *ctx, atclient_atke ret = 0; goto exit; exit: { return ret; } -} +} \ No newline at end of file diff --git a/packages/atclient/src/atclient_put_shared_key.c b/packages/atclient/src/atclient_put_shared_key.c index 709b8624..7819309d 100755 --- a/packages/atclient/src/atclient_put_shared_key.c +++ b/packages/atclient/src/atclient_put_shared_key.c @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -78,18 +77,18 @@ int atclient_put_shared_key(atclient *ctx, atclient_atkey *atkey, const char *va if (request_options != NULL && atclient_put_shared_key_request_options_is_shared_encryption_key_initialized(request_options)) { memcpy(shared_encryption_key, request_options->shared_encryption_key, shared_encryption_key_size); - } else { - ret = atclient_get_shared_encryption_key_shared_by_me(ctx, recipient_atsign_with_at, shared_encryption_key); + } else { + ret = atclient_get_shared_encryption_key_shared_by_me(ctx, recipient_atsign_with_at, + shared_encryption_key); if (ret == ATCLIENT_ERR_AT0015_KEY_NOT_FOUND) { - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, - "Did not find shared_encryption_key_shared_by_me.. Creating key pair for me and other...\n"); + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "Did not find shared_encryption_key_shared_by_me.. Creating key pair for me and other...\n"); if ((ret = atclient_create_shared_encryption_key_pair_for_me_and_other(ctx, recipient_atsign_with_at, - shared_encryption_key)) != 0) { + shared_encryption_key)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, - "atclient_create_shared_encryption_key_pair_for_me_and_other: %d\n", ret); + "atclient_create_shared_encryption_key_pair_for_me_and_other: %d\n", ret); goto exit; } - } else if (ret != 0) { + } else if(ret != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_get_shared_encryption_key_shared_by_me: %d\n", ret); goto exit; } @@ -98,18 +97,18 @@ int atclient_put_shared_key(atclient *ctx, atclient_atkey *atkey, const char *va /* * 4. Generate IV */ - if ((ret = atchops_iv_generate(iv)) != 0) { + if((ret = atchops_iv_generate(iv)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_iv_generate: %d\n", ret); goto exit; } memset(iv_base64, 0, sizeof(char) * iv_base64_size); - if ((ret = atchops_base64_encode(iv, iv_size, (unsigned char *)iv_base64, iv_base64_size, NULL)) != 0) { + if((ret = atchops_base64_encode(iv, iv_size, (unsigned char *) iv_base64, iv_base64_size, NULL)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_base64_encode: %d\n", ret); goto exit; } - if ((ret = atclient_atkey_metadata_set_iv_nonce(&(atkey->metadata), iv_base64)) != 0) { + if((ret = atclient_atkey_metadata_set_iv_nonce(&(atkey->metadata), iv_base64)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_atkey_metadata_set_iv_nonce: %d\n", ret); goto exit; } @@ -119,16 +118,15 @@ int atclient_put_shared_key(atclient *ctx, atclient_atkey *atkey, const char *va */ size_t value_encrypted_len = 0; memset(value_encrypted, 0, sizeof(unsigned char) * value_encrypted_size); - if ((ret = atchops_aes_ctr_encrypt(shared_encryption_key, ATCHOPS_AES_256, iv, (const unsigned char *)value, - value_len, value_encrypted, value_encrypted_size, &value_encrypted_len)) != 0) { + if ((ret = atchops_aes_ctr_encrypt(shared_encryption_key, ATCHOPS_AES_256, iv, (const unsigned char *) value, value_len, value_encrypted, + value_encrypted_size, &value_encrypted_len)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_aes_ctr_encrypt: %d\n", ret); goto exit; } size_t value_encrypted_base64_len = 0; memset(value_encrypted_base64, 0, sizeof(char) * value_encrypted_base64_size); - if ((ret = atchops_base64_encode(value_encrypted, value_encrypted_len, (unsigned char *)value_encrypted_base64, - value_encrypted_base64_size, &value_encrypted_base64_len)) != 0) { + if((ret = atchops_base64_encode(value_encrypted, value_encrypted_len, (unsigned char *) value_encrypted_base64, value_encrypted_base64_size, &value_encrypted_base64_len)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_base64_encode: %d\n", ret); goto exit; } @@ -148,8 +146,8 @@ int atclient_put_shared_key(atclient *ctx, atclient_atkey *atkey, const char *va } const size_t atkey_str_len = strlen(atkey_str); - const size_t update_cmd_size = strlen("update") + metadata_protocol_str_len + strlen(":") + atkey_str_len + - strlen(" ") + value_encrypted_base64_len + strlen("\r\n") + 1; + const size_t update_cmd_size = + strlen("update") + metadata_protocol_str_len + strlen(":") + atkey_str_len + strlen(" ") + value_encrypted_base64_len + strlen("\r\n") + 1; if ((update_cmd = malloc(sizeof(char) * update_cmd_size)) == NULL) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to allocate memory for update_cmd\n"); @@ -162,8 +160,8 @@ int atclient_put_shared_key(atclient *ctx, atclient_atkey *atkey, const char *va /* * 7. Send update command */ - if ((ret = atclient_connection_send(&ctx->atserver_connection, (unsigned char *)update_cmd, update_cmd_len, recv, - recv_size, &recv_len)) != 0) { + if ((ret = atclient_connection_send(&ctx->atserver_connection, (unsigned char *) update_cmd, update_cmd_len, recv, recv_size, + &recv_len)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_connection_send: %d\n", ret); goto exit; } @@ -175,7 +173,7 @@ int atclient_put_shared_key(atclient *ctx, atclient_atkey *atkey, const char *va char *response = (char *)recv; char *response_trimmed = NULL; // below method points the response_trimmed variable to the position of 'data:' substring - if (atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { + if(atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recv was \"%.*s\" and did not have prefix \"data:\"\n", (int)recv_len, recv); @@ -191,14 +189,13 @@ int atclient_put_shared_key(atclient *ctx, atclient_atkey *atkey, const char *va ret = 0; goto exit; -exit: { +exit: { free(recipient_atsign_with_at); free(update_cmd); free(metadata_protocol_str); free(atkey_str); free(recv); - return ret; -} + return ret; } } static int atclient_put_shared_key_validate_arguments(const atclient *ctx, const atclient_atkey *atkey, @@ -214,13 +211,13 @@ static int atclient_put_shared_key_validate_arguments(const atclient *ctx, const goto exit; } - if (!atclient_is_atsign_initialized(ctx)) { + if(!atclient_is_atsign_initialized(ctx)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "ctx.atsign is not initialized\n"); goto exit; } - if (!atclient_is_atserver_connection_started(ctx)) { + if(!atclient_is_atserver_connection_started(ctx)) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "ctx.atserver_connection is not started\n"); goto exit; diff --git a/packages/atclient/src/atkey.c b/packages/atclient/src/atkey.c index 83bb6a66..36bea17f 100644 --- a/packages/atclient/src/atkey.c +++ b/packages/atclient/src/atkey.c @@ -2,7 +2,6 @@ #include "atclient/metadata.h" #include "atclient/string_utils.h" #include "atlogger/atlogger.h" -#include #include #include #include @@ -79,10 +78,9 @@ size_t atclient_atkey_strlen(const atclient_atkey *atkey) { return 0; } - atclient_atkey_type type = atclient_atkey_get_type(atkey); + atclient_atkey_type type = atclient_atkey_get_type(atkey); - if ((!atclient_atkey_is_shared_by_initialized(atkey) || strlen(atkey->shared_by) <= 0) && - type != ATCLIENT_ATKEY_TYPE_RESERVED_KEY) { + if((!atclient_atkey_is_shared_by_initialized(atkey) || strlen(atkey->shared_by) <= 0) && type != ATCLIENT_ATKEY_TYPE_RESERVED_KEY){ atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey->shared_by is not initialized\n"); return 0; } @@ -105,8 +103,8 @@ size_t atclient_atkey_strlen(const atclient_atkey *atkey) { if (atclient_atkey_is_namespacestr_initialized(atkey) && strlen(atkey->namespace_str) > 0) { len += strlen(".") + strlen(atkey->namespace_str); } - if (atclient_atkey_is_shared_by_initialized(atkey)) { - len += strlen(atkey->shared_by); + if(atclient_atkey_is_shared_by_initialized(atkey)){ + len += strlen(atkey->shared_by); } return len; } diff --git a/packages/atclient/src/connection.c b/packages/atclient/src/connection.c index faa8a0d2..922d4c3e 100644 --- a/packages/atclient/src/connection.c +++ b/packages/atclient/src/connection.c @@ -4,8 +4,7 @@ #include "atclient/connection_hooks.h" #include "atclient/constants.h" #include "atlogger/atlogger.h" -#include -#include +#include #include #include #include @@ -309,7 +308,7 @@ int atclient_connection_write(atclient_connection *ctx, const unsigned char *val memcpy(valuecopy, value, value_len); atlogger_fix_stdout_buffer((char *)valuecopy, value_len); atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sSENT: %s\"%.*s\"%s\n", BBLU, HCYN, value_len, valuecopy, - ATCLIENT_RESET); + reset); free(valuecopy); } else { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, @@ -422,7 +421,7 @@ int atclient_connection_send(atclient_connection *ctx, const unsigned char *src, memcpy(srccopy, src, src_len); atlogger_fix_stdout_buffer((char *)srccopy, src_len); atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sSENT: %s\"%.*s\"%s\n", BBLU, HCYN, strlen((char *)srccopy), - srccopy, ATCLIENT_RESET); + srccopy, reset); free(srccopy); } else { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, @@ -540,7 +539,7 @@ int atclient_connection_send(atclient_connection *ctx, const unsigned char *src, memcpy(recvcopy, recv, *recv_len); atlogger_fix_stdout_buffer((char *)recvcopy, *recv_len); atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sRECV: %s\"%.*s\"%s\n", BMAG, HMAG, *recv_len, recvcopy, - ATCLIENT_RESET); + reset); free(recvcopy); } else { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, @@ -733,7 +732,7 @@ int atclient_connection_read(atclient_connection *ctx, unsigned char **value, si memcpy(recvcopy, recv, recv_len); atlogger_fix_stdout_buffer((char *)recvcopy, recv_len); atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sRECV: %s\"%.*s\"%s\n", BMAG, HMAG, recv_len, recvcopy, - ATCLIENT_RESET); + reset); free(recvcopy); } else { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, diff --git a/packages/atclient/src/encryption_key_helpers.c b/packages/atclient/src/encryption_key_helpers.c index 812d9786..9fdcaede 100644 --- a/packages/atclient/src/encryption_key_helpers.c +++ b/packages/atclient/src/encryption_key_helpers.c @@ -6,7 +6,6 @@ #include "atclient/constants.h" #include "atclient/string_utils.h" #include "atlogger/atlogger.h" -#include #include #include @@ -84,7 +83,7 @@ int atclient_get_public_encryption_key(atclient *ctx, const char *atsign, char * char *response = (char *)recv; char *response_trimmed = NULL; // below method points the response_trimmed variable to the position of 'data:' substring - if (atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { + if(atclient_string_utils_get_substring_position(response, ATCLIENT_DATA_TOKEN, &response_trimmed) != 0) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recv was \"%.*s\" and did not have prefix \"data:\"\n", (int)recv_len, recv); @@ -199,8 +198,7 @@ int atclient_get_shared_encryption_key_shared_by_me(atclient *ctx, const char *r if (!atclient_string_utils_starts_with(response, "data:")) { if (atclient_string_utils_starts_with(response, "error:AT0015-key not found")) { ret = ATCLIENT_ERR_AT0015_KEY_NOT_FOUND; - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, - "atclient_stringutils_starts_with: %d; error:AT0015-key not found\n", ret); + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_stringutils_starts_with: %d; error:AT0015-key not found\n", ret); goto exit; } } @@ -272,8 +270,7 @@ int atclient_get_shared_encryption_key_shared_by_other(atclient *ctx, const char const size_t shared_encryption_key_encrypted_base64_size = 2048; unsigned char shared_encryption_key_encrypted_base64[shared_encryption_key_encrypted_base64_size]; - const size_t shared_encryption_key_encrypted_size = - atchops_base64_decoded_size(shared_encryption_key_encrypted_base64_size); + const size_t shared_encryption_key_encrypted_size = atchops_base64_decoded_size(shared_encryption_key_encrypted_base64_size); unsigned char shared_encryption_key_encrypted[shared_encryption_key_encrypted_size]; /* @@ -359,7 +356,8 @@ exit: { } int atclient_create_shared_encryption_key_pair_for_me_and_other( - atclient *atclient, const char *recipient_atsign, unsigned char *shared_encryption_key_shared_by_me_with_other) { + atclient *atclient, const char *recipient_atsign, + unsigned char *shared_encryption_key_shared_by_me_with_other) { int ret = 1; @@ -371,6 +369,7 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( return ret; } + if (recipient_atsign == NULL) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "recipient_atsign is NULL\n"); return ret; @@ -405,8 +404,7 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( unsigned char shared_encryption_key_base64[shared_encryption_key_base64_size]; // encrypted for us - const size_t shared_encryption_key_base64_encrypted_for_us_size = - 256; // rsa encryption always outputs 256 bytes (2048 bit key) TODO: constant + const size_t shared_encryption_key_base64_encrypted_for_us_size = 256; // rsa encryption always outputs 256 bytes (2048 bit key) TODO: constant unsigned char shared_encryption_key_base64_encrypted_for_us[shared_encryption_key_base64_encrypted_for_us_size]; // encrypted for us (base64 encoded) @@ -416,8 +414,7 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( shared_encryption_key_base64_encrypted_for_us_base64[shared_encryption_key_base64_encrypted_for_us_base64_size]; // encrypted for them - const size_t shared_encryption_key_base64_encrypted_for_them_size = - 256; // rsa encryption always outputs 256 bytes (2048 bit key) TODO: constant + const size_t shared_encryption_key_base64_encrypted_for_them_size = 256; // rsa encryption always outputs 256 bytes (2048 bit key) TODO: constant unsigned char shared_encryption_key_base64_encrypted_for_them[shared_encryption_key_base64_encrypted_for_them_size]; // encrypted for them (base64 encoded) @@ -426,7 +423,7 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( unsigned char shared_encryption_key_base64_encrypted_for_them_base64 [shared_encryption_key_base64_encrypted_for_them_base64_size]; - char *update_cmd_for_us = NULL; // for us (update:shared_key.shared_with@shared_by command) + char *update_cmd_for_us = NULL; // for us (update:shared_key.shared_with@shared_by command) char *update_cmd_for_them = NULL; // for them (update:@shared_with:shared_key@shared_by command) const size_t recv_size = 256; // sufficient to receive response from a update: command @@ -457,8 +454,7 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( goto exit; } - if ((ret = atchops_rsa_key_populate_public_key(&public_key_struct, public_key_base64, strlen(public_key_base64))) != - 0) { + if ((ret = atchops_rsa_key_populate_public_key(&public_key_struct, public_key_base64, strlen(public_key_base64))) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atchops_rsa_key_populate_public_key: %d\n", ret); goto exit; } @@ -490,8 +486,7 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( memset(shared_encryption_key_base64_encrypted_for_us, 0, sizeof(unsigned char) * shared_encryption_key_base64_encrypted_for_us_size); if ((ret = atchops_rsa_encrypt(&atclient->atkeys.encrypt_public_key, (unsigned char *)shared_encryption_key_base64, - shared_encryption_key_base64_len, shared_encryption_key_base64_encrypted_for_us)) != - 0) { + shared_encryption_key_base64_len, shared_encryption_key_base64_encrypted_for_us)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "failed to encrypt shared enc key for us | atchops_rsa_encrypt: %d\n", ret); goto exit; @@ -536,8 +531,8 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( */ // 6a. `update:shared_key.recipient_atsign@myatsign ` const size_t update_cmd_for_us_size = strlen("update:shared_key.") + strlen(sharedwith_atsign_without_at) + - strlen(sharedby_atsign_with_at) + strlen(" ") + - shared_encryption_key_base64_encrypted_for_us_base64_len + strlen("\r\n") + 1; + strlen(sharedby_atsign_with_at) + strlen(" ") + + shared_encryption_key_base64_encrypted_for_us_base64_len + strlen("\r\n") + 1; if ((update_cmd_for_us = (char *)malloc(sizeof(char) * update_cmd_for_us_size)) == NULL) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to allocate memory for update_cmd_for_us\n"); @@ -547,9 +542,9 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( sharedby_atsign_with_at, shared_encryption_key_base64_encrypted_for_us_base64); // 6b. `update:@shared_with:shared_key@shared_by ` - const size_t update_cmd_for_them_size = - strlen("update:") + strlen(sharedwith_atsign_with_at) + strlen(":shared_key") + strlen(sharedby_atsign_with_at) + - strlen(" ") + shared_encryption_key_base64_encrypted_for_them_base64_len + strlen("\r\n") + 1; + const size_t update_cmd_for_them_size = strlen("update:") + strlen(sharedwith_atsign_with_at) + strlen(":shared_key") + + strlen(sharedby_atsign_with_at) + strlen(" ") + + shared_encryption_key_base64_encrypted_for_them_base64_len + strlen("\r\n") + 1; if ((update_cmd_for_them = (char *)malloc(sizeof(char) * update_cmd_for_them_size)) == NULL) { ret = 1; @@ -564,8 +559,8 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( */ // 7a. Our key - if ((ret = atclient_connection_send(&(atclient->atserver_connection), (unsigned char *)update_cmd_for_us, - update_cmd_for_us_size - 1, recv, recv_size, &recv_len)) != 0) { + if ((ret = atclient_connection_send(&(atclient->atserver_connection), (unsigned char *)update_cmd_for_us, update_cmd_for_us_size - 1, + recv, recv_size, &recv_len)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_connection_send: %d\n", ret); goto exit; } @@ -581,8 +576,8 @@ int atclient_create_shared_encryption_key_pair_for_me_and_other( recv_len = 0; // 7b. Their key - if ((ret = atclient_connection_send(&(atclient->atserver_connection), (unsigned char *)update_cmd_for_them, - update_cmd_for_them_size - 1, recv, recv_size, &recv_len)) != 0) { + if ((ret = atclient_connection_send(&(atclient->atserver_connection), (unsigned char *)update_cmd_for_them, update_cmd_for_them_size - 1, + recv, recv_size, &recv_len)) != 0) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_connection_send: %d\n", ret); goto exit; } diff --git a/packages/atclient/src/request_options.c b/packages/atclient/src/request_options.c index 6eb8c250..7d8e9880 100644 --- a/packages/atclient/src/request_options.c +++ b/packages/atclient/src/request_options.c @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -10,34 +9,16 @@ #define TAG "request_options" -/* - * 1A. Put Self Key - */ -static void atclient_get_self_key_request_options_set_store_atkey_metadata_initialized( - atclient_get_self_key_request_options *options, const bool initialized); +// default param values for ATCLIENT PKAM AUTHENTICATE OPTIONS +#define ATCLIENT_AUTHENTICATE_DEFAULT_ROOT_SERVER_HOST "root.atsign.org" +#define ATCLIENT_AUTHENTICATE_DEFAULT_ROOT_SERVER_PORT 64 -/* - * 1B. Put SharedKey - */ static void atclient_put_shared_key_request_options_set_shared_encryption_key_initialized( atclient_put_shared_key_request_options *options, const bool initialized); static void atclient_put_shared_key_request_options_set_iv_initialized(atclient_put_shared_key_request_options *options, const bool initialized); - -/* - * 1C. Put PublicKey - */ -// empty for now - -/* - * 2A. Get SelfKey - */ static void atclient_get_self_key_request_options_set_store_atkey_metadata_initialized( atclient_get_self_key_request_options *options, const bool initialized); - -/* - * 2B. Get SharedKey - */ static void atclient_get_shared_key_request_options_set_shared_encryption_key_initialized( atclient_get_shared_key_request_options *options, const bool initialized); static void atclient_get_shared_key_request_options_set_iv_initialized(atclient_get_shared_key_request_options *options, @@ -47,47 +28,19 @@ atclient_get_shared_key_request_options_set_bypass_cache_initialized(atclient_ge const bool initialized); static void atclient_get_shared_key_request_options_set_store_atkey_metadata_initialized( atclient_get_shared_key_request_options *options, const bool initialized); - -/* - * 2C. Get PublicKey - */ static void atclient_get_public_key_request_options_set_bypass_cache_initialized(atclient_get_public_key_request_options *options, const bool initialized); static void atclient_get_public_key_request_options_set_store_atkey_metadata_initialized( atclient_get_public_key_request_options *options, const bool initialized); - -/* - * 3. Delete - */ -static void -atclient_delete_request_options_set_skip_shared_by_check_intitialized(atclient_delete_request_options *options, - const bool initialized); - -/* - * 4. Get AtKeys - */ static void atclient_get_atkeys_request_options_set_regex_initialized(atclient_get_atkeys_request_options *options, const bool initialized); static void atclient_get_atkeys_request_options_set_show_hidden_initialized(atclient_get_atkeys_request_options *options, const bool initialized); - -/* - * 5. Authenticate Request Options - */ -static void atclient_authenticate_options_set_atdirectory_host_initialized(atclient_authenticate_options *options, - const bool initialized); - -static void atclient_authenticate_options_set_atdirectory_port_initialized(atclient_authenticate_options *options, - const bool initialized); - -static void atclient_authenticate_options_set_atserver_host_initialized(atclient_authenticate_options *options, - const bool initialized); - -static void atclient_authenticate_options_set_atserver_port_initialized(atclient_authenticate_options *options, - const bool initialized); - +static void +atclient_delete_request_options_skip_shared_by_check_set_intitialized(atclient_delete_request_options *options, + const bool initialized); /* * ================= * 1A. Put SelfKey @@ -1273,8 +1226,8 @@ void atclient_delete_request_options_free(atclient_delete_request_options *optio } /* - * 2. Reset the value - */ + * 2. Reset the value + */ if (atclient_delete_request_options_is_skip_shared_by_check_flag_initialized(options)) { atclient_delete_request_options_unset_skip_shared_by_check(options); } @@ -1299,7 +1252,7 @@ bool atclient_delete_request_options_is_skip_shared_by_check_flag_initialized( } static void -atclient_delete_request_options_set_skip_shared_by_check_intitialized(atclient_delete_request_options *options, +atclient_delete_request_options_skip_shared_by_check_set_intitialized(atclient_delete_request_options *options, const bool initialized) { /* * 1. Validate arguments @@ -1343,8 +1296,8 @@ void atclient_delete_request_options_set_skip_shared_by_check(atclient_delete_re /* * 3. Set value and set intiliazed to true */ - atclient_delete_request_options_set_skip_shared_by_check_intitialized(options, true); - memcpy(&(options->skip_shared_by_check), &option, sizeof(option)); + memcpy(&(options->skip_shared_by_check), &option, sizeof(option)); + atclient_delete_request_options_skip_shared_by_check_set_intitialized(options, true); } void atclient_delete_request_options_unset_skip_shared_by_check(atclient_delete_request_options *options) { @@ -1358,7 +1311,7 @@ void atclient_delete_request_options_unset_skip_shared_by_check(atclient_delete_ } options->skip_shared_by_check = false; - atclient_delete_request_options_set_skip_shared_by_check_intitialized(options, false); + atclient_delete_request_options_skip_shared_by_check_set_intitialized(options, false); } void atclient_get_atkeys_request_options_init(atclient_get_atkeys_request_options *options) { @@ -1598,8 +1551,8 @@ void atclient_get_atkeys_request_options_unset_show_hidden(atclient_get_atkeys_r void atclient_authenticate_options_init(atclient_authenticate_options *options) { memset(options, 0, sizeof(atclient_authenticate_options)); - options->atdirectory_host = ATCLIENT_ATDIRECTORY_PRODUCTION_HOST; - options->atdirectory_port = ATCLIENT_ATDIRECTORY_PRODUCTION_PORT; + options->atdirectory_host = ATCLIENT_AUTHENTICATE_DEFAULT_ROOT_SERVER_HOST; + options->atdirectory_port = ATCLIENT_AUTHENTICATE_DEFAULT_ROOT_SERVER_PORT; options->atserver_host = NULL; options->atserver_port = 0; } @@ -1618,11 +1571,11 @@ void atclient_authenticate_options_free(atclient_authenticate_options *options) */ if (atclient_authenticate_options_is_atdirectory_host_initialized(options)) { - atclient_authenticate_options_unset_atdirectory_host(options); + atclient_authenticate_options_unset_at_directory_host(options); } if (atclient_authenticate_options_is_atdirectory_port_initialized(options)) { - atclient_authenticate_options_unset_atdirectory_port(options); + atclient_authenticate_options_unset_at_directory_port(options); } if (atclient_authenticate_options_is_atserver_host_initialized(options)) { @@ -1648,8 +1601,8 @@ bool atclient_authenticate_options_is_atdirectory_host_initialized(const atclien /* * 2. Check if the at directory host is initialized */ - return options->_initialized_fields[ATCLIENT_AUTHENTICATE_OPTIONS_ATDIRECTORY_HOST_INDEX] & - ATCLIENT_AUTHENTICATE_OPTIONS_ATDIRECTORY_HOST_INITIALIZED; + return options->_initialized_fields[ATCLIENT_AUTHENTICATE_OPTIONS_AT_DIRECTORY_HOST_INDEX] & + ATCLIENT_AUTHENTICATE_OPTIONS_AT_DIRECTORY_HOST_INITIALIZED; } bool atclient_authenticate_options_is_atdirectory_port_initialized(const atclient_authenticate_options *options) { @@ -1666,8 +1619,8 @@ bool atclient_authenticate_options_is_atdirectory_port_initialized(const atclien /* * Check if the at directory port is initialized */ - return options->_initialized_fields[ATCLIENT_AUTHENTICATE_OPTIONS_ATDIRECTORY_PORT_INDEX] & - ATCLIENT_AUTHENTICATE_OPTIONS_ATDIRECTORY_PORT_INITIALIZED; + return options->_initialized_fields[ATCLIENT_AUTHENTICATE_OPTIONS_AT_DIRECTORY_PORT_INDEX] & + ATCLIENT_AUTHENTICATE_OPTIONS_AT_DIRECTORY_PORT_INITIALIZED; } bool atclient_authenticate_options_is_atserver_host_initialized(const atclient_authenticate_options *options) { @@ -1706,36 +1659,34 @@ bool atclient_authenticate_options_is_atserver_port_initialized(const atclient_a ATCLIENT_AUTHENTICATE_OPTIONS_ATSERVER_PORT_INITIALIZED; } -void atclient_authenticate_options_unset_atdirectory_host(atclient_authenticate_options *options) { +void atclient_authenticate_options_unset_at_directory_host(atclient_authenticate_options *options) { /* * 1. Validate arguments */ if (options == NULL) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, - "atclient_authenticate_options_unset_atdirectory_host: Invalid arguments\n"); + "atclient_authenticate_options_unset_at_directory_host: Invalid arguments\n"); return; } /* * 2. Unsetat directory */ - if (atclient_authenticate_options_is_atdirectory_host_initialized(options) && options->atdirectory_host != NULL) { + if (atclient_authenticate_options_is_atdirectory_host_initialized(options)) { free(options->atdirectory_host); } options->atdirectory_host = NULL; - atclient_authenticate_options_set_atdirectory_host_initialized(options, false); } -void atclient_authenticate_options_unset_atdirectory_port(atclient_authenticate_options *options) { +void atclient_authenticate_options_unset_at_directory_port(atclient_authenticate_options *options) { /* * 1. Validate arguments */ if (options == NULL) { atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, - "atclient_authenticate_options_unset_atdirectory_port: Invalid arguments\n"); + "atclient_authenticate_options_unset_at_directory_port: Invalid arguments\n"); return; } - options->atdirectory_port = ATCLIENT_ATDIRECTORY_PRODUCTION_PORT; - atclient_authenticate_options_set_atdirectory_port_initialized(options, false); + options->atdirectory_port = 64; } void atclient_authenticate_options_unset_atserver_host(atclient_authenticate_options *options) { @@ -1751,11 +1702,10 @@ void atclient_authenticate_options_unset_atserver_host(atclient_authenticate_opt /* * 2. Unset atserver host */ - if (atclient_authenticate_options_is_atserver_host_initialized(options) && options->atserver_host != NULL) { + if (atclient_authenticate_options_is_atserver_host_initialized(options)) { free(options->atserver_host); } options->atserver_host = NULL; - atclient_authenticate_options_set_atserver_host_initialized(options, false); } void atclient_authenticate_options_unset_atserver_port(atclient_authenticate_options *options) { @@ -1768,10 +1718,10 @@ void atclient_authenticate_options_unset_atserver_port(atclient_authenticate_opt return; } options->atserver_port = 0; - atclient_authenticate_options_set_atserver_port_initialized(options, false); } -int atclient_authenticate_options_set_atdirectory_host(atclient_authenticate_options *options, char *atdirectory_host) { +int atclient_authenticate_options_set_at_directory_host(atclient_authenticate_options *options, + char *atdirectory_host) { int ret = 1; /* @@ -1780,7 +1730,7 @@ int atclient_authenticate_options_set_atdirectory_host(atclient_authenticate_opt if (options == NULL) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, - "atclient_authenticate_options_set_atdirectory_host: Invalid arguments\n"); + "atclient_authenticate_options_set_at_directory_host: Invalid arguments\n"); return ret; } @@ -1788,33 +1738,19 @@ int atclient_authenticate_options_set_atdirectory_host(atclient_authenticate_opt * 2. Unset at directory host, if initialized */ if (atclient_authenticate_options_is_atdirectory_host_initialized(options)) { - atclient_authenticate_options_unset_atdirectory_host(options); + atclient_authenticate_options_unset_at_directory_host(options); } /* * 3. Set at directory host */ - const size_t atdirectory_host_size = strlen(atdirectory_host) + 1; - if ((options->atdirectory_host = (char *)malloc(sizeof(char) * atdirectory_host_size)) == NULL) { - ret = 1; - atlogger_log( - TAG, ATLOGGER_LOGGING_LEVEL_ERROR, - "atclient_authenticate_options_set_atdirectory_host: Failed to allocate memory for at directory host\n"); - goto exit; - } - - atclient_authenticate_options_set_atdirectory_host_initialized(options, true); - - const size_t atdirectory_host_len = strlen(atdirectory_host); - memcpy(options->atdirectory_host, atdirectory_host, atdirectory_host_len); - options->atdirectory_host[atdirectory_host_len] = '\0'; - + options->atdirectory_host = atdirectory_host; ret = 0; goto exit; exit: { return ret; } } -int atclient_authenticate_options_set_atdirectory_port(atclient_authenticate_options *options, int atdirectory_port) { +int atclient_authenticate_options_set_at_directory_port(atclient_authenticate_options *options, int atdirectory_port) { int ret = 1; /* @@ -1823,7 +1759,7 @@ int atclient_authenticate_options_set_atdirectory_port(atclient_authenticate_opt if (options == NULL) { ret = 1; atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, - "atclient_authenticate_options_set_atdirectory_port: Invalid arguments\n"); + "atclient_authenticate_options_set_at_directory_port: Invalid arguments\n"); return ret; } @@ -1831,14 +1767,13 @@ int atclient_authenticate_options_set_atdirectory_port(atclient_authenticate_opt * 2. Unset at directory port, if initialized */ if (atclient_authenticate_options_is_atdirectory_port_initialized(options)) { - atclient_authenticate_options_unset_atdirectory_host(options); + atclient_authenticate_options_unset_at_directory_host(options); } /* * 3. Set at directory port */ options->atdirectory_port = atdirectory_port; - atclient_authenticate_options_set_atdirectory_port_initialized(options, true); ret = 0; goto exit; exit: { return ret; } @@ -1867,19 +1802,7 @@ int atclient_authenticate_options_set_atserver_host(atclient_authenticate_option /* * 3. Set atserver host */ - const size_t atserver_host_size = strlen(atserver_host) + 1; - if ((options->atserver_host = (char *)malloc(sizeof(char) * atserver_host_size)) == NULL) { - ret = 1; - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, - "atclient_authenticate_options_set_atserver_host: Failed to allocate memory for atserver host\n"); - return ret; - } - - const size_t atserver_host_len = strlen(atserver_host); - memcpy(options->atserver_host, atserver_host, atserver_host_len); - options->atserver_host[atserver_host_len] = '\0'; - - atclient_authenticate_options_set_atserver_host_initialized(options, true); + options->atserver_host = atserver_host; ret = 0; goto exit; @@ -1911,106 +1834,9 @@ int atclient_authenticate_options_set_atserver_port(atclient_authenticate_option * 3. Set atserver port */ options->atserver_port = atserver_port; - atclient_authenticate_options_set_atserver_port_initialized(options, true); ret = 0; goto exit; exit: { return ret; } -} - -static void atclient_authenticate_options_set_atdirectory_host_initialized(atclient_authenticate_options *options, - const bool initialized) { - /* - * 1. Validate arguments - */ - if (options == NULL) { - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, - "atclient_authenticate_options_set_atdirectory_host_initialized: " - "Invalid arguments\n"); - return; - } - - /* - * 2. Set the at directory host initialized - */ - if (initialized) { - options->_initialized_fields[ATCLIENT_AUTHENTICATE_OPTIONS_ATDIRECTORY_HOST_INDEX] |= - ATCLIENT_AUTHENTICATE_OPTIONS_ATDIRECTORY_HOST_INITIALIZED; - } else { - options->_initialized_fields[ATCLIENT_AUTHENTICATE_OPTIONS_ATDIRECTORY_HOST_INDEX] &= - ~ATCLIENT_AUTHENTICATE_OPTIONS_ATDIRECTORY_HOST_INITIALIZED; - } -} - -static void atclient_authenticate_options_set_atdirectory_port_initialized(atclient_authenticate_options *options, - const bool initialized) { - /* - * 1. Validate arguments - */ - if (options == NULL) { - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, - "atclient_authenticate_options_set_atdirectory_port_initialized: " - "Invalid arguments\n"); - return; - } - - /* - * 2. Set the at directory port initialized - */ - if (initialized) { - options->_initialized_fields[ATCLIENT_AUTHENTICATE_OPTIONS_ATDIRECTORY_PORT_INDEX] |= - ATCLIENT_AUTHENTICATE_OPTIONS_ATDIRECTORY_PORT_INITIALIZED; - } else { - options->_initialized_fields[ATCLIENT_AUTHENTICATE_OPTIONS_ATDIRECTORY_PORT_INDEX] &= - ~ATCLIENT_AUTHENTICATE_OPTIONS_ATDIRECTORY_PORT_INITIALIZED; - } -} - -static void atclient_authenticate_options_set_atserver_host_initialized(atclient_authenticate_options *options, - const bool initialized) { - /* - * 1. Validate arguments - */ - if (options == NULL) { - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, - "atclient_authenticate_options_set_atserver_host_initialized: " - "Invalid arguments\n"); - return; - } - - /* - * 2. Set the atserver host initialized - */ - if (initialized) { - options->_initialized_fields[ATCLIENT_AUTHENTICATE_OPTIONS_ATSERVER_HOST_INDEX] |= - ATCLIENT_AUTHENTICATE_OPTIONS_ATSERVER_HOST_INITIALIZED; - } else { - options->_initialized_fields[ATCLIENT_AUTHENTICATE_OPTIONS_ATSERVER_HOST_INDEX] &= - ~ATCLIENT_AUTHENTICATE_OPTIONS_ATSERVER_HOST_INITIALIZED; - } -} - -static void atclient_authenticate_options_set_atserver_port_initialized(atclient_authenticate_options *options, - const bool initialized) { - /* - * 1. Validate arguments - */ - if (options == NULL) { - atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, - "atclient_authenticate_options_set_atserver_port_initialized: " - "Invalid arguments\n"); - return; - } - - /* - * 2. Set the atserver port initialized - */ - if (initialized) { - options->_initialized_fields[ATCLIENT_AUTHENTICATE_OPTIONS_ATSERVER_PORT_INDEX] |= - ATCLIENT_AUTHENTICATE_OPTIONS_ATSERVER_PORT_INITIALIZED; - } else { - options->_initialized_fields[ATCLIENT_AUTHENTICATE_OPTIONS_ATSERVER_PORT_INDEX] &= - ~ATCLIENT_AUTHENTICATE_OPTIONS_ATSERVER_PORT_INITIALIZED; - } -} +} \ No newline at end of file diff --git a/packages/atcommons/CMakeLists.txt b/packages/atcommons/CMakeLists.txt index 0fe01b70..89f101b6 100644 --- a/packages/atcommons/CMakeLists.txt +++ b/packages/atcommons/CMakeLists.txt @@ -4,12 +4,13 @@ option(ATCOMMONS_BUILD_TESTS "Build tests for atcommons" OFF) # Set include directory and file sources set(ATCOMMONS_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include) set( - ATCOMMONS_SOURCES - ${CMAKE_CURRENT_LIST_DIR}/src/enroll_operation.c - ${CMAKE_CURRENT_LIST_DIR}/src/enroll_status.c - ${CMAKE_CURRENT_LIST_DIR}/src/enroll_namespace.c - ${CMAKE_CURRENT_LIST_DIR}/src/enroll_params.c - ${CMAKE_CURRENT_LIST_DIR}/src/enroll_command_builder.c + ATCOMMONS_SOURCES + ${CMAKE_CURRENT_LIST_DIR}/src/enroll/enroll_operation.c + ${CMAKE_CURRENT_LIST_DIR}/src/enroll/enroll_status.c + ${CMAKE_CURRENT_LIST_DIR}/src/enroll/enroll_namespace.c + ${CMAKE_CURRENT_LIST_DIR}/src/enroll/enroll_params.c + ${CMAKE_CURRENT_LIST_DIR}/src/command_builders/enroll_command_builder.c + ${CMAKE_CURRENT_LIST_DIR}/tests ) # Project setup @@ -20,104 +21,100 @@ cmake_policy(SET CMP0135 NEW) ## not adding the esp target yet project( - atcommons - VERSION 0.0.1 - DESCRIPTION "Atsign technology common utilities and implementations" - HOMEPAGE_URL https://atsign.com - LANGUAGES C + atcommons + VERSION 0.0.1 + DESCRIPTION "Atsign technology common utilities and implementations" + HOMEPAGE_URL https://atsign.com + LANGUAGES C ) -if(NOT ESP_PLATFORM) - include(GNUInstallDirs) - - # Determine if atchops is being built as a subproject using add_subdirectory() - if(NOT DEFINED ATCOMMONS_AS_SUBPROJECT) - set(ATCOMMONS_AS_SUBPROJECT ON) - - if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) - set(ATCOMMONS_AS_SUBPROJECT OFF) - endif() - endif() - - message( - STATUS - "[ATCOMMONS] ATCOMMONS_AS_SUBPROJECT: ${ATCOMMONS_AS_SUBPROJECT}" - ) - - # Import cjson - if(NOT TARGET cjson) - include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/find_cjson.cmake) - endif() - - # Import atlogger - if(NOT TARGET atlogger) - set(atlogger_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../atlogger) - include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/atlogger.cmake) - endif() - - # Create library targets - if(NOT TARGET atcommons) - add_library(${PROJECT_NAME} STATIC ${ATCOMMONS_SOURCES}) - add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) - endif() - - # LINK - # Link include headers to library targets - target_include_directories( - ${PROJECT_NAME} - PUBLIC - $ - $ - $ - ) - - # Link dependencies to library targets - set(ATCOMMONS_INSTALL_TARGETS cjson atlogger) - target_link_libraries(${PROJECT_NAME} PUBLIC ${ATCOMMONS_INSTALL_TARGETS}) - - # INSTALL - # Install the include headers - install( - DIRECTORY ${ATCOMMONS_INCLUDE_DIR}/${PROJECT_NAME} - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - ) - - install( - FILES ${cJSON_SOURCE_DIR}/cJSON.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - ) - - # Install libraries to config target - install( - TARGETS ${PROJECT_NAME} ${ATCOMMONS_INSTALL_TARGETS} - EXPORT ${PROJECT_NAME}-config - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) - - # EXPORT - if(NOT ATCOMMONS_AS_SUBPROJECT AND ATCOMMONS_EXPORT) - # Export the library - export(PACKAGE ${PROJECT_NAME}) - # Install as a config.make +if (NOT ESP_PLATFORM) + include(GNUInstallDirs) + + # Determine if atchops is being built as a subproject using add_subdirectory() + if (NOT DEFINED ATCOMMONS_AS_SUBPROJECT) + set(ATCOMMONS_AS_SUBPROJECT ON) + + if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + set(ATCOMMONS_AS_SUBPROJECT OFF) + endif () + endif () + + message(STATUS "[ATCOMMONS] ATCOMMONS_AS_SUBPROJECT: ${ATCOMMONS_AS_SUBPROJECT}") + + # Import cjson + if (NOT TARGET cjson) + include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/find_cjson.cmake) + endif () + + # Import atlogger + if (NOT TARGET atlogger) + set(atlogger_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../atlogger) + include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/atlogger.cmake) + endif () + + # Create library targets + if (NOT TARGET atcommons) + add_library(${PROJECT_NAME} STATIC ${ATCOMMONS_SOURCES}) + add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) + endif () + + # LINK + # Link include headers to library targets + target_include_directories( + ${PROJECT_NAME} + PUBLIC + $ + $ + $ + ) + + # Link dependencies to library targets + set(ATCOMMONS_INSTALL_TARGETS cjson atlogger) + target_link_libraries(${PROJECT_NAME} PUBLIC ${ATCOMMONS_INSTALL_TARGETS}) + + # INSTALL + # Install the include headers install( - EXPORT ${PROJECT_NAME}-config - NAMESPACE ${PROJECT_NAME}:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} - FILE ${PROJECT_NAME}-config.cmake + DIRECTORY ${ATCOMMONS_INCLUDE_DIR}/${PROJECT_NAME} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) - #export the config.cmake - export( - EXPORT ${PROJECT_NAME}-config - NAMESPACE ${PROJECT_NAME}:: - FILE "cmake/${PROJECT_NAME}-config.cmake" + install( + FILES ${cJSON_SOURCE_DIR}/cJSON.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) - endif() - if(ATCOMMONS_BUILD_TESTS) - message("[ATCOMMONS] Building tests") - enable_testing() - add_subdirectory(tests) - endif() -endif() + # Install libraries to config target + install( + TARGETS ${PROJECT_NAME} ${ATCOMMONS_INSTALL_TARGETS} + EXPORT ${PROJECT_NAME}-config + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) + # EXPORT + if (NOT ATCOMMONS_AS_SUBPROJECT AND ATCOMMONS_EXPORT) + # Export the library + export(PACKAGE ${PROJECT_NAME}) + # Install as a config.make + install( + EXPORT ${PROJECT_NAME}-config + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + FILE ${PROJECT_NAME}-config.cmake + ) + + #export the config.cmake + export( + EXPORT ${PROJECT_NAME}-config + NAMESPACE ${PROJECT_NAME}:: + FILE "cmake/${PROJECT_NAME}-config.cmake" + ) + endif () + + if (ATCOMMONS_BUILD_TESTS) + message("[ATCOMMONS] Building tests") + enable_testing() + add_subdirectory(tests) + endif () +endif () \ No newline at end of file diff --git a/packages/atcommons/include/atcommons/cjson.h b/packages/atcommons/include/atcommons/cjson.h new file mode 100644 index 00000000..249e1f84 --- /dev/null +++ b/packages/atcommons/include/atcommons/cjson.h @@ -0,0 +1,10 @@ +#ifndef ATCOMMONS_CJSON_H +#define ATCOMMONS_CJSON_H + +#if defined(CONFIG_IDF_TARGET_ESP32) +#include +#else +#include "cJSON.h" +#endif + +#endif diff --git a/packages/atcommons/src/command_builders/enroll_command_builder.c b/packages/atcommons/src/command_builders/enroll_command_builder.c new file mode 100644 index 00000000..74745a84 --- /dev/null +++ b/packages/atcommons/src/command_builders/enroll_command_builder.c @@ -0,0 +1,89 @@ +#include "atcommons/enroll_command_builder.h" +#include "atcommons/enroll_operation.h" +#include "atcommons/enroll_params.h" +#include "atlogger/atlogger.h" + +#include +#include +#include +#include + +#define ENROLL_PREFIX "enroll:" +#define TAG "enroll command builder" + +int atcommons_build_enroll_command(char *command, const size_t cmd_size, size_t *cmd_len, + const atcommons_enroll_operation_t operation, const atcommons_enroll_params_t *params) { + int ret = 0; + int cur_len = 0; + char *params_json = NULL, *e_op = NULL; + size_t params_json_len = 0; + + e_op = malloc(sizeof(char) * MAX_ENROLL_OPERATION_STRING_LEN); + if (e_op == NULL) { + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Could not allocate memory for enroll op string\n"); + ret = -1; + goto free_params_json; + } + memset(e_op, 0, sizeof(char) * MAX_ENROLL_OPERATION_STRING_LEN); + + // A, B, C and D are used ONLY to calculate the expected command length + if (command == NULL && cmd_size == 0) { + /* + * A. Caclculate enroll prefix len + */ + cur_len += snprintf(NULL, 0, "%s", ENROLL_PREFIX); + + /* + * B. Calculate enroll operation len + */ + if ((ret = atcommons_enroll_operation_to_string(&e_op, operation)) != 0) { + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atcommons_atcommons_enroll_operation_to_string: %d\n", ret); + goto free_enroll_op; + } + cur_len += snprintf(NULL, 0, "%s:", e_op); + + /* + * C. Calculate enroll params json len + */ + atcommons_enroll_params_to_json(NULL, ¶ms_json_len, params); // fetch 'enroll_params_json' length + cur_len += params_json_len + 3; // +2 for \r\n\0 + + /* + * D. Populate 'cmd_len' with the calculated commmand length + */ + *cmd_len = cur_len; + ret = 1; // setting a non-zero exit code to ensure this if-clause is only used for commadn len calculation + goto free_enroll_op; + } + + /* + * 1. Write the enroll prefix into command + */ + cur_len += snprintf(command, cmd_size, "%s", ENROLL_PREFIX); + + /* + * 2. Convert enroll operation to string, then append to command + */ + if ((ret = atcommons_enroll_operation_to_string(&e_op, operation)) != 0) { + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atcommons_enroll_operation_to_string: %d\n", ret); + ret = 1; + return ret; + } + cur_len += snprintf(command + cur_len, cmd_size, "%s:", e_op); + + /* + * 3. Convert enroll params to JSON, then append to command + */ + if ((ret = atcommons_enroll_params_to_json(¶ms_json, ¶ms_json_len, params)) != 0) { + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atcommons_enroll_params_to_json: %d\n", ret); + goto exit; + } + + // populate enroll_params_json into 'command' + cur_len += snprintf(command + cur_len, cmd_size, "%s\r\n", params_json); + *cmd_len = cur_len; + +free_enroll_op: { free(e_op); } +free_params_json: { free(params_json); } +exit: { return ret; } +} diff --git a/packages/atcommons/src/enroll/enroll_namespace.c b/packages/atcommons/src/enroll/enroll_namespace.c new file mode 100644 index 00000000..26c02612 --- /dev/null +++ b/packages/atcommons/src/enroll/enroll_namespace.c @@ -0,0 +1,84 @@ +#include "atcommons/enroll_namespace.h" + +#include "cJSON.h" + +#include +#include +#include + +#include + +#define TAG "enroll_namespace" + +int atcommons_enroll_namespace_list_append(atcommons_enroll_namespace_list_t **ns_list, + atcommons_enroll_namespace_t *ns) { + // allocate enough memory for enroll_namespace_list struct, and the number of atcommons_enroll_namespace_t structs + // that are in the list + atcommons_enroll_namespace_list_t *temp = + realloc(*ns_list, sizeof(atcommons_enroll_namespace_list_t) + + sizeof(atcommons_enroll_namespace_t) * ((*ns_list)->length + 1)); + + if (temp == NULL) { + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Unable to realloc memory for enroll namespace list\n"); + return -1; + } + + // Add the new namespace to the end of the list + temp->namespaces[temp->length] = ns; + temp->length++; + + // Update the original ns_list to point to the new (reallocated) memory + *ns_list = temp; + + return 0; +} + +int atcommons_enroll_namespace_to_json(char *ns_str, const size_t ns_str_size, size_t *ns_str_len, + const atcommons_enroll_namespace_t *ns) { + if (ns == NULL) { + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "ns(namespace) cannot be null\n"); + return -1; + } + if (ns_str == NULL && ns_str_size == 0) { + *ns_str_len = snprintf(NULL, 0, "{\"%s\":\"%s\"}", ns->name, ns->access) + 1; // +1 for \0 + } + + *ns_str_len = snprintf(ns_str, ns_str_size, "{\"%s\":\"%s\"}", ns->name, ns->access); + + return 0; +} + +int atcommons_enroll_namespace_list_to_json(char **ns_list_string, size_t *ns_list_str_len, + const atcommons_enroll_namespace_list_t *ns_list) { + if (ns_list == NULL) { + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "ns_list(namespace list) cannot be null\n"); + return -1; + } + if (ns_list_str_len == NULL) { + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "ns_list_str_len(namespace_list string length) cannot be null\n"); + return -1; + } + // Create a new cJSON object + cJSON *json_obj = cJSON_CreateObject(); + if (json_obj == NULL) { + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to create JSON object\n"); + return -1; + } + + for (size_t ns_elmnt = 0; ns_elmnt < ns_list->length; ns_elmnt++) { + cJSON_AddStringToObject(json_obj, ns_list->namespaces[ns_elmnt]->name, ns_list->namespaces[ns_elmnt]->access); + } + + *ns_list_string = cJSON_PrintUnformatted(json_obj); + if (*ns_list_string == NULL) { + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to print JSON\n"); + cJSON_Delete(json_obj); + return -1; + } + if (ns_list_str_len != NULL) { + *ns_list_str_len = strlen(*ns_list_string); + } + + cJSON_Delete(json_obj); + return 0; +} diff --git a/packages/atcommons/src/enroll/enroll_operation.c b/packages/atcommons/src/enroll/enroll_operation.c new file mode 100644 index 00000000..2c8e6f9e --- /dev/null +++ b/packages/atcommons/src/enroll/enroll_operation.c @@ -0,0 +1,48 @@ +#include "atcommons/enroll_operation.h" + +#include +#include +#include + +#define ATCOMMONS_ENROLL_OPERATION_REQUEST "request" +#define ATCOMMONS_ENROLL_OPERATION_APPROVE "approve" +#define ATCOMMONS_ENROLL_OPERATION_DENY "deny" +#define ATCOMMONS_ENROLL_OPERATION_REVOKE "revoke" +#define ATCOMMONS_ENROLL_OPERATION_UNREVOKE "unrevoke" +#define ATCOMMONS_ENROLL_OPERATION_LIST "list" +#define ATCOMMONS_ENROLL_OPERATION_DELETE "delete" + +int atcommons_enroll_operation_to_string(char **op_name, const atcommons_enroll_operation_t e_op) { + int ret = 0; + if (op_name == NULL) { + ret = -1; + return ret; + } + + switch (e_op) { + case atcommons_apkam_request: + strcpy(*op_name, ATCOMMONS_ENROLL_OPERATION_REQUEST); + break; + case atcommons_apkam_approve: + strcpy(*op_name, ATCOMMONS_ENROLL_OPERATION_APPROVE); + break; + case atcommons_apkam_deny: + strcpy(*op_name, ATCOMMONS_ENROLL_OPERATION_DENY); + break; + case atcommons_apkam_revoke: + strcpy(*op_name, ATCOMMONS_ENROLL_OPERATION_REVOKE); + break; + case atcommons_apkam_unrevoke: + strcpy(*op_name, ATCOMMONS_ENROLL_OPERATION_UNREVOKE); + break; + case atcommons_apkam_list: + strcpy(*op_name, ATCOMMONS_ENROLL_OPERATION_LIST); + break; + case atcommons_apkam_delete: + strcpy(*op_name, ATCOMMONS_ENROLL_OPERATION_DELETE); + break; + default: + ret = 1; + } + return ret; +} diff --git a/packages/atcommons/src/enroll/enroll_params.c b/packages/atcommons/src/enroll/enroll_params.c new file mode 100644 index 00000000..27745d71 --- /dev/null +++ b/packages/atcommons/src/enroll/enroll_params.c @@ -0,0 +1,118 @@ +#include "atcommons/enroll_params.h" + +#include "cJSON.h" + +#include +#include +#include +#include +#include + +#define ENROLLMENT_ID "enrollmentId" +#define APP_NAME "appName" +#define DEVICE_NAME "deviceName" +#define OTP "otp" +#define NAMESPACES "namespaces" +#define APKAM_PUBLIC_KEY "apkamPublicKey" +#define ENCRYPTED_DEFAULT_ENCRYPTION_PRIVATE_KEY "encryptedDefaultEncryptionPrivateKey" +#define ENCRYPTED_DEFAULT_SELF_ENCRYPTION_KEY "encryptedDefaultSelfEncryptionKey" +#define ENCRYPTED_APKAM_SYMMETRIC_KEY "encryptedAPKAMSymmetricKey" +#define APKAM_KEYS_EXPIRY "apkamKeysExpiryInMillis" // in milliseconds + +#define TAG "enroll_params" + +int atcommons_enroll_params_init(atcommons_enroll_params_t *ep) { + /* + * 1. Validate arguments + */ + if (ep == NULL) { + return -1; + } + + /* + * 2. Initialize + */ + memset(ep, 0, sizeof(atcommons_enroll_params_t)); + + return 0; +} + +int atcommons_enroll_params_to_json(char **json_string, size_t *json_string_len, const atcommons_enroll_params_t *ep) { + int ret = 0; + + if (ep == NULL) { + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, + "enroll params cannot be null for atcommons_enroll_params_to_json\n"); + ret = -1; + return ret; + } + + cJSON *json_object = cJSON_CreateObject(); + if (json_object == NULL) { + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to create JSON object\n"); + ret = -1; + return ret; + } + + // Add each parameter to JSON only if it is not NULL + if (ep->enrollment_id != NULL) { + cJSON_AddStringToObject(json_object, ENROLLMENT_ID, ep->enrollment_id); + } + + if (ep->app_name != NULL) { + cJSON_AddStringToObject(json_object, APP_NAME, ep->app_name); + } + + if (ep->device_name != NULL) { + cJSON_AddStringToObject(json_object, DEVICE_NAME, ep->device_name); + } + + if (ep->otp != NULL) { + cJSON_AddStringToObject(json_object, OTP, ep->otp); + } + + char *ns_json = NULL; + // Ensure ns_list is not NULL before accessing namespaces + if (ep->ns_list != NULL && ep->ns_list->length > 0) { + size_t ns_list_str_len = 0; + if ((ret = atcommons_enroll_namespace_list_to_json(&ns_json, &ns_list_str_len, ep->ns_list)) != 0) { + atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, + "enroll_namespace_list serialization failed. atcommons_enroll_namespace_list_to_json: %d\n", ret); + ret = 1; + goto exit; + } + cJSON_AddRawToObject(json_object, NAMESPACES, ns_json); + } + + // Add Base64-encoded strings directly to JSON + if (ep->apkam_public_key != NULL) { + cJSON_AddStringToObject(json_object, APKAM_PUBLIC_KEY, (const char *)ep->apkam_public_key); + } + + if (ep->encrypted_default_encryption_private_key != NULL) { + cJSON_AddStringToObject(json_object, ENCRYPTED_DEFAULT_ENCRYPTION_PRIVATE_KEY, + (const char *)ep->encrypted_default_encryption_private_key); + } + + if (ep->encrypted_self_encryption_key != NULL) { + cJSON_AddStringToObject(json_object, ENCRYPTED_DEFAULT_SELF_ENCRYPTION_KEY, + (const char *)ep->encrypted_self_encryption_key); + } + + if (ep->encrypted_apkam_symmetric_key != NULL) { + cJSON_AddStringToObject(json_object, ENCRYPTED_APKAM_SYMMETRIC_KEY, + (const char *)ep->encrypted_apkam_symmetric_key); + } + // pass memory ownership of the json string to the caller + if (json_string != NULL) { + *json_string = cJSON_PrintUnformatted(json_object); + } + if (json_string_len != NULL) { + *json_string_len = strlen(cJSON_PrintUnformatted(json_object)); + } + +exit: + free(ns_json); + cJSON_Delete(json_object); + return ret; +} diff --git a/packages/atcommons/src/enroll/enroll_status.c b/packages/atcommons/src/enroll/enroll_status.c new file mode 100644 index 00000000..f8cb79bc --- /dev/null +++ b/packages/atcommons/src/enroll/enroll_status.c @@ -0,0 +1,29 @@ +#include "atcommons/enroll_status.h" + +#include +#include + +int enroll_status_to_string(char *status, const atcommons_enroll_status_t es) { + int ret = 0; + if (status == NULL) { + ret = -1; + goto exit; + } + + switch (es) { + case atcommons_enroll_status_pending: + strncpy(status, "pending", ATCOMMONS_ENROLL_STATUS_STRING_MAX_LEN); + case atcommons_enroll_status_approved: + strncpy(status, "approved", ATCOMMONS_ENROLL_STATUS_STRING_MAX_LEN); + case atcommons_enroll_status_denied: + strncpy(status, "denied", ATCOMMONS_ENROLL_STATUS_STRING_MAX_LEN); + case atcommons_enroll_status_revoked: + strncpy(status, "revoked", ATCOMMONS_ENROLL_STATUS_STRING_MAX_LEN); + case atcommons_enroll_status_expired: + strncpy(status, "expired", ATCOMMONS_ENROLL_STATUS_STRING_MAX_LEN); + default: + ret = -1; + } + + exit: { return ret; } +} diff --git a/packages/atlogger/src/atlogger.c b/packages/atlogger/src/atlogger.c index cf32b685..a7a803cd 100644 --- a/packages/atlogger/src/atlogger.c +++ b/packages/atlogger/src/atlogger.c @@ -5,10 +5,7 @@ #include #include #include - -#if !defined(ATLOGGER_DISABLE_TIMESTAMPS) && !defined(ATLOGGER_OVERRIDE_LOG_FUNCTION) #include -#endif #define PREFIX_BUFFER_LEN 64 #define INFO_PREFIX "\e[0;32m[INFO]\e[0m" @@ -26,12 +23,13 @@ static int is_ctx_initalized = 0; static atlogger_ctx *atlogger_get_instance() { if (is_ctx_initalized == 0) { + ctx.opts = ATLOGGER_ENABLE_TIMESTAMPS; + is_ctx_initalized = 1; } return &ctx; } -#ifndef ATLOGGER_OVERRIDE_LOG_FUNCTION static void atlogger_get_prefix(enum atlogger_logging_level logging_level, char *prefix, size_t prefixlen) { memset(prefix, 0, prefixlen); int off = 0; @@ -62,30 +60,30 @@ static void atlogger_get_prefix(enum atlogger_logging_level logging_level, char } } -#ifndef ATLOGGER_DISABLE_TIMESTAMPS + atlogger_ctx *ctx = atlogger_get_instance(); struct timespec timespec; - int res = clock_gettime(CLOCK_REALTIME, ×pec); - - if (res == 0) { - res = strftime(prefix + off, PREFIX_BUFFER_LEN - off, " %F %T", - gmtime(×pec.tv_sec)); // format accurate to the second - if (res != 0) { - off += res; - res = 0; + if (ctx->opts & ATLOGGER_ENABLE_TIMESTAMPS) { + int res = clock_gettime(CLOCK_REALTIME, ×pec); + + if (res == 0) { + res = strftime(prefix + off, PREFIX_BUFFER_LEN - off, " %F %T", + gmtime(×pec.tv_sec)); // format accurate to the second + if (res != 0) { + off += res; + res = 0; + } + } + if (res == 0) { + snprintf(prefix + off, PREFIX_BUFFER_LEN - off, ".%09lu", timespec.tv_nsec); + off += strlen(prefix + off); } - } - if (res == 0) { - snprintf(prefix + off, PREFIX_BUFFER_LEN - off, ".%09lu", timespec.tv_nsec); - off += strlen(prefix + off); - } -#endif - off -= 3; - snprintf(prefix + off, PREFIX_BUFFER_LEN - off, " |"); - off += 2; - prefix[off] = '\0'; + off -= 3; + snprintf(prefix + off, PREFIX_BUFFER_LEN - off, " |"); + off += 2; + prefix[off] = '\0'; + } } -#endif enum atlogger_logging_level atlogger_get_logging_level() { atlogger_ctx *ctx = atlogger_get_instance(); @@ -102,7 +100,6 @@ void atlogger_set_opts(int opts) { ctx->opts = opts; } -#ifndef ATLOGGER_OVERRIDE_LOG_FUNCTION void atlogger_log(const char *tag, const enum atlogger_logging_level level, const char *format, ...) { atlogger_ctx *ctx = atlogger_get_instance(); @@ -124,7 +121,6 @@ void atlogger_log(const char *tag, const enum atlogger_logging_level level, cons vprintf(format, args); va_end(args); } -#endif void atlogger_fix_stdout_buffer(char *str, const size_t strlen) { // if str == 'Jeremy\r\n', i want it to be 'Jeremy' @@ -148,7 +144,7 @@ void atlogger_fix_stdout_buffer(char *str, const size_t strlen) { } if (carriagereturnindex != -1) { - for (size_t i = carriagereturnindex; i < strlen - 1; i++) { + for (int i = carriagereturnindex; i < strlen - 1; i++) { str[i] = str[i + 1]; } str[strlen - 1] = '\0'; @@ -164,7 +160,7 @@ void atlogger_fix_stdout_buffer(char *str, const size_t strlen) { } if (newlineindex != -1) { - for (size_t i = newlineindex; i < strlen - 1; i++) { + for (int i = newlineindex; i < strlen - 1; i++) { str[i] = str[i + 1]; } str[strlen - 1] = '\0';