diff --git a/client/client b/client/client index aaf6aa3..b49feaf 100755 Binary files a/client/client and b/client/client differ diff --git a/client/include/cipher.h b/client/include/cipher.h index 422b0dd..a356bfe 100644 --- a/client/include/cipher.h +++ b/client/include/cipher.h @@ -1,6 +1,8 @@ #ifndef cipher_h #define cipher_h +#define OPENSSL_API_COMPAT 30000 + #include "../include/fraction.h" #include @@ -8,7 +10,8 @@ #include #include #include - +#include +#include typedef struct{ unsigned char *decryptedtext; @@ -16,5 +19,5 @@ typedef struct{ } decrypted; decrypted *decrypt_fraction(fraction_t *fraction); - +char *generate_publickey(void); #endif diff --git a/client/src/cipher.c b/client/src/cipher.c index ff46a82..db39723 100644 --- a/client/src/cipher.c +++ b/client/src/cipher.c @@ -1,5 +1,7 @@ #include "../include/cipher.h" #include "../include/fraction.h" +#include +#include decrypted decryptedstr; @@ -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; +} diff --git a/client/src/main.c b/client/src/main.c index e1b30d7..68251f4 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -7,7 +7,6 @@ #include "../include/sock.h" #include "../include/utils.h" #include "../include/log.h" -#include "../include/cipher.h" #include "../include/load.h" @@ -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; @@ -105,18 +108,15 @@ int main(void) { for (int i=0; i