From 14d59acb649ae345a8781bdc014c94973d71b1be Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sun, 20 Aug 2017 17:33:01 +0200 Subject: [PATCH] Change crypto to ssl --- src/CMakeLists.txt | 2 +- src/main.c | 19 +++++++++++++++++++ src/network/networksocket.c | 11 ++++++++--- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a1bfe0e..5739e76 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -38,7 +38,7 @@ SET(SOURCES utils/utils.c) SET(LIBS - ubox ubus json-c blobmsg_json config uci gcrypt glib2) + ubox ubus json-c blobmsg_json config uci gcrypt openssl) ADD_EXECUTABLE(dawn ${SOURCES} utils/dawn_uci.c include/dawn_uci.h) diff --git a/src/main.c b/src/main.c index 6cd53f8..2bd94b6 100644 --- a/src/main.c +++ b/src/main.c @@ -6,6 +6,13 @@ #include "ubus.h" #include "dawn_uci.h" +/* SSL TESTNG */ + +#include +#include + +BIO_METHOD * BIO_f_base64(void); + #define BUFSIZE 17 #define BUFSIZE_DIR 256 @@ -63,11 +70,23 @@ int main(int argc, char **argv) { * ---- */ + BIO *bio, *b64; + char message[] = "Hello World \n"; + + b64 = BIO_new(BIO_f_base64()); + bio = BIO_new_fp(stdout, BIO_NOCLOSE); + bio = BIO_push(b64, bio); + BIO_write(bio, message, strlen(message)); + BIO_flush(bio); + + BIO_free_all(bio); + char msg[] = "{\"bssid\":\"a4:2b:b0:de:f1:fd\",\"freq\":5180,\"ht_supported\":true,\"vht_supported\":true,\"clients\":{\"78:02:f8:bc:ac:0b\":{\"auth\":true,\"assoc\":true,\"authorized\":true,\"preauth\":false,\"wds\":false,\"wmm\":true,\"ht\":true,\"vht\":true,\"wps\":false,\"mfp\":false,\"aid\":1}}}"; gcrypt_init(); gcrypt_set_key_and_iv(shared_key, iv); printf("Encrypting msg: %s\n", msg); char *enc = gcrypt_encrypt_msg(msg, strlen(msg) + 1); + printf("Decrypting msg: %s\n", enc); printf("Sizeof: %d, Strlen: %d, Acutal: %d\n", sizeof(enc) * sizeof(char), strlen(enc), strlen(msg) + 1); diff --git a/src/network/networksocket.c b/src/network/networksocket.c index e1c5b1e..7c86af3 100644 --- a/src/network/networksocket.c +++ b/src/network/networksocket.c @@ -10,6 +10,11 @@ #include #include +#include +#include + +BIO_METHOD * BIO_f_base64(void); + #include "networksocket.h" #include "datastorage.h" #include "broadcastsocket.h" @@ -210,10 +215,10 @@ int send_string_enc(char *msg) { char *enc = gcrypt_encrypt_msg(msg, msglen + 1); - char* base64_msg_dec = g_base64_encode(msg, msglen + 1); + //char* base64_msg_dec = g_base64_encode(msg, msglen + 1); - //size_t base64_msg_len; - //char* base64_msg_dec = base64_encode((unsigned char*)enc, msglen, &base64_msg_len); + size_t base64_msg_len; + char* base64_msg_dec = base64_encode((unsigned char*)enc, msglen, &base64_msg_len); if (sendto(sock, base64_msg_dec,