Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: c at_activate and required components #423

Merged
merged 30 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9295b4e
feat: create atcommons and introduce enroll related deps
srieteja Sep 25, 2024
f786bc7
feat: introduce arg parser for at_activate
srieteja Oct 3, 2024
c7c637d
feat: add apkam_symmetric_key to atkeys_file
XavierChanth Sep 27, 2024
ff396f8
feat: add apkam_symmetric_key to atkeys
XavierChanth Sep 27, 2024
8964e73
feat: introduce atactivate + hex, base64 and utf8 utils
srieteja Oct 14, 2024
6710bfb
feat: cmakeLists update + default homedir impl + more atactivate code
srieteja Oct 21, 2024
c034d1e
docs: added docs + some more refactoring
srieteja Nov 6, 2024
b2925c7
fix: migration to mallocs + minor refactoring
srieteja Nov 7, 2024
061439b
chore: resolve compile warnings and refactor methods signatures
srieteja Nov 8, 2024
2e90e60
fix: import platform dependent header limits.
srieteja Nov 11, 2024
04a872b
chore: rename all instance of "atclient_pkam_authenticate_options_*" …
srieteja Nov 12, 2024
013fd0a
fix: analyzer warnings
srieteja Nov 13, 2024
6957202
chore: update .gitignore
srieteja Nov 13, 2024
ecf30f1
chore: fix method duplication
srieteja Nov 13, 2024
9a59586
chore: refactoring + add missing docs + better logging
srieteja Nov 14, 2024
2491f69
test: unit tests + refactoring
srieteja Nov 20, 2024
eba4ff0
test: unit tests + refactoring
srieteja Nov 20, 2024
e5153e9
Merge remote-tracking branch 'origin/create_at_commons' into create_a…
srieteja Nov 20, 2024
ac675cf
chore: address review comments
srieteja Nov 21, 2024
b23f45c
chore: address review comments - round 2
srieteja Nov 24, 2024
c90f62b
fix: atsign memory leak bug
srieteja Nov 24, 2024
88501e5
fix: atsign memory leak bug
srieteja Nov 24, 2024
6a3231d
Merge remote-tracking branch 'origin/create_at_commons' into create_a…
srieteja Nov 25, 2024
6af0010
chore(deps): bump github/codeql-action in the github-actions group
dependabot[bot] Nov 13, 2024
8e43d43
chore(deps): bump github/codeql-action in the github-actions group
dependabot[bot] Nov 15, 2024
70ded5f
chore(deps): bump github/codeql-action in the github-actions group
dependabot[bot] Nov 21, 2024
d3e102e
feat: introduce auth_cli
srieteja Nov 28, 2024
6fe4e57
Revert "feat: introduce auth_cli"
srieteja Nov 28, 2024
5162fb8
fix: address review comments
srieteja Nov 29, 2024
9e57229
chore: revert changes reg recursive write in atclient/connection.c
srieteja Dec 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1
uses: github/codeql-action/init@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand Down Expand Up @@ -81,6 +81,6 @@ jobs:
./build/main

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1
uses: github/codeql-action/analyze@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
with:
category: "/language:${{matrix.language}}"
2 changes: 1 addition & 1 deletion .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1
uses: github/codeql-action/upload-sarif@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
with:
sarif_file: results.sarif
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ __pycache__/
.pio/

test/*/test_*
/.clang-format
104 changes: 57 additions & 47 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,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
Expand All @@ -37,45 +37,55 @@ message(STATUS "Building atclient")
set(ATCLIENT_BUILD_TESTS ${ATSDK_BUILD_TESTS})
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/packages/atclient)

if(NOT ESP_PLATFORM)
# install dependencies
set(
ATSDK_TARGETS
mbedtls
mbedx509
mbedcrypto
everest
p256m
uuid4-static
atchops
cjson
atlogger
atclient
)
message(STATUS "Building atcommons")
set(ATCOMMONS_BUILD_TESTS ${ATSDK_BUILD_TESTS})
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/packages/atcommons)

install(
TARGETS ${ATSDK_TARGETS}
EXPORT ${PROJECT_NAME}-config
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
message(STATUS "Building atauth")
set(ATAUTH_BUILD_TESTS ${ATSDK_BUILD_TESTS})
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/packages/atauth)

# export dependencies
if(NOT ATSDK_AS_SUBPROJECT)
export(PACKAGE ${PROJECT_NAME})
if (NOT ESP_PLATFORM)
# install dependencies
set(
ATSDK_TARGETS
mbedtls
mbedx509
mbedcrypto
everest
p256m
uuid4-static
atchops
cjson
atlogger
atclient
atcommons
atauth
)

# 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
TARGETS ${ATSDK_TARGETS}
EXPORT ${PROJECT_NAME}-config
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

# export the config.cmake
export(
EXPORT ${PROJECT_NAME}-config
NAMESPACE ${PROJECT_NAME}::
FILE "cmake/${PROJECT_NAME}-config.cmake"
)
endif()
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 ()
10 changes: 10 additions & 0 deletions cmake/atauth.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if(NOT TARGET atauth)
include(FetchContent)
message(
STATUS
"[ATAUTH] package not found, fetching from local repository.."
)
FetchContent_Declare(atauth SOURCE_DIR ${atauth_DIR})
FetchContent_MakeAvailable(atauth)
install(TARGETS atauth)
endif()
15 changes: 8 additions & 7 deletions cmake/atclient.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
if(NOT TARGET atclient)
message(
STATUS
"[ATCLIENT] package not found, fetching from local repository.."
)
fetchcontent_declare(atclient SOURCE_DIR ${atclient_DIR})
fetchcontent_makeavailable(atclient)
install(TARGETS atclient)
include(FetchContent)
message(
STATUS
"[ATCLIENT] package not found, fetching from local repository.."
)
FetchContent_Declare(atclient SOURCE_DIR ${atclient_DIR})
FetchContent_MakeAvailable(atclient)
install(TARGETS atclient)
endif()
10 changes: 10 additions & 0 deletions cmake/atcommons.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if(NOT TARGET atcommons)
include(FetchContent)
message(
STATUS
"[ATCOMMONS] package not found, fetching from local repository.. [PATH: ${atcommons_DIR}]"
)
FetchContent_Declare(atcommons SOURCE_DIR ${atcommons_DIR})
FetchContent_MakeAvailable(atcommons)
install(TARGETS atcommons)
endif()
15 changes: 8 additions & 7 deletions cmake/atlogger.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
if(NOT TARGET atlogger)
message(
STATUS
"[ATLOGGER] package not found, fetching from local repository.."
)
fetchcontent_declare(atlogger SOURCE_DIR ${atlogger_DIR})
fetchcontent_makeavailable(atlogger)
install(TARGETS atlogger)
include(FetchContent)
message(
STATUS
"[ATLOGGER] package not found, fetching from local repository.."
)
fetchcontent_declare(atlogger SOURCE_DIR ${atlogger_DIR})
fetchcontent_makeavailable(atlogger)
install(TARGETS atlogger)
endif()
6 changes: 3 additions & 3 deletions cmake/find_cjson.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ set(CJSON_BUILD_SHARED_LIBS OFF CACHE BOOL "Build cjson shared libraries")
option(ENABLE_CJSON_TEST "Enable tests for cjson" OFF)
set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE OPT_IN) # only try find_package if FIND_PACKAGE_ARGS is set

message(STATUS "[cjson] fetching package...")
message(STATUS "[cJSON] fetching package...")
include(FetchContent)

fetchcontent_declare(
FetchContent_Declare(
cjson
URL https://github.com/DaveGamble/cJSON/archive/refs/tags/v1.7.17.zip
URL_HASH
SHA256=51f3b07aece8d1786e74b951fd92556506586cb36670741b6bfb79bf5d484216 # hash for v1.7.17 .zip release source code
# FIND_PACKAGE_ARGS 1.7.17 QUIET CONFIG
)

fetchcontent_makeavailable(cjson)
FetchContent_MakeAvailable(cjson)
install(TARGETS cjson)
11 changes: 6 additions & 5 deletions examples/desktop/at_talk/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <bits/getopt_core.h>
Copy link
Member

Choose a reason for hiding this comment

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

private header, see man getopt(3)


#define ROOT_HOST "root.atsign.org"
#define ROOT_PORT 64
Expand Down Expand Up @@ -96,8 +97,8 @@ int main(int argc, char *argv[]) {
* 4. Authenticate client connection (for crud operations)
*/
pthread_mutex_lock(&client_mutex);
atclient_pkam_authenticate_options options;
atclient_pkam_authenticate_options_init(&options);
atclient_authenticate_options options;
atclient_authenticate_options_init(&options);
if ((ret = atclient_pkam_authenticate(&atclient1, from_atsign, &atkeys, &options)) != 0) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "\natclient_pkam_authenticate: %d\n", ret);
goto exit;
Expand Down Expand Up @@ -189,7 +190,7 @@ exit: {
pthread_mutex_destroy(&monitor_mutex);
ret = pthread_cancel(tid);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "pthread exit: %d\n", ret);
atclient_pkam_authenticate_options_free(&options);
atclient_authenticate_options_free(&options);
return ret;
}
}
Expand Down Expand Up @@ -340,8 +341,8 @@ static int reconnect_clients(atclient *monitor, atclient *ctx, const char *atser
* 1. Reconnect client connection
*/
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "Reconnecting client connection...\n");
atclient_pkam_authenticate_options options;
atclient_pkam_authenticate_options_init(&options);
atclient_authenticate_options options;
atclient_authenticate_options_init(&options);
if ((ret = atclient_pkam_authenticate(ctx, from_atsign, atkeys, &options)) != 0) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_pkam_authenticate: %d\n", ret);
return ret;
Expand Down
1 change: 1 addition & 0 deletions examples/desktop/cram_authenticate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*build*/
10 changes: 10 additions & 0 deletions examples/desktop/cram_authenticate/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.19)

project(cram_authenticate LANGUAGES C VERSION 0.0.1)

add_executable(main ${CMAKE_CURRENT_LIST_DIR}/src/main.c)

find_package(atsdk CONFIG REQUIRED)

target_link_libraries(main PRIVATE atsdk::atclient atsdk::atchops atsdk::atcommons)

16 changes: 16 additions & 0 deletions examples/desktop/cram_authenticate/develop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -eu
FULL_PATH_TO_SCRIPT="$(realpath "${BASH_SOURCE[0]}")"
SCRIPT_DIRECTORY="$(dirname "$FULL_PATH_TO_SCRIPT")"
cd "$SCRIPT_DIRECTORY/../../../packages/atclient"
cmake -S . -B build
sudo cmake --build build --target install
pwd
cd "$SCRIPT_DIRECTORY"
cmake -S . -B build
cmake --build build --target all
echo "Running main:"
echo ""
echo ""
cd build && ./main
cd ..
41 changes: 41 additions & 0 deletions examples/desktop/cram_authenticate/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <atclient/atclient.h>
#include <atlogger/atlogger.h>
#include <atchops/base64.h>
#include <stdio.h>
#include <string.h>

#define ROOT_HOST "root.atsign.org"
#define ROOT_PORT 64

#define CRAM_SECRET "66e026167a79cb7e9d190afe7b01b3fc4f31bc3866a08cdcec06d82a7296e9febcac5d4f4a081728fb0ec9d08f27d4f866bd6570f3fe20c65464ace76643becb"
#define ATSIGN "@disciplinarygemini"

#define TAG "cram_authenticate"

int main(int argc, char **argv) {
int ret = 1;

atlogger_set_logging_level(ATLOGGER_LOGGING_LEVEL_DEBUG);

atclient_authenticate_options options;
atclient_authenticate_options_init(&options);

atclient atclient;
atclient_init(&atclient);

const char *atsign = ATSIGN;
const char *cram_secret = &CRAM_SECRET[0];

if ((ret = atclient_cram_authenticate(&atclient, ATSIGN, cram_secret, &options)) != 0) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to authenticate\n");
goto exit;
} else {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "Authenticated\n");
}

exit: {
atclient_free(&atclient);
atclient_authenticate_options_free(&options);
return ret;
}
}
6 changes: 3 additions & 3 deletions examples/desktop/crud/delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ int main() {
atclient_atkey_init(&atkey);
atclient_atkeys_init(&atkeys);

atclient_pkam_authenticate_options options;
atclient_pkam_authenticate_options_init(&options);
atclient_authenticate_options options;
atclient_authenticate_options_init(&options);

if ((ret = atclient_atkeys_populate_from_path(&atkeys, ATKEYS_FILE_PATH)) != 0) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to populate atkeys");
Expand Down Expand Up @@ -65,7 +65,7 @@ exit: {
atclient_free(&atclient);
atclient_atkey_free(&atkey);
atclient_atkeys_free(&atkeys);
atclient_pkam_authenticate_options_free(&options);
atclient_authenticate_options_free(&options);
return ret;
}
}
6 changes: 3 additions & 3 deletions examples/desktop/crud/get_publickey.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ int main() {
atclient_atkeys_init(&atkeys);
atclient_atkeys_populate_from_path(&atkeys, ATKEYS_FILE_PATH);

atclient_pkam_authenticate_options options;
atclient_pkam_authenticate_options_init(&options);
atclient_authenticate_options options;
atclient_authenticate_options_init(&options);

char *atkeystr = NULL;

Expand Down Expand Up @@ -94,7 +94,7 @@ exit: {
atclient_atkeys_free(&atkeys);
atclient_atkey_free(&atkey);
atclient_free(&atclient);
atclient_pkam_authenticate_options_free(&options);
atclient_authenticate_options_free(&options);
free(atkeystr);
return ret;
}
Expand Down
Loading
Loading