mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
Update crypt modul
This commit is contained in:
parent
57209931db
commit
88ca87c654
3 changed files with 13 additions and 10 deletions
|
@ -38,7 +38,7 @@ void gcrypt_set_key_and_iv(char *key, char *iv)
|
||||||
0);
|
0);
|
||||||
if (gcry_error_handle)
|
if (gcry_error_handle)
|
||||||
{
|
{
|
||||||
printf("gcry_cipher_open failed: %s/%s\n",
|
fprintf(stderr, "gcry_cipher_open failed: %s/%s\n",
|
||||||
gcry_strsource(gcry_error_handle),
|
gcry_strsource(gcry_error_handle),
|
||||||
gcry_strerror(gcry_error_handle));
|
gcry_strerror(gcry_error_handle));
|
||||||
return;
|
return;
|
||||||
|
@ -47,7 +47,7 @@ void gcrypt_set_key_and_iv(char *key, char *iv)
|
||||||
gcry_error_handle = gcry_cipher_setkey(gcry_cipher_hd, key, keylen);
|
gcry_error_handle = gcry_cipher_setkey(gcry_cipher_hd, key, keylen);
|
||||||
if (gcry_error_handle)
|
if (gcry_error_handle)
|
||||||
{
|
{
|
||||||
printf("gcry_cipher_setkey failed: %s/%s\n",
|
fprintf(stderr, "gcry_cipher_setkey failed: %s/%s\n",
|
||||||
gcry_strsource(gcry_error_handle),
|
gcry_strsource(gcry_error_handle),
|
||||||
gcry_strerror(gcry_error_handle));
|
gcry_strerror(gcry_error_handle));
|
||||||
return;
|
return;
|
||||||
|
@ -56,7 +56,7 @@ void gcrypt_set_key_and_iv(char *key, char *iv)
|
||||||
gcry_error_handle = gcry_cipher_setiv(gcry_cipher_hd, iv, blklen);
|
gcry_error_handle = gcry_cipher_setiv(gcry_cipher_hd, iv, blklen);
|
||||||
if (gcry_error_handle)
|
if (gcry_error_handle)
|
||||||
{
|
{
|
||||||
printf("gcry_cipher_setiv failed: %s/%s\n",
|
fprintf(stderr, "gcry_cipher_setiv failed: %s/%s\n",
|
||||||
gcry_strsource(gcry_error_handle),
|
gcry_strsource(gcry_error_handle),
|
||||||
gcry_strerror(gcry_error_handle));
|
gcry_strerror(gcry_error_handle));
|
||||||
return;
|
return;
|
||||||
|
@ -77,7 +77,6 @@ char* gcrypt_encrypt_msg(char* msg, size_t msg_length)
|
||||||
msg_length, // size_t
|
msg_length, // size_t
|
||||||
msg, // const void *
|
msg, // const void *
|
||||||
msg_length); // size_t
|
msg_length); // size_t
|
||||||
printf("Message encrypted: %s : %s size: %d\n", msg, out, msg_length);
|
|
||||||
if (gcry_error_handle)
|
if (gcry_error_handle)
|
||||||
{
|
{
|
||||||
printf("gcry_cipher_encrypt failed: %s/%s\n",
|
printf("gcry_cipher_encrypt failed: %s/%s\n",
|
||||||
|
@ -106,6 +105,7 @@ char* gcrypt_decrypt_msg(char* msg, size_t msg_length)
|
||||||
printf("gcry_cipher_encrypt failed: %s/%s\n",
|
printf("gcry_cipher_encrypt failed: %s/%s\n",
|
||||||
gcry_strsource(gcry_error_handle),
|
gcry_strsource(gcry_error_handle),
|
||||||
gcry_strerror(gcry_error_handle));
|
gcry_strerror(gcry_error_handle));
|
||||||
|
free(out_buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
char* out = malloc(strlen(out_buffer) + 1);
|
char* out = malloc(strlen(out_buffer) + 1);
|
||||||
|
|
|
@ -63,13 +63,16 @@ int main(int argc, char **argv) {
|
||||||
* ----
|
* ----
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char msg[] = "Hallo Lotta!!!!! :D";
|
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_init();
|
||||||
gcrypt_set_key_and_iv(shared_key, iv);
|
gcrypt_set_key_and_iv(shared_key, iv);
|
||||||
printf("Encrypting msg: %s\n", msg);
|
printf("Encrypting msg: %s\n", msg);
|
||||||
char* enc = gcrypt_encrypt_msg(msg, strlen(msg) + 1);
|
char* enc = gcrypt_encrypt_msg(msg, strlen(msg) + 1);
|
||||||
printf("Decrypting msg: %s\n", enc);
|
printf("Decrypting msg: %s\n", enc);
|
||||||
char* dec = gcrypt_decrypt_msg(enc, strlen(enc));
|
|
||||||
|
printf("Sizeof: %d, Strlen: %d, Acutal: %d\n", sizeof(enc) * sizeof(char), strlen(enc), strlen(msg) + 1);
|
||||||
|
|
||||||
|
char* dec = gcrypt_decrypt_msg(enc, strlen(msg) + 1);//sizeof(enc));
|
||||||
printf("Message decrypted: %s\n", dec);
|
printf("Message decrypted: %s\n", dec);
|
||||||
free(enc);
|
free(enc);
|
||||||
free(dec);
|
free(dec);
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
|
||||||
/* Network Defines */
|
/* Network Defines */
|
||||||
#define MAX_RECV_STRING 500
|
#define MAX_RECV_STRING 5000
|
||||||
#define NET_CONFIG_PATH "/etc/wlancontroller/networkconfig.conf"
|
#define NET_CONFIG_PATH "/etc/wlancontroller/networkconfig.conf"
|
||||||
|
|
||||||
/* Network Attributes */
|
/* Network Attributes */
|
||||||
|
@ -71,7 +71,7 @@ void *receive_msg(void *args) {
|
||||||
}
|
}
|
||||||
recv_string[recv_string_len] = '\0';
|
recv_string[recv_string_len] = '\0';
|
||||||
|
|
||||||
//printf("[WC] Network-Received: %s\n", recv_string);
|
printf("[WC] Network-Received: %s\n", recv_string);
|
||||||
|
|
||||||
probe_entry prob_req;
|
probe_entry prob_req;
|
||||||
struct blob_buf b;
|
struct blob_buf b;
|
||||||
|
@ -138,7 +138,7 @@ void *receive_msg_enc(void *args) {
|
||||||
}
|
}
|
||||||
recv_string[recv_string_len] = '\0';
|
recv_string[recv_string_len] = '\0';
|
||||||
|
|
||||||
char* dec = gcrypt_decrypt_msg(recv_string, strlen(recv_string));
|
char* dec = gcrypt_decrypt_msg(recv_string, recv_string_len);
|
||||||
|
|
||||||
printf("[WC] Network-Received: %s\n", dec);
|
printf("[WC] Network-Received: %s\n", dec);
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ int send_string_enc(char *msg) {
|
||||||
|
|
||||||
if (sendto(sock,
|
if (sendto(sock,
|
||||||
enc,
|
enc,
|
||||||
strlen(enc),
|
msglen + 1, // very important to use actual length of string because of '\0' in encrypted msg
|
||||||
0,
|
0,
|
||||||
(struct sockaddr *) &addr,
|
(struct sockaddr *) &addr,
|
||||||
sizeof(addr)) < 0) {
|
sizeof(addr)) < 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue