Skip to content

Commit

Permalink
feat: c at_activate and required components (#423)
Browse files Browse the repository at this point in the history
* feat: create atcommons and introduce enroll related deps

* feat: introduce arg parser for at_activate

* feat: add apkam_symmetric_key to atkeys_file

* feat: add apkam_symmetric_key to atkeys

* feat: introduce atactivate + hex, base64 and utf8 utils

* feat: cmakeLists update + default homedir impl + more atactivate code

* fix: import platform dependent header limits.

* chore: rename all instance of "atclient_pkam_authenticate_options_*" -> "atclient_authenticate_options_*"

* test: atcommons unit tests

* chore(deps): bump github/codeql-action in the github-actions group

Bumps the github-actions group with 1 update: [github/codeql-action](https://github.com/github/codeql-action).


Updates `github/codeql-action` from 3.27.1 to 3.27.3
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@4f3212b...396bb3e)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore(deps): bump github/codeql-action in the github-actions group

Bumps the github-actions group with 1 update: [github/codeql-action](https://github.com/github/codeql-action).


Updates `github/codeql-action` from 3.27.3 to 3.27.4
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@396bb3e...ea9e4e3)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore(deps): bump github/codeql-action in the github-actions group

Bumps the github-actions group with 1 update: [github/codeql-action](https://github.com/github/codeql-action).


Updates `github/codeql-action` from 3.27.4 to 3.27.5
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@ea9e4e3...f09c1c0)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <[email protected]>

* feat: introduce auth_cli

* Revert "feat: introduce auth_cli"

This reverts commit a3d043a.
This reverts commit d646b46.
This reverts commit aff312e.
This reverts commit e8c7b71.

* fix: address review comments

* chore: revert changes reg recursive write in atclient/connection.c

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: xavierchanth <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 2, 2024
1 parent a25c26f commit 9b9bdd4
Show file tree
Hide file tree
Showing 87 changed files with 3,090 additions and 329 deletions.
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>

#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
Loading

0 comments on commit 9b9bdd4

Please sign in to comment.