Skip to content

Commit

Permalink
test: CRUD functional_tests, atchops fixes, & misc changes (#210)
Browse files Browse the repository at this point in the history
* refactor: moved atclient crud implementations to their individual files

* fix: self key put bug

* refactor:

* refactor:

* refactor: made aes encrypt/decrypt more atomic

* fix: atclient_get_selfkey.c

* fix: atclient put selfkey

* fix: atclient get shared key

* fix: encrypt public key atkeys

* fix: atclient get shared key

* refactor: sha documentation and parameter names

* refactor: rsa to be more atomic (no base64 reliance)

* fix: aes ctr ciphertextlen in encrypt

* chore: test_aes_generate more logging

* feat: made sha and rsa encrypt/decrypt and sign/verify more atomic (no base64 dependencies)

* fix: sha test

* fix: working crud operations

* refactor: atclient_atlogger_log -> atlogger_log and atclient_atlogger_set_logging_level -> atlogger_set_logging_level

* refactor: removed more atclient_ prefixes in atlogger

* test: start on functional_tests

* test: start on shared key functional test

* docs: rsa.h

* feat: fix pkam authenticate

* chore: remove logging

* fix: put sharedkey example

* fix: atlogger syntax error

* fix: remove root_conn from atclient_put

* chore: optimize get_atkeys_path

* fix: flaky pkam authenticate

* test: functional test for putting sharedkey

* fix: rsa encrypt bug

* fix: rsa decrypt bug

* fix: removed unnecessary root_conn in encryption_key_helper functions

* fix: put_sharedkey desktop crud example

* fix: put shared key functional test

* test: get shared key as shared by

* fix: syntax fixes

* feat: rsa encrypt/decrypt more robust

* fix: syntax errors in our examples

* refactor: valuelen -> valuesize and valueolen -> valuelen

* test: functional test passing consistently

* test: working func test: test_atclient_sharedkey.c

* feat: github workflow functional tests

* fix:

* ci: load secrets

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci: teardown should fail test

* ci:

* ci:

* ci: sudo ?

* fix: fix flaking test_aes_generate unit test

* ci:

* ci:

* chore: keys folder

* ci:

* chore: gitignore atkeys

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci: oops

* ci:

* ci:

* ci:

* ci: try home directory

* ci:

* ci: back to relative directory

* ci:

* ci: try cd-ing then ctest?

* ci: comment out try ctest

* ci: try this

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* ci:

* fix: metadata isEncrypted:false not working

* test: test_atclient_selfkey.c

* refactor: functional_tests namespace

* test: lots of work

* test: more logging

* ci: sharedkey test improvements

* ci:

* ci:

* ci: done

* fix: desktop examples
  • Loading branch information
JeremyTubongbanua authored May 2, 2024
1 parent c7f01d5 commit 357c892
Show file tree
Hide file tree
Showing 55 changed files with 2,483 additions and 785 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Unit and Functional Tests

on:
workflow_dispatch:
push:
branches: [trunk]
pull_request:
branches: [trunk]

permissions: # added using https://github.com/step-security/secure-repo
contents: read

jobs:
unit-tests:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4

- name: atsdk Unit CTest
run: |
./tools/run_ctest.sh
functional-tests:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4

- name: Load secrets
working-directory: tests/functional_tests
run: |
mkdir -p ~/.atsign/keys/
echo "${{ secrets.ATKEYS_12ALPACA }}" > ~/.atsign/keys/@12alpaca_key.atKeys
echo "${{ secrets.ATKEYS_12SNOWBOATING }}" > ~/.atsign/keys/@12snowboating_key.atKeys
- name: Build and Run Functional Tests
working-directory: tests/functional_tests
run: |
tools/run_ctest.sh
20 changes: 0 additions & 20 deletions .github/workflows/unit_tests.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion examples/desktop/at_talk/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sudo rm -f bin/at_talk
# install dependencies
FULL_PATH_TO_SCRIPT="$(realpath "${BASH_SOURCE[0]}")"
SCRIPT_DIRECTORY="$(dirname "$FULL_PATH_TO_SCRIPT")"
"$SCRIPT_DIRECTORY/../../../packages/atclient/tools/install.sh"
"$SCRIPT_DIRECTORY/../../../tools/install.sh"
cd "$SCRIPT_DIRECTORY"

# configure
Expand Down
11 changes: 6 additions & 5 deletions examples/desktop/at_talk/src/main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <atclient/atclient.h>
#include <atclient/encryption_key_helpers.h>
#include <atclient/atkeysfile.h>
#include <atclient/atsign.h>
#include <atlogger/atlogger.h>
Expand All @@ -18,7 +19,7 @@
int main(int argc, char **argv) {
int ret = 0;

atclient_atlogger_set_logging_level(ATLOGGER_LOGGING_LEVEL_INFO);
atlogger_set_logging_level(ATLOGGER_LOGGING_LEVEL_INFO);

// Init atclient
atclient atclient;
Expand All @@ -39,7 +40,7 @@ int main(int argc, char **argv) {
atclient_atkeysfile_init(&atkeysfile);
ret = atclient_atkeysfile_read(&atkeysfile, ATKEYSFILE_PATH);
if (ret != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_atkeys_file_read: %d\n", ret);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_atkeys_file_read: %d\n", ret);
atclient_free(&atclient);
atclient_atkeysfile_free(&atkeysfile);
return ret;
Expand All @@ -50,7 +51,7 @@ int main(int argc, char **argv) {
atclient_atkeys_init(&atkeys);
ret = atclient_atkeys_populate_from_atkeysfile(&atkeys, atkeysfile);
if (ret != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_atkeys_populate_from_atkeysfile: %d\n", ret);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_atkeys_populate_from_atkeysfile: %d\n", ret);
goto exit1;
}

Expand Down Expand Up @@ -88,8 +89,8 @@ int main(int argc, char **argv) {
goto exit2;
}

atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "enc_key_shared_by_me: %s\n", enc_key_shared_by_me);
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "enc_key_shared_by_other: %s\n", enc_key_shared_by_other);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "enc_key_shared_by_me: %s\n", enc_key_shared_by_me);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "enc_key_shared_by_other: %s\n", enc_key_shared_by_other);

return ret;

Expand Down
14 changes: 7 additions & 7 deletions examples/desktop/crud/delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
int main() {
int ret = 1;

atclient_atlogger_set_logging_level(ATCLIENT_LOGGING_LEVEL);
atlogger_set_logging_level(ATCLIENT_LOGGING_LEVEL);

atclient atclient;
atclient_connection root_conn;
Expand All @@ -34,28 +34,28 @@ int main() {
atclient_atkeys_init(&atkeys);

if ((ret = atclient_connection_connect(&root_conn, "root.atsign.org", 64)) != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to connect");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to connect");
goto exit;
}

if ((ret = atclient_atkeys_populate_from_path(&atkeys, ATKEYS_FILE_PATH)) != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to populate atkeys");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to populate atkeys");
goto exit;
}

if ((ret = atclient_atkey_create_selfkey(&atkey, ATKEY_NAME, strlen(ATKEY_NAME), atsign.atsign, strlen(atsign.atsign),
ATKEY_NAME, strlen(ATKEY_NAME))) != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to create selfkey");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to create selfkey");
goto exit;
}

if ((ret = atclient_pkam_authenticate(&atclient, &root_conn, &atkeys, ATSIGN)) != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to authenticate");
if ((ret = atclient_pkam_authenticate(&atclient, &root_conn, &atkeys, atsign.atsign)) != 0) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to authenticate");
goto exit;
}

if ((ret = atclient_delete(&atclient, &atkey)) != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to delete");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to delete");
goto exit;
}

Expand Down
22 changes: 11 additions & 11 deletions examples/desktop/crud/get_publickey.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
int main() {
int ret = 1;

atclient_atlogger_set_logging_level(ATCLIENT_LOGGING_LEVEL);
atlogger_set_logging_level(ATCLIENT_LOGGING_LEVEL);

const size_t valuelen = 4096;
char value[valuelen];
Expand All @@ -54,44 +54,44 @@ int main() {
atclient_atstr atkeystr;
atclient_atstr_init(&atkeystr, ATCLIENT_ATKEY_FULL_LEN);

if ((ret = atclient_pkam_authenticate(&atclient, &root_connection, &atkeys, ATSIGN)) != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to authenticate");
if ((ret = atclient_pkam_authenticate(&atclient, &root_connection, &atkeys, atsign.atsign)) != 0) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to authenticate");
goto exit;
}

if ((ret = atclient_atkey_create_publickey(&atkey, ATKEY_NAME, strlen(ATKEY_NAME), ATKEY_SHAREDBY,
strlen(ATKEY_SHAREDBY), NULL, 0)) != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to create public key");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to create public key");
goto exit;
}

if ((ret = atclient_atkey_to_string(&atkey, atkeystr.str, atkeystr.len, &atkeystr.olen)) != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to convert to string");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to convert to string");
goto exit;
}

atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "atkeystr.str (%lu): \"%.*s\"\n", atkeystr.olen,
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "atkeystr.str (%lu): \"%.*s\"\n", atkeystr.olen,
(int)atkeystr.olen, atkeystr.str);

ret = atclient_get_publickey(&atclient, &root_connection, &atkey, value, valuelen, &valueolen, true);
ret = atclient_get_publickey(&atclient, &atkey, value, valuelen, &valueolen, true);
if (ret != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to get public key");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to get public key");
goto exit;
}

atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "Data: \"%.*s\"\n", (int)valueolen, value);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "Data: \"%.*s\"\n", (int)valueolen, value);

char metadatajsonstr[4096];
memset(metadatajsonstr, 0, 4096);
size_t metadatstrolen = 0;

ret = atclient_atkey_metadata_to_jsonstr(&atkey.metadata, metadatajsonstr, 4096, &metadatstrolen);
if (ret != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to convert metadata to json string");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to convert metadata to json string");
goto exit;
}

atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "Metadata: \"%.*s\"\n", (int)metadatstrolen,
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "Metadata: \"%.*s\"\n", (int)metadatstrolen,
metadatajsonstr);

ret = 0;
Expand Down
20 changes: 10 additions & 10 deletions examples/desktop/crud/get_selfkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
int main() {
int ret = 1;

atclient_atlogger_set_logging_level(ATLOGGER_LOGGING_LEVEL_DEBUG);
atlogger_set_logging_level(ATLOGGER_LOGGING_LEVEL_DEBUG);

const size_t valuelen = 1024;
char value[valuelen];
Expand All @@ -53,38 +53,38 @@ int main() {
atclient_atstr atkeystr;
atclient_atstr_init(&atkeystr, ATCLIENT_ATKEY_FULL_LEN);

if ((ret = atclient_pkam_authenticate(&atclient, &root_conn, &atkeys, ATSIGN)) != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to authenticate\n");
if ((ret = atclient_pkam_authenticate(&atclient, &root_conn, &atkeys, atsign.atsign)) != 0) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to authenticate\n");
goto exit;
} else {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "Successfully authenticated!\n");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "Successfully authenticated!\n");
}
atclient.atkeys = atkeys;
atclient.atsign = atsign;

if ((ret = atclient_atkey_create_selfkey(&atkey, ATKEY_NAME, strlen(ATKEY_NAME), atsign.atsign, strlen(atsign.atsign),
ATKEY_NAMESPACE, strlen(ATKEY_NAMESPACE))) != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to create public key\n");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to create public key\n");
goto exit;
} else {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "Created self key\n");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "Created self key\n");
}

if ((ret = atclient_atkey_to_string(&atkey, atkeystr.str, atkeystr.len, &atkeystr.olen)) != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to convert to string\n");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to convert to string\n");
goto exit;
}

atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "atkeystr.str (%lu): \"%.*s\"\n", atkeystr.olen,
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "atkeystr.str (%lu): \"%.*s\"\n", atkeystr.olen,
(int)atkeystr.olen, atkeystr.str);

ret = atclient_get_selfkey(&atclient, &atkey, value, valuelen, &(valueolen));
if (ret != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to get self key");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to get self key");
goto exit;
}

atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "value.str (%lu): \"%.*s\"\n", valueolen, (int)valueolen,
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "value.str (%lu): \"%.*s\"\n", valueolen, (int)valueolen,
value);

ret = 0;
Expand Down
24 changes: 12 additions & 12 deletions examples/desktop/crud/get_sharedkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int main() {

int ret = 1;

atclient_atlogger_set_logging_level(ATLOGGER_LOGGING_LEVEL_DEBUG);
atlogger_set_logging_level(ATLOGGER_LOGGING_LEVEL_DEBUG);

const size_t valuelen = 1024;
atclient_atstr value;
Expand All @@ -64,10 +64,10 @@ int main() {
atclient_atstr_init(&atkeystr, ATCLIENT_ATKEY_FULL_LEN);

if ((ret = atclient_pkam_authenticate(&atclient, &root_conn, &atkeys, ATCLIENT_ATSIGN)) != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to authenticate\n");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to authenticate\n");
goto exit;
} else {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "Authenticated\n");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "Authenticated\n");
}

atclient.atkeys = atkeys;
Expand All @@ -76,27 +76,27 @@ int main() {
if ((ret = atclient_atkey_create_sharedkey(&atkey, ATKEY_NAME, strlen(ATKEY_NAME), SENDER_ATSIGN,
strlen(SENDER_ATSIGN), RECIPIENT_ATSIGN, strlen(RECIPIENT_ATSIGN),
ATKEY_NAMESPACE, strlen(ATKEY_NAMESPACE))) != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to create shared key\n");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to create shared key\n");
goto exit;
} else {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "Created shared key\n");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "Created shared key\n");
}

if ((ret = atclient_atkey_to_string(&atkey, atkeystr.str, atkeystr.len, &atkeystr.olen)) != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to convert to string\n");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to convert to string\n");
goto exit;
}

atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "atkeystr.str (%lu): \"%.*s\"\n", atkeystr.olen,
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "atkeystr.str (%lu): \"%.*s\"\n", atkeystr.olen,
(int)atkeystr.olen, atkeystr.str);

ret = atclient_get_sharedkey(&atclient, &atkey, value.str, value.len, &value.olen, NULL, false);
if (ret != 0) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to get shared key");
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to get shared key");
goto exit;
}

atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "value.str (%lu): \"%.*s\"\n", value.olen, (int)value.olen,
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "value.str (%lu): \"%.*s\"\n", value.olen, (int)value.olen,
value.str);

const size_t value_hash_len = 32;
Expand All @@ -115,13 +115,13 @@ int main() {
sprintf(hex_value_hash + i * 2, "%02x", value_hash[i]);
}

atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "sha256(value) : %s\n", hex_value_hash);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "sha256(value) : %s\n", hex_value_hash);

if ((ret = memcmp(hex_value_hash, EXPECTED_DECRYPTED_VALUE_SHA_256, 64))) {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG,
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG,
"sha256(value) NOT equal to EXPECTED_DECRYPTED_VALUE_SHA_256\n");
} else {
atclient_atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG,
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG,
"sha256(value) equal to EXPECTED_DECRYPTED_VALUE_SHA_256\n");
}
free(value_hash);
Expand Down
Loading

0 comments on commit 357c892

Please sign in to comment.