diff options
Diffstat (limited to 'core/net_crypto.c')
-rw-r--r-- | core/net_crypto.c | 23 |
1 files changed, 22 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 | ||
578 | void 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 | ||
586 | void 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 | { |