mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
Format code
This commit is contained in:
parent
88ca87c654
commit
7ba1f28f6b
9 changed files with 77 additions and 73 deletions
|
@ -6,28 +6,25 @@
|
|||
#define GCRY_CIPHER GCRY_CIPHER_AES128 // Pick the cipher here
|
||||
#define GCRY_C_MODE GCRY_CIPHER_MODE_ECB // Pick the cipher mode here
|
||||
|
||||
gcry_error_t gcry_error_handle;
|
||||
gcry_error_t gcry_error_handle;
|
||||
gcry_cipher_hd_t gcry_cipher_hd;
|
||||
|
||||
void gcrypt_init()
|
||||
{
|
||||
if (!gcry_check_version (GCRYPT_VERSION))
|
||||
{
|
||||
fprintf(stderr,"gcrypt: library version mismatch");
|
||||
void gcrypt_init() {
|
||||
if (!gcry_check_version(GCRYPT_VERSION)) {
|
||||
fprintf(stderr, "gcrypt: library version mismatch");
|
||||
}
|
||||
gcry_error_t err = 0;
|
||||
err = gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN);
|
||||
err |= gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0);
|
||||
err |= gcry_control (GCRYCTL_RESUME_SECMEM_WARN);
|
||||
err |= gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
|
||||
err = gcry_control(GCRYCTL_SUSPEND_SECMEM_WARN);
|
||||
err |= gcry_control(GCRYCTL_INIT_SECMEM, 16384, 0);
|
||||
err |= gcry_control(GCRYCTL_RESUME_SECMEM_WARN);
|
||||
err |= gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
|
||||
|
||||
if (err) {
|
||||
fprintf(stderr,"gcrypt: failed initialization");
|
||||
fprintf(stderr, "gcrypt: failed initialization");
|
||||
}
|
||||
}
|
||||
|
||||
void gcrypt_set_key_and_iv(char *key, char *iv)
|
||||
{
|
||||
void gcrypt_set_key_and_iv(char *key, char *iv) {
|
||||
size_t keylen = gcry_cipher_get_algo_keylen(GCRY_CIPHER);
|
||||
size_t blklen = gcry_cipher_get_algo_blklen(GCRY_CIPHER);
|
||||
|
||||
|
@ -36,37 +33,33 @@ void gcrypt_set_key_and_iv(char *key, char *iv)
|
|||
GCRY_CIPHER, // int
|
||||
GCRY_C_MODE, // int
|
||||
0);
|
||||
if (gcry_error_handle)
|
||||
{
|
||||
if (gcry_error_handle) {
|
||||
fprintf(stderr, "gcry_cipher_open failed: %s/%s\n",
|
||||
gcry_strsource(gcry_error_handle),
|
||||
gcry_strerror(gcry_error_handle));
|
||||
gcry_strsource(gcry_error_handle),
|
||||
gcry_strerror(gcry_error_handle));
|
||||
return;
|
||||
}
|
||||
|
||||
gcry_error_handle = gcry_cipher_setkey(gcry_cipher_hd, key, keylen);
|
||||
if (gcry_error_handle)
|
||||
{
|
||||
if (gcry_error_handle) {
|
||||
fprintf(stderr, "gcry_cipher_setkey failed: %s/%s\n",
|
||||
gcry_strsource(gcry_error_handle),
|
||||
gcry_strerror(gcry_error_handle));
|
||||
gcry_strsource(gcry_error_handle),
|
||||
gcry_strerror(gcry_error_handle));
|
||||
return;
|
||||
}
|
||||
|
||||
gcry_error_handle = gcry_cipher_setiv(gcry_cipher_hd, iv, blklen);
|
||||
if (gcry_error_handle)
|
||||
{
|
||||
if (gcry_error_handle) {
|
||||
fprintf(stderr, "gcry_cipher_setiv failed: %s/%s\n",
|
||||
gcry_strsource(gcry_error_handle),
|
||||
gcry_strerror(gcry_error_handle));
|
||||
gcry_strsource(gcry_error_handle),
|
||||
gcry_strerror(gcry_error_handle));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// free out buffer after using!
|
||||
char* gcrypt_encrypt_msg(char* msg, size_t msg_length)
|
||||
{
|
||||
if ( 0U != (msg_length & 0xfU) )
|
||||
char *gcrypt_encrypt_msg(char *msg, size_t msg_length) {
|
||||
if (0U != (msg_length & 0xfU))
|
||||
msg_length += 0x10U - (msg_length & 0xfU);
|
||||
|
||||
//msg_length++; // increase because of \0
|
||||
|
@ -77,8 +70,7 @@ char* gcrypt_encrypt_msg(char* msg, size_t msg_length)
|
|||
msg_length, // size_t
|
||||
msg, // const void *
|
||||
msg_length); // size_t
|
||||
if (gcry_error_handle)
|
||||
{
|
||||
if (gcry_error_handle) {
|
||||
printf("gcry_cipher_encrypt failed: %s/%s\n",
|
||||
gcry_strsource(gcry_error_handle),
|
||||
gcry_strerror(gcry_error_handle));
|
||||
|
@ -88,27 +80,25 @@ char* gcrypt_encrypt_msg(char* msg, size_t msg_length)
|
|||
}
|
||||
|
||||
// free out buffer after using!
|
||||
char* gcrypt_decrypt_msg(char* msg, size_t msg_length)
|
||||
{
|
||||
if ( 0U != (msg_length & 0xfU) )
|
||||
char *gcrypt_decrypt_msg(char *msg, size_t msg_length) {
|
||||
if (0U != (msg_length & 0xfU))
|
||||
msg_length += 0x10U - (msg_length & 0xfU);
|
||||
|
||||
char* out_buffer = malloc(msg_length);
|
||||
char *out_buffer = malloc(msg_length);
|
||||
gcry_error_handle = gcry_cipher_decrypt(
|
||||
gcry_cipher_hd, // gcry_cipher_hd_t
|
||||
out_buffer, // void *
|
||||
msg_length, // size_t
|
||||
msg, // const void *
|
||||
msg_length); // size_t
|
||||
if (gcry_error_handle)
|
||||
{
|
||||
if (gcry_error_handle) {
|
||||
printf("gcry_cipher_encrypt failed: %s/%s\n",
|
||||
gcry_strsource(gcry_error_handle),
|
||||
gcry_strerror(gcry_error_handle));
|
||||
free(out_buffer);
|
||||
return NULL;
|
||||
}
|
||||
char* out = malloc(strlen(out_buffer) + 1);
|
||||
char *out = malloc(strlen(out_buffer) + 1);
|
||||
strcpy(out, out_buffer);
|
||||
free(out_buffer);
|
||||
return out;
|
||||
|
|
|
@ -4,7 +4,11 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
void gcrypt_init();
|
||||
|
||||
void gcrypt_set_key_and_iv(char *key, char *iv);
|
||||
char* gcrypt_encrypt_msg(char* msg, size_t msg_length);
|
||||
char* gcrypt_decrypt_msg(char* msg, size_t msg_length);
|
||||
|
||||
char *gcrypt_encrypt_msg(char *msg, size_t msg_length);
|
||||
|
||||
char *gcrypt_decrypt_msg(char *msg, size_t msg_length);
|
||||
|
||||
#endif //DAWN_CRYPTO_H
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
|
||||
struct probe_metric_s dawn_metric;
|
||||
|
||||
struct probe_metric_s
|
||||
{
|
||||
struct probe_metric_s {
|
||||
int ht_support;
|
||||
int vht_support;
|
||||
int n_ht_support;
|
||||
|
|
|
@ -6,8 +6,11 @@
|
|||
pthread_mutex_t send_mutex;
|
||||
|
||||
int init_socket_runopts(char *_ip, char *_port, int broadcast_socket);
|
||||
|
||||
int send_string(char *msg);
|
||||
|
||||
int send_string_enc(char *msg);
|
||||
|
||||
void close_socket();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,14 +7,20 @@
|
|||
#define MIN_PROBE_REQ 5 // TODO: Parse from config file...
|
||||
|
||||
int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir);
|
||||
|
||||
int parse_to_probe_req(struct blob_attr *msg, probe_entry *prob_req);
|
||||
|
||||
int parse_to_clients(struct blob_attr *msg, int do_kick, uint32_t id);
|
||||
|
||||
void del_client_interface(uint32_t id, const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time);
|
||||
|
||||
void del_client_all_interfaces(const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time);
|
||||
|
||||
void *update_clients_thread(void *arg);
|
||||
|
||||
void *kick_clients_thread(void *arg);
|
||||
|
||||
char* hostapd_dir_glob;
|
||||
char *hostapd_dir_glob;
|
||||
|
||||
/* Metrik
|
||||
|
||||
|
|
|
@ -6,27 +6,27 @@
|
|||
|
||||
|
||||
static int hex_to_bin(char ch) {
|
||||
if ((ch >= '0') && (ch <= '9')) return ch - '0';
|
||||
ch = tolower(ch);
|
||||
if ((ch >= 'a') && (ch <= 'f')) return ch - 'a' + 10;
|
||||
return -1;
|
||||
if ((ch >= '0') && (ch <= '9')) return ch - '0';
|
||||
ch = tolower(ch);
|
||||
if ((ch >= 'a') && (ch <= 'f')) return ch - 'a' + 10;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int hwaddr_aton(const char *txt, uint8_t *addr) {
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ETH_ALEN; i++) {
|
||||
int a, b;
|
||||
for (i = 0; i < ETH_ALEN; i++) {
|
||||
int a, b;
|
||||
|
||||
a = hex_to_bin(*txt++);
|
||||
if (a < 0) return -1;
|
||||
b = hex_to_bin(*txt++);
|
||||
if (b < 0) return -1;
|
||||
*addr++ = (a << 4) | b;
|
||||
if (i < 5 && *txt++ != ':') return -1;
|
||||
}
|
||||
a = hex_to_bin(*txt++);
|
||||
if (a < 0) return -1;
|
||||
b = hex_to_bin(*txt++);
|
||||
if (b < 0) return -1;
|
||||
*addr++ = (a << 4) | b;
|
||||
if (i < 5 && *txt++ != ':') return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -67,12 +67,12 @@ int main(int argc, char **argv) {
|
|||
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);
|
||||
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);
|
||||
|
||||
char* dec = gcrypt_decrypt_msg(enc, strlen(msg) + 1);//sizeof(enc));
|
||||
char *dec = gcrypt_decrypt_msg(enc, strlen(msg) + 1);//sizeof(enc));
|
||||
printf("Message decrypted: %s\n", dec);
|
||||
free(enc);
|
||||
free(dec);
|
||||
|
|
|
@ -29,6 +29,7 @@ char recv_string[MAX_RECV_STRING + 1];
|
|||
int recv_string_len;
|
||||
|
||||
void *receive_msg(void *args);
|
||||
|
||||
void *receive_msg_enc(void *args);
|
||||
|
||||
int init_socket_runopts(char *_ip, char *_port, int broadcast_socket) {
|
||||
|
@ -136,9 +137,9 @@ void *receive_msg_enc(void *args) {
|
|||
if (strlen(recv_string) <= 0) {
|
||||
return 0;
|
||||
}
|
||||
recv_string[recv_string_len] = '\0';
|
||||
//recv_string[recv_string_len] = '\0';
|
||||
|
||||
char* dec = gcrypt_decrypt_msg(recv_string, recv_string_len);
|
||||
char *dec = gcrypt_decrypt_msg(recv_string, recv_string_len);
|
||||
|
||||
printf("[WC] Network-Received: %s\n", dec);
|
||||
|
||||
|
@ -199,7 +200,7 @@ int send_string(char *msg) {
|
|||
int send_string_enc(char *msg) {
|
||||
pthread_mutex_lock(&send_mutex);
|
||||
size_t msglen = strlen(msg);
|
||||
char* enc = gcrypt_encrypt_msg(msg, msglen + 1);
|
||||
char *enc = gcrypt_encrypt_msg(msg, msglen + 1);
|
||||
|
||||
if (sendto(sock,
|
||||
enc,
|
||||
|
|
|
@ -67,7 +67,7 @@ int eval_probe_metric(struct client_s client_entry, struct probe_entry_s probe_e
|
|||
|
||||
|
||||
printf("Checking if client supports: AP_VHT: %d, CL_VHT: %d\n", ap_supports_vht, client_supports_vht);
|
||||
if(ap_supports_vht && client_supports_vht){
|
||||
if (ap_supports_vht && client_supports_vht) {
|
||||
printf("AAAHHHHHHHHHHH IDEAL!!!\n");
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ int eval_probe_metric(struct client_s client_entry, struct probe_entry_s probe_e
|
|||
|
||||
//score += (client_entry.signal > -60) ? metric.freq : 0;
|
||||
|
||||
printf("SCORE: %d\n",score);
|
||||
printf("SCORE: %d\n", score);
|
||||
|
||||
return score;
|
||||
}
|
||||
|
@ -100,18 +100,18 @@ int kick_client(struct client_s client_entry) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
printf("Found probe [i] : %d\n",i);
|
||||
printf("Found probe [i] : %d\n", i);
|
||||
|
||||
// find own probe entry and calculate score
|
||||
int j;
|
||||
for (j = i; j <= probe_entry_last; j++) {
|
||||
printf("[j] : %d\n",j);
|
||||
printf("[j] : %d\n", j);
|
||||
if (!mac_is_equal(probe_array[j].client_addr, client_entry.client_addr)) {
|
||||
// this shouldn't happen!
|
||||
//return 1; // kick client!
|
||||
return 0;
|
||||
}
|
||||
if (mac_is_equal(client_entry.bssid_addr, probe_array[j].bssid_addr)){
|
||||
if (mac_is_equal(client_entry.bssid_addr, probe_array[j].bssid_addr)) {
|
||||
own_score = eval_probe_metric(client_entry, probe_array[j]);
|
||||
break;
|
||||
}
|
||||
|
@ -119,12 +119,13 @@ int kick_client(struct client_s client_entry) {
|
|||
|
||||
int k;
|
||||
for (k = i; k <= probe_entry_last; k++) {
|
||||
printf("[k] : %d\n",k);
|
||||
printf("[k] : %d\n", k);
|
||||
if (!mac_is_equal(probe_array[k].client_addr, client_entry.client_addr)) {
|
||||
break;
|
||||
}
|
||||
if(!mac_is_equal(client_entry.bssid_addr, probe_array[k].bssid_addr) &&
|
||||
own_score < eval_probe_metric(client_entry, probe_array[k])) // that's wrong! find client_entry OR write things in probe array struct!
|
||||
if (!mac_is_equal(client_entry.bssid_addr, probe_array[k].bssid_addr) &&
|
||||
own_score < eval_probe_metric(client_entry,
|
||||
probe_array[k])) // that's wrong! find client_entry OR write things in probe array struct!
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -335,9 +336,9 @@ probe_entry insert_to_array(probe_entry entry, int inc_counter) {
|
|||
entry.counter = 0;
|
||||
probe_entry tmp = probe_array_delete(entry);
|
||||
|
||||
if(mac_is_equal(entry.bssid_addr,tmp.bssid_addr)
|
||||
&& mac_is_equal(entry.client_addr, tmp.client_addr)){
|
||||
entry.counter = tmp.counter;
|
||||
if (mac_is_equal(entry.bssid_addr, tmp.bssid_addr)
|
||||
&& mac_is_equal(entry.client_addr, tmp.client_addr)) {
|
||||
entry.counter = tmp.counter;
|
||||
}
|
||||
|
||||
if (inc_counter) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue