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
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
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;
124 * Message for notifying a disconnection in a path
126 struct GNUNET_CADET_ConnectionBrokenMessage
129 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN.
131 struct GNUNET_MessageHeader header;
136 uint32_t reserved GNUNET_PACKED;
139 * ID of the connection.
141 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
146 struct GNUNET_PeerIdentity peer1;
151 struct GNUNET_PeerIdentity peer2;
156 * Message to destroy a connection.
158 struct GNUNET_CADET_ConnectionDestroyMessage
161 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
163 struct GNUNET_MessageHeader header;
168 uint32_t reserved GNUNET_PACKED;
171 * ID of the connection.
173 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
177 /******************************************************************************/
178 /******************************* TUNNEL ***********************************/
179 /******************************************************************************/
182 * Unique identifier (counter) for an encrypted message in a channel.
183 * Used to match #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_ENCRYPTED_ACK
184 * and #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED_POLL messages
185 * against the respective #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
188 struct CadetEncryptedMessageIdentifier
191 * This number is incremented by one per message. It may wrap around.
192 * In network byte order.
194 uint32_t pid GNUNET_PACKED;
199 * Flags to be used in GNUNET_CADET_KX.
201 enum GNUNET_CADET_KX_Flags {
204 * Should the peer reply with its KX details?
206 GNUNET_CADET_KX_FLAG_NONE = 0,
209 * The peer should reply with its KX details?
211 GNUNET_CADET_KX_FLAG_FORCE_REPLY = 1
216 * Message for a Key eXchange for a tunnel.
218 struct GNUNET_CADET_TunnelKeyExchangeMessage
221 * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX or
222 * #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH as part
223 * of `struct GNUNET_CADET_TunnelKeyExchangeAuthMessage`.
225 struct GNUNET_MessageHeader header;
228 * Flags for the key exchange in NBO, based on
229 * `enum GNUNET_CADET_KX_Flags`.
231 uint32_t flags GNUNET_PACKED;
234 * ID of the connection.
236 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
239 * Sender's ephemeral public ECC key encoded in a
240 * format suitable for network transmission, as created
241 * using 'gcry_sexp_sprint'.
243 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
247 * Sender's ephemeral public ECC key encoded in a
248 * format suitable for network transmission, as created
249 * using 'gcry_sexp_sprint'.
251 struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral_key_XXX; // for debugging KX-crypto!
254 * Sender's ephemeral public ECC key encoded in a
255 * format suitable for network transmission, as created
256 * using 'gcry_sexp_sprint'.
258 struct GNUNET_CRYPTO_EddsaPrivateKey private_key_XXX; // for debugging KX-crypto!
262 * Sender's next ephemeral public ECC key encoded in a
263 * format suitable for network transmission, as created
264 * using 'gcry_sexp_sprint'.
266 struct GNUNET_CRYPTO_EcdhePublicKey ratchet_key;
272 * Message for a Key eXchange for a tunnel, with authentication.
273 * Used as a response to the initial KX as well as for rekeying.
275 struct GNUNET_CADET_TunnelKeyExchangeAuthMessage
279 * Message header with key material.
281 struct GNUNET_CADET_TunnelKeyExchangeMessage kx;
285 * Received ephemeral public ECC key encoded in a
286 * format suitable for network transmission, as created
287 * using 'gcry_sexp_sprint'.
289 struct GNUNET_CRYPTO_EcdhePublicKey r_ephemeral_key_XXX; // for debugging KX-crypto!
293 * KDF-proof that sender could compute the 3-DH, used in lieu of a
294 * signature or payload data.
296 struct GNUNET_HashCode auth;
302 * Encrypted axolotl header with numbers that identify which
303 * keys in which ratchet are to be used to decrypt the body.
305 struct GNUNET_CADET_AxHeader
309 * Number of messages sent with the current ratchet key.
311 uint32_t Ns GNUNET_PACKED;
314 * Number of messages sent with the previous ratchet key.
316 uint32_t PNs GNUNET_PACKED;
319 * Current ratchet key.
321 struct GNUNET_CRYPTO_EcdhePublicKey DHRs;
327 * Axolotl-encrypted tunnel message with application payload.
329 struct GNUNET_CADET_TunnelEncryptedMessage
332 * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
334 struct GNUNET_MessageHeader header;
337 * Reserved, for alignment.
339 uint32_t reserved GNUNET_PACKED;
342 * ID of the connection.
344 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
347 * MAC of the encrypted message, used to verify message integrity.
348 * Everything after this value will be encrypted with the header key
351 struct GNUNET_ShortHashCode hmac;
354 * Axolotl-header that specifies which keys to use in which ratchet
355 * to decrypt the body that follows.
357 struct GNUNET_CADET_AxHeader ax_header;
360 * Encrypted content follows.
365 /******************************************************************************/
366 /******************************* CHANNEL ***********************************/
367 /******************************************************************************/
371 * Message to create a Channel.
373 struct GNUNET_CADET_ChannelOpenMessage
376 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN
378 struct GNUNET_MessageHeader header;
383 uint32_t opt GNUNET_PACKED;
386 * Hash of destination port and listener.
388 struct GNUNET_HashCode h_port;
391 * ID of the channel within the tunnel.
393 struct GNUNET_CADET_ChannelTunnelNumber ctn;
398 * Message to acknowledge opening a channel of type
399 * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK.
401 struct GNUNET_CADET_ChannelOpenAckMessage
404 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK
406 struct GNUNET_MessageHeader header;
411 uint32_t reserved GNUNET_PACKED;
416 struct GNUNET_CADET_ChannelTunnelNumber ctn;
419 * Port number of the channel, used to prove to the
420 * initiator that the receiver knows the port.
422 struct GNUNET_HashCode port;
427 * Message to destroy a channel of type
428 * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY.
430 struct GNUNET_CADET_ChannelDestroyMessage
433 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY
435 struct GNUNET_MessageHeader header;
440 uint32_t reserved GNUNET_PACKED;
445 struct GNUNET_CADET_ChannelTunnelNumber ctn;
450 * Number used to uniquely identify messages in a CADET Channel.
452 struct ChannelMessageIdentifier
455 * Unique ID of the message, cycles around, in NBO.
457 uint32_t mid GNUNET_PACKED;
462 * Message for cadet data traffic.
464 struct GNUNET_CADET_ChannelAppDataMessage
467 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA.
469 struct GNUNET_MessageHeader header;
472 * Unique ID of the payload message.
474 struct ChannelMessageIdentifier mid;
479 struct GNUNET_CADET_ChannelTunnelNumber ctn;
488 * Message to acknowledge end-to-end data.
490 struct GNUNET_CADET_ChannelDataAckMessage
493 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK
495 struct GNUNET_MessageHeader header;
500 struct GNUNET_CADET_ChannelTunnelNumber ctn;
503 * Bitfield of already-received newer messages. Note that bit 0
504 * corresponds to @e mid + 1.
509 uint64_t futures GNUNET_PACKED;
512 * Next message ID expected.
514 struct ChannelMessageIdentifier mid;
518 GNUNET_NETWORK_STRUCT_END
520 #if 0 /* keep Emacsens' auto-indent happy */
527 /* ifndef CADET_PROTOCOL_H */
529 /* end of cadet_protocol.h */