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

Decrypt load refactor #36

Merged
merged 8 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ignored compiled client
src/client/client
client/client

# Prerequisites
*.d
Expand Down
Binary file removed client/client
Binary file not shown.
11 changes: 3 additions & 8 deletions client/include/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,17 @@
#define HTTP_OOM -3
#define HTTP_HEADERS_TOO_LONG -4

#define HTTP_VERBOSE 0

typedef struct {
int status_code;
char *request; // The actual request (for book keeping)
char *data;
size_t size;
} http_res_t;

void http_free(http_res_t *res);
void http_free(http_res_t *res);

int http_get(int sfd, const char *path, http_res_t *res);
int http_get(int sfd, const char *path, http_res_t *res);
/* Keeping in case we end up using it sometime */
int http_post(int sfd,const char* path,const char *content_type, const char* parameters, http_res_t *res);

long parse_http_status_code(const char *buf);
long parse_http_content_length(const char *buf);
int http_post(int sfd,const char* path,const char *content_type, const char* parameters, http_res_t *res);

#endif // HTTP_H
4 changes: 2 additions & 2 deletions client/include/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

int create_sock_and_conn(struct addrinfo *res);
void setup_hints(struct addrinfo *hints);
ssize_t recv_response(int sfd, char *buffer, size_t buffer_size);
ssize_t send_request(int sfd, const char *request);
ssize_t sock_recv_bytes(int sfd, char *buffer, size_t buffer_size);
ssize_t sock_send_string(int sfd, const char *request);
int sock_connect(int sfd, struct addrinfo *res);
int create_socket(struct addrinfo *res);
int h_getaddrinfo(const char *ip, const char *port, struct addrinfo *hints,
Expand Down
1 change: 1 addition & 0 deletions client/src/cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ decrypted_t *decrypt_fraction(fraction_t *fraction) {

if (decr == NULL) {
log_error("Could not allocate memory for decrypted struct");
free(decrypted_text);
return NULL;
}

Expand Down
18 changes: 9 additions & 9 deletions client/src/fraction.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,19 @@ int compare_fractions(const void *a, const void *b) {
}

void print_fraction(fraction_t fraction) {
log_debug("Magic: 0x%08x\n", fraction.magic);
log_debug("Index: %u\n", fraction.index);
log_debug("Magic: 0x%08x", fraction.magic);
log_debug("Index: %u", fraction.index);
if (log_get_level() == LOG_DEBUG) {
char iv_str[sizeof(fraction.iv) * 3] = {
0}; // 2 characters for hex + 1 for space
for (size_t i = 0; i < sizeof(fraction.iv); i++) {
snprintf(iv_str + i * 3, 4, "%02x ", (unsigned char)fraction.iv[i]);
}
log_debug("IV: %s\n", iv_str);
log_debug("IV: %s", iv_str);
}

log_debug("CRC-32: 0x%08x\n", fraction.crc);
log_debug("Data size: %lu\n\n", fraction.data_size);
log_debug("CRC-32: 0x%08x", fraction.crc);
log_debug("Data size: %lu", fraction.data_size);
}

int calc_crc(fraction_t *frac){
Expand All @@ -127,9 +127,9 @@ int calc_crc(fraction_t *frac){
uint32_t calculated_crc = crc32(buffer, offset);

if (calculated_crc != frac->crc) {
log_warn("Checksum incorrect\n");
log_warn("Checksum generated: %08X\n", calculated_crc);
log_warn("Checksum from fraction: %08X\n\n", frac->crc);
log_warn("Checksum incorrect");
log_warn("Checksum generated: %08X", calculated_crc);
log_warn("Checksum from fraction: %08X", frac->crc);
}

return calculated_crc == frac->crc;
Expand All @@ -139,7 +139,7 @@ int check_fractions(fraction_t *fraction, size_t size){
int res = 0;
for(size_t i = 0; i < size; i++){
if (!calc_crc(&fraction[i])) {
log_error("Failed to validate integrity of fraction:\n");
log_error("Failed to validate integrity of fraction:");
print_fraction(fraction[i]);
res += 1;
}
Expand Down
Loading
Loading