2 This file is part of GNUnet.
3 Copyright (C) 2007 - 2017 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file cadet/cadet_protocol.h
23 * @brief P2P messages used by CADET
24 * @author Bartlomiej Polot
25 * @author Christian Grothoff
28 #ifndef CADET_PROTOCOL_H_
29 #define CADET_PROTOCOL_H_
32 * At best, enable when debugging #5328!
36 #warning NEVER run this in production! KX debugging is on!
40 #include "gnunet_util_lib.h"
45 struct GNUNET_CADET_TunnelMessage;
49 /* keep Emacsens' auto-indent happy */
54 /******************************************************************************/
55 /******************** CADET NETWORK MESSAGES **************************/
56 /******************************************************************************/
58 GNUNET_NETWORK_STRUCT_BEGIN
61 /******************************************************************************/
62 /***************************** CONNECTION **********************************/
63 /******************************************************************************/
67 * Message for cadet connection creation.
69 struct GNUNET_CADET_ConnectionCreateMessage
72 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE
74 * Size: sizeof (struct GNUNET_CADET_ConnectionCreateMessage) +
75 * path_length * sizeof (struct GNUNET_PeerIdentity)
77 struct GNUNET_MessageHeader header;
80 * Connection options in network byte order.
81 * #GNUNET_CADET_OPTION_DEFAULT for buffered;
82 * #GNUNET_CADET_OPTION_NOBUFFER for unbuffered.
83 * Other flags are ignored and should not be set at this level.
85 uint32_t options GNUNET_PACKED;
88 * ID of the connection
90 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
93 * path_length structs defining the *whole* path from the origin [0] to the
94 * final destination [path_length-1].
96 /* struct GNUNET_PeerIdentity peers[path_length]; */
101 * Message for ack'ing a connection
103 struct GNUNET_CADET_ConnectionCreateAckMessage
106 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK
108 struct GNUNET_MessageHeader header;
113 uint32_t reserved GNUNET_PACKED;
116 * ID of the connection.
118 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
123 * Message for notifying a disconnection in a path
125 struct GNUNET_CADET_ConnectionBrokenMessage
128 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN.
130 struct GNUNET_MessageHeader header;
135 uint32_t reserved GNUNET_PACKED;
138 * ID of the connection.
140 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
145 struct GNUNET_PeerIdentity peer1;
150 struct GNUNET_PeerIdentity peer2;
155 * Message to destroy a connection.
157 struct GNUNET_CADET_ConnectionDestroyMessage
160 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
162 struct GNUNET_MessageHeader header;
167 uint32_t reserved GNUNET_PACKED;
170 * ID of the connection.
172 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
176 /******************************************************************************/
177 /******************************* TUNNEL ***********************************/
178 /******************************************************************************/
181 * Unique identifier (counter) for an encrypted message in a channel.
182 * Used to match #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_ENCRYPTED_ACK
183 * and #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED_POLL messages
184 * against the respective #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
187 struct CadetEncryptedMessageIdentifier
190 * This number is incremented by one per message. It may wrap around.
191 * In network byte order.
193 uint32_t pid GNUNET_PACKED;
198 * Flags to be used in GNUNET_CADET_KX.
200 enum GNUNET_CADET_KX_Flags
203 * Should the peer reply with its KX details?
205 GNUNET_CADET_KX_FLAG_NONE = 0,
208 * The peer should reply with its KX details?
210 GNUNET_CADET_KX_FLAG_FORCE_REPLY = 1
215 * Message for a Key eXchange for a tunnel.
217 struct GNUNET_CADET_TunnelKeyExchangeMessage
220 * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX or
221 * #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH as part
222 * of `struct GNUNET_CADET_TunnelKeyExchangeAuthMessage`.
224 struct GNUNET_MessageHeader header;
227 * Flags for the key exchange in NBO, based on
228 * `enum GNUNET_CADET_KX_Flags`.
230 uint32_t flags GNUNET_PACKED;
233 * ID of the connection.
235 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
238 * Sender's ephemeral public ECC key encoded in a
239 * format suitable for network transmission, as created
240 * using 'gcry_sexp_sprint'.
242 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
246 * Sender's ephemeral public ECC key encoded in a
247 * format suitable for network transmission, as created
248 * using 'gcry_sexp_sprint'.
250 struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral_key_XXX; // for debugging KX-crypto!
253 * Sender's ephemeral public ECC key encoded in a
254 * format suitable for network transmission, as created
255 * using 'gcry_sexp_sprint'.
257 struct GNUNET_CRYPTO_EddsaPrivateKey private_key_XXX; // for debugging KX-crypto!
261 * Sender's next ephemeral public ECC key encoded in a
262 * format suitable for network transmission, as created
263 * using 'gcry_sexp_sprint'.
265 struct GNUNET_CRYPTO_EcdhePublicKey ratchet_key;
270 * Message for a Key eXchange for a tunnel, with authentication.
271 * Used as a response to the initial KX as well as for rekeying.
273 struct GNUNET_CADET_TunnelKeyExchangeAuthMessage
276 * Message header with key material.
278 struct GNUNET_CADET_TunnelKeyExchangeMessage kx;
282 * Received ephemeral public ECC key encoded in a
283 * format suitable for network transmission, as created
284 * using 'gcry_sexp_sprint'.
286 struct GNUNET_CRYPTO_EcdhePublicKey r_ephemeral_key_XXX; // for debugging KX-crypto!
290 * KDF-proof that sender could compute the 3-DH, used in lieu of a
291 * signature or payload data.
293 struct GNUNET_HashCode auth;
298 * Encrypted axolotl header with numbers that identify which
299 * keys in which ratchet are to be used to decrypt the body.
301 struct GNUNET_CADET_AxHeader
304 * Number of messages sent with the current ratchet key.
306 uint32_t Ns GNUNET_PACKED;
309 * Number of messages sent with the previous ratchet key.
311 uint32_t PNs GNUNET_PACKED;
314 * Current ratchet key.
316 struct GNUNET_CRYPTO_EcdhePublicKey DHRs;
321 * Axolotl-encrypted tunnel message with application payload.
323 struct GNUNET_CADET_TunnelEncryptedMessage
326 * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
328 struct GNUNET_MessageHeader header;
331 * Reserved, for alignment.
333 uint32_t reserved GNUNET_PACKED;
336 * ID of the connection.
338 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
341 * MAC of the encrypted message, used to verify message integrity.
342 * Everything after this value will be encrypted with the header key
345 struct GNUNET_ShortHashCode hmac;
348 * Axolotl-header that specifies which keys to use in which ratchet
349 * to decrypt the body that follows.
351 struct GNUNET_CADET_AxHeader ax_header;
354 * Encrypted content follows.
359 /******************************************************************************/
360 /******************************* CHANNEL ***********************************/
361 /******************************************************************************/
365 * Message to create a Channel.
367 struct GNUNET_CADET_ChannelOpenMessage
370 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN
372 struct GNUNET_MessageHeader header;
377 uint32_t opt GNUNET_PACKED;
380 * Hash of destination port and listener.
382 struct GNUNET_HashCode h_port;
385 * ID of the channel within the tunnel.
387 struct GNUNET_CADET_ChannelTunnelNumber ctn;
392 * Message to acknowledge opening a channel of type
393 * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK.
395 struct GNUNET_CADET_ChannelOpenAckMessage
398 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK
400 struct GNUNET_MessageHeader header;
405 uint32_t reserved GNUNET_PACKED;
410 struct GNUNET_CADET_ChannelTunnelNumber ctn;
413 * Port number of the channel, used to prove to the
414 * initiator that the receiver knows the port.
416 struct GNUNET_HashCode port;
421 * Message to destroy a channel of type
422 * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY.
424 struct GNUNET_CADET_ChannelDestroyMessage
427 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY
429 struct GNUNET_MessageHeader header;
434 uint32_t reserved GNUNET_PACKED;
439 struct GNUNET_CADET_ChannelTunnelNumber ctn;
444 * Number used to uniquely identify messages in a CADET Channel.
446 struct ChannelMessageIdentifier
449 * Unique ID of the message, cycles around, in NBO.
451 uint32_t mid GNUNET_PACKED;
456 * Message for cadet data traffic.
458 struct GNUNET_CADET_ChannelAppDataMessage
461 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA.
463 struct GNUNET_MessageHeader header;
466 * Unique ID of the payload message.
468 struct ChannelMessageIdentifier mid;
473 struct GNUNET_CADET_ChannelTunnelNumber ctn;
482 * Message to acknowledge end-to-end data.
484 struct GNUNET_CADET_ChannelDataAckMessage
487 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK
489 struct GNUNET_MessageHeader header;
494 struct GNUNET_CADET_ChannelTunnelNumber ctn;
497 * Bitfield of already-received newer messages. Note that bit 0
498 * corresponds to @e mid + 1.
503 uint64_t futures GNUNET_PACKED;
506 * Next message ID expected.
508 struct ChannelMessageIdentifier mid;
512 GNUNET_NETWORK_STRUCT_END
514 #if 0 /* keep Emacsens' auto-indent happy */
521 /* ifndef CADET_PROTOCOL_H */
523 /* end of cadet_protocol.h */