aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-08-05 10:52:35 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2023-08-05 10:52:35 +0200
commit2c734ad638863dd49f1b880fe87f4bdd4dd751c9 (patch)
tree7b2a6488a4d3968161d0cb715b3a6edcbb7006e5
parent75009e70cd8e2bd906fe5f90c66d8482fc422539 (diff)
downloadgnunet-2c734ad638863dd49f1b880fe87f4bdd4dd751c9.tar.gz
gnunet-2c734ad638863dd49f1b880fe87f4bdd4dd751c9.zip
TNG: TCP communicator code KX needs to be checked per connection, not globally
-rw-r--r--src/transport/gnunet-communicator-tcp.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c
index 691319100..85c3eb422 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -661,6 +661,17 @@ struct Queue
661 * Store Context for retrieving the monotonic time send with the handshake ack. 661 * Store Context for retrieving the monotonic time send with the handshake ack.
662 */ 662 */
663 struct GNUNET_PEERSTORE_StoreContext *handshake_ack_monotime_sc; 663 struct GNUNET_PEERSTORE_StoreContext *handshake_ack_monotime_sc;
664
665 /**
666 * Size of data received without KX challenge played back.
667 */
668 // TODO remove?
669 size_t unverified_size;
670
671 /**
672 * Has the initial (core) handshake already happened?
673 */
674 int initial_core_kx_done;
664}; 675};
665 676
666 677
@@ -887,11 +898,6 @@ struct ListenTask *lts_tail;
887 */ 898 */
888int addrs_lens; 899int addrs_lens;
889 900
890/**
891 * Size of data received without KX challenge played back.
892 */
893// TODO remove?
894size_t unverified_size;
895 901
896/** 902/**
897 * Database for peer's HELLOs. 903 * Database for peer's HELLOs.
@@ -1860,24 +1866,23 @@ queue_write (void *cls)
1860static size_t 1866static size_t
1861try_handle_plaintext (struct Queue *queue) 1867try_handle_plaintext (struct Queue *queue)
1862{ 1868{
1863 const struct GNUNET_MessageHeader *hdr = 1869 const struct GNUNET_MessageHeader *hdr;
1864 (const struct GNUNET_MessageHeader *) queue->pread_buf; 1870 const struct TCPConfirmationAck *tca;
1865 const struct TCPConfirmationAck *tca = (const struct 1871 const struct TCPBox *box;
1866 TCPConfirmationAck *) queue->pread_buf; 1872 const struct TCPRekey *rekey;
1867 const struct TCPBox *box = (const struct TCPBox *) queue->pread_buf; 1873 const struct TCPFinish *fin;
1868 const struct TCPRekey *rekey = (const struct TCPRekey *) queue->pread_buf;
1869 const struct TCPFinish *fin = (const struct TCPFinish *) queue->pread_buf;
1870 struct TCPRekey rekeyz; 1874 struct TCPRekey rekeyz;
1871 struct TCPFinish finz; 1875 struct TCPFinish finz;
1872 struct GNUNET_ShortHashCode tmac; 1876 struct GNUNET_ShortHashCode tmac;
1873 uint16_t type; 1877 uint16_t type;
1874 size_t size = 0; /* make compiler happy */ 1878 size_t size = 0;
1875 struct TcpHandshakeAckSignature thas; 1879 struct TcpHandshakeAckSignature thas;
1876 const struct GNUNET_CRYPTO_ChallengeNonceP challenge = queue->challenge; 1880 const struct GNUNET_CRYPTO_ChallengeNonceP challenge = queue->challenge;
1877 1881
1878 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1882 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1879 "try handle plaintext!\n"); 1883 "try handle plaintext!\n");
1880 1884
1885 hdr = (const struct GNUNET_MessageHeader *) queue->pread_buf;
1881 if ((sizeof(*hdr) > queue->pread_off)) 1886 if ((sizeof(*hdr) > queue->pread_off))
1882 { 1887 {
1883 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1885,11 +1890,11 @@ try_handle_plaintext (struct Queue *queue)
1885 return 0; /* not even a header */ 1890 return 0; /* not even a header */
1886 } 1891 }
1887 1892
1888 if ((-1 != unverified_size) && (unverified_size > INITIAL_CORE_KX_SIZE)) 1893 if ((GNUNET_YES != queue->initial_core_kx_done) && (queue->unverified_size > INITIAL_CORE_KX_SIZE))
1889 { 1894 {
1890 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1895 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1891 "Already received data of size %lu bigger than KX size %lu!\n", 1896 "Already received data of size %lu bigger than KX size %lu!\n",
1892 unverified_size, 1897 queue->unverified_size,
1893 INITIAL_CORE_KX_SIZE); 1898 INITIAL_CORE_KX_SIZE);
1894 GNUNET_break_op (0); 1899 GNUNET_break_op (0);
1895 queue_finish (queue); 1900 queue_finish (queue);
@@ -1900,6 +1905,7 @@ try_handle_plaintext (struct Queue *queue)
1900 switch (type) 1905 switch (type)
1901 { 1906 {
1902 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK: 1907 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK:
1908 tca = (const struct TCPConfirmationAck *) queue->pread_buf;
1903 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1909 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1904 "start processing ack\n"); 1910 "start processing ack\n");
1905 if (sizeof(*tca) > queue->pread_off) 1911 if (sizeof(*tca) > queue->pread_off)
@@ -1972,7 +1978,7 @@ try_handle_plaintext (struct Queue *queue)
1972 queue->address->sa_family, NULL); 1978 queue->address->sa_family, NULL);
1973 } 1979 }
1974 1980
1975 unverified_size = -1; 1981 queue->unverified_size = -1;
1976 1982
1977 char *foreign_addr; 1983 char *foreign_addr;
1978 1984
@@ -2012,6 +2018,7 @@ try_handle_plaintext (struct Queue *queue)
2012 break; 2018 break;
2013 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX: 2019 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX:
2014 /* Special case: header size excludes box itself! */ 2020 /* Special case: header size excludes box itself! */
2021 box = (const struct TCPBox *) queue->pread_buf;
2015 if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off) 2022 if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
2016 return 0; 2023 return 0;
2017 calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac); 2024 calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
@@ -2028,6 +2035,7 @@ try_handle_plaintext (struct Queue *queue)
2028 break; 2035 break;
2029 2036
2030 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY: 2037 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY:
2038 rekey = (const struct TCPRekey *) queue->pread_buf;
2031 if (sizeof(*rekey) > queue->pread_off) 2039 if (sizeof(*rekey) > queue->pread_off)
2032 return 0; 2040 return 0;
2033 if (ntohs (hdr->size) != sizeof(*rekey)) 2041 if (ntohs (hdr->size) != sizeof(*rekey))
@@ -2052,6 +2060,7 @@ try_handle_plaintext (struct Queue *queue)
2052 break; 2060 break;
2053 2061
2054 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH: 2062 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH:
2063 fin = (const struct TCPFinish *) queue->pread_buf;
2055 if (sizeof(*fin) > queue->pread_off) 2064 if (sizeof(*fin) > queue->pread_off)
2056 return 0; 2065 return 0;
2057 if (ntohs (hdr->size) != sizeof(*fin)) 2066 if (ntohs (hdr->size) != sizeof(*fin))
@@ -2083,8 +2092,8 @@ try_handle_plaintext (struct Queue *queue)
2083 return 0; 2092 return 0;
2084 } 2093 }
2085 GNUNET_assert (0 != size); 2094 GNUNET_assert (0 != size);
2086 if (-1 != unverified_size) 2095 if (-1 != queue->unverified_size)
2087 unverified_size += size; 2096 queue->unverified_size += size;
2088 return size; 2097 return size;
2089} 2098}
2090 2099