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: write atkeys to file #428

Open
wants to merge 12 commits into
base: trunk
Choose a base branch
from
Open

feat: write atkeys to file #428

wants to merge 12 commits into from

Conversation

JeremyTubongbanua
Copy link
Member

@JeremyTubongbanua JeremyTubongbanua commented Oct 15, 2024

closes #415

- What I did
3 new functions

  • atkeys_file: atclient_atkeys_file_write_to_path
  • atkeys: atclient_atkeys_write_to_atkeys_file
  • atkeys: atclient_atkeys_write_to_path (this function depends on the two functions stated above)
  • New atclient test test_atkeys_write.c -> this reads an atkeys file (string version), writes it to a file, then we read the file that we wrote, then use the new atkeys1 struct to pkam authenticate, to ensure that reading was successful
  • Misc formatting throughout codebase
  • Misc includes that were causing test fails on my local machine

- How to verify it

Manual test: read an atkeys file, write it to a second file, then try utilizing the atkeys that was written to the second file

#include <atlogger/atlogger.h>
#include <atclient/atkeys.h>
#include <atclient/atclient.h>
#include <string.h>

#define TAG "main"

int main() {
  int ret = 1;

  atlogger_set_logging_level(ATLOGGER_LOGGING_LEVEL_DEBUG);

  atclient_atkeys atkeys;
  atclient_atkeys_init(&atkeys);

  atclient_atkeys atkeys1;
  atclient_atkeys_init(&atkeys1);

  atclient atclient;
  atclient_init(&atclient);

  if((ret = atclient_atkeys_populate_from_path(&atkeys, "/Users/jeremytubongbanua/.atsign/keys/@smoothalligator_key.atKeys") != 0)) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to populate atkeys from path\n");
    goto exit;
  }

  if((ret = atclient_atkeys_write_to_path(&atkeys, "/Users/jeremytubongbanua/Desktop/@smoothalligator1_key.atKeys")) != 0) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to write atkeys to path\n");
    goto exit;
  }

  if((ret = atclient_atkeys_populate_from_path(&atkeys1, "/Users/jeremytubongbanua/Desktop/@smoothalligator1_key.atKeys") != 0)) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to populate atkeys from path\n");
    goto exit;
  }

  // compare fields
  if(strcmp(atkeys.pkam_public_key_base64, atkeys1.pkam_public_key_base64) != 0) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "pkam_public_key_base64 does not match\n");
    goto exit;
  } else {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "pkam_public_key_base64 matches: \"%s\"\n", atkeys.pkam_public_key_base64);
  }

  if(strcmp(atkeys.pkam_private_key_base64, atkeys1.pkam_private_key_base64) != 0) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "pkam_private_key_base64 does not match\n");
    goto exit;
  } else {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "pkam_private_key_base64 matches: \"%s\"\n", atkeys.pkam_private_key_base64);
  }

  if(strcmp(atkeys.encrypt_public_key_base64, atkeys1.encrypt_public_key_base64) != 0) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "encrypt_public_key_base64 does not match\n");
    goto exit;
  } else {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "encrypt_public_key_base64 matches: \"%s\"\n", atkeys.encrypt_public_key_base64);
  }

  if(strcmp(atkeys.encrypt_private_key_base64, atkeys1.encrypt_private_key_base64) != 0) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "encrypt_private_key_base64 does not match\n");
    goto exit;
  } else {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "encrypt_private_key_base64 matches: \"%s\"\n", atkeys.encrypt_private_key_base64);
  }

  if(strcmp(atkeys.self_encryption_key_base64, atkeys1.self_encryption_key_base64) != 0) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "self_encryption_key_base64 does not match\n");
    goto exit;
  } else {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "self_encryption_key_base64 matches: \"%s\"\n", atkeys.self_encryption_key_base64);
  }

  if(atclient_atkeys_is_enrollment_id_initialized(&atkeys) && atkeys.enrollment_id != NULL) {
    if(strcmp(atkeys.enrollment_id, atkeys1.enrollment_id) != 0) {
      atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "enrollment_id does not match\n");
      goto exit;
    } else {
      
    }
  }

  if((ret = atclient_pkam_authenticate(&atclient, "@smoothalligator", &atkeys1, NULL)) != 0) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to authenticate\n");
    goto exit;
  }

  ret = 0;

exit: { return ret; }
}

Output

➜  playground git:(jt/write-atkeys) ✗ ./build/main
[DEBG] 2024-10-15 19:52:22.953148 | main | pkam_public_key_base64 matches: "*******"
[DEBG] 2024-10-15 19:52:22.954076 | main | pkam_private_key_base64 matches: "*******"
[DEBG] 2024-10-15 19:52:22.954177 | main | encrypt_public_key_base64 matches: "*******"
[DEBG] 2024-10-15 19:52:22.954182 | main | encrypt_private_key_base64 matches: "*******"
[DEBG] 2024-10-15 19:52:22.954233 | main | self_encryption_key_base64 matches: "b****"
[INFO] 2024-10-15 19:52:22.954243 | atclient | Missing atServer host or port. Using production atDirectory to look up atServer host and port
[DEBG] 2024-10-15 19:52:23.992848 | connection |        SENT: "smoothalligator"
[DEBG] 2024-10-15 19:52:24.109146 | connection |        RECV: "245b44d4-a4bd-5f33-b077-c559f956486a.swarm0001.atsign.zone:1722"
[DEBG] 2024-10-15 19:52:26.027684 | connection |        SENT: "from:smoothalligator"
[DEBG] 2024-10-15 19:52:26.128181 | connection |        RECV: "data:_1287817d-8779-4842-8589-a7851bac680a@smoothalligator:5385361e-2529-4140-a8c6-e56ce7e34ebe"
[DEBG] 2024-10-15 19:52:26.148021 | connection |        SENT: "pkam:WqZ/f+PEUaqEFBqv0JzJD+09BjHomd/PjzXe91SIUHa1JuKhfyRvB/E2W7Eg0WgDJpv45NUYktqityYqudc0yOcOv3Tb5kL3i+HAh6nrrLkkEi20bLaXLSy8m0C58ewAwZ2hb0RNDxr3HKms1OthwSlnJ2HDMHFNuyq1U27S36KWszx1s2TM7QPl7r/QZVVLRhIAVcf9mB/mF+SG1hA9TNeJ1KIKq2dpoOvpevFo5KD2+j4+AHxfmfF8QAw1jaXxULv9A16x3KXA+FzdgMOpYumtGdISQOgDiMf/68hctV6MvbYDQb9NtGXafysmRl4WjuBGeGWXD0mbsN5tj4cpUQ=="
[DEBG] 2024-10-15 19:52:26.299715 | connection |        RECV: "data:success"

- Description for the changelog
feat: write atkeys to file

@JeremyTubongbanua JeremyTubongbanua marked this pull request as ready for review October 15, 2024 20:52
@JeremyTubongbanua JeremyTubongbanua self-assigned this Oct 15, 2024
@srieteja
Copy link
Contributor

@JeremyTubongbanua apkamSymmetricKey is now a part of the atKeys file, since implementation of APKAM. Could you please add impl to write that into the keys file too. Support for APKAMSymmetricKey is still not integrated into the at_c client. It's currently in this PR #412, could you please cherry pick these commits into this branch.

Copy link
Contributor

@srieteja srieteja left a comment

Choose a reason for hiding this comment

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

See earlier comment reg APKAMSymmetricKey

Copy link
Member

@XavierChanth XavierChanth left a comment

Choose a reason for hiding this comment

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

Address the tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

at_c: Writing atkeys to a file
3 participants