Skip to content

Commit

Permalink
Merge pull request #1522 from atsign-foundation/atc-0-3-1
Browse files Browse the repository at this point in the history
fix: undo sys/wait removal
  • Loading branch information
XavierChanth authored Nov 12, 2024
2 parents 01af0c2 + 4e8298f commit 6776bed
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 72 deletions.
2 changes: 1 addition & 1 deletion packages/c/cmake/atsdk.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if(NOT atsdk_FOUND)
FetchContent_Declare(
atsdk
GIT_REPOSITORY https://github.com/atsign-foundation/at_c.git
GIT_TAG 42daadfd9f4b6b83e6d4b3ad328a691a91bcfe4c
GIT_TAG 6650e33ab80e9d873ede6d0213fa2999054fce7b
)
FetchContent_MakeAvailable(atsdk)
install(TARGETS atclient atchops atlogger)
Expand Down
3 changes: 3 additions & 0 deletions packages/c/srv/src/params.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ void apply_default_values_to_srv_params(srv_params_t *params) {
}

int parse_srv_params(srv_params_t *params, int argc, const char **argv, srv_env_t *environment) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
struct argparse_option options[] = {
OPT_BOOLEAN(0, "help", NULL, "show this help message and exit", argparse_help_cb, 0, OPT_NONEG),
OPT_STRING('h', "host", &params->host, "rvd host"),
Expand All @@ -33,6 +35,7 @@ int parse_srv_params(srv_params_t *params, int argc, const char **argv, srv_env_
"How long to keep the socket connector open if there have been no connections"),
OPT_END(),
};
#pragma clang diagnostic pop

struct argparse argparse;
argparse_init(&argparse, options, NULL, 0);
Expand Down
4 changes: 2 additions & 2 deletions packages/c/srv/src/side.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <srv/params.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>

#define TAG "srv - side"
Expand Down Expand Up @@ -118,7 +117,8 @@ void *srv_side_handle(void *side) {
}
memset(buffer, 0, BUFFER_LEN * sizeof(unsigned char));
}
if (output) free(output);
if (output)
free(output);
free(buffer);
mbedtls_net_close(&s->socket);
} else {
Expand Down
16 changes: 9 additions & 7 deletions packages/c/srv/src/srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int run_srv_daemon_side_multi(srv_params_t *params) {
// This socket will decrypt the messages comming from the other side
// which provide the information to create new sockets
side_t control_side;
side_hints_t hints_control = {1, 0, params->host, params->port};
side_hints_t hints_control = {1, 0, params->host, params->port, NULL};
if (params->rv_e2ee) {
hints_control.transformer = &decrypter;
}
Expand Down Expand Up @@ -166,7 +166,7 @@ int run_srv_daemon_side_multi(srv_params_t *params) {
goto exit;
}

for (int i = 0; i < nrequests; i++) {
for (size_t i = 0; i < nrequests; i++) {
// Now process each of those requests
res = parse_control_message(requests[i], &messagetype, &new_session_aes_key_string, &new_session_aes_iv_string);
if (res != 0) {
Expand Down Expand Up @@ -246,14 +246,13 @@ int run_srv_daemon_side_multi(srv_params_t *params) {
int socket_to_socket(const srv_params_t *params, const char *auth_string, chunked_transformer_t *encrypter,
chunked_transformer_t *decrypter, bool is_srv_ready) {
side_t sides[2];
side_hints_t hints_a = {1, 0, params->local_host, params->local_port};
side_hints_t hints_b = {0, 0, params->host, params->port};
side_hints_t hints_a = {1, 0, params->local_host, params->local_port, NULL};
side_hints_t hints_b = {0, 0, params->host, params->port, NULL};

if (params->rv_e2ee) {
hints_a.transformer = encrypter;
hints_b.transformer = decrypter;
}

atlogger_log(TAG, INFO, "Initializing connection for side a\n");
int res = srv_side_init(&hints_a, &sides[0]);
if (res != 0) {
Expand All @@ -270,7 +269,8 @@ int socket_to_socket(const srv_params_t *params, const char *auth_string, chunke

int fds[2], tidx;
int exit_res = 0;
pthread_t threads[2], tid;
pthread_t threads[2];
pthread_t tid = NULL;
pipe(fds);

srv_link_sides(&sides[0], &sides[1], fds);
Expand Down Expand Up @@ -350,10 +350,13 @@ int socket_to_socket(const srv_params_t *params, const char *auth_string, chunke
return 0;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
int server_to_socket(const srv_params_t *params, const char *auth_string, chunked_transformer_t *encrypter,
chunked_transformer_t *decrypter) {
return 0;
}
#pragma clang diagnostic pop

int create_encrypter_and_decrypter(const char *session_aes_key_string, const char *session_aes_iv_string,
chunked_transformer_t *encrypter, chunked_transformer_t *decrypter) {
Expand Down Expand Up @@ -438,7 +441,6 @@ int aes_ctr_crypt_stream(const chunked_transformer_t *self, size_t len, const un

static int process_multiple_requests(char *original, char **requests[], size_t *num_out_requests) {
int ret = -1;
int num_requests = 0;

char *temp = NULL;
char *saveptr = original;
Expand Down
5 changes: 5 additions & 0 deletions packages/c/sshnpd/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.2.4

- fix: Disabled clang-tidy missing-includes, as it malformed header includes
- fix: Restore the malformed headers

## 0.2.3

- Update to atSDK v0.3.1 with type fixes
Expand Down
4 changes: 2 additions & 2 deletions packages/c/sshnpd/include/sshnpd/handle_npt_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include <pthread.h>

void handle_npt_request(atclient *atclient, pthread_mutex_t *atclient_lock, sshnpd_params *params,
bool *is_child_process, atclient_monitor_response *message, char *home_dir, FILE *authkeys_file,
char *authkeys_filename, atchops_rsa_key_private_key signing_key);
bool *is_child_process, atclient_monitor_response *message,
atchops_rsa_key_private_key signing_key);
#endif
4 changes: 2 additions & 2 deletions packages/c/sshnpd/include/sshnpd/handle_ssh_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <pthread.h>

void handle_ssh_request(atclient *atclient, pthread_mutex_t *atclient_lock, sshnpd_params *params,
bool *is_child_process, atclient_monitor_response *message, char *home_dir, FILE *authkeys_file,
char *authkeys_filename, atchops_rsa_key_private_key signing_key);
bool *is_child_process, atclient_monitor_response *message,
atchops_rsa_key_private_key signing_key);

#endif
2 changes: 1 addition & 1 deletion packages/c/sshnpd/include/sshnpd/version.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef SSHNPD_VERSION_H
#define SSHNPD_VERSION_H
#define SSHNPD_VERSION "0.2.3"
#define SSHNPD_VERSION "0.2.4"
#endif
4 changes: 2 additions & 2 deletions packages/c/sshnpd/src/background_jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void *refresh_device_entry(void *void_refresh_device_entry_params) {
pthread_exit(NULL);
}

int index;
size_t index;
for (index = 0; index < num_managers; index++) {
// device_info
size_t buffer_len = strlen(params->params->manager_list[index]) + infokey_base_len;
Expand Down Expand Up @@ -144,7 +144,7 @@ void *refresh_device_entry(void *void_refresh_device_entry_params) {

fflush(stdout);

for (int i = 0; i < num_managers; i++) {
for (size_t i = 0; i < num_managers; i++) {
if (params->params->hide) {
ret = atclient_delete(params->atclient, infokeys + i, NULL, NULL);
} else {
Expand Down
6 changes: 3 additions & 3 deletions packages/c/sshnpd/src/handle_npt_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
#include <sshnpd/run_srv_process.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>

#define LOGGER_TAG "NPT_REQUEST"

void handle_npt_request(atclient *atclient, pthread_mutex_t *atclient_lock, sshnpd_params *params,
bool *is_child_process, atclient_monitor_response *message, char *home_dir, FILE *authkeys_file,
char *authkeys_filename, atchops_rsa_key_private_key signing_key) {
bool *is_child_process, atclient_monitor_response *message,
atchops_rsa_key_private_key signing_key) {
int res = 0;
if (!atclient_atnotification_is_from_initialized(&message->notification) && message->notification.from != NULL) {
atlogger_log(LOGGER_TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to initialize the from field of the notification\n");
Expand Down Expand Up @@ -510,7 +511,6 @@ void handle_npt_request(atclient *atclient, pthread_mutex_t *atclient_lock, sshn

pid_t pid = fork();
int status;
bool free_envelope = true;

if (pid == 0) {
// child process
Expand Down
6 changes: 3 additions & 3 deletions packages/c/sshnpd/src/handle_ssh_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
#include <sshnpd/run_srv_process.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>

#define LOGGER_TAG "SSH_REQUEST"

void handle_ssh_request(atclient *atclient, pthread_mutex_t *atclient_lock, sshnpd_params *params,
bool *is_child_process, atclient_monitor_response *message, char *home_dir, FILE *authkeys_file,
char *authkeys_filename, atchops_rsa_key_private_key signing_key) {
bool *is_child_process, atclient_monitor_response *message,
atchops_rsa_key_private_key signing_key) {
int res = 0;
if (!atclient_atnotification_is_from_initialized(&message->notification) && message->notification.from != NULL) {
atlogger_log(LOGGER_TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to initialize the from field of the notification\n");
Expand Down Expand Up @@ -496,7 +497,6 @@ void handle_ssh_request(atclient *atclient, pthread_mutex_t *atclient_lock, sshn

pid_t pid = fork();
int status;
bool free_envelope = true;

if (pid == 0) {
// child process
Expand Down
2 changes: 1 addition & 1 deletion packages/c/sshnpd/src/handle_sshpublickey.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void handle_sshpublickey(sshnpd_params *params, atclient_monitor_response *messa
}

char *ssh_key = (char *)message->notification.decrypted_value;
size_t ssh_key_len = strlen(ssh_key);
// size_t ssh_key_len = strlen(ssh_key);

bool is_valid_prefix = false;
for (int i = 1; i < SUPPORTED_KEY_PREFIX_LEN; i++) {
Expand Down
4 changes: 2 additions & 2 deletions packages/c/sshnpd/src/handler_commons.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define LOGGER_TAG "VERIFY_REQUEST_SIGNATURE"

int verify_envelope_signature(atchops_rsa_key_public_key publickey, const unsigned char *payload,
unsigned char *signature, const char *hashing_algo, const char *signing_algo) {
unsigned char *signature, const char *hashing_algo) {
int ret = 0;

atchops_md_type mdtype;
Expand All @@ -19,7 +19,7 @@ int verify_envelope_signature(atchops_rsa_key_public_key publickey, const unsign
return -1;
}

ret = atchops_rsa_verify(&publickey, ATCHOPS_MD_SHA256, payload, strlen((char *)payload), signature);
ret = atchops_rsa_verify(&publickey, mdtype, payload, strlen((char *)payload), signature);
if (ret != 0) {
atlogger_log(LOGGER_TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "verify_envelope_signature (failed)\n");
return -1;
Expand Down
Loading

0 comments on commit 6776bed

Please sign in to comment.