Skip to content

Commit

Permalink
fix: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
srieteja committed Nov 29, 2024
1 parent 6fe4e57 commit 5162fb8
Show file tree
Hide file tree
Showing 30 changed files with 165 additions and 164 deletions.
10 changes: 7 additions & 3 deletions packages/atauth/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Configurable options
option(ATAUTH_BUILD_TESTS "Build tests for atauth" OFF)
option(ATAUTH_BUILD_EXECUTABLES "Build executables in atauth" ON)

# Set include directory and file sources
set (ATAUTH_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include)
Expand Down Expand Up @@ -117,11 +118,14 @@ if(NOT ESP_PLATFORM)
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

add_executable(atactivate ${CMAKE_CURRENT_LIST_DIR}/src/atactivate.c)
target_link_libraries(atactivate PRIVATE cjson atlogger atcommons atchops atclient atauth)
# Build atactivate executable
if (ATAUTH_BUILD_EXECUTABLES)
add_executable(atactivate ${CMAKE_CURRENT_LIST_DIR}/src/atactivate.c)
target_link_libraries(atactivate PRIVATE cjson atlogger atcommons atchops atclient atauth)
endif ()

# EXPORT
if(NOT ATAUTH_AS_SUBPROJECT)
if (NOT ATAUTH_AS_SUBPROJECT)
# install as a config.make
install(
EXPORT ${PROJECT_NAME}-config
Expand Down
10 changes: 0 additions & 10 deletions packages/atauth/include/atauth/cjson.h

This file was deleted.

6 changes: 2 additions & 4 deletions packages/atauth/include/atauth/send_enroll_request.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#ifndef ATAUTH_SEND_ENROLL_REQUEST
#define ATAUTH_SEND_ENROLL_REQUEST

#include "../../../atclient/include/atclient/atclient.h"
// #include <atclient/atclient.h>
#include <atclient/atclient.h>
#include <atcommons/enroll_params.h>
#include <stddef.h>

#define ENROLL_ID_MAX_LEN 50

Expand All @@ -20,6 +18,6 @@
*
* @returns 0 on success, non-zero error code on failure.
*/
int atauth_send_enroll_request(atclient *client, const enroll_params_t *ep, char *enroll_id, char *enroll_status);
int atauth_send_enroll_request(atclient *client, const atcommons_enroll_params_t *ep, char *enroll_id, char *enroll_status);

#endif
6 changes: 3 additions & 3 deletions packages/atauth/src/atactivate.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int main(int argc, char *argv[]) {
char *atsign = NULL, *cram_secret = NULL, *root_host = NULL, *atkeys_fp = NULL, *otp = NULL;
int *root_port = NULL;
char enrollment_id[ENROLL_ID_MAX_LEN];
char status[ENROLL_STATUS_STRING_MAX_LEN];
char status[ATCOMMONS_ENROLL_STATUS_STRING_MAX_LEN];

// intialize iv used for aes encryption of keys
unsigned char *iv = malloc(sizeof(unsigned char) * ATCHOPS_IV_BUFFER_SIZE);
Expand Down Expand Up @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) {
malloc(sizeof(unsigned char) * aes256_encrypted_rsa_2048_privkey_base64_len);

// allocate memory for enroll params
enroll_params_t *ep = malloc(sizeof(enroll_params_t)); // Allocate enrollment params
atcommons_enroll_params_t *ep = malloc(sizeof(atcommons_enroll_params_t)); // Allocate enrollment params

// ensure all the above memory allocations hold
if (iv == NULL) {
Expand Down Expand Up @@ -134,7 +134,7 @@ int main(int argc, char *argv[]) {
memset(encrypted_default_encryption_private_key_base64, 0,
sizeof(unsigned char) * aes256_encrypted_rsa_2048_privkey_base64_len);
memset(encrypted_self_encryption_key_base64, 0, sizeof(unsigned char) * aes256_encrypted_aes_key_base64_len);
memset(ep, 0, sizeof(enroll_params_t));
memset(ep, 0, sizeof(atcommons_enroll_params_t));

/*
* 1. Parse args
Expand Down
4 changes: 2 additions & 2 deletions packages/atauth/src/send_enroll_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#define TAG "send_enroll_request"

int atauth_send_enroll_request(atclient *client, const enroll_params_t *ep, char *enroll_id, char *enroll_status) {
int atauth_send_enroll_request(atclient *client, const atcommons_enroll_params_t *ep, char *enroll_id, char *enroll_status) {
int ret = 0;
const size_t recv_size = 100; // to hold the response for enroll request
unsigned char recv[recv_size];
Expand All @@ -29,7 +29,7 @@ int atauth_send_enroll_request(atclient *client, const enroll_params_t *ep, char
/*
* 1. Fetch enroll:request command length and allocate memory
*/
const enroll_operation_t e_op = atcommons_apkam_request;
const atcommons_enroll_operation_t e_op = atcommons_apkam_request;
size_t cmd_len = 0;
atcommons_build_enroll_command(NULL, 0, &cmd_len, e_op, ep); // fetch enroll_command length
const size_t cmd_size = cmd_len;
Expand Down
15 changes: 10 additions & 5 deletions packages/atchops/include/atchops/hex.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef UTILS_H
#define UTILS_H

#ifndef ATCHOPS_HEX_H
#define ATCHOPS_HEX_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>

/**
Expand Down Expand Up @@ -33,6 +35,9 @@ int atchops_hex_to_bytes(unsigned char *bytes, const size_t byte_len, const char
*
* @return 0 on success, or -1 if the `hex_str` buffer is too small to store the resulting string.
*/
int atchops_bytes_to_hex (char *hex_str, const size_t hex_str_len, const unsigned char *bytes, const size_t bytes_len);
int atchops_bytes_to_hex(char *hex_str, const size_t hex_str_len, const unsigned char *bytes, const size_t bytes_len);

#endif // UTILS_H
#ifdef __cplusplus
}
#endif
#endif
23 changes: 15 additions & 8 deletions packages/atchops/include/atchops/utf8.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
#ifndef UTF8_H
#define UTF8_H
#ifndef ATCHOPS_UTF8_H
#define ATCHOPS_UTF8_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>

/**
*
* @param input
* @param output
* @param output_length
* @return
* @brief UTF_8 encodes a string. Can be used to convert a unsgined char array into bytes
*
* @param input pointer to char buffer that is supposed to be encoded
* @param output double pointer to the output buffer that contains the bytes of the input string
* @param output_length pointer to the length of the output buffer
* @return
*/
int atchops_utf8_encode(const char *input, unsigned char **output, size_t *output_length);

#endif //UTF8_H
#ifdef __cplusplus
}
#endif
#endif
8 changes: 5 additions & 3 deletions packages/atclient/include/atclient/atkeys_file.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef ATCLIENT_atkeys_file_H
#define ATCLIENT_atkeys_file_H

#ifndef ATCLIENT_ATKEYS_FILE_H
#define ATCLIENT_ATKEYS_FILE_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Expand Down
10 changes: 10 additions & 0 deletions packages/atclient/src/atclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,11 @@ int atclient_cram_authenticate(atclient *ctx, const char *atsign, const char *cr
goto exit;
}
char *atsign_without_at = malloc(sizeof(char) * strlen(atsign_with_at) + 1);
if(atsign_without_at == NULL) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Could not allocate memory for atsign_without_at");
ret = -1;
goto exit;
}
strcpy(atsign_without_at, atsign_with_at + 1);
// Now we have two variables that we can use: `atsign_with_at` and `atsign_without_at`

Expand Down Expand Up @@ -555,6 +560,11 @@ int atclient_cram_authenticate(atclient *ctx, const char *atsign, const char *cr
* 10a. Build `cram:` noop_cmd
*/
cram_cmd = malloc(sizeof(char) * ATCLIENT_CRAM_COMMAND_LEN + 1); // free later
if(cram_cmd == NULL) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Could not allocate memory for cram_cmd");
ret = -1;
goto exit;
}
ret = snprintf(cram_cmd, ATCLIENT_CRAM_COMMAND_LEN + 1, "%s:%s\r\n", ATCLIENT_CRAM_PREFIX, digest_hex_encoded);
/*
* 10b. Send `cram:` noop_cmd
Expand Down
22 changes: 10 additions & 12 deletions packages/atclient/src/atkeys_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,12 @@ int atclient_atkeys_file_from_string(atclient_atkeys_file *atkeys_file, const ch
}

cJSON *apkam_symmetric_key = cJSON_GetObjectItem(root, ATCLIENT_ATKEYS_FILE_APKAM_SYMMETRIC_KEY_JSON_KEY);
if (apkam_symmetric_key == NULL) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to read apkamSymmetricKey from JSON\n");
goto exit;
}
if ((ret = set_apkam_symmetric_key_str(atkeys_file, apkam_symmetric_key->valuestring,
strlen(apkam_symmetric_key->valuestring))) != 0) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "set_apkam_symmetric_key_str: %d\n", ret);
goto exit;
if (apkam_symmetric_key != NULL) {
if ((ret = set_apkam_symmetric_key_str(atkeys_file, apkam_symmetric_key->valuestring,
strlen(apkam_symmetric_key->valuestring))) != 0) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "set_apkam_symmetric_key_str: %d\n", ret);
goto exit;
}
}

cJSON *enrollment_id = cJSON_GetObjectItem(root, ATCLIENT_ATKEYS_FILE_APKAM_ENROLLMENT_ID_JSON_KEY);
Expand Down Expand Up @@ -217,7 +215,7 @@ int atclient_atkeys_file_write_to_path(atclient_atkeys_file *atkeys_file, const
* 2. Variables
*/

cJSON *root = NULL; // free later
cJSON *root = NULL; // free later
char *json_str = NULL; // free later

root = cJSON_CreateObject();
Expand Down Expand Up @@ -246,7 +244,7 @@ int atclient_atkeys_file_write_to_path(atclient_atkeys_file *atkeys_file, const
cJSON_AddStringToObject(root, "selfEncryptionKey", atkeys_file->self_encryption_key_str);
}

if(is_apkam_symmetric_key_str_initialized(atkeys_file)) {
if (is_apkam_symmetric_key_str_initialized(atkeys_file)) {
cJSON_AddStringToObject(root, "apkamSymmetricKey", atkeys_file->apkam_symmetric_key_str);
}

Expand Down Expand Up @@ -275,10 +273,10 @@ int atclient_atkeys_file_write_to_path(atclient_atkeys_file *atkeys_file, const

ret = 0;
exit: {
if(json_str != NULL) {
if (json_str != NULL) {
free(json_str);
}
if(root != NULL) {
if (root != NULL) {
cJSON_Delete(root);
}
return ret;
Expand Down
Empty file.
1 change: 0 additions & 1 deletion packages/atclient/src/request_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,6 @@ void atclient_delete_request_options_free(atclient_delete_request_options *optio
* 1. Validate arguments
*/
if (options == NULL) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_delete_request_options_free: Invalid arguments\n");
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/atcommons/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(
${CMAKE_CURRENT_LIST_DIR}/src/enroll/enroll_namespace.c
${CMAKE_CURRENT_LIST_DIR}/src/enroll/enroll_params.c
${CMAKE_CURRENT_LIST_DIR}/src/command_builders/enroll_command_builder.c
${CMAKE_CURRENT_LIST_DIR}/tests/at_expect.c
${CMAKE_CURRENT_LIST_DIR}/tests
)

# Project setup
Expand Down
6 changes: 0 additions & 6 deletions packages/atcommons/include/atcommons/at_expect.h

This file was deleted.

4 changes: 2 additions & 2 deletions packages/atcommons/include/atcommons/cjson.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef ATCLIENT_CJSON_H
#define ATCLIENT_CJSON_H
#ifndef ATCOMMONS_CJSON_H
#define ATCOMMONS_CJSON_H

#if defined(CONFIG_IDF_TARGET_ESP32)
#include <cjson.h>
Expand Down
12 changes: 6 additions & 6 deletions packages/atcommons/include/atcommons/enroll_command_builder.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef ENROLL_VERB_BUILDER_H
#define ENROLL_VERB_BUILDER_H
#ifndef ATCOMMONS_ENROLL_VERB_BUILDER_H
#define ATCOMMONS_ENROLL_VERB_BUILDER_H

#include "enroll_operation.h"
#include "enroll_params.h"
#include "atcommons/enroll_operation.h"
#include "atcommons/enroll_params.h"
#include <stddef.h>

/**
Expand All @@ -18,7 +18,7 @@
* @param params A pointer to the enroll_params_t struct that holds the parameters for the current enrollment operations
* @return 0 on success, non-zero indicating failure
*/
int atcommons_build_enroll_command(char *command, size_t cmd_size, size_t *cmd_len, enroll_operation_t operation,
const enroll_params_t *params);
int atcommons_build_enroll_command(char *command, size_t cmd_size, size_t *cmd_len,
atcommons_enroll_operation_t operation, const atcommons_enroll_params_t *params);

#endif
17 changes: 9 additions & 8 deletions packages/atcommons/include/atcommons/enroll_namespace.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#ifndef ENROLL_NAMESPACE_STRUCT_H
#define ENROLL_NAMESPACE_STRUCT_H
#ifndef ATCOMMONS_ENROLL_NAMESPACE_H
#define ATCOMMONS_ENROLL_NAMESPACE_H

#include <stddef.h>

typedef struct {
char *name;
char *access;
} enroll_namespace_t;
} atcommons_enroll_namespace_t;

typedef struct {
size_t length;
enroll_namespace_t *namespaces[];
} enroll_namespace_list_t;
atcommons_enroll_namespace_t *namespaces[];
} atcommons_enroll_namespace_list_t;

/**
* @brief serializes enroll_namespace struct to JSON string
Expand All @@ -26,7 +26,7 @@ typedef struct {
* @return int 0 on success, non-zero int on failure
*/
int atcommons_enroll_namespace_to_json(char *ns_str, const size_t ns_str_size, size_t *ns_str_len,
const enroll_namespace_t *ns);
const atcommons_enroll_namespace_t *ns);

/**
* @brief serialises a list of enroll_namespace[s] to JSON string
Expand All @@ -40,7 +40,7 @@ int atcommons_enroll_namespace_to_json(char *ns_str, const size_t ns_str_size, s
* @return int 0 on success, non-zero int on failure
*/
int atcommons_enroll_namespace_list_to_json(char **ns_list_string, size_t *ns_list_str_len,
const enroll_namespace_list_t *ns_list);
const atcommons_enroll_namespace_list_t *ns_list);

/**
* @brief appends an enroll_namespace struct to an enroll_namespace_list struct.
Expand All @@ -56,6 +56,7 @@ int atcommons_enroll_namespace_list_to_json(char **ns_list_string, size_t *ns_li
* the list
* @return int 0 on success, non-zero int on failure
*/
int atcommons_enroll_namespace_list_append(enroll_namespace_list_t **ns_list, enroll_namespace_t *ns);
int atcommons_enroll_namespace_list_append(atcommons_enroll_namespace_list_t **ns_list,
atcommons_enroll_namespace_t *ns);

#endif
8 changes: 4 additions & 4 deletions packages/atcommons/include/atcommons/enroll_operation.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef ENROLL_OPERATION_H
#define ENROLL_OPERATION_H
#ifndef ATCOMMONS_ENROLL_OPERATION_H
#define ATCOMMONS_ENROLL_OPERATION_H

#define MAX_ENROLL_OPERATION_STRING_LEN 8

Expand All @@ -11,7 +11,7 @@ typedef enum {
atcommons_apkam_unrevoke,
atcommons_apkam_list,
atcommons_apkam_delete
} enroll_operation_t;
} atcommons_enroll_operation_t;

/**
* @brief Parses enroll operation type enroll_operation_t and converts that into a string
Expand All @@ -20,6 +20,6 @@ typedef enum {
* @param e_op enroll operation as enum enroll_operation_t
* @return int 0 on success, non-zero on failure
*/
int enroll_operation_to_string(char **op_name, enroll_operation_t e_op);
int atcommons_enroll_operation_to_string(char **op_name, atcommons_enroll_operation_t e_op);

#endif
Loading

0 comments on commit 5162fb8

Please sign in to comment.