diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Messenger.c | 2 | ||||
-rw-r--r-- | toxcore/net_crypto.c | 67 |
2 files changed, 35 insertions, 34 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 1a5c93aa..7fdae8f0 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1738,7 +1738,7 @@ static void LANdiscovery(Messenger *m) | |||
1738 | } | 1738 | } |
1739 | } | 1739 | } |
1740 | 1740 | ||
1741 | int handle_new_connections(void *object, New_Connection *n_c) | 1741 | static int handle_new_connections(void *object, New_Connection *n_c) |
1742 | { | 1742 | { |
1743 | Messenger *m = object; | 1743 | Messenger *m = object; |
1744 | int friend_id = getfriend_id(m, n_c->public_key); | 1744 | int friend_id = getfriend_id(m, n_c->public_key); |
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index d71ccdda..a0a913d2 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -506,6 +506,32 @@ static int send_temp_packet(Net_Crypto *c, int crypt_connection_id) | |||
506 | return 0; | 506 | return 0; |
507 | } | 507 | } |
508 | 508 | ||
509 | /* Create a handshake packet and set it as a temp packet. | ||
510 | * cookie must be COOKIE_LENGTH. | ||
511 | * | ||
512 | * return -1 on failure. | ||
513 | * return 0 on success. | ||
514 | */ | ||
515 | static int create_send_handshake(Net_Crypto *c, int crypt_connection_id, uint8_t *cookie) | ||
516 | { | ||
517 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | ||
518 | |||
519 | if (conn == 0) | ||
520 | return -1; | ||
521 | |||
522 | uint8_t handshake_packet[HANDSHAKE_PACKET_LENGTH]; | ||
523 | |||
524 | if (create_crypto_handshake(c, handshake_packet, cookie, conn->sent_nonce, conn->sessionpublic_key, | ||
525 | conn->public_key) != sizeof(handshake_packet)) | ||
526 | return -1; | ||
527 | |||
528 | if (new_temp_packet(c, crypt_connection_id, handshake_packet, sizeof(handshake_packet)) != 0) | ||
529 | return -1; | ||
530 | |||
531 | send_temp_packet(c, crypt_connection_id); | ||
532 | return 0; | ||
533 | } | ||
534 | |||
509 | /* Handle a packet that was recieved for the connection. | 535 | /* Handle a packet that was recieved for the connection. |
510 | * | 536 | * |
511 | * return -1 on failure. | 537 | * return -1 on failure. |
@@ -535,16 +561,9 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, uint | |||
535 | if (number != conn->cookie_request_number) | 561 | if (number != conn->cookie_request_number) |
536 | return -1; | 562 | return -1; |
537 | 563 | ||
538 | uint8_t handshake_packet[HANDSHAKE_PACKET_LENGTH]; | 564 | if (create_send_handshake(c, crypt_connection_id, cookie) != 0) |
539 | |||
540 | if (create_crypto_handshake(c, handshake_packet, cookie, conn->sent_nonce, conn->sessionpublic_key, | ||
541 | conn->public_key) != sizeof(handshake_packet)) | ||
542 | return -1; | ||
543 | |||
544 | if (new_temp_packet(c, crypt_connection_id, handshake_packet, sizeof(handshake_packet)) != 0) | ||
545 | return -1; | 565 | return -1; |
546 | 566 | ||
547 | send_temp_packet(c, crypt_connection_id); | ||
548 | conn->status = CRYPTO_CONN_HANDSHAKE_SENT; | 567 | conn->status = CRYPTO_CONN_HANDSHAKE_SENT; |
549 | return 0; | 568 | return 0; |
550 | } | 569 | } |
@@ -561,16 +580,8 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, uint | |||
561 | encrypt_precompute(conn->peersessionpublic_key, conn->sessionsecret_key, conn->shared_key); | 580 | encrypt_precompute(conn->peersessionpublic_key, conn->sessionsecret_key, conn->shared_key); |
562 | 581 | ||
563 | if (conn->status == CRYPTO_CONN_COOKIE_REQUESTING) { | 582 | if (conn->status == CRYPTO_CONN_COOKIE_REQUESTING) { |
564 | uint8_t handshake_packet[HANDSHAKE_PACKET_LENGTH]; | 583 | if (create_send_handshake(c, crypt_connection_id, cookie) != 0) |
565 | |||
566 | if (create_crypto_handshake(c, handshake_packet, cookie, conn->sent_nonce, conn->sessionpublic_key, | ||
567 | conn->public_key) != sizeof(handshake_packet)) | ||
568 | return -1; | 584 | return -1; |
569 | |||
570 | if (new_temp_packet(c, crypt_connection_id, handshake_packet, sizeof(handshake_packet)) != 0) | ||
571 | return -1; | ||
572 | |||
573 | send_temp_packet(c, crypt_connection_id); | ||
574 | } | 585 | } |
575 | 586 | ||
576 | conn->status = CRYPTO_CONN_NOT_CONFIRMED; | 587 | conn->status = CRYPTO_CONN_NOT_CONFIRMED; |
@@ -761,9 +772,12 @@ static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, uint8_ | |||
761 | memcpy(conn->peersessionpublic_key, n_c.peersessionpublic_key, crypto_box_PUBLICKEYBYTES); | 772 | memcpy(conn->peersessionpublic_key, n_c.peersessionpublic_key, crypto_box_PUBLICKEYBYTES); |
762 | encrypt_precompute(conn->peersessionpublic_key, conn->sessionsecret_key, conn->shared_key); | 773 | encrypt_precompute(conn->peersessionpublic_key, conn->sessionsecret_key, conn->shared_key); |
763 | 774 | ||
764 | conn->status = CRYPTO_CONN_NOT_CONFIRMED; | ||
765 | crypto_connection_add_source(c, crypt_connection_id, source); | 775 | crypto_connection_add_source(c, crypt_connection_id, source); |
766 | ret = 0; | 776 | |
777 | if (create_send_handshake(c, crypt_connection_id, n_c.cookie) == 0) { | ||
778 | conn->status = CRYPTO_CONN_NOT_CONFIRMED; | ||
779 | ret = 0; | ||
780 | } | ||
767 | } | 781 | } |
768 | 782 | ||
769 | free(n_c.cookie); | 783 | free(n_c.cookie); |
@@ -805,13 +819,7 @@ int accept_crypto_connection(Net_Crypto *c, New_Connection *n_c) | |||
805 | if (n_c->cookie_length != COOKIE_LENGTH) | 819 | if (n_c->cookie_length != COOKIE_LENGTH) |
806 | return -1; | 820 | return -1; |
807 | 821 | ||
808 | uint8_t handshake_packet[HANDSHAKE_PACKET_LENGTH]; | 822 | if (create_send_handshake(c, crypt_connection_id, n_c->cookie) != 0) |
809 | |||
810 | if (create_crypto_handshake(c, handshake_packet, n_c->cookie, conn->sent_nonce, conn->sessionpublic_key, | ||
811 | conn->public_key) != sizeof(handshake_packet)) | ||
812 | return -1; | ||
813 | |||
814 | if (new_temp_packet(c, crypt_connection_id, handshake_packet, sizeof(handshake_packet)) != 0) | ||
815 | return -1; | 823 | return -1; |
816 | 824 | ||
817 | send_temp_packet(c, crypt_connection_id); | 825 | send_temp_packet(c, crypt_connection_id); |
@@ -1058,12 +1066,6 @@ void load_keys(Net_Crypto *c, uint8_t *keys) | |||
1058 | memcpy(c->self_secret_key, keys + crypto_box_PUBLICKEYBYTES, crypto_box_SECRETKEYBYTES); | 1066 | memcpy(c->self_secret_key, keys + crypto_box_PUBLICKEYBYTES, crypto_box_SECRETKEYBYTES); |
1059 | } | 1067 | } |
1060 | 1068 | ||
1061 | /* Handle received packets for not yet established crypto connections. */ | ||
1062 | static void receive_crypto(Net_Crypto *c) | ||
1063 | { | ||
1064 | |||
1065 | } | ||
1066 | |||
1067 | /* Run this to (re)initialize net_crypto. | 1069 | /* Run this to (re)initialize net_crypto. |
1068 | * Sets all the global connection variables to their default values. | 1070 | * Sets all the global connection variables to their default values. |
1069 | */ | 1071 | */ |
@@ -1105,7 +1107,6 @@ void do_net_crypto(Net_Crypto *c) | |||
1105 | { | 1107 | { |
1106 | unix_time_update(); | 1108 | unix_time_update(); |
1107 | kill_timedout(c); | 1109 | kill_timedout(c); |
1108 | receive_crypto(c); | ||
1109 | send_crypto_packets(c); | 1110 | send_crypto_packets(c); |
1110 | } | 1111 | } |
1111 | 1112 | ||