summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/net_crypto.c23
-rw-r--r--core/net_crypto.h8
2 files changed, 30 insertions, 1 deletions
diff --git a/core/net_crypto.c b/core/net_crypto.c
index faeb6be6..d4a3ba7b 100644
--- a/core/net_crypto.c
+++ b/core/net_crypto.c
@@ -468,6 +468,12 @@ int crypto_inbound(uint8_t * public_key, uint8_t * secret_nonce, uint8_t * sessi
468 { 468 {
469 if(incoming_connections[i] != -1) 469 if(incoming_connections[i] != -1)
470 { 470 {
471 if(is_connected(incoming_connections[i]) == 4 || is_connected(incoming_connections[i]) == 0)
472 {
473 kill_connection(incoming_connections[i]);
474 incoming_connections[i] = -1;
475 continue;
476 }
471 if(id_packet(incoming_connections[i]) == 2) 477 if(id_packet(incoming_connections[i]) == 2)
472 { 478 {
473 uint8_t temp_data[MAX_DATA_SIZE]; 479 uint8_t temp_data[MAX_DATA_SIZE];
@@ -567,6 +573,22 @@ void new_keys()
567 crypto_box_keypair(self_public_key,self_secret_key); 573 crypto_box_keypair(self_public_key,self_secret_key);
568} 574}
569 575
576//save the public and private keys to the keys array
577//Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES
578void save_keys(uint8_t * keys)
579{
580 memcpy(keys, self_public_key, crypto_box_PUBLICKEYBYTES);
581 memcpy(keys + crypto_box_PUBLICKEYBYTES, self_secret_key, crypto_box_SECRETKEYBYTES);
582}
583
584//load the public and private keys from the keys array
585//Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES
586void load_keys(uint8_t * keys)
587{
588 memcpy(self_public_key, keys, crypto_box_PUBLICKEYBYTES);
589 memcpy(self_secret_key, keys + crypto_box_PUBLICKEYBYTES, crypto_box_SECRETKEYBYTES);
590}
591
570//TODO: optimize this 592//TODO: optimize this
571//adds an incoming connection to the incoming_connection list. 593//adds an incoming connection to the incoming_connection list.
572//returns 0 if successful 594//returns 0 if successful
@@ -621,7 +643,6 @@ static void receive_crypto()
621 } 643 }
622 if(id_packet(crypto_connections[i].number) == 2)//handle handshake packet. 644 if(id_packet(crypto_connections[i].number) == 2)//handle handshake packet.
623 { 645 {
624
625 len = read_packet(crypto_connections[i].number, temp_data); 646 len = read_packet(crypto_connections[i].number, temp_data);
626 if(handle_cryptohandshake(public_key, secret_nonce, session_key, temp_data, len)) 647 if(handle_cryptohandshake(public_key, secret_nonce, session_key, temp_data, len))
627 { 648 {
diff --git a/core/net_crypto.h b/core/net_crypto.h
index 2476db10..df2cb9ca 100644
--- a/core/net_crypto.h
+++ b/core/net_crypto.h
@@ -118,6 +118,14 @@ int is_cryptoconnected(int crypt_connection_id);
118//Only call this function the first time the program starts. 118//Only call this function the first time the program starts.
119void new_keys(); 119void new_keys();
120 120
121//save the public and private keys to the keys array
122//Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES
123void save_keys(uint8_t * keys);
124
125//load the public and private keys from the keys array
126//Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES
127void load_keys(uint8_t * keys);
128
121//run this to (re)initialize net_crypto 129//run this to (re)initialize net_crypto
122//sets all the global connection variables to their default values. 130//sets all the global connection variables to their default values.
123void initNetCrypto(); 131void initNetCrypto();