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 14 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: 0 additions & 4 deletions .clang-format

This file was deleted.

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
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Configurable options
set(TARGET_ESPIDF FALSE CACHE BOOL "Build for the espidf platform")
option(ATSDK_BUILD_TESTS "Build tests for atsdk" OFF)
option(ATSDK_BUILD_TESTS "Build tests for atsdk" ON)

# Basic project setup
cmake_minimum_required(VERSION 3.24)
Expand Down Expand Up @@ -37,6 +37,14 @@ message(STATUS "Building atclient")
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_TESTS})
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/packages/atauth)

if(NOT ESP_PLATFORM)
# install dependencies
set(
Expand All @@ -51,6 +59,8 @@ if(NOT ESP_PLATFORM)
cjson
atlogger
atclient
atcommons
atauth
)

install(
Expand Down
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()
20 changes: 20 additions & 0 deletions cmake/find_argp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This installs the target cjson
# Configurable variables
set(ARGP_BUILD_SHARED_LIBS OFF CACHE BOOL "Build argp shared libraries")
option(ENABLE_ARGP_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 "[Argp] fetching package...")
include(FetchContent)

FetchContent_Declare(
argp
URL https://github.com/jmhodges/argp-standalone

# URL_HASH
# SHA256=51f3b07aece8d1786e74b951fd92556506586cb36670741b6bfb79bf5d484216 # hash for v1.7.17 .zip release source code
# FIND_PACKAGE_ARGS 1.7.17 QUIET CONFIG
)

FetchContent_MakeAvailable(argp)
install(TARGETS argp)
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
6 changes: 3 additions & 3 deletions examples/desktop/crud/get_selfkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,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 @@ -90,7 +90,7 @@ exit: {
atclient_atkey_free(&atkey);
atclient_atkeys_free(&atkeys);
atclient_free(&atclient);
atclient_pkam_authenticate_options_free(&options);
atclient_authenticate_options_free(&options);
free(atkeystr);
return ret;
}
Expand Down
6 changes: 3 additions & 3 deletions examples/desktop/crud/get_sharedkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ int main() {
atclient_atkeys_init(&atkeys);
atclient_atkeys_populate_from_path(&atkeys, ATSIGN_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 @@ -128,7 +128,7 @@ exit: {
atclient_atkey_free(&atkey);
atclient_atkeys_free(&atkeys);
atclient_free(&atclient);
atclient_pkam_authenticate_options_free(&options);
atclient_authenticate_options_free(&options);
free(atkeystr);
return ret;
}
Expand Down
6 changes: 3 additions & 3 deletions examples/desktop/crud/put_publickey.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,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 @@ -93,7 +93,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
6 changes: 3 additions & 3 deletions examples/desktop/crud/put_selfkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,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 @@ -91,7 +91,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
6 changes: 3 additions & 3 deletions examples/desktop/crud/put_sharedkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,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 @@ -87,7 +87,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