Skip to content

Commit

Permalink
chore: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
srieteja committed Dec 16, 2024
1 parent 4d8bda5 commit 80f123c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 136 deletions.
3 changes: 0 additions & 3 deletions packages/atauth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ set(
${CMAKE_CURRENT_LIST_DIR}/src/auth_cli.c
${CMAKE_CURRENT_LIST_DIR}/src/atauth_build_atkeys_file_path.c
${CMAKE_CURRENT_LIST_DIR}/src/atauth_fetch_home_dir.c
../../examples/desktop/at_talk/src/main.c
../../examples/desktop/connection_hooks/main.c
../../examples/desktop/crud/delete.c
)

# Project setup
Expand Down
21 changes: 10 additions & 11 deletions packages/atauth/include/atauth/atauth_constants.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#define DEFAULT_FIRST_APP_NAME "firstApp"
#define DEFAULT_FIRST_DEVICE_NAME "firstDevice"
#define AES_256_KEY_BYTES 32
#define RSA_2048_PRIVKEY_BYTES 1300 // in PKCS#8 format includes padding
#define ATAUTH_DEFAULT_FIRST_APP_NAME "firstApp"
#define ATAUTH_DEFAULT_FIRST_DEVICE_NAME "firstDevice"
#define ATAUTH_AES_256_KEY_BYTES 32
#define ATAUTH_RSA_2048_PRIVKEY_BYTES 1300 // in PKCS#8 format includes padding

#define DEFAULT_APKAM_RETRY_INTERVAL 10 // seconds
#define MAX_APKAM_AUTH_RETRY_ATTMEPTS 10
#define ENROLLMENT_DENIED_ERR_CODE "error:AT0025"
#define ENROLLMENT_PENDING_ERR_CODE "error:AT0026"
#define ATAUTH_DEFAULT_APKAM_RETRY_INTERVAL 10 // seconds
#define ATAUTH_MAX_APKAM_AUTH_RETRY_ATTMEPTS 10
#define ATAUTH_ENROLLMENT_DENIED_ERR_CODE "error:AT0025"
#define ATAUTH_ENROLLMENT_PENDING_ERR_CODE "error:AT0026"


#define ENCRYPTED_DEFAULT_ENC_PRIVKEY_NAME "default_enc_private_key"
#define ENCRYPTED_SELF_ENC_KEY_NAME "default_self_enc_key"
#define ATAUTH_ENCRYPTED_DEFAULT_ENC_PRIVKEY_NAME "default_enc_private_key"
#define ATAUTH_ENCRYPTED_SELF_ENC_KEY_NAME "default_self_enc_key"
8 changes: 4 additions & 4 deletions packages/atauth/src/atactivate.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int main(int argc, char *argv[]) {

// initialize apkam symmetric key and self encryption key (bytes)
unsigned char *self_encryption_key_bytes, *apkam_symmetric_key_bytes;
size_t aes256_key_unsigned_char_bytes_size = sizeof(unsigned char) * AES_256_KEY_BYTES;
size_t aes256_key_unsigned_char_bytes_size = sizeof(unsigned char) * ATAUTH_AES_256_KEY_BYTES;
self_encryption_key_bytes = malloc(aes256_key_unsigned_char_bytes_size);
apkam_symmetric_key_bytes = malloc(aes256_key_unsigned_char_bytes_size);

Expand All @@ -40,7 +40,7 @@ int main(int argc, char *argv[]) {
unsigned char *apkam_symmetric_key_base64 = malloc(aes256_key_unsigned_char_base64_size);

// intialize encrypted APKAM symmetric Key and encrypted default encryption private key (bytes)
const size_t rsa_2048_privkey_base64_len = atchops_base64_encoded_size(RSA_2048_PRIVKEY_BYTES);
const size_t rsa_2048_privkey_base64_len = atchops_base64_encoded_size(ATAUTH_RSA_2048_PRIVKEY_BYTES);
const size_t aes256_encrypted_rsa_privkey_size = atchops_aes_ctr_ciphertext_size(
rsa_2048_privkey_base64_len); // size for an AES256 encrypted RSA2048 privkey in bytes
const size_t aes256_encrypted_rsa_privkey_unsigned_char_size =
Expand Down Expand Up @@ -295,8 +295,8 @@ int main(int argc, char *argv[]) {

// 4.3 Initialize enrollment params
atcommons_enroll_params_init(ep);
ep->app_name = DEFAULT_FIRST_APP_NAME;
ep->device_name = DEFAULT_FIRST_DEVICE_NAME;
ep->app_name = ATAUTH_DEFAULT_FIRST_APP_NAME;
ep->device_name = ATAUTH_DEFAULT_FIRST_DEVICE_NAME;
ep->apkam_public_key = (unsigned char *)atkeys.pkam_public_key_base64;
ep->encrypted_default_encryption_private_key = encrypted_default_encryption_private_key_base64;
ep->encrypted_self_encryption_key = encrypted_self_encryption_key_base64;
Expand Down
14 changes: 7 additions & 7 deletions packages/atauth/src/auth_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) {
char status[ATCOMMONS_ENROLL_STATUS_STRING_MAX_LEN];

// initialize apkam symmetric key buffer (bytes)
size_t aes256_key_unsigned_char_bytes_size = sizeof(unsigned char) * AES_256_KEY_BYTES;
size_t aes256_key_unsigned_char_bytes_size = sizeof(unsigned char) * ATAUTH_AES_256_KEY_BYTES;
unsigned char apkam_symmetric_key_bytes[aes256_key_unsigned_char_bytes_size];

// initialize apkam symmetric key buffer (base64)
Expand Down Expand Up @@ -242,7 +242,7 @@ int main(int argc, char *argv[]) {
char *encrypted_default_self_encryption_key = NULL;

// 4.1.1 Fetch encrypted default encryption private key
if ((ret = get_apkam_key(&encrypted_default_encryption_private_key, ENCRYPTED_DEFAULT_ENC_PRIVKEY_NAME,
if ((ret = get_apkam_key(&encrypted_default_encryption_private_key, ATAUTH_ENCRYPTED_DEFAULT_ENC_PRIVKEY_NAME,
&at_client.atserver_connection, enrollment_id, atsign)) != 0) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed fetching def_encryption_privkey | get_apkam_key: %d\n",
ret);
Expand All @@ -251,7 +251,7 @@ int main(int argc, char *argv[]) {
}

// 4.1.2 Fetch encrypted self encryption key
if ((ret = get_apkam_key(&encrypted_default_self_encryption_key, ENCRYPTED_SELF_ENC_KEY_NAME,
if ((ret = get_apkam_key(&encrypted_default_self_encryption_key, ATAUTH_ENCRYPTED_SELF_ENC_KEY_NAME,
&at_client.atserver_connection, enrollment_id, atsign)) != 0) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed fetching def_encryption_privkey | get_apkam_key: %d\n",
ret);
Expand Down Expand Up @@ -417,7 +417,7 @@ exit: {
}

// retries APKAM auth using the set of atkeys provided until the authentication succeeds
// sleeps `DEFAULT_APKAM_RETRY_INTERVAL` seconds after each attempt
// sleeps `ATAUTH_DEFAULT_APKAM_RETRY_INTERVAL` seconds after each attempt
int retry_pkam_auth_until_success(atclient *ctx, const char *atsign, const atclient_atkeys *atkeys,
const atclient_authenticate_options *opts) {
int ret = 1;
Expand All @@ -437,8 +437,8 @@ int retry_pkam_auth_until_success(atclient *ctx, const char *atsign, const atcli
return ret;
}
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "APKAM auth failed. Retrying in %d secs\n",
DEFAULT_APKAM_RETRY_INTERVAL);
sleep(DEFAULT_APKAM_RETRY_INTERVAL);
ATAUTH_DEFAULT_APKAM_RETRY_INTERVAL);
sleep(ATAUTH_DEFAULT_APKAM_RETRY_INTERVAL);
}
}

Expand Down Expand Up @@ -498,7 +498,7 @@ exit: {

// returns 1 if the error_message contains the ENROLLMENT_DENIED error code, otherwise 0
int is_enrollment_denied(const char *err_msg) {
return strncmp(err_msg, ENROLLMENT_DENIED_ERR_CODE, strlen(ENROLLMENT_DENIED_ERR_CODE)) == 0 ? 1 : 0;
return strncmp(err_msg, ATAUTH_ENROLLMENT_DENIED_ERR_CODE, strlen(ATAUTH_ENROLLMENT_DENIED_ERR_CODE)) == 0 ? 1 : 0;
}

int create_new_atserver_connection(atclient *ctx, const char *atsign, const atclient_authenticate_options *options) {
Expand Down
100 changes: 0 additions & 100 deletions packages/atauth/src/enc_test.c

This file was deleted.

1 change: 0 additions & 1 deletion packages/atclient/src/atclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,6 @@ int atclient_send_heartbeat(atclient *heartbeat_conn) {
memset(recv, 0, sizeof(unsigned char) * recvsize);
}
size_t recv_len = 0;
char *ptr = (char *)recv;

if ((ret = atclient_connection_send(&heartbeat_conn->atserver_connection, (unsigned char *)noop_cmd, noop_cmd_len,
recv, recvsize, &recv_len)) != 0) {
Expand Down
10 changes: 0 additions & 10 deletions packages/atcommons/include/atcommons/cjson.h

This file was deleted.

0 comments on commit 80f123c

Please sign in to comment.