Skip to content

Commit

Permalink
Revert "feat: introduce auth_cli"
Browse files Browse the repository at this point in the history
This reverts commit a3d043a.
This reverts commit d646b46.
This reverts commit aff312e.
This reverts commit e8c7b71.
  • Loading branch information
srieteja committed Nov 28, 2024
1 parent d3e102e commit 6fe4e57
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 474 deletions.
8 changes: 3 additions & 5 deletions packages/atauth/include/atauth/atactivate_arg_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
* @param argv The array of arguments
* @param atsign pointer to store the atsign value
* @param cram_secret pointer to store the cram_secret value
* @param otp OTP fetched from otp verb handler
* @param otp
* @param atkeys_fp pointer to store the file path of the atkeys
* @param app_name
* @param device_name
* @param namespaces
* @param root_host pointer to store the root host server address
* @param root_port pointer to store the root port value
* @return int 0 on success, non-zero on error
*/
int atactivate_parse_args(int argc, char *argv[], char **atsign, char **cram_secret, char **otp, char **atkeys_fp,
char **app_name, char **device_name, char **namespaces, char **root_host);
char **root_host, int *root_port);

#endif // ATACTIVATE_ARG_PARSER_H
8 changes: 4 additions & 4 deletions packages/atauth/src/atactivate.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <stdlib.h>
#include <string.h>

#define TAG "at_activate_cli"
#define TAG "atactivate"
#define DEFAULT_FIRST_APP_NAME "firstApp"
#define DEFAULT_FIRST_DEVICE_NAME "firstDevice"
#define AES_256_KEY_BYTES 32
Expand All @@ -24,6 +24,7 @@ int main(int argc, char *argv[]) {
atlogger_set_logging_level(ATLOGGER_LOGGING_LEVEL_INFO);
int ret = 0;
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];

Expand Down Expand Up @@ -138,8 +139,7 @@ int main(int argc, char *argv[]) {
/*
* 1. Parse args
*/
if ((ret = atactivate_parse_args(argc, argv, &atsign, &cram_secret, &otp, &atkeys_fp, NULL, NULL, NULL,
&root_host)) != 0) {
if ((ret = atactivate_parse_args(argc, argv, &atsign, &cram_secret, &otp, &atkeys_fp, &root_host, root_port)) != 0) {
goto exit;
}
// 1.1 if atkeys filepath was not passed through args, build default atkeys file path
Expand Down Expand Up @@ -312,7 +312,7 @@ int main(int argc, char *argv[]) {
/*
* 6. Perform PKAM auth
*/
if ((ret = atclient_pkam_authenticate(&at_client, atsign, &atkeys, &options, NULL)) != 0) {
if ((ret = atclient_pkam_authenticate(&at_client, atsign, &atkeys, &options)) != 0) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "PKAM auth failed | atclient_pkam_authenticate: %d\n", ret);
goto atclient_exit;
}
Expand Down
58 changes: 14 additions & 44 deletions packages/atauth/src/atactivate_arg_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define DEFAULT_ROOT_PORT 64

int atactivate_parse_args(int argc, char *argv[], char **atsign, char **cram_secret, char **otp, char **atkeys_fp,
char **app_name, char **device_name, char **namespaces, char **root_host) {
char **root_host, int *root_port) {
int ret = 0;
int opt;

Expand All @@ -19,9 +19,15 @@ int atactivate_parse_args(int argc, char *argv[], char **atsign, char **cram_sec
return -1;
}
strcpy(*root_host, DEFAULT_ROOT_SERVER);
root_port = malloc(sizeof(int));
if (root_port == NULL) {
fprintf(stderr, "Memory allocation failed for root_port\n");
return -1;
}
*root_port = DEFAULT_ROOT_PORT;

// Parse command-line arguments
while ((opt = getopt(argc, argv, "a:c:k:o:p:d:n:r:h")) != -1) {
while ((opt = getopt(argc, argv, "a:c:k:o:r:p:h")) != -1) {
switch (opt) {
case 'a':
*atsign = malloc(sizeof(char) * strlen(optarg) + 1);
Expand All @@ -33,8 +39,6 @@ int atactivate_parse_args(int argc, char *argv[], char **atsign, char **cram_sec
strcpy(*atsign, optarg);
break;
case 'c':
if (cram_secret == NULL)
break;
*cram_secret = malloc(sizeof(char) * strlen(optarg) + 1);
if (*cram_secret == NULL) {
fprintf(stderr, "Memory allocation failed for cram_secret\n");
Expand All @@ -44,8 +48,6 @@ int atactivate_parse_args(int argc, char *argv[], char **atsign, char **cram_sec
strcpy(*cram_secret, optarg);
break;
case 'k':
if (atkeys_fp == NULL)
break;
*atkeys_fp = malloc(sizeof(char) * strlen(optarg) + 1);
if (*atkeys_fp == NULL) {
fprintf(stderr, "Memory allocation failed for atkeys file path\n");
Expand All @@ -55,49 +57,14 @@ int atactivate_parse_args(int argc, char *argv[], char **atsign, char **cram_sec
strcpy(*atkeys_fp, optarg);
break;
case 'o':
if (otp == NULL)
break;
*otp = malloc(sizeof(char) * strlen(optarg));
if (*otp == NULL) {
if(*otp == NULL) {
fprintf(stderr, "Memory allocation failed for atkeys file path\n");
ret = -1;
goto exit;
}
strcpy(*otp, optarg);
break;
case 'p':
if (app_name == NULL)
break;
*app_name = realloc(*root_host, sizeof(char) * strlen(optarg) + 1);
if (*app_name == NULL) {
fprintf(stderr, "Memory reallocation failed for app_name\n");
ret = -1;
goto exit;
}
strcpy(*app_name, optarg);
break;
case 'd':
if (device_name == NULL)
break;
*device_name = realloc(*root_host, sizeof(char) * strlen(optarg) + 1);
if (*device_name == NULL) {
fprintf(stderr, "Memory reallocation failed for device_name\n");
ret = -1;
goto exit;
}
strcpy(*device_name, optarg);
break;
case 'n':
if (namespaces == NULL)
break;
*namespaces = realloc(*namespaces, sizeof(char) * strlen(optarg) + 1);
if (*namespaces == NULL) {
fprintf(stderr, "Memory reallocation failed for namespaces\n");
ret = -1;
goto exit;
}
strcpy(*namespaces, optarg);
break;
case 'r':
*root_host = realloc(*root_host, sizeof(char) * strlen(optarg) + 1);
if (*root_host == NULL) {
Expand All @@ -107,6 +74,9 @@ int atactivate_parse_args(int argc, char *argv[], char **atsign, char **cram_sec
}
strcpy(*root_host, optarg);
break;
case 'p':
*root_port = atoi(optarg);
break;
case 'h':
fprintf(stderr, "Usage: %s -a atsign -c cram-secret -o otp [-r root-server] [-p port]\n", argv[0]);
exit(0); // force exit to display usage
Expand All @@ -117,13 +87,13 @@ int atactivate_parse_args(int argc, char *argv[], char **atsign, char **cram_sec
}
}

if (atsign == NULL) {
if (*atsign == NULL) {
fprintf(stderr, "Error: -a (atsign) is mandatory.\n");
fprintf(stderr, "Usage: %s -a atsign -c cram-secret -o otp [-r root-server] [-p port]\n", argv[0]);
ret = 1;
}

if (cram_secret == NULL && otp == NULL) {
if(*cram_secret == NULL && *otp == NULL) {
fprintf(stderr, "Cannot proceed without either of CRAM secret on enroll OTP.\n");
fprintf(stderr, "Usage: %s -a atsign -c cram-secret -o otp [-r root-server] [-p port]\n", argv[0]);
ret = 1;
Expand Down
Loading

0 comments on commit 6fe4e57

Please sign in to comment.