From f7f26f6ca1b76d2734463d4989b9541df48a6773 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Sat, 29 Oct 2016 23:46:44 +0000 Subject: [PATCH] Refactor encrypted traffic handling - eliminate encapsulation for KX/DATA - simplify cases - remove dead code - Organize message types --- src/cadet/cadet_common.c | 15 +- src/cadet/cadet_protocol.h | 224 ++++---- src/cadet/gnunet-service-cadet_connection.c | 16 +- src/cadet/gnunet-service-cadet_connection.h | 2 +- src/cadet/gnunet-service-cadet_peer.c | 86 ++- src/cadet/gnunet-service-cadet_tunnel.c | 554 ++++++++------------ src/cadet/gnunet-service-cadet_tunnel.h | 17 +- src/include/gnunet_constants.h | 2 +- src/include/gnunet_protocols.h | 114 ++-- 9 files changed, 433 insertions(+), 597 deletions(-) diff --git a/src/cadet/cadet_common.c b/src/cadet/cadet_common.c index c24bc5c4b..a9d9a35be 100644 --- a/src/cadet/cadet_common.c +++ b/src/cadet/cadet_common.c @@ -192,17 +192,17 @@ GC_m2s (uint16_t m) break; /** - * Key exchange encapsulation. + * Key exchange message. */ case GNUNET_MESSAGE_TYPE_CADET_KX: s = "KX"; break; /** - * Axolotl key exchange message. + * Encrypted. */ - case GNUNET_MESSAGE_TYPE_CADET_AX_KX: - s = "AX_KX"; + case GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED: + s = "ENCRYPTED"; break; /** @@ -275,13 +275,6 @@ GC_m2s (uint16_t m) s = "CHAN_NACK"; break; - /** - * Axolotl encrypted payload. - */ - case GNUNET_MESSAGE_TYPE_CADET_AX: - s = "AX"; - break; - /** * Local payload traffic */ diff --git a/src/cadet/cadet_protocol.h b/src/cadet/cadet_protocol.h index 2df652e34..d034c63b0 100644 --- a/src/cadet/cadet_protocol.h +++ b/src/cadet/cadet_protocol.h @@ -47,6 +47,12 @@ extern "C" GNUNET_NETWORK_STRUCT_BEGIN + +/******************************************************************************/ +/***************************** CONNECTION **********************************/ +/******************************************************************************/ + + /** * Message for cadet connection creation. */ @@ -102,15 +108,15 @@ struct GNUNET_CADET_ConnectionACK /** - * Message for encapsulation of a Key eXchange message in a connection. + * Message for notifying a disconnection in a path */ -struct GNUNET_CADET_KX +struct GNUNET_CADET_ConnectionBroken { /** - * Type: #GNUNET_MESSAGE_TYPE_CADET_KX. + * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN */ struct GNUNET_MessageHeader header; - + /** * For alignment. */ @@ -121,43 +127,128 @@ struct GNUNET_CADET_KX */ struct GNUNET_CADET_Hash cid; - /* Specific KX message follows. */ + /** + * ID of the endpoint + */ + struct GNUNET_PeerIdentity peer1; + + /** + * ID of the endpoint + */ + struct GNUNET_PeerIdentity peer2; }; /** - * Flags to be used in GNUNET_CADET_AX_KX. + * Message to destroy a connection. */ -enum GNUNET_CADET_AX_KX_Flags { +struct GNUNET_CADET_ConnectionDestroy +{ + /** + * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY + */ + struct GNUNET_MessageHeader header; + + /** + * For alignment. + */ + uint32_t reserved GNUNET_PACKED; + + /** + * ID of the connection. + */ + struct GNUNET_CADET_Hash cid; +}; + + +/** + * Message to acknowledge cadet encrypted traffic. + */ +struct GNUNET_CADET_ACK +{ + /** + * Type: #GNUNET_MESSAGE_TYPE_CADET_ACK + */ + struct GNUNET_MessageHeader header; + + /** + * Maximum packet ID authorized. + */ + uint32_t ack GNUNET_PACKED; + + /** + * ID of the connection. + */ + struct GNUNET_CADET_Hash cid; +}; + + +/** + * Message to query a peer about its Flow Control status regarding a tunnel. + */ +struct GNUNET_CADET_Poll +{ + /** + * Type: #GNUNET_MESSAGE_TYPE_CADET_POLL + */ + struct GNUNET_MessageHeader header; + + /** + * Last packet sent. + */ + uint32_t pid GNUNET_PACKED; + + /** + * ID of the connection. + */ + struct GNUNET_CADET_Hash cid; + +}; + + + +/******************************************************************************/ +/******************************* TUNNEL ***********************************/ +/******************************************************************************/ + +/** + * Flags to be used in GNUNET_CADET_KX. + */ +enum GNUNET_CADET_KX_Flags { /** * Should the peer reply with its KX details? */ - GNUNET_CADET_AX_KX_FLAG_NONE = 0, + GNUNET_CADET_KX_FLAG_NONE = 0, /** * The peer should reply with its KX details? */ - GNUNET_CADET_AX_KX_FLAG_FORCE_REPLY = 1 + GNUNET_CADET_KX_FLAG_FORCE_REPLY = 1 }; /** - * Message for encapsulation of a Key eXchange message in a connection. + * Message for a Key eXchange for a tunnel. */ -struct GNUNET_CADET_AX_KX +struct GNUNET_CADET_KX { /** - * Type: #GNUNET_MESSAGE_TYPE_CADET_AX_KX. + * Type: #GNUNET_MESSAGE_TYPE_CADET_KX. */ struct GNUNET_MessageHeader header; /** * Flags for the key exchange in NBO, based on - * `enum GNUNET_CADET_AX_KX_Flags`. + * `enum GNUNET_CADET_KX_Flags`. */ uint32_t flags GNUNET_PACKED; + /** + * ID of the connection. + */ + struct GNUNET_CADET_Hash cid; + /** * Sender's ephemeral public ECC key encoded in a * format suitable for network transmission, as created @@ -177,10 +268,10 @@ struct GNUNET_CADET_AX_KX /** * Axolotl tunnel message. */ -struct GNUNET_CADET_AX +struct GNUNET_CADET_Encrypted { /** - * Type: #GNUNET_MESSAGE_TYPE_CADET_AXOLOTL_DATA + * Type: #GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED */ struct GNUNET_MessageHeader header; @@ -226,6 +317,11 @@ struct GNUNET_CADET_AX }; + +/******************************************************************************/ +/******************************* CHANNEL ***********************************/ +/******************************************************************************/ + /** * Message to create a Channel. */ @@ -326,104 +422,6 @@ struct GNUNET_CADET_DataACK }; -/** - * Message to acknowledge cadet encrypted traffic. - */ -struct GNUNET_CADET_ACK -{ - /** - * Type: #GNUNET_MESSAGE_TYPE_CADET_ACK - */ - struct GNUNET_MessageHeader header; - - /** - * Maximum packet ID authorized. - */ - uint32_t ack GNUNET_PACKED; - - /** - * ID of the connection. - */ - struct GNUNET_CADET_Hash cid; -}; - - -/** - * Message to query a peer about its Flow Control status regarding a tunnel. - */ -struct GNUNET_CADET_Poll -{ - /** - * Type: #GNUNET_MESSAGE_TYPE_CADET_POLL - */ - struct GNUNET_MessageHeader header; - - /** - * Last packet sent. - */ - uint32_t pid GNUNET_PACKED; - - /** - * ID of the connection. - */ - struct GNUNET_CADET_Hash cid; - -}; - - -/** - * Message for notifying a disconnection in a path - */ -struct GNUNET_CADET_ConnectionBroken -{ - /** - * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN - */ - struct GNUNET_MessageHeader header; - - /** - * For alignment. - */ - uint32_t reserved GNUNET_PACKED; - - /** - * ID of the connection. - */ - struct GNUNET_CADET_Hash cid; - - /** - * ID of the endpoint - */ - struct GNUNET_PeerIdentity peer1; - - /** - * ID of the endpoint - */ - struct GNUNET_PeerIdentity peer2; -}; - - -/** - * Message to destroy a connection. - */ -struct GNUNET_CADET_ConnectionDestroy -{ - /** - * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY - */ - struct GNUNET_MessageHeader header; - - /** - * For alignment. - */ - uint32_t reserved GNUNET_PACKED; - - /** - * ID of the connection. - */ - struct GNUNET_CADET_Hash cid; -}; - GNUNET_NETWORK_STRUCT_END diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index 205f0b3b3..c88df79fd 100644 --- a/src/cadet/gnunet-service-cadet_connection.c +++ b/src/cadet/gnunet-service-cadet_connection.c @@ -736,7 +736,7 @@ conn_message_sent (void *cls, } GNUNET_free (q); } - else if (type == GNUNET_MESSAGE_TYPE_CADET_AX) + else if (type == GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED) { /* SHOULD NO LONGER HAPPEN FIXME: REMOVE CASE */ // If NULL == q and ENCRYPTED == type, message must have been ch_mngmnt @@ -771,7 +771,7 @@ conn_message_sent (void *cls, schedule_next_keepalive (c, fwd); break; - case GNUNET_MESSAGE_TYPE_CADET_AX: + case GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED: if (GNUNET_YES == sent) { GNUNET_assert (NULL != q); @@ -2517,7 +2517,7 @@ check_message (const struct GNUNET_MessageHeader *message, /* Check PID for payload messages */ type = ntohs (message->type); - if (GNUNET_MESSAGE_TYPE_CADET_AX == type) + if (GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED == type) { fc = fwd ? &c->bck_fc : &c->fwd_fc; LOG (GNUNET_ERROR_TYPE_DEBUG, " PID %u (expected %u - %u)\n", @@ -2611,7 +2611,7 @@ GCC_handle_kx (struct CadetPeer *peer, GNUNET_break (0); return; } - GCT_handle_kx (c->t, &msg[1].header); + GCT_handle_kx (c->t, msg); GCC_check_connections (); return; } @@ -2633,7 +2633,7 @@ GCC_handle_kx (struct CadetPeer *peer, */ void GCC_handle_encrypted (struct CadetPeer *peer, - const struct GNUNET_CADET_AX *msg) + const struct GNUNET_CADET_Encrypted *msg) { const struct GNUNET_CADET_Hash* cid; struct CadetConnection *c; @@ -2670,7 +2670,7 @@ GCC_handle_encrypted (struct CadetPeer *peer, GNUNET_break (GNUNET_NO != c->destroy); return; } - GCT_handle_encrypted (c->t, &msg->header); + GCT_handle_encrypted (c->t, msg); GCC_send_ack (c, fwd, GNUNET_NO); GCC_check_connections (); return; @@ -3275,7 +3275,7 @@ GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, GC_f2s(fwd), size); switch (type) { - case GNUNET_MESSAGE_TYPE_CADET_AX: + case GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED: LOG (GNUNET_ERROR_TYPE_DEBUG, " Q_N+ %p %u\n", fc, fc->queue_n); LOG (GNUNET_ERROR_TYPE_DEBUG, "last pid sent %u\n", fc->last_pid_sent); LOG (GNUNET_ERROR_TYPE_DEBUG, " ack recv %u\n", fc->last_ack_recv); @@ -3312,7 +3312,7 @@ GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, GNUNET_break (0); LOG (GNUNET_ERROR_TYPE_DEBUG, "queue full: %u/%u\n", fc->queue_n, fc->queue_max); - if (GNUNET_MESSAGE_TYPE_CADET_AX == type) + if (GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED == type) { fc->queue_n--; } diff --git a/src/cadet/gnunet-service-cadet_connection.h b/src/cadet/gnunet-service-cadet_connection.h index 4e994f2be..27f105f81 100644 --- a/src/cadet/gnunet-service-cadet_connection.h +++ b/src/cadet/gnunet-service-cadet_connection.h @@ -197,7 +197,7 @@ GCC_handle_kx (struct CadetPeer *peer, */ void GCC_handle_encrypted (struct CadetPeer *peer, - const struct GNUNET_CADET_AX *msg); + const struct GNUNET_CADET_Encrypted *msg); /** * Core handler for axolotl key exchange traffic. diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c index da9b1bbe1..c312d56bf 100644 --- a/src/cadet/gnunet-service-cadet_peer.c +++ b/src/cadet/gnunet-service-cadet_peer.c @@ -547,32 +547,6 @@ handle_poll (void *cls, const struct GNUNET_CADET_Poll *msg) } -/** - * Check if the Key eXchange message has the appropriate size. - * - * @param cls Closure (unused). - * @param msg Message to check. - * - * @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise. - */ -static int -check_kx (void *cls, const struct GNUNET_CADET_KX *msg) -{ - uint16_t size; - uint16_t expected_size; - - size = ntohs (msg->header.size); - expected_size = sizeof (struct GNUNET_CADET_KX) - + sizeof (struct GNUNET_MessageHeader); - - if (size < expected_size) - { - GNUNET_break_op (0); - return GNUNET_NO; - } - return GNUNET_YES; -} - /** * Handle for #GNUNET_MESSAGE_TYPE_CADET_KX * @@ -596,13 +570,13 @@ handle_kx (void *cls, const struct GNUNET_CADET_KX *msg) * @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise. */ static int -check_encrypted (void *cls, const struct GNUNET_CADET_AX *msg) +check_encrypted (void *cls, const struct GNUNET_CADET_Encrypted *msg) { uint16_t size; uint16_t minimum_size; size = ntohs (msg->header.size); - minimum_size = sizeof (struct GNUNET_CADET_AX) + minimum_size = sizeof (struct GNUNET_CADET_Encrypted) + sizeof (struct GNUNET_MessageHeader); if (size < minimum_size) @@ -614,13 +588,13 @@ check_encrypted (void *cls, const struct GNUNET_CADET_AX *msg) } /** - * Handle for #GNUNET_MESSAGE_TYPE_CADET_AX (AXolotl encrypted traffic). + * Handle for #GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED. * * @param cls Closure (CadetPeer for neighbor that sent the message). * @param msg Message itself. */ static void -handle_encrypted (void *cls, const struct GNUNET_CADET_AX *msg) +handle_encrypted (void *cls, const struct GNUNET_CADET_Encrypted *msg) { struct CadetPeer *peer = cls; GCC_handle_encrypted (peer, msg); @@ -643,37 +617,37 @@ connect_to_core (const struct GNUNET_CONFIGURATION_Handle *c) { struct GNUNET_MQ_MessageHandler core_handlers[] = { GNUNET_MQ_hd_var_size (create, - GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, - struct GNUNET_CADET_ConnectionCreate, - NULL), + GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, + struct GNUNET_CADET_ConnectionCreate, + NULL), GNUNET_MQ_hd_fixed_size (confirm, - GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK, - struct GNUNET_CADET_ConnectionACK, - NULL), + GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK, + struct GNUNET_CADET_ConnectionACK, + NULL), GNUNET_MQ_hd_fixed_size (broken, - GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN, - struct GNUNET_CADET_ConnectionBroken, - NULL), + GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN, + struct GNUNET_CADET_ConnectionBroken, + NULL), GNUNET_MQ_hd_fixed_size (destroy, - GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY, - struct GNUNET_CADET_ConnectionDestroy, - NULL), + GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY, + struct GNUNET_CADET_ConnectionDestroy, + NULL), GNUNET_MQ_hd_fixed_size (ack, - GNUNET_MESSAGE_TYPE_CADET_ACK, - struct GNUNET_CADET_ACK, - NULL), + GNUNET_MESSAGE_TYPE_CADET_ACK, + struct GNUNET_CADET_ACK, + NULL), GNUNET_MQ_hd_fixed_size (poll, - GNUNET_MESSAGE_TYPE_CADET_POLL, - struct GNUNET_CADET_Poll, - NULL), - GNUNET_MQ_hd_var_size (kx, - GNUNET_MESSAGE_TYPE_CADET_KX, - struct GNUNET_CADET_KX, - NULL), + GNUNET_MESSAGE_TYPE_CADET_POLL, + struct GNUNET_CADET_Poll, + NULL), + GNUNET_MQ_hd_fixed_size (kx, + GNUNET_MESSAGE_TYPE_CADET_KX, + struct GNUNET_CADET_KX, + NULL), GNUNET_MQ_hd_var_size (encrypted, - GNUNET_MESSAGE_TYPE_CADET_AX, - struct GNUNET_CADET_AX, - NULL), + GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED, + struct GNUNET_CADET_Encrypted, + NULL), GNUNET_MQ_handler_end () }; core_handle = GNUNET_CORE_connecT (c, NULL, @@ -755,7 +729,7 @@ get_priority (struct CadetPeerQueue *q) } /* Bulky payload has lower priority, control traffic has higher. */ - if (GNUNET_MESSAGE_TYPE_CADET_AX == q->type) + if (GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED == q->type) return low; return high; } diff --git a/src/cadet/gnunet-service-cadet_tunnel.c b/src/cadet/gnunet-service-cadet_tunnel.c index 26c1ea3d4..249974d81 100644 --- a/src/cadet/gnunet-service-cadet_tunnel.c +++ b/src/cadet/gnunet-service-cadet_tunnel.c @@ -95,18 +95,6 @@ struct CadetTConnection }; -/** - * Encryption systems possible. - */ -enum CadetTunnelEncryption -{ - /** - * Default Axolotl system. - */ - CADET_Axolotl - -}; - /** * Struct to old keys for skipped messages while advancing the Axolotl ratchet. */ @@ -266,11 +254,6 @@ struct CadetTunnel */ struct CadetPeer *peer; - /** - * Type of encryption used in the tunnel. - */ - enum CadetTunnelEncryption enc_type; - /** * Axolotl info. */ @@ -550,8 +533,7 @@ is_ready (struct CadetTunnel *t) conn_ok = CADET_TUNNEL_READY == t->cstate; enc_ok = CADET_TUNNEL_KEY_OK == t->estate || CADET_TUNNEL_KEY_REKEY == t->estate - || (CADET_TUNNEL_KEY_PING == t->estate - && CADET_Axolotl == t->enc_type); + || CADET_TUNNEL_KEY_PING == t->estate; ready = conn_ok && enc_ok; ready = ready || GCT_is_loopback (t); return ready; @@ -869,7 +851,7 @@ t_ax_decrypt (struct CadetTunnel *t, void *dst, const void *src, size_t size) * @param msg Message whose header to encrypt. */ static void -t_h_encrypt (struct CadetTunnel *t, struct GNUNET_CADET_AX *msg) +t_h_encrypt (struct CadetTunnel *t, struct GNUNET_CADET_Encrypted *msg) { struct GNUNET_CRYPTO_SymmetricInitializationVector iv; struct CadetTunnelAxolotl *ax; @@ -902,8 +884,8 @@ t_h_encrypt (struct CadetTunnel *t, struct GNUNET_CADET_AX *msg) * @param dst Where to decrypt header to. */ static void -t_h_decrypt (struct CadetTunnel *t, const struct GNUNET_CADET_AX *src, - struct GNUNET_CADET_AX *dst) +t_h_decrypt (struct CadetTunnel *t, const struct GNUNET_CADET_Encrypted *src, + struct GNUNET_CADET_Encrypted *dst) { struct GNUNET_CRYPTO_SymmetricInitializationVector iv; struct CadetTunnelAxolotl *ax; @@ -941,12 +923,12 @@ t_h_decrypt (struct CadetTunnel *t, const struct GNUNET_CADET_AX *src, */ static int try_old_ax_keys (struct CadetTunnel *t, void *dst, - const struct GNUNET_CADET_AX *src, size_t size) + const struct GNUNET_CADET_Encrypted *src, size_t size) { struct CadetTunnelSkippedKey *key; struct GNUNET_CADET_Hash *hmac; struct GNUNET_CRYPTO_SymmetricInitializationVector iv; - struct GNUNET_CADET_AX plaintext_header; + struct GNUNET_CADET_Encrypted plaintext_header; struct GNUNET_CRYPTO_SymmetricSessionKey *valid_HK; size_t esize; size_t res; @@ -955,7 +937,7 @@ try_old_ax_keys (struct CadetTunnel *t, void *dst, LOG (GNUNET_ERROR_TYPE_DEBUG, "Trying old keys\n"); hmac = &plaintext_header.hmac; - esize = size - sizeof (struct GNUNET_CADET_AX); + esize = size - sizeof (struct GNUNET_CADET_Encrypted); /* Find a correct Header Key */ for (key = t->ax->skipped_head; NULL != key; key = key->next) @@ -976,8 +958,8 @@ try_old_ax_keys (struct CadetTunnel *t, void *dst, return -1; /* Should've been checked in -cadet_connection.c handle_cadet_encrypted. */ - GNUNET_assert (size > sizeof (struct GNUNET_CADET_AX)); - len = size - sizeof (struct GNUNET_CADET_AX); + GNUNET_assert (size > sizeof (struct GNUNET_CADET_Encrypted)); + len = size - sizeof (struct GNUNET_CADET_Encrypted); GNUNET_assert (len >= sizeof (struct GNUNET_MessageHeader)); /* Decrypt header */ @@ -1120,20 +1102,20 @@ store_ax_keys (struct CadetTunnel *t, */ static int t_ax_decrypt_and_validate (struct CadetTunnel *t, void *dst, - const struct GNUNET_CADET_AX *src, size_t size) + const struct GNUNET_CADET_Encrypted *src, + size_t size) { struct CadetTunnelAxolotl *ax; struct GNUNET_CADET_Hash msg_hmac; struct GNUNET_HashCode hmac; - struct GNUNET_CADET_AX plaintext_header; + struct GNUNET_CADET_Encrypted plaintext_header; uint32_t Np; uint32_t PNp; - size_t esize; - size_t osize; + size_t esize; /* Size of encryped payload */ + size_t osize; /* Size of output (decrypted payload) */ + esize = size - sizeof (struct GNUNET_CADET_Encrypted); ax = t->ax; - esize = size - sizeof (struct GNUNET_CADET_AX); - if (NULL == ax) return -1; @@ -1350,10 +1332,10 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message, struct CadetTunnelQueue *existing_q) { struct GNUNET_MessageHeader *msg; - struct GNUNET_CADET_AX *ax_msg; + struct GNUNET_CADET_Encrypted *ax_msg; struct CadetTunnelQueue *tq; size_t size = ntohs (message->size); - char cbuf[sizeof (struct GNUNET_CADET_AX) + size] GNUNET_ALIGN; + char cbuf[sizeof (struct GNUNET_CADET_Encrypted) + size] GNUNET_ALIGN; size_t esize; uint32_t mid; uint16_t type; @@ -1381,11 +1363,10 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message, GNUNET_assert (GNUNET_NO == GCT_is_loopback (t)); - GNUNET_assert (CADET_Axolotl == t->enc_type); - ax_msg = (struct GNUNET_CADET_AX *) cbuf; + ax_msg = (struct GNUNET_CADET_Encrypted *) cbuf; msg = &ax_msg->header; - msg->size = htons (sizeof (struct GNUNET_CADET_AX) + size); - msg->type = htons (GNUNET_MESSAGE_TYPE_CADET_AX); + msg->size = htons (sizeof (struct GNUNET_CADET_Encrypted) + size); + msg->type = htons (GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED); esize = t_ax_encrypt (t, &ax_msg[1], message, size); ax_msg->Ns = htonl (t->ax->Ns++); ax_msg->PNs = htonl (t->ax->PNs); @@ -1505,12 +1486,12 @@ send_queued_data (struct CadetTunnel *t) /** - * @brief Resend the AX KX until we complete the handshake. + * @brief Resend the KX until we complete the handshake. * * @param cls Closure (tunnel). */ static void -ax_kx_resend (void *cls) +kx_resend (void *cls) { struct CadetTunnel *t = cls; @@ -1522,7 +1503,7 @@ ax_kx_resend (void *cls) return; } - GCT_send_ax_kx (t, CADET_TUNNEL_KEY_SENT >= t->estate); + GCT_send_kx (t, CADET_TUNNEL_KEY_SENT >= t->estate); } @@ -1549,98 +1530,15 @@ ephm_sent (void *cls, if (CADET_TUNNEL_KEY_OK == t->estate) return; - if (CADET_Axolotl == t->enc_type) - { - if (NULL != t->rekey_task) - { - GNUNET_break (0); - GCT_debug (t, GNUNET_ERROR_TYPE_WARNING); - GNUNET_SCHEDULER_cancel (t->rekey_task); - } - t->rekey_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &ax_kx_resend, t); - } -} - - -/** - * Sends key exchange message on a tunnel, choosing the best connection. - * Should not be called on loopback tunnels. - * - * @param t Tunnel on which this message is transmitted. - * @param message Message to send. Function modifies it. - * - * @return Handle to the message in the connection queue. - */ -static struct CadetConnectionQueue * -send_kx (struct CadetTunnel *t, - const struct GNUNET_MessageHeader *message) -{ - struct CadetConnection *c; - struct GNUNET_CADET_KX *msg; - size_t size = ntohs (message->size); - char cbuf[sizeof (struct GNUNET_CADET_KX) + size]; - uint16_t type; - int fwd; - - LOG (GNUNET_ERROR_TYPE_DEBUG, "GMT KX on Tunnel %s\n", GCT_2s (t)); - - /* Avoid loopback. */ - if (GCT_is_loopback (t)) + if (NULL != t->rekey_task) { GNUNET_break (0); - return NULL; - } - type = ntohs (message->type); - - /* Even if tunnel is "being destroyed", send anyway. - * Could be a response to a rekey initiated by remote peer, - * who is trying to create a new channel! - */ - - /* Must have a connection, or be looking for one. */ - if (NULL == t->connection_head) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, "%s with no connection\n", GC_m2s (type)); - if (CADET_TUNNEL_SEARCHING != t->cstate) - { - GNUNET_break (0); - GCT_debug (t, GNUNET_ERROR_TYPE_ERROR); - } - return NULL; - } - - msg = (struct GNUNET_CADET_KX *) cbuf; - msg->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_KX); - msg->header.size = htons (sizeof (struct GNUNET_CADET_KX) + size); - msg->reserved = htonl (0); - c = tunnel_get_connection (t); - if (NULL == c) - { - if (NULL == t->destroy_task && CADET_TUNNEL_READY == t->cstate) - { - GNUNET_break (0); - GCT_debug (t, GNUNET_ERROR_TYPE_ERROR); - } - return NULL; - } - msg->cid = *GCC_get_id (c); - switch (type) - { - case GNUNET_MESSAGE_TYPE_CADET_AX_KX: - GNUNET_assert (NULL == t->ephm_h); - break; - default: - LOG (GNUNET_ERROR_TYPE_DEBUG, "unkown type %s\n", GC_m2s (type)); - GNUNET_assert (0); + GCT_debug (t, GNUNET_ERROR_TYPE_WARNING); + GNUNET_SCHEDULER_cancel (t->rekey_task); } - GNUNET_memcpy (&msg[1], message, size); - - fwd = GCC_is_origin (c, GNUNET_YES); + t->rekey_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &kx_resend, t); - return GCC_send_prebuilt_message (&msg->header, type, 0, c, - fwd, GNUNET_YES, - &ephm_sent, t); } @@ -1964,148 +1862,6 @@ destroy_ax (struct CadetTunnel *t) } -/** - * Handle Axolotl handshake. - * - * @param t Tunnel this message came on. - * @param msg Key eXchange Pong message. - */ -static void -handle_kx_ax (struct CadetTunnel *t, const struct GNUNET_CADET_AX_KX *msg) -{ - struct CadetTunnelAxolotl *ax; - struct GNUNET_HashCode key_material[3]; - struct GNUNET_CRYPTO_SymmetricSessionKey keys[5]; - const char salt[] = "CADET Axolotl salt"; - const struct GNUNET_PeerIdentity *pid; - int am_I_alice; - - LOG (GNUNET_ERROR_TYPE_INFO, "<== { AX_KX} on %s\n", GCT_2s (t)); - - if (NULL == t->ax) - { - /* Something is wrong if ax is NULL. Whose fault it is? */ - GNUNET_break (CADET_Axolotl == t->enc_type); - return; - } - ax = t->ax; - - pid = GCT_get_destination (t); - if (0 > GNUNET_CRYPTO_cmp_peer_identity (&my_full_id, pid)) - am_I_alice = GNUNET_YES; - else if (0 < GNUNET_CRYPTO_cmp_peer_identity (&my_full_id, pid)) - am_I_alice = GNUNET_NO; - else - { - GNUNET_break_op (0); - return; - } - - if (0 != (GNUNET_CADET_AX_KX_FLAG_FORCE_REPLY & ntohl (msg->flags))) - { - if (NULL != t->rekey_task) - { - GNUNET_SCHEDULER_cancel (t->rekey_task); - t->rekey_task = NULL; - } - GCT_send_ax_kx (t, GNUNET_NO); - } - - if (0 == memcmp (&ax->DHRr, &msg->ratchet_key, sizeof(msg->ratchet_key))) - { - LOG (GNUNET_ERROR_TYPE_INFO, " known ratchet key, exit\n"); - return; - } - - LOG (GNUNET_ERROR_TYPE_INFO, " is Alice? %s\n", am_I_alice ? "YES" : "NO"); - - ax->DHRr = msg->ratchet_key; - - /* ECDH A B0 */ - if (GNUNET_YES == am_I_alice) - { - GNUNET_CRYPTO_eddsa_ecdh (id_key, /* A */ - &msg->ephemeral_key, /* B0 */ - &key_material[0]); - } - else - { - GNUNET_CRYPTO_ecdh_eddsa (ax->kx_0, /* B0 */ - &pid->public_key, /* A */ - &key_material[0]); - } - - /* ECDH A0 B */ - if (GNUNET_YES == am_I_alice) - { - GNUNET_CRYPTO_ecdh_eddsa (ax->kx_0, /* A0 */ - &pid->public_key, /* B */ - &key_material[1]); - } - else - { - GNUNET_CRYPTO_eddsa_ecdh (id_key, /* A */ - &msg->ephemeral_key, /* B0 */ - &key_material[1]); - - - } - - /* ECDH A0 B0 */ - /* (This is the triple-DH, we could probably safely skip this, - as A0/B0 are already in the key material.) */ - GNUNET_CRYPTO_ecc_ecdh (ax->kx_0, /* A0 or B0 */ - &msg->ephemeral_key, /* B0 or A0 */ - &key_material[2]); - - #if DUMP_KEYS_TO_STDERR - { - unsigned int i; - for (i = 0; i < 3; i++) - LOG (GNUNET_ERROR_TYPE_INFO, "km[%u]: %s\n", - i, GNUNET_h2s (&key_material[i])); - } - #endif - - /* KDF */ - GNUNET_CRYPTO_kdf (keys, sizeof (keys), - salt, sizeof (salt), - &key_material, sizeof (key_material), NULL); - - if (0 == memcmp (&ax->RK, &keys[0], sizeof(ax->RK))) - { - LOG (GNUNET_ERROR_TYPE_INFO, " known handshake key, exit\n"); - return; - } - ax->RK = keys[0]; - if (GNUNET_YES == am_I_alice) - { - ax->HKr = keys[1]; - ax->NHKs = keys[2]; - ax->NHKr = keys[3]; - ax->CKr = keys[4]; - ax->ratchet_flag = GNUNET_YES; - } - else - { - ax->HKs = keys[1]; - ax->NHKr = keys[2]; - ax->NHKs = keys[3]; - ax->CKs = keys[4]; - ax->ratchet_flag = GNUNET_NO; - ax->ratchet_allowed = GNUNET_NO; - ax->ratchet_counter = 0; - ax->ratchet_expiration = - GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), ratchet_time); - } - ax->PNs = 0; - ax->Nr = 0; - ax->Ns = 0; - GCT_change_estate (t, CADET_TUNNEL_KEY_PING); - send_queued_data (t); -} - - /** * Demultiplex by message type and call appropriate handler for a message * towards a channel of a local tunnel. @@ -2175,40 +1931,28 @@ handle_decrypted (struct CadetTunnel *t, /******************************************************************************/ /******************************** API ***********************************/ /******************************************************************************/ + /** - * Decrypt old format and demultiplex by message type. Call appropriate handler - * for a message towards a channel of a local tunnel. + * Decrypt and process an encrypted message. + * + * Calls the appropriate handler for a message in a channel of a local tunnel. * * @param t Tunnel this message came on. * @param msg Message header. */ void GCT_handle_encrypted (struct CadetTunnel *t, - const struct GNUNET_MessageHeader *msg) + const struct GNUNET_CADET_Encrypted *msg) { - uint16_t size = ntohs (msg->size); + uint16_t size = ntohs (msg->header.size); char cbuf [size]; int decrypted_size; - uint16_t type; const struct GNUNET_MessageHeader *msgh; unsigned int off; - type = ntohs (msg->type); - switch (type) - { - case GNUNET_MESSAGE_TYPE_CADET_AX: - { - const struct GNUNET_CADET_AX *emsg; + GNUNET_STATISTICS_update (stats, "# received encrypted", 1, GNUNET_NO); - GNUNET_STATISTICS_update (stats, "# received Axolotl", 1, GNUNET_NO); - emsg = (const struct GNUNET_CADET_AX *) msg; - decrypted_size = t_ax_decrypt_and_validate (t, cbuf, emsg, size); - } - break; - default: - GNUNET_break_op (0); - return; - } + decrypted_size = t_ax_decrypt_and_validate (t, cbuf, msg, size); if (-1 == decrypted_size) { @@ -2250,35 +1994,144 @@ GCT_handle_encrypted (struct CadetTunnel *t, /** - * Demultiplex an encapsulated KX message by message type. + * Handle a Key eXchange message. * * @param t Tunnel on which the message came. - * @param message Payload of KX message. - * - * FIXME: not needed anymore - * - substitute with call to kx_ax - * - eliminate encapsulation + * @param msg KX message itself. */ void GCT_handle_kx (struct CadetTunnel *t, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_CADET_KX *msg) { - uint16_t type; - char buf[256]; + struct CadetTunnelAxolotl *ax; + struct GNUNET_HashCode key_material[3]; + struct GNUNET_CRYPTO_SymmetricSessionKey keys[5]; + const char salt[] = "CADET Axolotl salt"; + const struct GNUNET_PeerIdentity *pid; + int am_I_alice; - type = ntohs (message->type); - LOG (GNUNET_ERROR_TYPE_DEBUG, "kx message received: %s\n", GC_m2s (type)); - sprintf (buf, "# received KX of type %hu (%s)", type, GC_m2s (type)); - GNUNET_STATISTICS_update (stats, buf, 1, GNUNET_NO); - switch (type) + LOG (GNUNET_ERROR_TYPE_INFO, "<== { KX} on %s\n", GCT_2s (t)); + + if (NULL == t->ax) { - case GNUNET_MESSAGE_TYPE_CADET_AX_KX: - handle_kx_ax (t, (const struct GNUNET_CADET_AX_KX *) message); - break; - default: - GNUNET_break_op (0); - LOG (GNUNET_ERROR_TYPE_WARNING, "kx message %s unknown\n", GC_m2s (type)); + /* Something is wrong if ax is NULL. Whose fault it is? */ + return; + } + ax = t->ax; + + pid = GCT_get_destination (t); + if (0 > GNUNET_CRYPTO_cmp_peer_identity (&my_full_id, pid)) + am_I_alice = GNUNET_YES; + else if (0 < GNUNET_CRYPTO_cmp_peer_identity (&my_full_id, pid)) + am_I_alice = GNUNET_NO; + else + { + GNUNET_break_op (0); + return; + } + + if (0 != (GNUNET_CADET_KX_FLAG_FORCE_REPLY & ntohl (msg->flags))) + { + if (NULL != t->rekey_task) + { + GNUNET_SCHEDULER_cancel (t->rekey_task); + t->rekey_task = NULL; + } + GCT_send_kx (t, GNUNET_NO); + } + + if (0 == memcmp (&ax->DHRr, &msg->ratchet_key, sizeof(msg->ratchet_key))) + { + LOG (GNUNET_ERROR_TYPE_INFO, " known ratchet key, exit\n"); + return; + } + + LOG (GNUNET_ERROR_TYPE_INFO, " is Alice? %s\n", am_I_alice ? "YES" : "NO"); + + ax->DHRr = msg->ratchet_key; + + /* ECDH A B0 */ + if (GNUNET_YES == am_I_alice) + { + GNUNET_CRYPTO_eddsa_ecdh (id_key, /* A */ + &msg->ephemeral_key, /* B0 */ + &key_material[0]); + } + else + { + GNUNET_CRYPTO_ecdh_eddsa (ax->kx_0, /* B0 */ + &pid->public_key, /* A */ + &key_material[0]); + } + + /* ECDH A0 B */ + if (GNUNET_YES == am_I_alice) + { + GNUNET_CRYPTO_ecdh_eddsa (ax->kx_0, /* A0 */ + &pid->public_key, /* B */ + &key_material[1]); + } + else + { + GNUNET_CRYPTO_eddsa_ecdh (id_key, /* A */ + &msg->ephemeral_key, /* B0 */ + &key_material[1]); + + + } + + /* ECDH A0 B0 */ + /* (This is the triple-DH, we could probably safely skip this, + as A0/B0 are already in the key material.) */ + GNUNET_CRYPTO_ecc_ecdh (ax->kx_0, /* A0 or B0 */ + &msg->ephemeral_key, /* B0 or A0 */ + &key_material[2]); + + #if DUMP_KEYS_TO_STDERR + { + unsigned int i; + for (i = 0; i < 3; i++) + LOG (GNUNET_ERROR_TYPE_INFO, "km[%u]: %s\n", + i, GNUNET_h2s (&key_material[i])); + } + #endif + + /* KDF */ + GNUNET_CRYPTO_kdf (keys, sizeof (keys), + salt, sizeof (salt), + &key_material, sizeof (key_material), NULL); + + if (0 == memcmp (&ax->RK, &keys[0], sizeof(ax->RK))) + { + LOG (GNUNET_ERROR_TYPE_INFO, " known handshake key, exit\n"); + return; + } + ax->RK = keys[0]; + if (GNUNET_YES == am_I_alice) + { + ax->HKr = keys[1]; + ax->NHKs = keys[2]; + ax->NHKr = keys[3]; + ax->CKr = keys[4]; + ax->ratchet_flag = GNUNET_YES; + } + else + { + ax->HKs = keys[1]; + ax->NHKr = keys[2]; + ax->NHKs = keys[3]; + ax->CKs = keys[4]; + ax->ratchet_flag = GNUNET_NO; + ax->ratchet_allowed = GNUNET_NO; + ax->ratchet_counter = 0; + ax->ratchet_expiration = + GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), ratchet_time); } + ax->PNs = 0; + ax->Nr = 0; + ax->Ns = 0; + GCT_change_estate (t, CADET_TUNNEL_KEY_PING); + send_queued_data (t); } /** @@ -2296,7 +2149,7 @@ GCT_init (const struct GNUNET_CONFIGURATION_Handle *c, LOG (GNUNET_ERROR_TYPE_DEBUG, "init\n"); expected_overhead = 0; - expected_overhead += sizeof (struct GNUNET_CADET_AX); + expected_overhead += sizeof (struct GNUNET_CADET_Encrypted); expected_overhead += sizeof (struct GNUNET_CADET_Data); expected_overhead += sizeof (struct GNUNET_CADET_ACK); GNUNET_assert (GNUNET_CONSTANTS_CADET_P2P_OVERHEAD == expected_overhead); @@ -2396,8 +2249,8 @@ GCT_change_cstate (struct CadetTunnel* t, enum CadetTunnelCState cstate) } else if (CADET_TUNNEL_KEY_UNINITIALIZED == t->estate) { - LOG (GNUNET_ERROR_TYPE_DEBUG, " cstate triggered kx\n"); - GCT_send_ax_kx (t, GNUNET_NO); + LOG (GNUNET_ERROR_TYPE_DEBUG, " cstate triggered KX\n"); + GCT_send_kx (t, GNUNET_NO); } else { @@ -3346,34 +3199,55 @@ GCT_send_prebuilt_message (const struct GNUNET_MessageHeader *message, /** - * Send an Axolotl KX message. + * Send a KX message. * * @param t Tunnel on which to send it. * @param force_reply Force the other peer to reply with a KX message. */ void -GCT_send_ax_kx (struct CadetTunnel *t, int force_reply) +GCT_send_kx (struct CadetTunnel *t, int force_reply) { - struct GNUNET_CADET_AX_KX msg; - enum GNUNET_CADET_AX_KX_Flags flags; + struct CadetConnection *c; + struct GNUNET_CADET_KX msg; + enum GNUNET_CADET_KX_Flags flags; - LOG (GNUNET_ERROR_TYPE_INFO, "==> { AX_KX} on %s\n", GCT_2s (t)); + LOG (GNUNET_ERROR_TYPE_INFO, "==> { KX} on %s\n", GCT_2s (t)); if (NULL != t->ephm_h) { - LOG (GNUNET_ERROR_TYPE_INFO, " already queued\n"); + LOG (GNUNET_ERROR_TYPE_INFO, " already queued, nop\n"); + return; + } + + /* Avoid loopback. */ + if (GCT_is_loopback (t)) + { + GNUNET_break (0); + return; + } + c = tunnel_get_connection (t); + if (NULL == c) + { + if (NULL == t->destroy_task && CADET_TUNNEL_READY == t->cstate) + { + GNUNET_break (0); + GCT_debug (t, GNUNET_ERROR_TYPE_ERROR); + } return; } msg.header.size = htons (sizeof (msg)); - msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_AX_KX); - flags = GNUNET_CADET_AX_KX_FLAG_NONE; - if (force_reply) - flags |= GNUNET_CADET_AX_KX_FLAG_FORCE_REPLY; + msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_KX); + flags = GNUNET_CADET_KX_FLAG_NONE; + if (GNUNET_YES == force_reply) + flags |= GNUNET_CADET_KX_FLAG_FORCE_REPLY; msg.flags = htonl (flags); + msg.cid = *GCC_get_id (c); GNUNET_CRYPTO_ecdhe_key_get_public (t->ax->kx_0, &msg.ephemeral_key); GNUNET_CRYPTO_ecdhe_key_get_public (t->ax->DHRs, &msg.ratchet_key); - t->ephm_h = send_kx (t, &msg.header); + t->ephm_h = GCC_send_prebuilt_message (&msg.header, 0, 0, + c, GCC_is_origin (c, GNUNET_YES), + GNUNET_YES, &ephm_sent, t); if (CADET_TUNNEL_KEY_UNINITIALIZED == t->estate) GCT_change_estate (t, CADET_TUNNEL_KEY_SENT); } @@ -3532,8 +3406,8 @@ ax_debug (const struct CadetTunnelAxolotl *ax, enum GNUNET_ErrorType level) void GCT_debug (const struct CadetTunnel *t, enum GNUNET_ErrorType level) { - struct CadetTChannel *iterch; - struct CadetTConnection *iterc; + struct CadetTChannel *iter_ch; + struct CadetTConnection *iter_c; int do_log; do_log = GNUNET_get_log_call_status (level & (~GNUNET_ERROR_TYPE_BULK), @@ -3546,33 +3420,20 @@ GCT_debug (const struct CadetTunnel *t, enum GNUNET_ErrorType level) LOG2 (level, "TTT cstate %s, estate %s\n", cstate2s (t->cstate), estate2s (t->estate)); #if DUMP_KEYS_TO_STDERR - if (CADET_Axolotl == t->enc_type) - { - ax_debug (t->ax, level); - } - else - { - LOG2 (level, "TTT peers EPHM:\t %s\n", - GNUNET_i2s ((struct GNUNET_PeerIdentity *) &t->peers_ephemeral_key)); - LOG2 (level, "TTT ENC key:\t %s\n", - GNUNET_i2s ((struct GNUNET_PeerIdentity *) &t->e_key)); - LOG2 (level, "TTT DEC key:\t %s\n", - GNUNET_i2s ((struct GNUNET_PeerIdentity *) &t->d_key)); - } + ax_debug (t->ax, level); #endif LOG2 (level, "TTT tq_head %p, tq_tail %p\n", t->tq_head, t->tq_tail); LOG2 (level, "TTT destroy %p\n", t->destroy_task); - LOG2 (level, "TTT channels:\n"); - for (iterch = t->channel_head; NULL != iterch; iterch = iterch->next) + for (iter_ch = t->channel_head; NULL != iter_ch; iter_ch = iter_ch->next) { - GCCH_debug (iterch->ch, level); + GCCH_debug (iter_ch->ch, level); } LOG2 (level, "TTT connections:\n"); - for (iterc = t->connection_head; NULL != iterc; iterc = iterc->next) + for (iter_c = t->connection_head; NULL != iter_c; iter_c = iter_c->next) { - GCC_debug (iterc->c, level); + GCC_debug (iter_c->c, level); } LOG2 (level, "TTT DEBUG TUNNEL END\n"); @@ -3636,3 +3497,4 @@ GCT_iterate_channels (struct CadetTunnel *t, GCT_chan_iter iter, void *cls) for (cht = t->channel_head; NULL != cht; cht = cht->next) iter (cls, cht->ch); } + diff --git a/src/cadet/gnunet-service-cadet_tunnel.h b/src/cadet/gnunet-service-cadet_tunnel.h index 8d65cbebd..e3ca57e9c 100644 --- a/src/cadet/gnunet-service-cadet_tunnel.h +++ b/src/cadet/gnunet-service-cadet_tunnel.h @@ -295,26 +295,27 @@ GCT_get_channel (struct CadetTunnel *t, CADET_ChannelNumber chid); /** - * Decrypt and demultiplex by message type. Call appropriate handler - * for a message towards a channel of a local tunnel. + * Decrypt and process an encrypted message. + * + * Calls the appropriate handler for a message in a channel of a local tunnel. * * @param t Tunnel this message came on. * @param msg Message header. */ void GCT_handle_encrypted (struct CadetTunnel *t, - const struct GNUNET_MessageHeader *msg); + const struct GNUNET_CADET_Encrypted *msg); /** - * Demultiplex an encapsulated KX message by message type. + * Handle a Key eXchange message. * * @param t Tunnel on which the message came. - * @param message KX message itself. + * @param msg KX message itself. */ void GCT_handle_kx (struct CadetTunnel *t, - const struct GNUNET_MessageHeader *message); + const struct GNUNET_CADET_KX *msg); /** @@ -494,13 +495,13 @@ GCT_send_prebuilt_message (const struct GNUNET_MessageHeader *message, /** - * Send an Axolotl KX message. + * Send a KX message. * * @param t Tunnel on which to send it. * @param force_reply Force the other peer to reply with a KX message. */ void -GCT_send_ax_kx (struct CadetTunnel *t, int force_reply); +GCT_send_kx (struct CadetTunnel *t, int force_reply); /** diff --git a/src/include/gnunet_constants.h b/src/include/gnunet_constants.h index a40354fb5..ef9b27318 100644 --- a/src/include/gnunet_constants.h +++ b/src/include/gnunet_constants.h @@ -127,7 +127,7 @@ extern "C" /** * Size of the CADET message overhead: - * + sizeof (struct GNUNET_CADET_AX) + * = sizeof (struct GNUNET_CADET_Encrypted) * + sizeof (struct GNUNET_CADET_Data) * + sizeof (struct GNUNET_CADET_ACK)) * diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index ea94645c5..9cb553282 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -2610,77 +2610,82 @@ extern "C" /*******************************************************************************/ -/******************************************************************************* - * CADET message types - ******************************************************************************/ - -/** - * Type of message used to transport messages throug a CADET-tunnel (LEGACY) +/******************************************************************************/ +/*********************************** CADET **********************************/ +/******************************************************************************/ +/* CADET: message types 1000-1059 + * 1000-1009 Connection-level Messages + * 1010-1019 Channel-level Messages + * 1020-1029 Local Client-Service + * 1030-1039 Local Service Monitoring + * 1040-1049 Application Data + * 1050-1059 Reserved */ -#define GNUNET_MESSAGE_TYPE_CADET 1000 -/** - * Type of message used to send another peer which messages we want to receive - * through a cadet-tunnel (LEGACY) - */ -#define GNUNET_MESSAGE_TYPE_CADET_HELLO 1001 +/******************************** Connection ********************************/ /** * Request the creation of a connection */ -#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE 1002 +#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE 1000 /** * Send origin an ACK that the connection is complete */ -#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK 1003 +#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK 1001 /** * Notify that a connection is no longer valid */ -#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN 1004 +#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN 1002 + +/** + * Request the destuction of a connection + */ +#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY 1003 /** * At some point, the route will spontaneously change TODO */ -#define GNUNET_MESSAGE_TYPE_CADET_PATH_CHANGED 1005 +#define GNUNET_MESSAGE_TYPE_CADET_PATH_CHANGED 1004 /** - * Payload data (usually inside a encrypted tunnel). + * Hop-by-hop, connection dependent ACK. */ -#define GNUNET_MESSAGE_TYPE_CADET_DATA 1006 +#define GNUNET_MESSAGE_TYPE_CADET_ACK 1005 /** - * Confirm payload data end-to-end. + * Poll for a hop-by-hop ACK. */ -#define GNUNET_MESSAGE_TYPE_CADET_DATA_ACK 1007 +#define GNUNET_MESSAGE_TYPE_CADET_POLL 1006 /** * Key exchange encapsulation. */ -#define GNUNET_MESSAGE_TYPE_CADET_KX 1008 +#define GNUNET_MESSAGE_TYPE_CADET_KX 1007 /** - * Request the destuction of a connection + * Axolotl encrypted data. */ -#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY 1009 +#define GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED 1008 + +/********************************** Channel *********************************/ /** - * Hop-by-hop, connection dependent ACK. + * Payload data (inside an encrypted tunnel). */ -#define GNUNET_MESSAGE_TYPE_CADET_ACK 1010 +#define GNUNET_MESSAGE_TYPE_CADET_DATA 1010 /** - * Poll for a hop-by-hop ACK. + * Confirm payload data end-to-end. */ -#define GNUNET_MESSAGE_TYPE_CADET_POLL 1011 +#define GNUNET_MESSAGE_TYPE_CADET_DATA_ACK 1011 /** * Announce connection is still alive (direction sensitive). */ #define GNUNET_MESSAGE_TYPE_CADET_KEEPALIVE 1012 - /** * Ask the cadet service to create a new channel. */ @@ -2701,86 +2706,89 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_NACK 1016 -/** - * Axolotl key exchange. - */ -#define GNUNET_MESSAGE_TYPE_CADET_AX_KX 1017 - -/** - * Axolotl encrypted data. - */ -#define GNUNET_MESSAGE_TYPE_CADET_AX 1018 +/*********************************** Local **********************************/ /** * Payload client <-> service */ -#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA 1019 +#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA 1020 /** * Local ACK for data. */ -#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK 1020 +#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK 1021 /** * Start listening on a port. */ -#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN 1021 +#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN 1022 /** * Stop listening on a port. */ -#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE 1022 +#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE 1023 + +/********************************** Monitor *********************************/ + /** * Local information about all channels of service. */ -#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNELS 1023 +#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNELS 1030 /** * Local information of service about a specific channel. */ -#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL 1024 +#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL 1031 /** * Local information about all tunnels of service. */ -#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS 1025 +#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS 1032 /** * Local information of service about a specific tunnel. */ -#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL 1026 +#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL 1033 /** * Local information about all connections of service. */ -#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CONNECTIONS 1027 +#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CONNECTIONS 1034 /** * Local information of service about a specific connection. */ -#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CONNECTION 1028 +#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CONNECTION 1035 /** * Local information about all peers known to the service. */ -#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS 1029 +#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS 1036 /** * Local information of service about a specific peer. */ -#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER 1030 +#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER 1037 /** - * Traffic (net-cat style) used by the Command Line Interface. + * Debug request. */ -#define GNUNET_MESSAGE_TYPE_CADET_CLI 1031 +#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_DUMP 1038 + +/******************************** Application *******************************/ /** - * Debug request. + * Traffic (net-cat style) used by the Command Line Interface. */ -#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_DUMP 1032 +#define GNUNET_MESSAGE_TYPE_CADET_CLI 1040 + +/******************************************************************************/ + +/******************************************************************************/ +/************************************* NAT **********************************/ +/******************************************************************************/ /** * Message to ask NAT service to register a client. -- 2.25.1